#include <metal_stdlib>

using namespace metal;
void tint_zero_workgroup_memory(uint local_idx, threadgroup atomic_int* const tint_symbol) {
  if ((local_idx < 1u)) {
    atomic_store_explicit(tint_symbol, 0, memory_order_relaxed);
  }
  threadgroup_barrier(mem_flags::mem_threadgroup);
}

void atomicXor_75dc95(threadgroup atomic_int* const tint_symbol_1, device int* const tint_symbol_2) {
  int arg_1 = 1;
  int res = atomic_fetch_xor_explicit(tint_symbol_1, arg_1, memory_order_relaxed);
  *(tint_symbol_2) = res;
}

void compute_main_inner(uint local_invocation_index, threadgroup atomic_int* const tint_symbol_3, device int* const tint_symbol_4) {
  tint_zero_workgroup_memory(local_invocation_index, tint_symbol_3);
  atomicXor_75dc95(tint_symbol_3, tint_symbol_4);
}

kernel void compute_main(device int* tint_symbol_6 [[buffer(0)]], uint local_invocation_index [[thread_index_in_threadgroup]]) {
  threadgroup atomic_int tint_symbol_5;
  compute_main_inner(local_invocation_index, &(tint_symbol_5), tint_symbol_6);
  return;
}

