// File: /workspace/github_c_makefile_star2_O3/JesseBuesking[P]omnomnum/omnomnum.c
// Function: normalize
void normalize(const char *data, size_t data_len, ParserState *state) {
    YYSTYPEList l = find_numbers(data, data_len, state);

    if (l.used == 0) {
        state->result = sdsnew(data);
    } else {
        state->result = sdsempty();

        unsigned int lastpos = 0;
        unsigned int i = 0;

        for (i = 0; i < l.used; ++i) {
            YYSTYPE y = l.values[i];

#if debug
            printf("begin: %d, end: %d, value: %lf, suffix: %d\n", y.begin, y.end, y.dbl, y.suffix);
#endif

            if (lastpos < y.begin) {
                // Copy the part of the string leading up to the number to
                // the final string.
                state->result = sdscatlen(
                        state->result,
                        data + lastpos,
                        y.begin - lastpos
                        );
                sdsclear(numberHolder);
            }
            lastpos = y.end;

            yystypeToString(&numberHolder, y, state->precision);
            state->result = sdscatsds(state->result, numberHolder);

            sdsclear(numberHolder);

            // in case the last string was exceptionally large, free up memory
            // TODO test this out
            if (sdslen(numberHolder) > 1) {
                sdsRemoveFreeSpace(numberHolder);
            }
        }

        // Copy what's left of the string to the final string.
        state->result = sdscatlen(
                state->result,
                data + l.values[l.used-1].end,
                data_len - l.values[l.used-1].end
                );
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
leaq 0x70(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x28fc
movq 0x8(%r12), %r13
testq %r13, %r13
je 0x2c10
movq %r15, 0x38(%rsp)
movq %r14, 0x30(%rsp)
callq 0x6261
movq %rax, 0x8(%rbx)
xorl %eax, %eax
movl $0x1, %r15d
movq 0x70(%rsp), %rbp
leaq 0x99bb(%rip), %r12      # 0xc4a8
xorl %r14d, %r14d
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
movups (%rbp,%rax), %xmm0
movups 0x10(%rbp,%rax), %xmm1
movups 0x20(%rbp,%rax), %xmm2
movaps %xmm2, 0x60(%rsp)
movaps %xmm1, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movl 0x64(%rsp), %edx
subl %r14d, %edx
jbe 0x2b40
movq 0x8(%rbx), %rdi
movl %r14d, %esi
addq 0x30(%rsp), %rsi
callq 0x692c
movq %rax, 0x8(%rbx)
movq 0xf5d5(%rip), %rdi      # 0x12110
callq 0x6371
movl 0x68(%rsp), %r14d
movl (%rbx), %esi
movaps 0x40(%rsp), %xmm0
movaps 0x50(%rsp), %xmm1
movaps 0x60(%rsp), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq 0xf5a5(%rip), %rdi      # 0x12110
callq 0x27e9
movq 0x8(%rbx), %rdi
movq 0xf595(%rip), %rsi      # 0x12110
callq 0x6a1e
movq %rax, 0x8(%rbx)
movq 0xf585(%rip), %rdi      # 0x12110
callq 0x6371
movq 0xf579(%rip), %rdi      # 0x12110
movzbl -0x1(%rdi), %eax
movl %eax, %ecx
andl $0x7, %ecx
cmpl $0x4, %ecx
ja 0x2bd3
movslq (%r12,%rcx,4), %rcx
addq %r12, %rcx
jmpq *%rcx
shrl $0x3, %eax
jmp 0x2bc8
movq -0x11(%rdi), %rax
jmp 0x2bc8
movzwl -0x5(%rdi), %eax
jmp 0x2bc8
movl -0x9(%rdi), %eax
jmp 0x2bc8
movzbl -0x3(%rdi), %eax
cmpq $0x2, %rax
jb 0x2bd3
callq 0x65d1
movl %r15d, %eax
incl %r15d
cmpq %rax, %r13
ja 0x2af0
movq 0x8(%rbx), %rdi
leaq (,%r13,2), %rax
addq %r13, %rax
shlq $0x4, %rax
movl -0x8(%rbp,%rax), %eax
movq 0x30(%rsp), %rsi
addq %rax, %rsi
movq 0x38(%rsp), %rdx
subq %rax, %rdx
callq 0x692c
jmp 0x2c18
movq %r14, %rdi
callq 0x6284
movq %rax, 0x8(%rbx)
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop