target/scratch3.c
static struct scr3_block *scr3_impl_switch_helper(scr3_reg_t reg, int lval,
                                                  int hval,
                                                  struct scr3_block *cases[],
                                                  int cases_size) {
  if (hval - lval <= 1) {
    return lval < cases_size ? cases[lval] : NULL;
  } else {
    int mval = (lval + hval) / 2;
    struct scr3_block *case1, *case2;
    case1 = scr3_impl_switch_helper(reg, lval, mval, cases, cases_size);
    case2 = scr3_impl_switch_helper(reg, mval, hval, cases, cases_size);
    if (!case1 && !case2) return NULL;

    struct scr3_block *if_else = scr3_build_if_else(
        NULL,
        scr3_build_lt(scr3_src_reg(reg), scr3_src_imm(format("%d", mval))),
        case1, case2);
    if (case1) case1->prev = if_else;
    if (case2) case2->prev = if_else;
    return if_else;
  }
}
// generate binary search [lval, hval)
generate binary search [lval, hval)
generate binary search [ lval hval )
static struct scr3_block *scr3_impl_switch_helper(scr3_reg_t reg, int lval,
                                                  int hval,
                                                  struct scr3_block *cases[],
                                                  int cases_size) {
  if (hval - lval <= 1) {
    return lval < cases_size ? cases[lval] : NULL;
  } else {
    int mval = (lval + hval) / 2;
    struct scr3_block *case1, *case2;
    case1 = scr3_impl_switch_helper(reg, lval, mval, cases, cases_size);
    case2 = scr3_impl_switch_helper(reg, mval, hval, cases, cases_size);
    if (!case1 && !case2) return NULL;
    struct scr3_block *if_else = scr3_build_if_else(
        NULL,
        scr3_build_lt(scr3_src_reg(reg), scr3_src_imm(format("%d", mval))),
        case1, case2);
    if (case1) case1->prev = if_else;
    if (case2) case2->prev = if_else;
    return if_else;
  }
}
static struct scr3_block * scr3_impl_switch_helper ( scr3_reg_t reg , int lval , int hval , struct scr3_block * cases [ ] , int cases_size ) { if ( hval - lval <= 1 ) { return lval < cases_size ? cases [ lval ] : NULL ; } else { int mval = ( lval + hval ) / 2 ; struct scr3_block * case1 , * case2 ; case1 = scr3_impl_switch_helper ( reg , lval , mval , cases , cases_size ) ; case2 = scr3_impl_switch_helper ( reg , mval , hval , cases , cases_size ) ; if ( ! case1 && ! case2 ) return NULL ; struct scr3_block * if_else = scr3_build_if_else ( NULL , scr3_build_lt ( scr3_src_reg ( reg ) , scr3_src_imm ( format ( " " , mval ) ) ) , case1 , case2 ) ; if ( case1 ) case1 -> prev = if_else ; if ( case2 ) case2 -> prev = if_else ; return if_else ; } }
generate binary search [lval, hval)
generate binary search [ lval hval )