// File: /workspace/github_c_makefile_star2_O1/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 0x28f0
movq 0x8(%r12), %r13
testq %r13, %r13
je 0x2c0c
movq %r15, 0x38(%rsp)
movq %r14, 0x30(%rsp)
callq 0x623e
movq %rax, 0x8(%rbx)
xorl %eax, %eax
movl $0x1, %ebp
movq 0x70(%rsp), %r15
leaq 0x99c8(%rip), %r12      # 0xc4a8
xorl %r14d, %r14d
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
movups (%r15,%rax), %xmm0
movups 0x10(%r15,%rax), %xmm1
movups 0x20(%r15,%rax), %xmm2
movaps %xmm2, 0x60(%rsp)
movaps %xmm1, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movl 0x64(%rsp), %edx
subl %r14d, %edx
jbe 0x2b35
movq 0x8(%rbx), %rdi
movl %r14d, %esi
addq 0x30(%rsp), %rsi
callq 0x6907
movq %rax, 0x8(%rbx)
movq 0xf5e0(%rip), %rdi      # 0x12110
callq 0x633f
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 0xf5b0(%rip), %rdi      # 0x12110
callq 0x27dd
movq 0x8(%rbx), %rdi
movq 0xf5a0(%rip), %rsi      # 0x12110
callq 0x69fe
movq %rax, 0x8(%rbx)
movq 0xf590(%rip), %rdi      # 0x12110
callq 0x633f
movq 0xf584(%rip), %rdi      # 0x12110
movzbl -0x1(%rdi), %eax
movl %eax, %ecx
andl $0x7, %ecx
cmpl $0x4, %ecx
ja 0x2bbf
movslq (%r12,%rcx,4), %rcx
addq %r12, %rcx
jmpq *%rcx
shrl $0x3, %eax
jmp 0x2bc1
movq -0x11(%rdi), %rax
jmp 0x2bc1
movzwl -0x5(%rdi), %eax
jmp 0x2bc1
movl -0x9(%rdi), %eax
jmp 0x2bc1
movzbl -0x3(%rdi), %eax
jmp 0x2bc1
xorl %eax, %eax
cmpq $0x2, %rax
jb 0x2bcc
callq 0x65b5
movl %ebp, %eax
incl %ebp
cmpq %rax, %r13
ja 0x2ae3
movq 0x8(%rbx), %rdi
movq 0x70(%rsp), %rax
leaq (,%r13,2), %rcx
addq %r13, %rcx
shlq $0x4, %rcx
movl -0x8(%rax,%rcx), %eax
movq 0x30(%rsp), %rsi
addq %rax, %rsi
movq 0x38(%rsp), %rdx
subq %rax, %rdx
callq 0x6907
jmp 0x2c14
movq %r14, %rdi
callq 0x6261
movq %rax, 0x8(%rbx)
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop