// File: lukewagner[P]asmjs2wasm/src/cashew/parser.h
// Function: cashew::Parser<asmjs_ast::Node*, Builder>::parseSwitch(cashew::Parser<asmjs_ast::Node*, Builder>::Frag&, char*&, char const*)
NodeRef parseSwitch(Frag& frag, char*& src, const char* seps) {
    NodeRef ret = builder.makeSwitch(parseParenned(src));
    src = skipSpace(src);
    assert(*src == '{');
    src++;
    while (1) {
      // find all cases and possibly a default
      src = skipSpace(src);
      if (*src == '}') break;
      Frag next(src);
      if (next.type == KEYWORD) {
        if (next.str == CASE) {
          src += next.size;
          src = skipSpace(src);
          NodeRef arg;
          Frag value(src);
          if (value.isNumber()) {
            arg = parseFrag(value);
            src += value.size;
          } else {
            assert(value.type == OPERATOR);
            assert(value.str == MINUS);
            src += value.size;
            src = skipSpace(src);
            Frag value2(src);
            assert(value2.isNumber());
            arg = builder.makePrefix(MINUS, parseFrag(value2));
            src += value2.size;
          }
          builder.appendCaseToSwitch(ret, arg);
          src = skipSpace(src);
          assert(*src == ':');
          src++;
          continue;
        } else if (next.str == DEFAULT) {
          src += next.size;
          builder.appendDefaultToSwitch(ret);
          src = skipSpace(src);
          assert(*src == ':');
          src++;
          continue;
        }
        // otherwise, may be some keyword that happens to start a block (e.g. case 1: _return_ 5)
      }
      // not case X: or default: or }, so must be some code
      src = skipSpace(src);
      bool explicitBlock = *src == '{';
      builder.appendCodeToSwitch(ret, parseMaybeBracketedBlock(src, ";}", CASE, DEFAULT), explicitBlock);
    }
    src = skipSpace(src);
    assert(*src == '}');
    src++;
    return ret;
  }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x90(%rbp)
movq %rdi, %rax
addq $0x28, %rax
movq %rax, -0x88(%rbp)
movq -0x18(%rbp), %rsi
callq 0xc8f0
movq -0x88(%rbp), %rdi
movq %rax, %rsi
callq 0xcd40
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x5d30
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movsbl (%rax), %eax
cmpl $0x7b, %eax
jne 0xbe77
jmp 0xbe96
leaq 0x976e(%rip), %rdi      # 0x155ec
leaq 0x9482(%rip), %rsi      # 0x15307
movl $0x1d2, %edx            # imm = 0x1D2
leaq 0x9ab4(%rip), %rcx      # 0x15945
callq 0x2130
movq -0x18(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x5d30
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movsbl (%rax), %eax
cmpl $0x7d, %eax
jne 0xbece
jmp 0xc242
movq -0x18(%rbp), %rax
movq (%rax), %rsi
leaq -0x38(%rbp), %rdi
callq 0x5f00
cmpl $0x0, -0x2c(%rbp)
jne 0xc1a0
leaq -0x38(%rbp), %rdi
leaq 0x1652d(%rip), %rsi     # 0x22420
callq 0x6680
testb $0x1, %al
jne 0xbf01
jmp 0xc103
movl -0x30(%rbp), %edx
movq -0x18(%rbp), %rax
movq (%rax), %rcx
movslq %edx, %rdx
addq %rdx, %rcx
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x5d30
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rsi
leaq -0x50(%rbp), %rdi
callq 0x5f00
leaq -0x50(%rbp), %rdi
callq 0xcd80
testb $0x1, %al
jne 0xbf49
jmp 0xbf75
movq -0x90(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0xaf00
movq %rax, -0x40(%rbp)
movl -0x48(%rbp), %edx
movq -0x18(%rbp), %rax
movq (%rax), %rcx
movslq %edx, %rdx
addq %rdx, %rcx
movq %rcx, (%rax)
jmp 0xc092
cmpl $0x1, -0x44(%rbp)
jne 0xbf7d
jmp 0xbf9c
leaq 0x9a51(%rip), %rdi      # 0x159d5
leaq 0x937c(%rip), %rsi      # 0x15307
movl $0x1e3, %edx            # imm = 0x1E3
leaq 0x99ae(%rip), %rcx      # 0x15945
callq 0x2130
leaq -0x50(%rbp), %rdi
leaq 0x16351(%rip), %rsi     # 0x222f8
callq 0x6680
testb $0x1, %al
jne 0xbfb2
jmp 0xbfb4
jmp 0xbfd3
leaq 0x9a31(%rip), %rdi      # 0x159ec
leaq 0x9345(%rip), %rsi      # 0x15307
movl $0x1e4, %edx            # imm = 0x1E4
leaq 0x9977(%rip), %rcx      # 0x15945
callq 0x2130
movl -0x48(%rbp), %edx
movq -0x18(%rbp), %rax
movq (%rax), %rcx
movslq %edx, %rdx
addq %rdx, %rcx
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x5d30
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rsi
leaq -0x60(%rbp), %rdi
callq 0x5f00
leaq -0x60(%rbp), %rdi
callq 0xcd80
testb $0x1, %al
jne 0xc01b
jmp 0xc01d
jmp 0xc03c
leaq 0x99db(%rip), %rdi      # 0x159ff
leaq 0x92dc(%rip), %rsi      # 0x15307
movl $0x1e8, %edx            # imm = 0x1E8
leaq 0x990e(%rip), %rcx      # 0x15945
callq 0x2130
movq -0x90(%rbp), %rdi
movq %rdi, %rax
addq $0x28, %rax
movq %rax, -0x98(%rbp)
leaq 0x162a0(%rip), %rax     # 0x222f8
movq (%rax), %rax
movq %rax, -0x68(%rbp)
leaq -0x60(%rbp), %rsi
callq 0xaf00
movq -0x98(%rbp), %rdi
movq %rax, %rdx
movq -0x68(%rbp), %rsi
callq 0xcdb0
movq %rax, -0x40(%rbp)
movl -0x58(%rbp), %edx
movq -0x18(%rbp), %rax
movq (%rax), %rcx
movslq %edx, %rdx
addq %rdx, %rcx
movq %rcx, (%rax)
movq -0x90(%rbp), %rdi
addq $0x28, %rdi
movq -0x28(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0xce00
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x5d30
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movsbl (%rax), %eax
cmpl $0x3a, %eax
jne 0xc0d1
jmp 0xc0f0
leaq 0x9939(%rip), %rdi      # 0x15a11
leaq 0x9228(%rip), %rsi      # 0x15307
movl $0x1ee, %edx            # imm = 0x1EE
leaq 0x985a(%rip), %rcx      # 0x15945
callq 0x2130
movq -0x18(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
jmp 0xbea4
leaq -0x38(%rbp), %rdi
leaq 0x1631a(%rip), %rsi     # 0x22428
callq 0x6680
testb $0x1, %al
jne 0xc11c
jmp 0xc19c
movq -0x90(%rbp), %rdi
movl -0x30(%rbp), %edx
movq -0x18(%rbp), %rax
movq (%rax), %rcx
movslq %edx, %rdx
addq %rdx, %rcx
movq %rcx, (%rax)
addq $0x28, %rdi
movq -0x28(%rbp), %rsi
callq 0xce70
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x5d30
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movsbl (%rax), %eax
cmpl $0x3a, %eax
jne 0xc16a
jmp 0xc189
leaq 0x98a0(%rip), %rdi      # 0x15a11
leaq 0x918f(%rip), %rsi      # 0x15307
movl $0x1f5, %edx            # imm = 0x1F5
leaq 0x97c1(%rip), %rcx      # 0x15945
callq 0x2130
movq -0x18(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
jmp 0xbea4
jmp 0xc19e
jmp 0xc1a0
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x5d30
movq -0x90(%rbp), %rdi
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movsbl (%rax), %eax
cmpl $0x7b, %eax
sete %al
andb $0x1, %al
movb %al, -0x69(%rbp)
movq %rdi, %rax
addq $0x28, %rax
movq %rax, -0xa8(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x18(%rbp), %rsi
leaq 0x1622a(%rip), %rax     # 0x22420
movq (%rax), %rax
movq %rax, -0x78(%rbp)
leaq 0x16224(%rip), %rax     # 0x22428
movq (%rax), %rax
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rcx
movq -0x80(%rbp), %r8
leaq 0x9469(%rip), %rdx      # 0x15683
callq 0xcf20
movq -0xa8(%rbp), %rdi
movq -0xa0(%rbp), %rsi
movq %rax, %rdx
movb -0x69(%rbp), %al
andb $0x1, %al
movzbl %al, %ecx
callq 0xced0
jmp 0xbea4
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x5d30
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movsbl (%rax), %eax
cmpl $0x7d, %eax
jne 0xc269
jmp 0xc288
leaq 0x9416(%rip), %rdi      # 0x15686
leaq 0x9090(%rip), %rsi      # 0x15307
movl $0x201, %edx            # imm = 0x201
leaq 0x96c2(%rip), %rcx      # 0x15945
callq 0x2130
movq -0x18(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)