// File: /workspace/github_c_makefile_star2_O1/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:
movl %edi, %eax
cmpl $0x270f, %edi           # imm = 0x270F
ja 0x8b9c
imulq $0x51eb851f, %rax, %rdx # imm = 0x51EB851F
shrq $0x25, %rdx
imull $0x64, %edx, %r8d
addl %edx, %edx
movq %rsi, %rax
cmpl $0x3e8, %edi            # imm = 0x3E8
jb 0x8b52
leaq 0x64b7(%rip), %rax      # 0xf000
movb (%rdx,%rax), %cl
leaq 0x1(%rsi), %rax
movb %cl, (%rsi)
movl %edi, %ecx
subl %r8d, %ecx
cmpl $0x64, %edi
jb 0x8b6f
movl %edx, %edx
leaq 0x649b(%rip), %r8       # 0xf000
movb 0x1(%rdx,%r8), %dl
movb %dl, (%rax)
incq %rax
addl %ecx, %ecx
cmpl $0xa, %edi
jb 0x8b85
leaq 0x6483(%rip), %rdx      # 0xf000
movb (%rcx,%rdx), %dl
movb %dl, (%rax)
incq %rax
movl %ecx, %ecx
leaq 0x6472(%rip), %rdx      # 0xf000
movb 0x1(%rcx,%rdx), %cl
movb %cl, (%rax)
incq %rax
jmp 0x8d38
cmpl $0x5f5e0ff, %edi        # imm = 0x5F5E0FF
ja 0x8c85
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
imulq $0x28f5c29, %rdx, %rax  # imm = 0x28F5C29
shrq $0x20, %rax
imull $0x64, %eax, %r10d
imulq $0x28f5c29, %rcx, %r8   # imm = 0x28F5C29
shrq $0x20, %r8
imull $0x64, %r8d, %eax
subl %eax, %ecx
movq %rsi, %rax
cmpl $0x989680, %edi         # imm = 0x989680
jb 0x8c0d
leaq 0x63fe(%rip), %rax      # 0xf000
movb (%r9,%rax), %r11b
leaq 0x1(%rsi), %rax
movb %r11b, (%rsi)
subl %r10d, %edx
addl %r8d, %r8d
addl %ecx, %ecx
cmpl $0xf4240, %edi          # imm = 0xF4240
jb 0x8c32
movl %r9d, %r9d
leaq 0x63d9(%rip), %r10      # 0xf000
movb 0x1(%r9,%r10), %r9b
movb %r9b, (%rax)
incq %rax
addl %edx, %edx
cmpl $0x186a0, %edi          # imm = 0x186A0
jb 0x8c4d
leaq 0x63bd(%rip), %rdi      # 0xf000
movb (%rdx,%rdi), %dil
movb %dil, (%rax)
incq %rax
movl %edx, %edx
leaq 0x63aa(%rip), %rdi      # 0xf000
movb 0x1(%rdx,%rdi), %dl
movb %dl, (%rax)
movb (%r8,%rdi), %dl
movb %dl, 0x1(%rax)
movl %r8d, %edx
movb 0x1(%rdx,%rdi), %dl
movb %dl, 0x2(%rax)
movb (%rcx,%rdi), %dl
movb %dl, 0x3(%rax)
movl %ecx, %ecx
movb 0x1(%rcx,%rdi), %cl
movb %cl, 0x4(%rax)
addq $0x5, %rax
jmp 0x8d38
imulq $0x55e63b89, %rax, %r8  # imm = 0x55E63B89
shrq $0x39, %r8
imull $0x5f5e100, %r8d, %eax  # imm = 0x5F5E100
movl %edi, %ecx
subl %eax, %ecx
leaq 0x635e(%rip), %rdx      # 0xf000
cmpl $0x3b9aca00, %edi       # imm = 0x3B9ACA00
jb 0x8cba
movl %r8d, %eax
movzwl (%rdx,%rax,2), %eax
movw %ax, (%rsi)
leaq 0x2(%rsi), %rax
jmp 0x8cc5
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
imulq $0x28f5c29, %rdi, %r9   # imm = 0x28F5C29
shrq $0x20, %r9
imull $0x64, %r9d, %r9d
subl %r9d, %edi
imulq $0x28f5c29, %rcx, %r9   # imm = 0x28F5C29
shrq $0x20, %r9
imull $0x64, %r9d, %r10d
subl %r10d, %ecx
movzwl (%r8,%rdx), %r8d
movw %r8w, (%rax)
movzwl (%rdx,%rdi,2), %edi
movw %di, 0x2(%rax)
movzwl (%rdx,%r9,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