#include <metal_stdlib>

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


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

float4 quadSwapY_b9d9e7(thread tint_private_vars_struct* const tint_private_vars) {
  float4 res = tint_msl_quadSwapY(float4(1.0f), tint_private_vars);
  return res;
}

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

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

