#include <metal_stdlib>

using namespace metal;
int tint_insert_bits(int v, int n, uint offset, uint count) {
  uint const s = min(offset, 32u);
  uint const e = min(32u, (s + count));
  return insert_bits(v, n, s, (e - s));
}

int insertBits_65468b() {
  int arg_0 = 1;
  int arg_1 = 1;
  uint arg_2 = 1u;
  uint arg_3 = 1u;
  int res = tint_insert_bits(arg_0, arg_1, arg_2, arg_3);
  return res;
}

fragment void fragment_main(device int* tint_symbol_1 [[buffer(0)]]) {
  *(tint_symbol_1) = insertBits_65468b();
  return;
}

kernel void compute_main(device int* tint_symbol_2 [[buffer(0)]]) {
  *(tint_symbol_2) = insertBits_65468b();
  return;
}

struct VertexOutput {
  float4 pos;
  int prevent_dce;
};

struct tint_symbol {
  int prevent_dce [[user(locn0)]] [[flat]];
  float4 pos [[position]];
};

VertexOutput vertex_main_inner() {
  VertexOutput out = {};
  out.pos = float4(0.0f);
  out.prevent_dce = insertBits_65468b();
  return out;
}

vertex tint_symbol vertex_main() {
  VertexOutput const inner_result = vertex_main_inner();
  tint_symbol wrapper_result = {};
  wrapper_result.pos = inner_result.pos;
  wrapper_result.prevent_dce = inner_result.prevent_dce;
  return wrapper_result;
}

