// File: /workspace/github_c_makefile_star2_O2/wjmelements[P]evm/src/scan.c
// Function: scanOp
static void scanOp(const char **iter) {
    scanWaste(iter);
    if (isConstant(*iter)) {
        op_t op = parseConstant(iter);
        scanWaste(iter);
        scanstackPush(op);
        return;
    }
    if (isLowerCase(**iter)) {
        scanLabel(iter);
        return;
    }
    if (**iter == '{' ) {
        scanDataSection(iter);
        return;
    }
    if (**iter == ',') {
        if (!inDataSection) {
            fprintf(stderr, "Found unexpected comma when scanning for next op at line %u\n", lineNumber);
            exit(1);
        }
        scanDataSection(iter);
        return;
    }
    if (**iter == '#') {
        scanDataLen(iter);
        return;
    }
    op_t op = parseOp(*iter, iter);
    char next = scanWaste(iter);
    scanstackPush(op);
    if (next != '(') {
        return;
    }
    scanChar(iter, '(');
    for (uint8_t i = 0; i < argCount[op]; i++) {
        if (i) {
            scanWaste(iter);
            scanChar(iter, ',');
        }
        scanWaste(iter);
        if (isConstant(*iter)) {
            scanstackPush(parseConstant(iter));
        } else if (isLowerCase(**iter)) {
            scanLabel(iter);
        } else if (**iter == '#') {
            scanDataLen(iter);
        } else {
            const char *end;
            op_t next = parseOp(*iter, &end);
            // TODO maybe next can be read from stack after scanOp instead of parsing twice
            if (!retCount[next]) {
                fprintf(stderr, "When reading args for op %s found unexpected op %s, at line %u", opString[op], opString[next], lineNumber);
                exit(1);
            }
            i += (retCount[next] - 1);
            scanOp(iter);
        }
    }
    scanWaste(iter);
    scanChar(iter, ')');
    scanWaste(iter);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
callq 0xd7a6
movq (%rbx), %rdi
movzbl (%rdi), %eax
cmpl $0x2d, %eax
setne %cl
leal -0x3a(%rax), %edx
cmpb $-0xa, %dl
setb %dl
testb %dl, %cl
je 0xd286
leal -0x7b(%rax), %ecx
cmpb $-0x1a, %cl
jae 0xd2c2
cmpl $0x23, %eax
je 0xd2f7
cmpl $0x2c, %eax
je 0xd2d8
cmpl $0x7b, %eax
je 0xd2e1
movq %rbx, %rsi
callq 0xc1d8
movl %eax, %ebp
movq %rbx, %rdi
callq 0xd7a6
movzbl 0x2049c9c(%rip), %ecx   # 0x2056e2c
leal 0x1(%rcx), %edx
movb %dl, 0x2049c93(%rip)    # 0x2056e2c
leaq 0x204f4b0(%rip), %r15   # 0x205c650
movb %bpl, (%rcx,%r15)
cmpb $0x28, %al
jne 0xd2b3
pushq $0x28
popq %rsi
movq %rbx, %rdi
callq 0xda51
movzbl %bpl, %ecx
leaq 0x2d1e(%rip), %rax      # 0xfee0
movq %rcx, 0x8(%rsp)
movb (%rax,%rcx), %r13b
xorl %r12d, %r12d
leaq 0x10(%rsp), %r14
pushq $0x2c
popq %rbp
cmpb %r13b, %r12b
jae 0xd30d
testb %r12b, %r12b
je 0xd1f6
movq %rbx, %rdi
callq 0xd7a6
movq %rbx, %rdi
movl %ebp, %esi
callq 0xda51
movq %rbx, %rdi
callq 0xd7a6
movq (%rbx), %rdi
movb (%rdi), %al
leal -0x3a(%rax), %ecx
cmpb $-0xa, %cl
setb %cl
cmpb $0x2d, %al
setne %dl
testb %cl, %dl
je 0xd22b
leal -0x7b(%rax), %ecx
cmpb $-0x1a, %cl
jae 0xd249
cmpb $0x23, %al
jne 0xd253
movq %rbx, %rdi
callq 0xd9bc
jmp 0xd27e
movq %rbx, %rdi
callq 0xcea5
movzbl 0x2049bf2(%rip), %ecx   # 0x2056e2c
leal 0x1(%rcx), %edx
movb %dl, 0x2049be9(%rip)    # 0x2056e2c
movb %al, (%rcx,%r15)
jmp 0xd27e
movq %rbx, %rdi
callq 0xd81b
jmp 0xd27e
movq %r14, %rsi
callq 0xc1d8
movzbl %al, %eax
leaq 0x2d7b(%rip), %rcx      # 0xffe0
movb (%rcx,%rax), %cl
testb %cl, %cl
je 0xd32a
addb %cl, %r12b
decb %r12b
movq %rbx, %rdi
callq 0xd11d
incb %r12b
jmp 0xd1d6
movq %rbx, %rdi
callq 0xcea5
movl %eax, %ebp
movq %rbx, %rdi
callq 0xd7a6
movzbl 0x2049b8d(%rip), %eax   # 0x2056e2c
leal 0x1(%rax), %ecx
movb %cl, 0x2049b84(%rip)    # 0x2056e2c
leaq 0x204f3a1(%rip), %rcx   # 0x205c650
movb %bpl, (%rax,%rcx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xd81b
cmpb $0x0, 0x2049b45(%rip)   # 0x2056e24
je 0xd35f
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xd896
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xd9bc
movq %rbx, %rdi
callq 0xd7a6
pushq $0x29
popq %rsi
movq %rbx, %rdi
callq 0xda51
movq %rbx, %rdi
callq 0xd7a6
jmp 0xd2b3
movq 0x8cc7(%rip), %rcx      # 0x15ff8
movq (%rcx), %rdi
leaq 0x8eb5(%rip), %rcx      # 0x161f0
movq 0x8(%rsp), %rdx
movq (%rcx,%rdx,8), %rdx
movq (%rcx,%rax,8), %rcx
movl 0x2049ad9(%rip), %r8d   # 0x2056e28
leaq 0x3f0e(%rip), %rsi      # 0x11264
xorl %eax, %eax
callq 0x31d0
jmp 0xd37d
movq 0x8c92(%rip), %rax      # 0x15ff8
movq (%rax), %rdi
movl 0x2049ab9(%rip), %edx   # 0x2056e28
leaq 0x3eb1(%rip), %rsi      # 0x11227
xorl %eax, %eax
callq 0x31d0
pushq $0x1
popq %rdi
callq 0x3280