// File: /workspace/github_c_makefile_star2_O2/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 0x283c
movq 0x8(%r12), %r13
testq %r13, %r13
je 0x2af6
movq %r15, 0x38(%rsp)
movq %r14, 0x30(%rsp)
callq 0x5c78
movq %rax, 0x8(%rbx)
xorl %r14d, %r14d
movq 0x70(%rsp), %rbp
leaq 0x8acb(%rip), %r15      # 0xb4a8
xorl %r12d, %r12d
movl %r12d, %r12d
cmpq %r12, %r13
jbe 0x2ad3
imulq $0x30, %r12, %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 0x2a38
movq 0x8(%rbx), %rdi
movl %r14d, %esi
addq 0x30(%rsp), %rsi
callq 0x610b
movq %rax, 0x8(%rbx)
movq 0xe6dd(%rip), %rdi      # 0x11110
callq 0x5d5f
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 0xe6ad(%rip), %rdi      # 0x11110
callq 0x2729
movq 0x8(%rbx), %rdi
movq 0xe69d(%rip), %rsi      # 0x11110
callq 0x6191
movq %rax, 0x8(%rbx)
movq 0xe68d(%rip), %rdi      # 0x11110
callq 0x5d5f
movq 0xe681(%rip), %rdi      # 0x11110
movzbl -0x1(%rdi), %eax
movl %eax, %ecx
andl $0x7, %ecx
cmpl $0x4, %ecx
ja 0x2acb
movslq (%r15,%rcx,4), %rcx
addq %r15, %rcx
jmpq *%rcx
shrl $0x3, %eax
jmp 0x2ac0
movq -0x11(%rdi), %rax
jmp 0x2ac0
movzwl -0x5(%rdi), %eax
jmp 0x2ac0
movl -0x9(%rdi), %eax
jmp 0x2ac0
movzbl -0x3(%rdi), %eax
cmpq $0x2, %rax
jb 0x2acb
callq 0x5f03
incl %r12d
jmp 0x29e0
movq 0x8(%rbx), %rdi
imulq $0x30, %r13, %rax
movl -0x8(%rbp,%rax), %eax
movq 0x30(%rsp), %rsi
addq %rax, %rsi
movq 0x38(%rsp), %rdx
subq %rax, %rdx
callq 0x610b
jmp 0x2afe
movq %r14, %rdi
callq 0x5c86
movq %rax, 0x8(%rbx)
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq