// File: /workspace/github_c_makefile_star2_O2/JesseBuesking[P]omnomnum/branchlut/branchlut.c
// Function: u32toa_branchlut
int u32toa_branchlut(uint32_t value, char* buffer) {
    char* start = buffer;
    if (value < 10000) {
        const uint32_t d1 = (value / 100) << 1;
        const uint32_t d2 = (value % 100) << 1;

        if (value >= 1000)
            *buffer++ = gDigitsLut[d1];
        if (value >= 100)
            *buffer++ = gDigitsLut[d1 + 1];
        if (value >= 10)
            *buffer++ = gDigitsLut[d2];
        *buffer++ = gDigitsLut[d2 + 1];
    }
    else if (value < 100000000) {
        // value = bbbbcccc
        const uint32_t b = value / 10000;
        const uint32_t c = value % 10000;

        const uint32_t d1 = (b / 100) << 1;
        const uint32_t d2 = (b % 100) << 1;

        const uint32_t d3 = (c / 100) << 1;
        const uint32_t d4 = (c % 100) << 1;

        if (value >= 10000000)
            *buffer++ = gDigitsLut[d1];
        if (value >= 1000000)
            *buffer++ = gDigitsLut[d1 + 1];
        if (value >= 100000)
            *buffer++ = gDigitsLut[d2];
        *buffer++ = gDigitsLut[d2 + 1];

        *buffer++ = gDigitsLut[d3];
        *buffer++ = gDigitsLut[d3 + 1];
        *buffer++ = gDigitsLut[d4];
        *buffer++ = gDigitsLut[d4 + 1];
    }
    else {
        // value = aabbbbcccc in decimal

        const uint32_t a = value / 100000000; // 1 to 42
        value %= 100000000;

        if (a >= 10) {
            const unsigned i = a << 1;
            *buffer++ = gDigitsLut[i];
            *buffer++ = gDigitsLut[i + 1];
        }
        else
            *buffer++ = '0' + (char) (a);

        const uint32_t b = value / 10000; // 0 to 9999
        const uint32_t c = value % 10000; // 0 to 9999

        const uint32_t d1 = (b / 100) << 1;
        const uint32_t d2 = (b % 100) << 1;

        const uint32_t d3 = (c / 100) << 1;
        const uint32_t d4 = (c % 100) << 1;

        *buffer++ = gDigitsLut[d1];
        *buffer++ = gDigitsLut[d1 + 1];
        *buffer++ = gDigitsLut[d2];
        *buffer++ = gDigitsLut[d2 + 1];
        *buffer++ = gDigitsLut[d3];
        *buffer++ = gDigitsLut[d3 + 1];
        *buffer++ = gDigitsLut[d4];
        *buffer++ = gDigitsLut[d4 + 1];
    }
    *buffer++ = '\0';
    return (int)(buffer - start);
}

// Assembly:
cmpl $0x270f, %edi           # imm = 0x270F
ja 0x799d
movw $0x64, %cx
movl %edi, %eax
xorl %edx, %edx
divw %cx
movzwl %ax, %r8d
addl %r8d, %r8d
movzwl %dx, %eax
addl %eax, %eax
cmpl $0x3e8, %edi            # imm = 0x3E8
jb 0x7a18
leaq 0x64d2(%rip), %rcx      # 0xde60
movb (%r8,%rcx), %dl
leaq 0x1(%rsi), %rcx
movb %dl, (%rsi)
jmp 0x7a24
cmpl $0x5f5e0ff, %edi        # imm = 0x5F5E0FF
ja 0x7a5f
movl $0x2710, %ecx           # imm = 0x2710
movl %edi, %eax
xorl %edx, %edx
divl %ecx
movl %eax, %ecx
movl %edx, %r9d
movl $0xf4240, %r8d          # imm = 0xF4240
movl %edi, %eax
xorl %edx, %edx
divl %r8d
movl %eax, %r8d
movw $0x64, %r10w
movl %ecx, %eax
xorl %edx, %edx
divw %r10w
movl %edx, %ecx
movl %r9d, %eax
xorl %edx, %edx
divw %r10w
addl %r8d, %r8d
movzwl %cx, %r9d
addl %r9d, %r9d
movzwl %ax, %eax
addl %eax, %eax
movzwl %dx, %edx
addl %edx, %edx
cmpl $0x989680, %edi         # imm = 0x989680
jb 0x7a9e
leaq 0x6458(%rip), %rcx      # 0xde60
movb (%r8,%rcx), %dil
leaq 0x1(%rsi), %rcx
movb %dil, (%rsi)
jmp 0x7aad
movq %rsi, %rcx
cmpl $0x64, %edi
jb 0x7b14
movzwl %r8w, %edx
leaq 0x6431(%rip), %rdi      # 0xde60
movb 0x1(%rdx,%rdi), %dl
movb %dl, (%rcx)
incq %rcx
leaq 0x6421(%rip), %rdx      # 0xde60
movb (%rax,%rdx), %dl
movb %dl, (%rcx)
incq %rcx
movzwl %ax, %eax
leaq 0x640f(%rip), %rdx      # 0xde60
movb 0x1(%rax,%rdx), %al
movb %al, (%rcx)
incq %rcx
jmp 0x7b98
movl $0x5f5e100, %ecx        # imm = 0x5F5E100
movl %edi, %eax
xorl %edx, %edx
divl %ecx
movl %edx, %r8d
leaq 0x63ec(%rip), %r10      # 0xde60
cmpl $0x3b9aca00, %edi       # imm = 0x3B9ACA00
jb 0x7b25
movl %eax, %eax
movb (%r10,%rax,2), %cl
addq %rax, %rax
movb %cl, (%rsi)
movl %eax, %eax
movb 0x1(%rax,%r10), %al
leaq 0x2(%rsi), %rcx
movb %al, 0x1(%rsi)
jmp 0x7b2d
movq %rsi, %rcx
cmpl $0xf4240, %edi          # imm = 0xF4240
jb 0x7ba2
movl %r8d, %edi
leaq 0x63a9(%rip), %r8       # 0xde60
movb 0x1(%rdi,%r8), %dil
movb %dil, (%rcx)
incq %rcx
leaq 0x6397(%rip), %rdi      # 0xde60
movb (%r9,%rdi), %dil
movb %dil, (%rcx)
incq %rcx
movzwl %r9w, %edi
leaq 0x6382(%rip), %r8       # 0xde60
movb 0x1(%rdi,%r8), %dil
movb %dil, (%rcx)
movb (%rax,%r8), %dil
movb %dil, 0x1(%rcx)
movzwl %ax, %eax
movb 0x1(%rax,%r8), %al
movb %al, 0x2(%rcx)
movb (%rdx,%r8), %al
movb %al, 0x3(%rcx)
movzwl %dx, %eax
movb 0x1(%rax,%r8), %al
movb %al, 0x4(%rcx)
addq $0x5, %rcx
jmp 0x7b98
movq %rsi, %rcx
cmpl $0xa, %edi
jae 0x7a38
jmp 0x7a47
orb $0x30, %al
leaq 0x1(%rsi), %rcx
movb %al, (%rsi)
movl $0x2710, %edi           # imm = 0x2710
movl %r8d, %eax
xorl %edx, %edx
divl %edi
movl %eax, %edi
movl %edx, %r9d
movl $0xf4240, %r11d         # imm = 0xF4240
movl %r8d, %eax
xorl %edx, %edx
divl %r11d
movl %eax, %r8d
movw $0x64, %r11w
movl %edi, %eax
xorl %edx, %edx
divw %r11w
movl %edx, %edi
movl %r9d, %eax
xorl %edx, %edx
divw %r11w
movzwl %di, %edi
movzwl %ax, %eax
movzwl %dx, %edx
movzwl (%r10,%r8,2), %r8d
movw %r8w, (%rcx)
movzwl (%r10,%rdi,2), %edi
movw %di, 0x2(%rcx)
movzwl (%r10,%rax,2), %eax
movw %ax, 0x4(%rcx)
movzwl (%r10,%rdx,2), %eax
movw %ax, 0x6(%rcx)
addq $0x8, %rcx
movb $0x0, (%rcx)
subl %esi, %ecx
incl %ecx
movl %ecx, %eax
retq
movq %rsi, %rcx
cmpl $0x186a0, %edi          # imm = 0x186A0
jae 0x7ac2
jmp 0x7ad3