#include <metal_stdlib>

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


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

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

fragment void fragment_main(device uint* 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) = quadSwapY_0c4938(&(tint_private_vars));
  return;
}

kernel void compute_main(device uint* 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) = quadSwapY_0c4938(&(tint_private_vars));
  return;
}

