// File: /workspace/github_cpp_makefile_star2_O2/lukewagner[P]asmjs2wasm/src/cashew/parser.h
// Function: cashew::Parser<asmjs_ast::Node*, Builder>::parseExpression(cashew::Parser<asmjs_ast::Node*, Builder>::ExpressionElement, char*&, char const*)
NodeRef parseExpression(ExpressionElement initial, char*&src, const char* seps) {
    //dump("parseExpression", src);
    ExpressionParts& parts = expressionPartsStack.back();
    src = skipSpace(src);
    if (*src == 0 || hasChar(seps, *src)) {
      if (parts.size() > 0) {
        parts.push_back(initial); // cherry on top of the cake
      }
      return initial.getNode();
    }
    bool top = parts.size() == 0;
    if (initial.isNode) {
      Frag next(src);
      if (next.type == OPERATOR) {
        parts.push_back(initial);
        src += next.size;
        parts.push_back(next.str);
      } else {
        if (*src == '(') {
          initial = parseCall(initial.getNode(), src);
        } else if (*src == '[') {
          initial = parseIndexing(initial.getNode(), src);
        } else {
          dump("bad parseExpression state", src);
          assert(0);
        }
        return parseExpression(initial, src, seps);
      }
    } else {
      parts.push_back(initial);
    }
    NodeRef last = parseElement(src, seps);
    if (!top) return last;
    {
      ExpressionParts& parts = expressionPartsStack.back(); // |parts| may have been invalidated by that call
      // we are the toplevel. sort it all out
      // collapse right to left, highest priority first
      //dumpParts(parts, 0);
      for (auto& ops : operatorClasses) {
        if (ops.rtl) {
          // right to left
          for (int i = parts.size()-1; i >= 0; i--) {
            if (parts[i].isNode) continue;
            IString op = parts[i].getOp();
            if (!ops.ops.has(op)) continue;
            if (ops.type == OperatorClass::Binary && i > 0 && i < (int)parts.size()-1) {
              parts[i] = makeBinary(parts[i-1].getNode(), op, parts[i+1].getNode());
              parts.erase(parts.begin() + i + 1);
              parts.erase(parts.begin() + i - 1);
            } else if (ops.type == OperatorClass::Prefix && i < (int)parts.size()-1) {
              if (i > 0 && parts[i-1].isNode) continue; // cannot apply prefix operator if it would join two nodes
              parts[i] = builder.makePrefix(op, parts[i+1].getNode());
              parts.erase(parts.begin() + i + 1);
            } else if (ops.type == OperatorClass::Tertiary) {
              // we must be at  X ? Y : Z
              //                      ^
              //dumpParts(parts, i);
              if (op != COLON) continue;
              assert(i < (int)parts.size()-1 && i >= 3);
              if (parts[i-2].getOp() != QUESTION) continue; // e.g. x ? y ? 1 : 0 : 2
              parts[i-3] = builder.makeConditional(parts[i-3].getNode(), parts[i-1].getNode(), parts[i+1].getNode());
              parts.erase(parts.begin() + i - 2, parts.begin() + i + 2);
              i = parts.size(); // basically a reset, due to things like x ? y ? 1 : 0 : 2
            } // TODO: postfix
          }
        } else {
          // left to right
          for (int i = 0; i < (int)parts.size(); i++) {
            if (parts[i].isNode) continue;
            IString op = parts[i].getOp();
            if (!ops.ops.has(op)) continue;
            if (ops.type == OperatorClass::Binary && i > 0 && i < (int)parts.size()-1) {
              parts[i] = makeBinary(parts[i-1].getNode(), op, parts[i+1].getNode());
              parts.erase(parts.begin() + i + 1);
              parts.erase(parts.begin() + i - 1);
              i--;
            } else if (ops.type == OperatorClass::Prefix && i < (int)parts.size()-1) {
              if (i > 0 && parts[i-1].isNode) continue; // cannot apply prefix operator if it would join two nodes
              parts[i] = builder.makePrefix(op, parts[i+1].getNode());
              parts.erase(parts.begin() + i + 1);
              i = std::max(i-2, 0); // allow a previous prefix operator to cascade
            } // TODO: tertiary, postfix
          }
        }
      }
      assert(parts.size() == 1);
      NodeRef ret = parts[0].getNode();
      parts.clear();
      return ret;
    }
  }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r8, %r14
movq %rcx, %r15
movl %esi, %ebp
movq %rdi, %r13
movb %bpl, 0x20(%rsp)
movq %rdx, 0x28(%rsp)
movq 0x8(%rdi), %rbx
leaq -0x18(%rbx), %r12
movq (%rcx), %rdi
callq 0x3546
movq %rax, (%r15)
movb (%rax), %al
testb %al, %al
je 0x496b
movsbl %al, %esi
movq %r14, %rdi
callq 0x35b8
testb %al, %al
je 0x499b
movq -0x10(%rbx), %rax
cmpq -0x18(%rbx), %rax
je 0x4982
leaq 0x20(%rsp), %rsi
movq %r12, %rdi
callq 0x655c
leaq 0x20(%rsp), %rdi
callq 0x657a
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x18(%rbx), %rax
movq %rax, 0x8(%rsp)
movq -0x10(%rbx), %rbx
testb $0x1, %bpl
je 0x49ff
movq %r13, %rbp
movq (%r15), %rsi
leaq 0x10(%rsp), %r13
movq %r13, %rdi
callq 0x35cc
cmpl $0x1, 0xc(%r13)
jne 0x4e6b
leaq 0x20(%rsp), %rsi
movq %r12, %rdi
callq 0x655c
movslq 0x18(%rsp), %rax
addq %rax, (%r15)
movq 0x10(%rsp), %rax
leaq 0x48(%rsp), %rsi
movb $0x0, (%rsi)
movq %rax, 0x8(%rsi)
movq %r12, %rdi
callq 0x67a8
movq %rbp, %r13
jmp 0x4a0c
leaq 0x20(%rsp), %rsi
movq %r12, %rdi
callq 0x655c
movq %r13, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x4474
cmpq 0x8(%rsp), %rbx
jne 0x498c
movq %r13, %rcx
movq 0x8(%r13), %r13
leaq -0x18(%r13), %r14
leaq 0x9a39(%rip), %rax      # 0xe470
movq (%rax), %rdx
movq 0x8(%rax), %rax
movq %rax, 0x40(%rsp)
movq %rcx, 0x38(%rsp)
leaq 0x28(%rcx), %rax
movq %rax, 0x30(%rsp)
cmpq 0x40(%rsp), %rdx
je 0x4e3a
movq %rdx, 0x8(%rsp)
cmpb $0x0, 0x38(%rdx)
je 0x4cac
movq -0x10(%r13), %r12
subq -0x18(%r13), %r12
shrq $0x4, %r12
movl %r12d, %ebx
decl %r12d
js 0x4e2c
movl %r12d, %r15d
movq (%r14), %rdi
shlq $0x4, %r15
cmpb $0x0, (%rdi,%r15)
jne 0x4a77
addq %r15, %rdi
callq 0x65a4
movq %rax, 0x10(%rsp)
movq 0x8(%rsp), %rbp
movq %rbp, %rdi
leaq 0x10(%rsp), %rsi
callq 0x3e72
testb %al, %al
je 0x4a77
movl 0x3c(%rbp), %eax
testl %eax, %eax
setne %cl
testl %r12d, %r12d
sete %dl
orb %cl, %dl
movl %ebx, %ebp
jne 0x4b56
movq -0x18(%r13), %rax
movq -0x10(%r13), %rcx
subq %rax, %rcx
shrq $0x4, %rcx
decl %ecx
cmpl %ecx, %r12d
jge 0x4a77
shlq $0x4, %rbp
leaq (%rax,%rbp), %rdi
addq $-0x20, %rdi
callq 0x657a
movq %rax, (%rsp)
movq 0x10(%rsp), %rbx
addq (%r14), %rbp
movq %rbp, %rdi
callq 0x657a
movq 0x38(%rsp), %rdi
movq (%rsp), %rsi
movq %rbx, %rdx
movq %rax, %rcx
callq 0x65ce
movq (%r14), %rcx
movb $0x1, (%rcx,%r15)
movq %rax, 0x8(%rcx,%r15)
movq (%r14), %rax
leaq (%rax,%r15), %rsi
addq $0x10, %rsi
movq %r14, %rdi
callq 0x65ea
movq (%r14), %rax
leaq (%rax,%r15), %rsi
addq $-0x10, %rsi
movq %r14, %rdi
callq 0x65ea
jmp 0x4a77
cmpl $0x3, %eax
je 0x4bd3
cmpl $0x1, %eax
jne 0x4a77
movq -0x18(%r13), %rdi
movq -0x10(%r13), %rax
subq %rdi, %rax
shrq $0x4, %rax
decl %eax
cmpl %eax, %r12d
jge 0x4a77
testl %r12d, %r12d
je 0x4b95
movq %rbp, %rax
shlq $0x4, %rax
cmpb $0x0, -0x20(%rdi,%rax)
jne 0x4a77
movq 0x10(%rsp), %rbx
shlq $0x4, %rbp
addq %rbp, %rdi
callq 0x657a
movq 0x30(%rsp), %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x5fb6
movq (%r14), %rcx
movb $0x1, (%rcx,%r15)
movq %rax, 0x8(%rcx,%r15)
movq (%r14), %rax
leaq (%rax,%r15), %rsi
addq $0x10, %rsi
jmp 0x4b49
movq 0x10(%rsp), %rax
leaq 0x9809(%rip), %rcx      # 0xe3e8
cmpq (%rcx), %rax
jne 0x4a77
cmpl $0x3, %r12d
jb 0x4ed7
movq -0x18(%r13), %rdi
movq -0x10(%r13), %rax
subq %rdi, %rax
shrq $0x4, %rax
decl %eax
cmpl %eax, %r12d
jge 0x4ed7
leal -0x3(%rbx), %eax
shlq $0x4, %rax
addq %rax, %rdi
callq 0x65a4
leaq 0x97be(%rip), %rcx      # 0xe3e0
cmpq (%rcx), %rax
jne 0x4a77
leal -0x4(%rbx), %r12d
shlq $0x4, %r12
movq -0x18(%r13), %rdi
addq %r12, %rdi
callq 0x657a
movq %rax, (%rsp)
addl $-0x2, %ebx
shlq $0x4, %rbx
addq -0x18(%r13), %rbx
movq %rbx, %rdi
callq 0x657a
movq %rax, %rbx
shlq $0x4, %rbp
addq -0x18(%r13), %rbp
movq %rbp, %rdi
callq 0x657a
movq 0x30(%rsp), %rdi
movq (%rsp), %rsi
movq %rbx, %rdx
movq %rax, %rcx
callq 0x6624
movq -0x18(%r13), %rcx
movb $0x1, (%rcx,%r12)
movq %rax, 0x8(%rcx,%r12)
movq -0x18(%r13), %rax
leaq (%rax,%r15), %rsi
addq $-0x20, %rsi
leaq (%rax,%r15), %rdx
addq $0x20, %rdx
movq %r14, %rdi
callq 0x665a
jmp 0x4a6b
xorl %r15d, %r15d
movq -0x18(%r13), %rdi
movq -0x10(%r13), %rax
subq %rdi, %rax
shrq $0x4, %rax
cmpl %eax, %r15d
jge 0x4e2c
movslq %r15d, %rbp
shlq $0x4, %rbp
cmpb $0x0, (%rdi,%rbp)
jne 0x4e24
addq %rbp, %rdi
callq 0x65a4
movq %rax, 0x10(%rsp)
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
leaq 0x10(%rsp), %rsi
callq 0x3e72
testb %al, %al
je 0x4e24
movl 0x3c(%rbx), %eax
testl %eax, %eax
setne %cl
testl %r15d, %r15d
setle %dl
orb %cl, %dl
movl %r15d, %ebx
jne 0x4da9
movq -0x18(%r13), %rdi
movq -0x10(%r13), %rax
subq %rdi, %rax
shrq $0x4, %rax
decl %eax
cmpl %eax, %r15d
jge 0x4e24
decl %r15d
movq %r15, %rax
shlq $0x4, %rax
addq %rax, %rdi
callq 0x657a
movq %rax, (%rsp)
movq 0x10(%rsp), %r12
movq (%r14), %rax
shlq $0x4, %rbx
leaq (%rax,%rbx), %rdi
addq $0x10, %rdi
callq 0x657a
movq 0x38(%rsp), %rdi
movq (%rsp), %rsi
movq %r12, %rdx
movq %rax, %rcx
callq 0x65ce
movq (%r14), %rcx
movb $0x1, (%rcx,%rbp)
movq %rax, 0x8(%rcx,%rbp)
movq (%r14), %rax
leaq (%rax,%rbp), %rsi
addq $0x10, %rsi
movq %r14, %rdi
callq 0x65ea
movq (%r14), %rax
leaq (%rax,%rbp), %rsi
addq $-0x10, %rsi
movq %r14, %rdi
callq 0x65ea
jmp 0x4e24
cmpl $0x1, %eax
jne 0x4e24
movq -0x18(%r13), %rax
movq -0x10(%r13), %rcx
subq %rax, %rcx
shrq $0x4, %rcx
decl %ecx
cmpl %ecx, %r15d
jge 0x4e24
testl %r15d, %r15d
jle 0x4dd4
shlq $0x4, %rbx
cmpb $0x0, -0x10(%rax,%rbx)
jne 0x4e24
movq 0x10(%rsp), %rbx
leaq (%rax,%rbp), %rdi
addq $0x10, %rdi
callq 0x657a
movq 0x30(%rsp), %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x5fb6
movq (%r14), %rcx
movb $0x1, (%rcx,%rbp)
movq %rax, 0x8(%rcx,%rbp)
movq (%r14), %rax
leaq (%rax,%rbp), %rsi
addq $0x10, %rsi
movq %r14, %rdi
callq 0x65ea
cmpl $0x3, %r15d
pushq $0x2
popq %rax
cmovll %eax, %r15d
addl $-0x2, %r15d
incl %r15d
jmp 0x4caf
movq 0x8(%rsp), %rdx
addq $0x40, %rdx
jmp 0x4a51
movq -0x18(%r13), %rdi
movq -0x10(%r13), %rax
subq %rdi, %rax
cmpq $0x10, %rax
jne 0x4ef6
callq 0x657a
movq -0x18(%r13), %rcx
cmpq %rcx, -0x10(%r13)
je 0x498c
movq %rcx, -0x10(%r13)
jmp 0x498c
movq (%r15), %rsi
movzbl (%rsi), %eax
cmpl $0x5b, %eax
movq %rbp, %rbx
je 0x4e9c
cmpl $0x28, %eax
jne 0x4f15
leaq 0x20(%rsp), %rdi
callq 0x657a
movq %rbx, %rdi
movq %rax, %rsi
movq %r15, %rdx
callq 0x61a4
jmp 0x4eb4
leaq 0x20(%rsp), %rdi
callq 0x657a
movq %rbx, %rdi
movq %rax, %rsi
movq %r15, %rdx
callq 0x62ce
movb $0x1, 0x20(%rsp)
movq %rax, 0x28(%rsp)
pushq $0x1
popq %rsi
movq %rbx, %rdi
movq %rax, %rdx
movq %r15, %rcx
movq %r14, %r8
callq 0x4920
jmp 0x498c
leaq 0x3dc4(%rip), %rdi      # 0x8ca2
leaq 0x3312(%rip), %rsi      # 0x81f7
leaq 0x3d17(%rip), %rcx      # 0x8c03
movl $0x2f0, %edx            # imm = 0x2F0
callq 0x2120
leaq 0x3dc7(%rip), %rdi      # 0x8cc4
leaq 0x32f3(%rip), %rsi      # 0x81f7
leaq 0x3cf8(%rip), %rcx      # 0x8c03
movl $0x30b, %edx            # imm = 0x30B
callq 0x2120
leaq 0x3ccd(%rip), %rdi      # 0x8be9
callq 0x3e80
leaq 0x3b80(%rip), %rdi      # 0x8aa8
leaq 0x32c8(%rip), %rsi      # 0x81f7
leaq 0x3ccd(%rip), %rcx      # 0x8c03
movl $0x2ce, %edx            # imm = 0x2CE
callq 0x2120