#include <metal_stdlib>

using namespace metal;
struct tint_private_vars_struct {
  uint tint_msl_thread_index_in_quadgroup;
};


uint3 tint_msl_quadSwapY(uint3 e, thread tint_private_vars_struct* const tint_private_vars) {
  return quad_shuffle(e,((*(tint_private_vars)).tint_msl_thread_index_in_quadgroup ^ 2u));
}

uint3 quadSwapY_06a67c(thread tint_private_vars_struct* const tint_private_vars) {
  uint3 arg_0 = uint3(1u);
  uint3 res = tint_msl_quadSwapY(arg_0, tint_private_vars);
  return res;
}

fragment void fragment_main(device packed_uint3* tint_symbol [[buffer(0)]], uint tint_thread_index_in_quadgroup [[thread_index_in_quadgroup]]) {
  thread tint_private_vars_struct tint_private_vars = {};
  {
    tint_private_vars.tint_msl_thread_index_in_quadgroup = tint_thread_index_in_quadgroup;
  }
  *(tint_symbol) = packed_uint3(quadSwapY_06a67c(&(tint_private_vars)));
  return;
}

kernel void compute_main(device packed_uint3* tint_symbol_1 [[buffer(0)]], uint tint_thread_index_in_quadgroup_1 [[thread_index_in_quadgroup]]) {
  thread tint_private_vars_struct tint_private_vars = {};
  {
    tint_private_vars.tint_msl_thread_index_in_quadgroup = tint_thread_index_in_quadgroup_1;
  }
  *(tint_symbol_1) = packed_uint3(quadSwapY_06a67c(&(tint_private_vars)));
  return;
}

