#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int uint64_t;
typedef int int64_t;

/* Variables and functions */
int clz64(int);
int /*<<< orphan*/ reverse(char *);
char *lltoa(int64_t value, char *buf, int base) {
  switch (base) {
  default:
  case 10: {
    int i = 0;
    int64_t sign = value;
    if (value < 0)
      value = -value;
    uint64_t v = value;
    do {
      buf[i++] = '0' + v % 10;
      v /= 10;
    } while (v > 0);
    if (sign < 0)
      buf[i++] = '-';
    buf[i] = '\0';
    reverse(buf);
    break;
  }
  case 16: {
    int i = 0, lz = clz64(value) & 0x3c, nyb = 60 - lz;
    do {
      int64_t c = (value >> nyb) & 0xf;
      nyb -= 4;
      if (c > 9)
        c = 'A' + c - 10;
      else
        c = '0' + c;
      buf[i++] = c;
    } while (nyb >= 0);
    buf[i] = '\0';
  } break;
  }
  return buf;
}


x86 assembly (clang, -O0):
<lltoa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
sub    $0xa,%eax
je     115c <lltoa+0x3c>
jmp    1146 <lltoa+0x26>
mov    -0x34(%rbp),%eax
sub    $0x10,%eax
je     11f6 <lltoa+0xd6>
jmp    1157 <lltoa+0x37>
jmp    115c <lltoa+0x3c>
movl   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    117b <lltoa+0x5b>
xor    %eax,%eax
sub    -0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x30,%edx
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x18(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jg     1181 <lltoa+0x61>
cmpl   $0x0,-0x1c(%rbp)
jge    11dc <lltoa+0xbc>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x18(%rbp)
movslq %ecx,%rcx
movb   $0x2d,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1030 <reverse@plt>
jmp    1281 <lltoa+0x161>
movl   $0x0,-0x24(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <clz64@plt>
and    $0x3c,%eax
mov    %eax,-0x28(%rbp)
mov    $0x3c,%eax
sub    -0x28(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x4(%rbp),%eax
mov    -0x2c(%rbp),%ecx
sar    %cl,%eax
and    $0xf,%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
sub    $0x4,%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x9,-0x30(%rbp)
jle    1248 <lltoa+0x128>
mov    -0x30(%rbp),%eax
add    $0x41,%eax
sub    $0xa,%eax
mov    %eax,-0x30(%rbp)
jmp    1251 <lltoa+0x131>
mov    -0x30(%rbp),%eax
add    $0x30,%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x24(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
cmpl   $0x0,-0x2c(%rbp)
jge    1216 <lltoa+0xf6>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lltoa>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%r14d
cmp    $0x10,%edx
jne    1157 <lltoa+0x37>
mov    %r14d,%edi
call   1040 <clz64@plt>
and    $0x3c,%eax
mov    %eax,%ecx
xor    $0x3c,%ecx
mov    %ecx,%edx
shr    $0x2,%edx
add    $0x1,%rdx
test   %eax,%eax
je     11c4 <lltoa+0xa4>
xor    %eax,%eax
jmp    1870 <lltoa+0x750>
mov    %r14d,%ecx
neg    %ecx
cmovs  %r14d,%ecx
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movslq %ecx,%rdx
imul   $0x66666667,%rdx,%rcx
mov    %rcx,%rsi
shr    $0x3f,%rsi
sar    $0x22,%rcx
add    %esi,%ecx
lea    (%rcx,%rcx,1),%esi
lea    (%rsi,%rsi,4),%esi
mov    %edx,%edi
sub    %esi,%edi
add    $0x30,%dil
mov    %dil,(%rbx,%rax,1)
add    $0x1,%rax
cmp    $0x9,%edx
jg     1170 <lltoa+0x50>
test   %r14d,%r14d
jns    11b1 <lltoa+0x91>
mov    %eax,%ecx
add    $0x1,%rax
movb   $0x2d,(%rbx,%rcx,1)
cltq
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rdi
call   1030 <reverse@plt>
jmp    18a0 <lltoa+0x780>
mov    %edx,%eax
and    $0xfffffff0,%eax
movd   %ecx,%xmm0
pshufd $0x0,%xmm0,%xmm8
movdqa 0xe24(%rip),%xmm15
paddd  %xmm8,%xmm15
movdqa 0xe27(%rip),%xmm7
paddd  %xmm8,%xmm7
movdqa 0xe29(%rip),%xmm11
paddd  %xmm8,%xmm11
paddd  0xe2b(%rip),%xmm8
movd   %r14d,%xmm0
pshufd $0x0,%xmm0,%xmm9
lea    -0x10(%rax),%rsi
mov    %rsi,%r8
shr    $0x4,%r8
add    $0x1,%r8
test   %rsi,%rsi
je     18ac <lltoa+0x78c>
mov    %r8,%rdi
and    $0xfffffffffffffffe,%rdi
xor    %esi,%esi
movdqa 0xe16(%rip),%xmm13
movaps 0xe2e(%rip),%xmm14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movdqa %xmm7,(%rsp)
pshuflw $0xfe,%xmm11,%xmm0
movdqa %xmm9,%xmm1
psrad  %xmm0,%xmm1
pshuflw $0x54,%xmm11,%xmm2
movdqa %xmm9,%xmm0
psrad  %xmm2,%xmm0
pshufd $0xee,%xmm11,%xmm2
pshuflw $0xfe,%xmm2,%xmm3
movdqa %xmm9,%xmm4
psrad  %xmm3,%xmm4
punpcklqdq %xmm1,%xmm0
pshuflw $0x54,%xmm2,%xmm1
movdqa %xmm9,%xmm2
psrad  %xmm1,%xmm2
punpckhqdq %xmm4,%xmm2
pshuflw $0xfe,%xmm8,%xmm1
movdqa %xmm9,%xmm3
psrad  %xmm1,%xmm3
shufps $0xcc,%xmm2,%xmm0
pshuflw $0x54,%xmm8,%xmm1
movdqa %xmm9,%xmm5
psrad  %xmm1,%xmm5
pshufd $0xee,%xmm8,%xmm1
pshuflw $0xfe,%xmm1,%xmm2
movdqa %xmm9,%xmm4
psrad  %xmm2,%xmm4
punpcklqdq %xmm3,%xmm5
pshuflw $0x54,%xmm1,%xmm1
movdqa %xmm9,%xmm2
psrad  %xmm1,%xmm2
punpckhqdq %xmm4,%xmm2
pshuflw $0xfe,%xmm15,%xmm1
movdqa %xmm9,%xmm3
psrad  %xmm1,%xmm3
shufps $0xcc,%xmm2,%xmm5
pshuflw $0x54,%xmm15,%xmm1
movdqa %xmm9,%xmm4
psrad  %xmm1,%xmm4
pshufd $0xee,%xmm15,%xmm1
pshuflw $0xfe,%xmm1,%xmm2
movdqa %xmm9,%xmm6
psrad  %xmm2,%xmm6
punpcklqdq %xmm3,%xmm4
pshuflw $0x54,%xmm1,%xmm1
movdqa %xmm9,%xmm2
psrad  %xmm1,%xmm2
punpckhqdq %xmm6,%xmm2
pshuflw $0xfe,%xmm7,%xmm1
movdqa %xmm9,%xmm6
psrad  %xmm1,%xmm6
shufps $0xcc,%xmm2,%xmm4
pshuflw $0x54,%xmm7,%xmm1
movdqa %xmm9,%xmm3
psrad  %xmm1,%xmm3
pshufd $0xee,%xmm7,%xmm1
pshuflw $0xfe,%xmm1,%xmm2
movdqa %xmm9,%xmm7
psrad  %xmm2,%xmm7
punpcklqdq %xmm6,%xmm3
pshuflw $0x54,%xmm1,%xmm1
movdqa %xmm9,%xmm2
psrad  %xmm1,%xmm2
punpckhqdq %xmm7,%xmm2
shufps $0xcc,%xmm2,%xmm3
movaps 0xcb6(%rip),%xmm12
andps  %xmm12,%xmm3
andps  %xmm12,%xmm4
andps  %xmm12,%xmm5
andps  %xmm12,%xmm0
movaps %xmm0,%xmm2
pcmpgtd %xmm13,%xmm2
movaps %xmm5,%xmm1
pcmpgtd %xmm13,%xmm1
movaps %xmm3,%xmm10
pcmpgtd %xmm13,%xmm10
movaps %xmm3,%xmm6
movdqa 0xca1(%rip),%xmm12
paddd  %xmm12,%xmm6
orps   %xmm14,%xmm3
pand   %xmm10,%xmm6
pandn  %xmm3,%xmm10
movaps %xmm4,%xmm3
pcmpgtd %xmm13,%xmm3
por    %xmm6,%xmm10
movaps %xmm4,%xmm6
paddd  %xmm12,%xmm6
orps   %xmm14,%xmm4
pand   %xmm3,%xmm6
pandn  %xmm4,%xmm3
movaps %xmm0,%xmm4
paddd  %xmm12,%xmm4
por    %xmm6,%xmm3
movaps %xmm5,%xmm6
paddd  %xmm12,%xmm6
orps   %xmm14,%xmm0
orps   %xmm14,%xmm5
packuswb %xmm3,%xmm10
pand   %xmm1,%xmm6
pandn  %xmm5,%xmm1
por    %xmm6,%xmm1
pand   %xmm2,%xmm4
pandn  %xmm0,%xmm2
por    %xmm4,%xmm2
packuswb %xmm2,%xmm1
packuswb %xmm10,%xmm1
movdqu %xmm1,(%rbx,%rsi,1)
movdqa (%rsp),%xmm1
movdqa 0xc39(%rip),%xmm6
paddd  %xmm6,%xmm1
movdqa %xmm15,%xmm2
paddd  %xmm6,%xmm2
movdqa %xmm8,%xmm3
movdqa %xmm11,%xmm4
paddd  %xmm6,%xmm4
pshuflw $0xfe,%xmm4,%xmm0
movdqa %xmm9,%xmm5
psrad  %xmm0,%xmm5
paddd  %xmm6,%xmm3
pshuflw $0x54,%xmm4,%xmm6
movdqa %xmm9,%xmm0
psrad  %xmm6,%xmm0
pshufd $0xee,%xmm4,%xmm4
pshuflw $0xfe,%xmm4,%xmm6
movdqa %xmm9,%xmm7
psrad  %xmm6,%xmm7
punpcklqdq %xmm5,%xmm0
pshuflw $0x54,%xmm4,%xmm4
movdqa %xmm9,%xmm5
psrad  %xmm4,%xmm5
punpckhqdq %xmm7,%xmm5
pshuflw $0xfe,%xmm3,%xmm4
movdqa %xmm9,%xmm6
psrad  %xmm4,%xmm6
shufps $0xcc,%xmm5,%xmm0
pshuflw $0x54,%xmm3,%xmm4
movdqa %xmm9,%xmm5
psrad  %xmm4,%xmm5
pshufd $0xee,%xmm3,%xmm3
pshuflw $0xfe,%xmm3,%xmm4
movdqa %xmm9,%xmm7
psrad  %xmm4,%xmm7
punpcklqdq %xmm6,%xmm5
pshuflw $0x54,%xmm3,%xmm3
movdqa %xmm9,%xmm4
psrad  %xmm3,%xmm4
punpckhqdq %xmm7,%xmm4
pshuflw $0xfe,%xmm2,%xmm3
movdqa %xmm9,%xmm6
psrad  %xmm3,%xmm6
shufps $0xcc,%xmm4,%xmm5
pshuflw $0x54,%xmm2,%xmm3
movdqa %xmm9,%xmm4
psrad  %xmm3,%xmm4
pshufd $0xee,%xmm2,%xmm2
pshuflw $0xfe,%xmm2,%xmm3
movdqa %xmm9,%xmm7
psrad  %xmm3,%xmm7
punpcklqdq %xmm6,%xmm4
pshuflw $0x54,%xmm2,%xmm2
movdqa %xmm9,%xmm3
psrad  %xmm2,%xmm3
punpckhqdq %xmm7,%xmm3
pshuflw $0xfe,%xmm1,%xmm2
movdqa %xmm9,%xmm6
psrad  %xmm2,%xmm6
shufps $0xcc,%xmm3,%xmm4
pshuflw $0x54,%xmm1,%xmm3
movdqa %xmm9,%xmm2
psrad  %xmm3,%xmm2
pshufd $0xee,%xmm1,%xmm1
pshuflw $0xfe,%xmm1,%xmm3
movdqa %xmm9,%xmm7
psrad  %xmm3,%xmm7
punpcklqdq %xmm6,%xmm2
pshuflw $0x54,%xmm1,%xmm1
movdqa %xmm9,%xmm3
psrad  %xmm1,%xmm3
punpckhqdq %xmm7,%xmm3
shufps $0xcc,%xmm3,%xmm2
movaps 0xaaf(%rip),%xmm6
andps  %xmm6,%xmm2
andps  %xmm6,%xmm4
movaps %xmm2,%xmm1
pcmpgtd %xmm13,%xmm1
movaps %xmm2,%xmm3
paddd  %xmm12,%xmm3
orps   %xmm14,%xmm2
pand   %xmm1,%xmm3
pandn  %xmm2,%xmm1
movaps %xmm4,%xmm2
pcmpgtd %xmm13,%xmm2
por    %xmm3,%xmm1
movaps %xmm4,%xmm3
paddd  %xmm12,%xmm3
orps   %xmm14,%xmm4
pand   %xmm2,%xmm3
pandn  %xmm4,%xmm2
andps  %xmm6,%xmm5
andps  %xmm6,%xmm0
por    %xmm3,%xmm2
movaps %xmm5,%xmm3
pcmpgtd %xmm13,%xmm3
packuswb %xmm2,%xmm1
movaps %xmm5,%xmm2
paddd  %xmm12,%xmm2
orps   %xmm14,%xmm5
pand   %xmm3,%xmm2
pandn  %xmm5,%xmm3
movaps %xmm0,%xmm4
pcmpgtd %xmm13,%xmm4
por    %xmm2,%xmm3
movaps %xmm0,%xmm2
paddd  %xmm12,%xmm2
movdqa (%rsp),%xmm7
orps   %xmm14,%xmm0
pand   %xmm4,%xmm2
pandn  %xmm0,%xmm4
por    %xmm2,%xmm4
packuswb %xmm4,%xmm3
packuswb %xmm1,%xmm3
movdqu %xmm3,0x10(%rbx,%rsi,1)
add    $0x20,%rsi
movdqa 0xa50(%rip),%xmm0
paddd  %xmm0,%xmm8
paddd  %xmm0,%xmm11
paddd  %xmm0,%xmm7
paddd  %xmm0,%xmm15
add    $0xfffffffffffffffe,%rdi
jne    1250 <lltoa+0x130>
test   $0x1,%r8b
je     1857 <lltoa+0x737>
pshuflw $0xfe,%xmm11,%xmm0
movdqa %xmm9,%xmm1
psrad  %xmm0,%xmm1
pshuflw $0x54,%xmm11,%xmm0
movdqa %xmm9,%xmm10
psrad  %xmm0,%xmm10
punpcklqdq %xmm1,%xmm10
pshufd $0xee,%xmm11,%xmm0
pshuflw $0xfe,%xmm0,%xmm1
movdqa %xmm9,%xmm2
psrad  %xmm1,%xmm2
pshuflw $0x54,%xmm0,%xmm0
movdqa %xmm9,%xmm1
psrad  %xmm0,%xmm1
punpckhqdq %xmm2,%xmm1
shufps $0xcc,%xmm1,%xmm10
pshuflw $0xfe,%xmm8,%xmm0
movdqa %xmm9,%xmm1
psrad  %xmm0,%xmm1
pshuflw $0x54,%xmm8,%xmm0
movdqa %xmm9,%xmm11
psrad  %xmm0,%xmm11
punpcklqdq %xmm1,%xmm11
pshufd $0xee,%xmm8,%xmm0
pshuflw $0xfe,%xmm0,%xmm1
movdqa %xmm9,%xmm2
psrad  %xmm1,%xmm2
pshuflw $0x54,%xmm0,%xmm0
movdqa %xmm9,%xmm1
psrad  %xmm0,%xmm1
punpckhqdq %xmm2,%xmm1
shufps $0xcc,%xmm1,%xmm11
pshuflw $0xfe,%xmm15,%xmm0
movdqa %xmm9,%xmm1
psrad  %xmm0,%xmm1
pshuflw $0x54,%xmm15,%xmm0
movdqa %xmm9,%xmm5
psrad  %xmm0,%xmm5
punpcklqdq %xmm1,%xmm5
pshufd $0xee,%xmm15,%xmm0
pshuflw $0xfe,%xmm0,%xmm1
movdqa %xmm9,%xmm2
psrad  %xmm1,%xmm2
pshuflw $0x54,%xmm0,%xmm0
movdqa %xmm9,%xmm1
psrad  %xmm0,%xmm1
punpckhqdq %xmm2,%xmm1
shufps $0xcc,%xmm1,%xmm5
pshuflw $0xfe,%xmm7,%xmm0
movdqa %xmm9,%xmm2
psrad  %xmm0,%xmm2
pshuflw $0x54,%xmm7,%xmm0
movdqa %xmm9,%xmm1
psrad  %xmm0,%xmm1
punpcklqdq %xmm2,%xmm1
pshufd $0xee,%xmm7,%xmm0
pshuflw $0xfe,%xmm0,%xmm2
movdqa %xmm9,%xmm3
psrad  %xmm2,%xmm3
pshuflw $0x54,%xmm0,%xmm0
psrad  %xmm0,%xmm9
punpckhqdq %xmm3,%xmm9
shufps $0xcc,%xmm9,%xmm1
movaps 0x8a1(%rip),%xmm0
andps  %xmm0,%xmm1
andps  %xmm0,%xmm5
andps  %xmm0,%xmm11
andps  %xmm0,%xmm10
movdqa 0x89b(%rip),%xmm0
movaps %xmm10,%xmm3
pcmpgtd %xmm0,%xmm3
movaps %xmm11,%xmm2
pcmpgtd %xmm0,%xmm2
movaps %xmm5,%xmm4
pcmpgtd %xmm0,%xmm4
movaps %xmm1,%xmm6
pcmpgtd %xmm0,%xmm6
movdqa 0x885(%rip),%xmm0
movaps %xmm10,%xmm8
paddd  %xmm0,%xmm8
movaps %xmm11,%xmm9
paddd  %xmm0,%xmm9
movaps %xmm5,%xmm7
paddd  %xmm0,%xmm7
paddd  %xmm1,%xmm0
movaps 0x870(%rip),%xmm12
orps   %xmm12,%xmm10
orps   %xmm12,%xmm11
orps   %xmm12,%xmm5
orps   %xmm12,%xmm1
pand   %xmm6,%xmm0
pandn  %xmm1,%xmm6
por    %xmm0,%xmm6
pand   %xmm4,%xmm7
pandn  %xmm5,%xmm4
por    %xmm7,%xmm4
packuswb %xmm4,%xmm6
pand   %xmm2,%xmm9
pandn  %xmm11,%xmm2
por    %xmm9,%xmm2
pand   %xmm3,%xmm8
pandn  %xmm10,%xmm3
por    %xmm8,%xmm3
packuswb %xmm3,%xmm2
packuswb %xmm6,%xmm2
movdqu %xmm2,(%rbx,%rsi,1)
cmp    %rdx,%rax
je     189c <lltoa+0x77c>
lea    0x0(,%rax,4),%esi
sub    %esi,%ecx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14d,%esi
sar    %cl,%esi
and    $0xf,%esi
add    $0xfffffffc,%ecx
lea    0x30(%rsi),%edi
lea    0x37(%rsi),%ebp
cmp    $0xa,%esi
movzbl %bpl,%esi
movzbl %dil,%edi
cmovae %esi,%edi
mov    %dil,(%rbx,%rax,1)
add    $0x1,%rax
cmp    %rax,%rdx
jne    1870 <lltoa+0x750>
movb   $0x0,(%rbx,%rdx,1)
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %esi,%esi
test   $0x1,%r8b
jne    1667 <lltoa+0x547>
jmp    1857 <lltoa+0x737>

LLVM IR (-O0):
define i8* @lltoa(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%14 = load i32, i32* %6
switch i32 %14, label %15 [
i32 10, label %16
i32 16, label %56
]
15: ; preds = %3
br label %16
16: ; preds = %3, %15
store i32 0, i32* %7
%17 = load i32, i32* %4
store i32 %17, i32* %8
%18 = load i32, i32* %4
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i32, i32* %4
%22 = sub nsw i32 0, %21
store i32 %22, i32* %4
br label %23
23: ; preds = %20, %16
%24 = load i32, i32* %4
store i32 %24, i32* %9
br label %25
25: ; preds = %37, %23
%26 = load i32, i32* %9
%27 = srem i32 %26, 10
%28 = add nsw i32 48, %27
%29 = trunc i32 %28 to i8
%30 = load i8*, i8** %5
%31 = load i32, i32* %7
%32 = add nsw i32 %31, 1
store i32 %32, i32* %7
%33 = sext i32 %31 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
store i8 %29, i8* %34
%35 = load i32, i32* %9
%36 = sdiv i32 %35, 10
store i32 %36, i32* %9
br label %37
37: ; preds = %25
%38 = load i32, i32* %9
%39 = icmp sgt i32 %38, 0
br i1 %39, label %25, label %40
40: ; preds = %37
%41 = load i32, i32* %8
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %49
43: ; preds = %40
%44 = load i8*, i8** %5
%45 = load i32, i32* %7
%46 = add nsw i32 %45, 1
store i32 %46, i32* %7
%47 = sext i32 %45 to i64
%48 = getelementptr inbounds i8, i8* %44, i64 %47
store i8 45, i8* %48
br label %49
49: ; preds = %43, %40
%50 = load i8*, i8** %5
%51 = load i32, i32* %7
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
store i8 0, i8* %53
%54 = load i8*, i8** %5
%55 = call i32 @reverse(i8* %54)
br label %94
56: ; preds = %3
store i32 0, i32* %10
%57 = load i32, i32* %4
%58 = call i32 @clz64(i32 %57)
%59 = and i32 %58, 60
store i32 %59, i32* %11
%60 = load i32, i32* %11
%61 = sub nsw i32 60, %60
store i32 %61, i32* %12
br label %62
62: ; preds = %86, %56
%63 = load i32, i32* %4
%64 = load i32, i32* %12
%65 = ashr i32 %63, %64
%66 = and i32 %65, 15
store i32 %66, i32* %13
%67 = load i32, i32* %12
%68 = sub nsw i32 %67, 4
store i32 %68, i32* %12
%69 = load i32, i32* %13
%70 = icmp sgt i32 %69, 9
br i1 %70, label %71, label %75
71: ; preds = %62
%72 = load i32, i32* %13
%73 = add nsw i32 65, %72
%74 = sub nsw i32 %73, 10
store i32 %74, i32* %13
br label %78
75: ; preds = %62
%76 = load i32, i32* %13
%77 = add nsw i32 48, %76
store i32 %77, i32* %13
br label %78
78: ; preds = %75, %71
%79 = load i32, i32* %13
%80 = trunc i32 %79 to i8
%81 = load i8*, i8** %5
%82 = load i32, i32* %10
%83 = add nsw i32 %82, 1
store i32 %83, i32* %10
%84 = sext i32 %82 to i64
%85 = getelementptr inbounds i8, i8* %81, i64 %84
store i8 %80, i8* %85
br label %86
86: ; preds = %78
%87 = load i32, i32* %12
%88 = icmp sge i32 %87, 0
br i1 %88, label %62, label %89
89: ; preds = %86
%90 = load i8*, i8** %5
%91 = load i32, i32* %10
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds i8, i8* %90, i64 %92
store i8 0, i8* %93
br label %94
94: ; preds = %89, %49
%95 = load i8*, i8** %5
ret i8* %95
}

LLVM IR (-O2):
define i8* @lltoa(i32 %0, i8* returned %1, i32 %2) {
%4 = icmp eq i32 %2, 16
br i1 %4, label %30, label %5
5: ; preds = %3
%6 = icmp slt i32 %0, 0
%7 = sub nsw i32 0, %0
%8 = select i1 %6, i32 %7, i32 %0
br label %9
9: ; preds = %9, %5
%10 = phi i64 [ %15, %9 ], [ 0, %5 ]
%11 = phi i32 [ %17, %9 ], [ %8, %5 ]
%12 = srem i32 %11, 10
%13 = trunc i32 %12 to i8
%14 = add nsw i8 %13, 48
%15 = add nuw i64 %10, 1
%16 = getelementptr inbounds i8, i8* %1, i64 %10
store i8 %14, i8* %16
%17 = sdiv i32 %11, 10
%18 = icmp sgt i32 %11, 9
br i1 %18, label %9, label %19
19: ; preds = %9
br i1 %6, label %20, label %24
20: ; preds = %19
%21 = add i64 %10, 2
%22 = and i64 %15, 4294967295
%23 = getelementptr inbounds i8, i8* %1, i64 %22
store i8 45, i8* %23
br label %24
24: ; preds = %20, %19
%25 = phi i64 [ %21, %20 ], [ %15, %19 ]
%26 = shl i64 %25, 32
%27 = ashr exact i64 %26, 32
%28 = getelementptr inbounds i8, i8* %1, i64 %27
store i8 0, i8* %28
%29 = tail call i32 @reverse(i8* %1)
br label %118
30: ; preds = %3
%31 = tail call i32 @clz64(i32 %0)
%32 = and i32 %31, 60
%33 = xor i32 %32, 60
%34 = lshr exact i32 %33, 2
%35 = add nuw nsw i32 %34, 1
%36 = zext i32 %35 to i64
%37 = icmp eq i32 %32, 0
br i1 %37, label %38, label %99
38: ; preds = %30
%39 = and i64 %36, 16
%40 = trunc i64 %39 to i32
%41 = mul nsw i32 %40, -4
%42 = or i32 %33, %41
%43 = insertelement <16 x i32> poison, i32 %33, i64 0
%44 = shufflevector <16 x i32> %43, <16 x i32> poison, <16 x i32> zeroinitializer
%45 = add nsw <16 x i32> %44, <i32 0, i32 -4, i32 -8, i32 -12, i32 -16, i32 -20, i32 -24, i32 -28, i32 -32, i32 -36, i32 -40, i32 -44, i32 -48, i32 -52, i32 -56, i32 -60>
%46 = insertelement <16 x i32> poison, i32 %0, i64 0
%47 = shufflevector <16 x i32> %46, <16 x i32> poison, <16 x i32> zeroinitializer
%48 = add nsw i64 %39, -16
%49 = lshr exact i64 %48, 4
%50 = add nuw nsw i64 %49, 1
%51 = and i64 %50, 1
%52 = icmp eq i64 %48, 0
br i1 %52, label %83, label %53
53: ; preds = %38
%54 = and i64 %50, 2305843009213693950
br label %55
55: ; preds = %55, %53
%56 = phi i64 [ 0, %53 ], [ %79, %55 ]
%57 = phi <16 x i32> [ %45, %53 ], [ %80, %55 ]
%58 = phi i64 [ 0, %53 ], [ %81, %55 ]
%59 = ashr <16 x i32> %47, %57
%60 = and <16 x i32> %59, <i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15>
%61 = icmp ugt <16 x i32> %60, <i32 9, i32 9, i32 9, i32 9, i32 9, i32 9, i32 9, i32 9, i32 9, i32 9, i32 9, i32 9, i32 9, i32 9, i32 9, i32 9>
%62 = add nuw nsw <16 x i32> %60, <i32 55, i32 55, i32 55, i32 55, i32 55, i32 55, i32 55, i32 55, i32 55, i32 55, i32 55, i32 55, i32 55, i32 55, i32 55, i32 55>
%63 = or <16 x i32> %60, <i32 48, i32 48, i32 48, i32 48, i32 48, i32 48, i32 48, i32 48, i32 48, i32 48, i32 48, i32 48, i32 48, i32 48, i32 48, i32 48>
%64 = select <16 x i1> %61, <16 x i32> %62, <16 x i32> %63
%65 = trunc <16 x i32> %64 to <16 x i8>
%66 = getelementptr inbounds i8, i8* %1, i64 %56
%67 = bitcast i8* %66 to <16 x i8>*
store <16 x i8> %65, <16 x i8>* %67
%68 = or i64 %56, 16
%69 = add <16 x i32> %57, <i32 -64, i32 -64, i32 -64, i32 -64, i32 -64, i32 -64, i32 -64, i32 -64, i32 -64, i32 -64, i32 -64, i32 -64, i32 -64, i32 -64, i32 -64, i32 -64>
%70 = ashr <16 x i32> %47, %69
%71 = and <16 x i32> %70, <i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15>
%72 = icmp ugt <16 x i32> %71, <i32 9, i32 9, i32 9, i32 9, i32 9, i32 9, i32 9, i32 9, i32 9, i32 9, i32 9, i32 9, i32 9, i32 9, i32 9, i32 9>
%73 = add nuw nsw <16 x i32> %71, <i32 55, i32 55, i32 55, i32 55, i32 55, i32 55, i32 55, i32 55, i32 55, i32 55, i32 55, i32 55, i32 55, i32 55, i32 55, i32 55>
%74 = or <16 x i32> %71, <i32 48, i32 48, i32 48, i32 48, i32 48, i32 48, i32 48, i32 48, i32 48, i32 48, i32 48, i32 48, i32 48, i32 48, i32 48, i32 48>
%75 = select <16 x i1> %72, <16 x i32> %73, <16 x i32> %74
%76 = trunc <16 x i32> %75 to <16 x i8>
%77 = getelementptr inbounds i8, i8* %1, i64 %68
%78 = bitcast i8* %77 to <16 x i8>*
store <16 x i8> %76, <16 x i8>* %78
%79 = add nuw i64 %56, 32
%80 = add <16 x i32> %57, <i32 -128, i32 -128, i32 -128, i32 -128, i32 -128, i32 -128, i32 -128, i32 -128, i32 -128, i32 -128, i32 -128, i32 -128, i32 -128, i32 -128, i32 -128, i32 -128>
%81 = add i64 %58, 2
%82 = icmp eq i64 %81, %54
br i1 %82, label %83, label %55
83: ; preds = %55, %38
%84 = phi i64 [ 0, %38 ], [ %79, %55 ]
%85 = phi <16 x i32> [ %45, %38 ], [ %80, %55 ]
%86 = icmp eq i64 %51, 0
br i1 %86, label %97, label %87
87: ; preds = %83
%88 = ashr <16 x i32> %47, %85
%89 = and <16 x i32> %88, <i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15, i32 15>
%90 = icmp ugt <16 x i32> %89, <i32 9, i32 9, i32 9, i32 9, i32 9, i32 9, i32 9, i32 9, i32 9, i32 9, i32 9, i32 9, i32 9, i32 9, i32 9, i32 9>
%91 = add nuw nsw <16 x i32> %89, <i32 55, i32 55, i32 55, i32 55, i32 55, i32 55, i32 55, i32 55, i32 55, i32 55, i32 55, i32 55, i32 55, i32 55, i32 55, i32 55>
%92 = or <16 x i32> %89, <i32 48, i32 48, i32 48, i32 48, i32 48, i32 48, i32 48, i32 48, i32 48, i32 48, i32 48, i32 48, i32 48, i32 48, i32 48, i32 48>
%93 = select <16 x i1> %90, <16 x i32> %91, <16 x i32> %92
%94 = trunc <16 x i32> %93 to <16 x i8>
%95 = getelementptr inbounds i8, i8* %1, i64 %84
%96 = bitcast i8* %95 to <16 x i8>*
store <16 x i8> %94, <16 x i8>* %96
br label %97
97: ; preds = %83, %87
%98 = icmp eq i64 %39, %36
br i1 %98, label %116, label %99
99: ; preds = %30, %97
%100 = phi i64 [ 0, %30 ], [ %39, %97 ]
%101 = phi i32 [ %33, %30 ], [ %42, %97 ]
br label %102
102: ; preds = %99, %102
%103 = phi i64 [ %113, %102 ], [ %100, %99 ]
%104 = phi i32 [ %107, %102 ], [ %101, %99 ]
%105 = ashr i32 %0, %104
%106 = and i32 %105, 15
%107 = add nsw i32 %104, -4
%108 = icmp ugt i32 %106, 9
%109 = add nuw nsw i32 %106, 55
%110 = or i32 %106, 48
%111 = select i1 %108, i32 %109, i32 %110
%112 = trunc i32 %111 to i8
%113 = add nuw nsw i64 %103, 1
%114 = getelementptr inbounds i8, i8* %1, i64 %103
store i8 %112, i8* %114
%115 = icmp eq i64 %113, %36
br i1 %115, label %116, label %102
116: ; preds = %102, %97
%117 = getelementptr inbounds i8, i8* %1, i64 %36
store i8 0, i8* %117
br label %118
118: ; preds = %116, %24
ret i8* %1
}