#include <metal_stdlib>

using namespace metal;
struct tint_private_vars_struct {
  int a;
  float b;
};

int tint_div(int lhs, int rhs) {
  return (lhs / select(rhs, 1, bool((rhs == 0) | bool((lhs == (-2147483647 - 1)) & (rhs == -1)))));
}

int tint_mod(int lhs, int rhs) {
  int const rhs_or_one = select(rhs, 1, bool((rhs == 0) | bool((lhs == (-2147483647 - 1)) & (rhs == -1))));
  if (any(((uint((lhs | rhs_or_one)) & 2147483648u) != 0u))) {
    return as_type<int>((as_type<uint>(lhs) - as_type<uint>(as_type<int>((as_type<uint>((lhs / rhs_or_one)) * as_type<uint>(rhs_or_one))))));
  } else {
    return (lhs % rhs_or_one);
  }
}

void foo(int maybe_zero, thread tint_private_vars_struct* const tint_private_vars) {
  (*(tint_private_vars)).a = tint_div((*(tint_private_vars)).a, maybe_zero);
  (*(tint_private_vars)).a = tint_mod((*(tint_private_vars)).a, maybe_zero);
  (*(tint_private_vars)).b = ((*(tint_private_vars)).b / 0.0f);
  (*(tint_private_vars)).b = fmod((*(tint_private_vars)).b, 0.0f);
  (*(tint_private_vars)).b = ((*(tint_private_vars)).b / float(maybe_zero));
  (*(tint_private_vars)).b = fmod((*(tint_private_vars)).b, float(maybe_zero));
}

