#include <metal_stdlib>

using namespace metal;
struct tint_private_vars_struct {
  uint4 tint_subgroup_size_mask;
};


uint4 tint_msl_subgroup_ballot(thread tint_private_vars_struct* const tint_private_vars) {
  uint4 const tint_symbol = uint4(as_type<uint2>((ulong)simd_active_threads_mask()), 0u, 0u);
  return (tint_symbol & (*(tint_private_vars)).tint_subgroup_size_mask);
}

void subgroupBallot_7e6d0e(thread tint_private_vars_struct* const tint_private_vars, device uint4* const tint_symbol_1) {
  uint4 res = tint_msl_subgroup_ballot(tint_private_vars);
  *(tint_symbol_1) = res;
}

kernel void compute_main(device uint4* tint_symbol_2 [[buffer(0)]], uint tint_subgroup_size [[threads_per_simdgroup]]) {
  thread tint_private_vars_struct tint_private_vars = {};
  {
    bool const gt = (tint_subgroup_size > 32u);
    tint_private_vars.tint_subgroup_size_mask[0u] = select((1u << (tint_subgroup_size - 1u)), 4294967295u, gt);
    tint_private_vars.tint_subgroup_size_mask[1u] = select(0u, (1u << (tint_subgroup_size - 33u)), gt);
  }
  subgroupBallot_7e6d0e(&(tint_private_vars), tint_symbol_2);
  return;
}

