// File: /workspace/github_c_makefile_star2_O0/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:
subq $0xb8, %rsp
movq %rdi, 0x38(%rsp)
movq %rdi, 0x40(%rsp)
movq %rsi, 0xb0(%rsp)
movq %rdx, 0xa8(%rsp)
movq %rcx, 0xa0(%rsp)
movq 0xb0(%rsp), %rsi
movq 0xa8(%rsp), %rdx
leaq 0x50(%rsp), %rdi
callq 0x11a30
movl $0xffffffff, 0x4c(%rsp) # imm = 0xFFFFFFFF
movq 0xa0(%rsp), %rax
movb $0x0, 0x31(%rax)
movq 0xa0(%rsp), %rax
movl $0xffffffff, 0x34(%rax) # imm = 0xFFFFFFFF
movb $0x0, 0x78(%rsp)
movb $0x0, 0x90(%rsp)
movl $0x0, 0x9c(%rsp)
movb $0x0, 0x91(%rsp)
movq 0xa0(%rsp), %rdi
movq 0x16523(%rip), %rsi     # 0x20108
leaq 0x70(%rsp), %rdx
leaq 0x50(%rsp), %rcx
callq 0xa030
movl %eax, 0x4c(%rsp)
movq 0x50(%rsp), %rax
cmpq 0x58(%rsp), %rax
jbe 0x9c09
jmp 0x9cd6
cmpl $0x0, 0x4c(%rsp)
jg 0x9c2e
cmpl $0x0, 0x4c(%rsp)
jge 0x9c29
movl 0x4c(%rsp), %esi
leaq 0x10958(%rip), %rdi     # 0x1a57a
movb $0x0, %al
callq 0x10a0
jmp 0x9cd6
cmpl $0x2710, 0x4c(%rsp)     # imm = 0x2710
je 0x9cc2
movq 0xa0(%rsp), %rax
cmpl $0x2711, 0x34(%rax)     # imm = 0x2711
je 0x9cc2
movq 0x68(%rsp), %rax
movq 0xb0(%rsp), %rcx
subq %rcx, %rax
movl %eax, 0x94(%rsp)
movq 0x50(%rsp), %rax
movq 0xb0(%rsp), %rcx
subq %rcx, %rax
movl %eax, 0x98(%rsp)
movq 0x16486(%rip), %rdi     # 0x20108
movl 0x4c(%rsp), %esi
movq 0xa0(%rsp), %rdx
movups 0x70(%rsp), %xmm0
movups 0x80(%rsp), %xmm1
movups 0x90(%rsp), %xmm2
movq %rsp, %rax
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x13d0
movq 0xa0(%rsp), %rax
movb $0x1, 0x31(%rax)
movl 0x4c(%rsp), %ecx
movq 0xa0(%rsp), %rax
movl %ecx, 0x34(%rax)
jmp 0x9bb6
movq 0xa0(%rsp), %rax
testb $0x1, 0x31(%rax)
je 0x9d2b
movq 0x1641d(%rip), %rdi     # 0x20108
movq 0xa0(%rsp), %rdx
xorl %eax, %eax
movups 0x70(%rsp), %xmm0
movups 0x80(%rsp), %xmm1
movups 0x90(%rsp), %xmm2
movq %rsp, %rax
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
xorl %esi, %esi
callq 0x13d0
movq 0x163e2(%rip), %rdi     # 0x20108
callq 0x1350
movq 0x40(%rsp), %rax
movq 0x38(%rsp), %rcx
movq 0xa0(%rsp), %rdx
movq 0x18(%rdx), %rsi
movq %rsi, (%rcx)
movq 0x20(%rdx), %rsi
movq %rsi, 0x8(%rcx)
movq 0x28(%rdx), %rdx
movq %rdx, 0x10(%rcx)
addq $0xb8, %rsp
retq
nopl (%rax)