#include <metal_stdlib>
using namespace metal;

#define TINT_ISOLATE_UB(VOLATILE_NAME) \
  volatile bool VOLATILE_NAME = true; \
  if (VOLATILE_NAME)

kernel void tint_symbol() {
  {
    int i = 0;
    TINT_ISOLATE_UB(tint_volatile_true) while(true) {
      if ((i < 2)) {
      } else {
        break;
      }
      bool tint_continue = false;
      switch(i) {
        case 0:
        {
          {
            int j = 0;
            TINT_ISOLATE_UB(tint_volatile_true_1) while(true) {
              if ((j < 2)) {
              } else {
                break;
              }
              bool tint_continue = false;
              switch(j) {
                case 0:
                {
                  tint_continue = true;
                  break;
                }
                default:
                {
                  break;
                }
              }
              if (tint_continue) {
                {
                  j = as_type<int>((as_type<uint>(j) + as_type<uint>(2)));
                }
                continue;
              }
              {
                j = as_type<int>((as_type<uint>(j) + as_type<uint>(2)));
              }
              continue;
            }
          }
          tint_continue = true;
          break;
        }
        default:
        {
          break;
        }
      }
      if (tint_continue) {
        {
          i = as_type<int>((as_type<uint>(i) + as_type<uint>(2)));
        }
        continue;
      }
      {
        i = as_type<int>((as_type<uint>(i) + as_type<uint>(2)));
      }
      continue;
    }
  }
}
