// File: /workspace/github_c_makefile_star2_O2/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 0x5b30
movb $0x0, 0x31(%rbx)
pushq $-0x1
popq %rbp
leaq 0x38(%rsp), %r13
movl %ebp, 0x34(%rbx)
movb $0x0, 0x40(%rsp)
andw $0x0, 0x58(%rsp)
andl $0x0, 0x64(%rsp)
movq 0xe87f(%rip), %rsi      # 0x11108
movq %rbx, %rdi
movq %r13, %rdx
movq %r12, %rcx
callq 0x2b14
movl %eax, %ebp
movq 0x68(%rsp), %rax
cmpq 0x70(%rsp), %rax
ja 0x2918
testl %ebp, %ebp
jle 0x2906
cmpl $0x2710, %ebp           # imm = 0x2710
je 0x286f
cmpl $0x2711, 0x34(%rbx)     # imm = 0x2711
je 0x286f
movl 0x80(%rsp), %ecx
subl %r15d, %ecx
movl %ecx, 0x5c(%rsp)
subl %r15d, %eax
movl %eax, 0x60(%rsp)
movq 0xe832(%rip), %rdi      # 0x11108
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 0x12ad
movb $0x1, 0x31(%rbx)
jmp 0x286f
jns 0x2918
leaq 0x8bcb(%rip), %rdi      # 0xb4da
movl %ebp, %esi
xorl %eax, %eax
callq 0x1090
cmpb $0x1, 0x31(%rbx)
jne 0x2958
movq 0xe7e3(%rip), %rdi      # 0x11108
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 0x12ad
movq 0xe7b5(%rip), %rdi      # 0x11108
callq 0x1282
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