// File: /workspace/github_c_makefile_star2_O1/JesseBuesking[P]omnomnum/omnomnum.c
// Function: find_numbers
YYSTYPEList find_numbers(const char *data, size_t data_len, ParserState *state) {
    YYSTYPE yylval;
    scanstate ss;
    scanstate_init(&ss, data, data_len);

    int scanner_value = -1;
    state->is_parsing = false;

#if debug
    ParseTrace(stderr, (char*)"[Parser] >> ");
#endif
    state->last_token = -1;

    for(;;) {
        RESET_YYSTYPE(yylval);
        scanner_value = omnomnum_scanner_start(state, pParser, &yylval, &ss);

#if debug
        sds value = sdsnewlen(ss.token, ss.cursor - ss.token);
        printf("token is %s at %d - %d\n", value, ss.token - data, ss.cursor - data);
        sdsfree(value);
#endif

        // failsafe to make sure we stay within the bounds
        if (ss.cursor > ss.limit) {
            // at the end of the string? end the loop.
            break;
        }

        if (scanner_value <= 0) {
            if (scanner_value < 0) {
                printf("Scanner returned an error: %d\n", scanner_value);
            }

            // equal to 0 (end of input)
            break;
        }

        if (scanner_value != TOKEN_SEPARATOR && state->last_token != TOKEN_CHARACTERS) {
            // update position information
            yylval.begin = ss.token - data;
            yylval.end = ss.cursor - data;

            // parse stuff
            Parse(pParser, scanner_value, yylval, state);
            state->is_parsing = true;
        }

        state->last_token = scanner_value;
    }

    if (state->is_parsing) {
        Parse(pParser, 0, yylval, state);
        ParseReset(pParser);
    }

    YYSTYPEList l = state->yystypeList;

#if debug
    printf("numbers: %zu\n", l.used);
#endif

    // I don't think this is necessary. The original thought was that if ever
    // RTL languages were supported, we'd need to reorder the items added.
    // However, I *think* the parser will always parse LTR, which means this
    // would do nothing. Since, for now, LTR english is the target language
    // supported, I'm disabling this.
    /*sortYYSTYPElist(&l);*/

    return l;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rcx, %rbx
movq %rsi, %r15
movq %rdi, %r14
leaq 0x68(%rsp), %r12
movq %r12, %rdi
callq 0x6110
xorl %eax, %eax
movb %al, 0x31(%rbx)
movl $0xffffffff, 0x34(%rbx) # imm = 0xFFFFFFFF
leaq 0x38(%rsp), %rdx
movb %al, 0x8(%rdx)
movw $0x0, 0x20(%rdx)
movl $0x0, 0x2c(%rdx)
movq 0xf7c9(%rip), %rsi      # 0x12108
movq %rbx, %rdi
movq %r12, %rcx
callq 0x2c2c
movl %eax, %ebp
movq (%r12), %rax
cmpq 0x8(%r12), %rax
ja 0x2a17
leaq 0x38(%rsp), %r12
leaq 0x68(%rsp), %r13
testl %ebp, %ebp
jle 0x2a05
cmpl $0x2710, %ebp           # imm = 0x2710
je 0x29c5
cmpl $0x2711, 0x34(%rbx)     # imm = 0x2711
je 0x29c5
movl 0x80(%rsp), %ecx
subl %r15d, %ecx
movl %ecx, 0x5c(%rsp)
subl %r15d, %eax
movl %eax, 0x60(%rsp)
movq 0xf76e(%rip), %rdi      # 0x12108
movups 0x38(%rsp), %xmm0
movups 0x48(%rsp), %xmm1
movups 0x58(%rsp), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movl %ebp, %esi
movq %rbx, %rdx
callq 0x12bb
movb $0x1, 0x31(%rbx)
movl %ebp, 0x34(%rbx)
movb $0x0, 0x40(%rsp)
movw $0x0, 0x58(%rsp)
movl $0x0, 0x64(%rsp)
movq 0xf725(%rip), %rsi      # 0x12108
movq %rbx, %rdi
movq %r12, %rdx
movq %r13, %rcx
callq 0x2c2c
movl %eax, %ebp
movq 0x68(%rsp), %rax
cmpq 0x70(%rsp), %rax
jbe 0x2965
jmp 0x2a17
jns 0x2a17
leaq 0x9acc(%rip), %rdi      # 0xc4da
movl %ebp, %esi
xorl %eax, %eax
callq 0x1090
cmpb $0x1, 0x31(%rbx)
jne 0x2a57
movq 0xf6e4(%rip), %rdi      # 0x12108
movups 0x38(%rsp), %xmm0
movups 0x48(%rsp), %xmm1
movups 0x58(%rsp), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
xorl %esi, %esi
movq %rbx, %rdx
callq 0x12bb
movq 0xf6b6(%rip), %rdi      # 0x12108
callq 0x1289
movq 0x28(%rbx), %rax
movq %rax, 0x10(%r14)
movups 0x18(%rbx), %xmm0
movups %xmm0, (%r14)
movq %r14, %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq