// File: /workspace/github_c_makefile_star2_O1/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
pushq %rax
movq %rdi, %rbx
callq 0x1099c
movq (%rbx), %rdi
movzbl (%rdi), %eax
cmpl $0x2d, %eax
setne %cl
leal -0x3a(%rax), %edx
cmpb $-0xa, %dl
setb %dl
testb %dl, %cl
je 0x10519
leal -0x7b(%rax), %ecx
cmpb $-0x1a, %cl
jae 0x10555
cmpl $0x23, %eax
je 0x1058a
cmpl $0x2c, %eax
je 0x1056b
cmpl $0x7b, %eax
je 0x10574
movq %rbx, %rsi
callq 0xf358
movl %eax, %ebp
movq %rbx, %rdi
callq 0x1099c
movzbl 0x2049a27(%rip), %ecx   # 0x2059e2c
leal 0x1(%rcx), %edx
movb %dl, 0x2049a1e(%rip)    # 0x2059e2c
leaq 0x204f23b(%rip), %r12   # 0x205f650
movb %bpl, (%rcx,%r12)
cmpb $0x28, %al
jne 0x10546
movq %rbx, %rdi
movl $0x28, %esi
callq 0x10cb7
movzbl %bpl, %r14d
leaq 0x2aa7(%rip), %rax      # 0x12ee0
movb (%rax,%r14), %bpl
testb %bpl, %bpl
je 0x104fa
xorl %r13d, %r13d
movq %rsp, %r15
testb %r13b, %r13b
je 0x10466
movq %rbx, %rdi
callq 0x1099c
movq %rbx, %rdi
movl $0x2c, %esi
callq 0x10cb7
movq %rbx, %rdi
callq 0x1099c
movq (%rbx), %rdi
movb (%rdi), %al
leal -0x3a(%rax), %ecx
cmpb $-0xa, %cl
setb %cl
cmpb $0x2d, %al
setne %dl
testb %cl, %dl
je 0x1049b
leal -0x7b(%rax), %ecx
cmpb $-0x1a, %cl
jae 0x104b9
cmpb $0x23, %al
jne 0x104c3
movq %rbx, %rdi
callq 0x10c1d
jmp 0x104ee
movq %rbx, %rdi
callq 0x1006d
movzbl 0x2049982(%rip), %ecx   # 0x2059e2c
leal 0x1(%rcx), %edx
movb %dl, 0x2049979(%rip)    # 0x2059e2c
movb %al, (%rcx,%r12)
jmp 0x104ee
movq %rbx, %rdi
callq 0x10a41
jmp 0x104ee
movq %r15, %rsi
callq 0xf358
movzbl %al, %esi
leaq 0x2b0b(%rip), %rax      # 0x12fe0
movb (%rax,%rsi), %al
testb %al, %al
je 0x105a0
addb %al, %r13b
decb %r13b
movq %rbx, %rdi
callq 0x10395
incb %r13b
cmpb %bpl, %r13b
jb 0x1044c
movq %rbx, %rdi
callq 0x1099c
movq %rbx, %rdi
movl $0x29, %esi
callq 0x10cb7
movq %rbx, %rdi
callq 0x1099c
jmp 0x10546
movq %rbx, %rdi
callq 0x1006d
movl %eax, %ebp
movq %rbx, %rdi
callq 0x1099c
movzbl 0x20498fa(%rip), %eax   # 0x2059e2c
leal 0x1(%rax), %ecx
movb %cl, 0x20498f1(%rip)    # 0x2059e2c
leaq 0x204f10e(%rip), %rcx   # 0x205f650
movb %bpl, (%rax,%rcx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x10a41
cmpb $0x0, 0x20498b2(%rip)   # 0x2059e24
je 0x105a8
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x10b0d
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x10c1d
movq %r14, %rdi
callq 0x4197
callq 0x4170