// File: /workspace/github_c_makefile_star2_O3/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 0x8b5f
movl $0xffff, %eax           # imm = 0xFFFF
movl %edi, %ecx
andl %eax, %ecx
shrl $0x2, %ecx
imull $0x147b, %ecx, %edx     # imm = 0x147B
shrl $0x11, %edx
imull $0x64, %edx, %r8d
addl %edx, %edx
movl %edi, %ecx
subl %r8d, %ecx
andl %eax, %ecx
addl %ecx, %ecx
cmpl $0x3e8, %edi            # imm = 0x3E8
jb 0x8bf7
leaq 0x6311(%rip), %rax      # 0xee60
movb (%rdx,%rax), %dil
leaq 0x1(%rsi), %rax
movb %dil, (%rsi)
jmp 0x8c03
movl %edi, %eax
cmpl $0x5f5e0ff, %edi        # imm = 0x5F5E0FF
ja 0x8c3d
movl $0xd1b71759, %edx       # imm = 0xD1B71759
imulq %rax, %rdx
shrq $0x2d, %rdx
imull $0x2710, %edx, %r8d     # imm = 0x2710
movl %edi, %ecx
subl %r8d, %ecx
imulq $0x431bde83, %rax, %r9  # imm = 0x431BDE83
shrq $0x31, %r9
andl $-0x2, %r9d
movl $0xffff, %eax           # imm = 0xFFFF
movl %edx, %r8d
andl %eax, %r8d
shrl $0x2, %r8d
imull $0x147b, %r8d, %r8d     # imm = 0x147B
shrl $0x11, %r8d
imull $0x64, %r8d, %r8d
subl %r8d, %edx
andl %eax, %edx
addl %edx, %edx
imull $0x147b, %ecx, %r10d    # imm = 0x147B
shrl $0x13, %r10d
leal (%r10,%r10), %r8d
imull $0x64, %r10d, %r10d
subl %r10d, %ecx
andl %eax, %ecx
addl %ecx, %ecx
cmpl $0x989680, %edi         # imm = 0x989680
jb 0x8c79
leaq 0x6279(%rip), %rax      # 0xee60
movb (%r9,%rax), %dil
leaq 0x1(%rsi), %rax
movb %dil, (%rsi)
jmp 0x8c88
movq %rsi, %rax
cmpl $0x64, %edi
jb 0x8ce9
movzwl %dx, %edx
leaq 0x6253(%rip), %rdi      # 0xee60
movb 0x1(%rdx,%rdi), %dl
movb %dl, (%rax)
incq %rax
leaq 0x6243(%rip), %rdx      # 0xee60
movb (%rcx,%rdx), %dl
movb %dl, (%rax)
incq %rax
movzwl %cx, %ecx
leaq 0x6231(%rip), %rdx      # 0xee60
movb 0x1(%rcx,%rdx), %cl
movb %cl, (%rax)
incq %rax
jmp 0x8d8e
imulq $0x55e63b89, %rax, %r8  # imm = 0x55E63B89
shrq $0x39, %r8
imull $0x5f5e100, %r8d, %eax  # imm = 0x5F5E100
movl %edi, %ecx
subl %eax, %ecx
leaq 0x6206(%rip), %rdx      # 0xee60
cmpl $0x3b9aca00, %edi       # imm = 0x3B9ACA00
jb 0x8cfa
movl %r8d, %eax
movzwl (%rdx,%rax,2), %eax
movw %ax, (%rsi)
leaq 0x2(%rsi), %rax
jmp 0x8d05
movq %rsi, %rax
cmpl $0xf4240, %edi          # imm = 0xF4240
jb 0x8d96
movl %r9d, %edi
leaq 0x61ce(%rip), %r9       # 0xee60
movb 0x1(%rdi,%r9), %dil
movb %dil, (%rax)
incq %rax
leaq 0x61bc(%rip), %rdi      # 0xee60
movb (%rdx,%rdi), %dil
movb %dil, (%rax)
incq %rax
movzwl %dx, %edx
leaq 0x61a8(%rip), %rdi      # 0xee60
movb 0x1(%rdx,%rdi), %dl
movb %dl, (%rax)
movb (%r8,%rdi), %dl
movb %dl, 0x1(%rax)
movzwl %r8w, %edx
movb 0x1(%rdx,%rdi), %dl
movb %dl, 0x2(%rax)
movb (%rcx,%rdi), %dl
movb %dl, 0x3(%rax)
movzwl %cx, %ecx
movb 0x1(%rcx,%rdi), %cl
movb %cl, 0x4(%rax)
addq $0x5, %rax
jmp 0x8d8e
movq %rsi, %rax
cmpl $0xa, %edi
jae 0x8c16
jmp 0x8c25
orb $0x30, %r8b
leaq 0x1(%rsi), %rax
movb %r8b, (%rsi)
movl %ecx, %r8d
movl $0xd1b71759, %edi       # imm = 0xD1B71759
imulq %r8, %rdi
shrq $0x2d, %rdi
imull $0x2710, %edi, %r9d     # imm = 0x2710
subl %r9d, %ecx
imulq $0x431bde83, %r8, %r8   # imm = 0x431BDE83
shrq $0x31, %r8
andl $-0x2, %r8d
movl $0xffff, %r9d           # imm = 0xFFFF
movl %edi, %r10d
andl %r9d, %r10d
shrl $0x2, %r10d
imull $0x147b, %r10d, %r10d   # imm = 0x147B
shrl $0x11, %r10d
imull $0x64, %r10d, %r10d
subl %r10d, %edi
andl %r9d, %edi
imull $0x147b, %ecx, %r10d    # imm = 0x147B
shrl $0x13, %r10d
imull $0x64, %r10d, %r11d
subl %r11d, %ecx
andl %r9d, %ecx
movzwl (%r8,%rdx), %r8d
movw %r8w, (%rax)
movzwl (%rdx,%rdi,2), %edi
movw %di, 0x2(%rax)
movzwl (%rdx,%r10,2), %edi
movw %di, 0x4(%rax)
movzwl (%rdx,%rcx,2), %ecx
movw %cx, 0x6(%rax)
addq $0x8, %rax
movb $0x0, (%rax)
subl %esi, %eax
incl %eax
retq
movq %rsi, %rax
cmpl $0x186a0, %edi          # imm = 0x186A0
jae 0x8c9d
jmp 0x8cae