void format_int(unsigned char *out, unsigned int in, unsigned char length,
                unsigned char endianess) {
  int i, idx;
  for (i = 0; i < length; i++) {
    idx = endianess == 0 ? i : length - 1 - i;
    out[i] = (in & 0xFF << idx * 8) >> idx * 8;
  }
}


x86 assembly (clang, -O0):
<format_int>:
push   %rbp
mov    %rsp,%rbp
mov    %cl,%al
mov    %dl,%cl
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %cl,-0xd(%rbp)
mov    %al,-0xe(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
movzbl -0xd(%rbp),%ecx
cmp    %ecx,%eax
jge    118d <format_int+0x8d>
movzbl -0xe(%rbp),%eax
cmp    $0x0,%eax
jne    1143 <format_int+0x43>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1150 <format_int+0x50>
movzbl -0xd(%rbp),%eax
sub    $0x1,%eax
sub    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x18(%rbp),%ecx
shl    $0x3,%ecx
mov    $0xff,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
mov    -0x18(%rbp),%ecx
shl    $0x3,%ecx
shr    %cl,%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    111c <format_int+0x1c>
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_int>:
push   %rbx
test   %edx,%edx
je     19f5 <format_int+0x8f5>
mov    %ecx,%r9d
movzbl %dl,%r8d
cmp    $0x10,%r8b
jae    111d <format_int+0x1d>
xor    %ebx,%ebx
jmp    19c2 <format_int+0x8c2>
mov    %r8d,%ebx
and    $0xfffffff0,%ebx
movd   %edx,%xmm0
pshufd $0x0,%xmm0,%xmm0
movdqa %xmm0,-0x40(%rsp)
movd   %esi,%xmm0
pshufd $0x0,%xmm0,%xmm0
movdqa %xmm0,-0x30(%rsp)
lea    -0x10(%rbx),%rax
mov    %rax,%r10
shr    $0x4,%r10
add    $0x1,%r10
test   %rax,%rax
je     1724 <format_int+0x624>
mov    %r10,%rcx
and    $0xfffffffffffffffe,%rcx
movdqa 0xe97(%rip),%xmm9
movdqa 0xe9f(%rip),%xmm2
movdqa 0xea6(%rip),%xmm10
movdqa 0xead(%rip),%xmm13
xor    %r11d,%r11d
movdqa 0xec1(%rip),%xmm12
jmp    1449 <format_int+0x349>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movdqa -0x40(%rsp),%xmm5
movdqa %xmm5,%xmm3
psubd  %xmm13,%xmm3
movdqa 0xeb9(%rip),%xmm1
paddd  %xmm1,%xmm3
movdqa %xmm5,%xmm2
psubd  %xmm10,%xmm2
paddd  %xmm1,%xmm2
movdqa %xmm5,%xmm0
movdqa %xmm9,%xmm11
psubd  %xmm9,%xmm0
paddd  %xmm1,%xmm0
movdqa -0x20(%rsp),%xmm9
psubd  %xmm9,%xmm5
paddd  %xmm1,%xmm5
movdqa %xmm3,%xmm8
movdqa %xmm2,%xmm14
pslld  $0x3,%xmm14
movdqa %xmm0,%xmm15
pslld  $0x3,%xmm15
movdqa %xmm5,%xmm6
pslld  $0x3,%xmm6
pslld  $0x1a,%xmm5
movdqa 0xe25(%rip),%xmm1
paddd  %xmm1,%xmm5
cvttps2dq %xmm5,%xmm5
pshufd $0xf5,%xmm5,%xmm7
pmuludq %xmm12,%xmm5
pshufd $0xe8,%xmm5,%xmm4
pmuludq %xmm12,%xmm7
pshufd $0xe8,%xmm7,%xmm7
punpckldq %xmm7,%xmm4
pslld  $0x1a,%xmm0
paddd  %xmm1,%xmm0
cvttps2dq %xmm0,%xmm0
pshufd $0xf5,%xmm0,%xmm7
pmuludq %xmm12,%xmm0
pshufd $0xe8,%xmm0,%xmm0
pmuludq %xmm12,%xmm7
pshufd $0xe8,%xmm7,%xmm7
punpckldq %xmm7,%xmm0
pslld  $0x1a,%xmm2
paddd  %xmm1,%xmm2
cvttps2dq %xmm2,%xmm2
pshufd $0xf5,%xmm2,%xmm7
pmuludq %xmm12,%xmm2
pshufd $0xe8,%xmm2,%xmm2
pmuludq %xmm12,%xmm7
pshufd $0xe8,%xmm7,%xmm7
punpckldq %xmm7,%xmm2
pslld  $0x1a,%xmm3
paddd  %xmm1,%xmm3
cvttps2dq %xmm3,%xmm3
pshufd $0xf5,%xmm3,%xmm7
pmuludq %xmm12,%xmm3
pshufd $0xe8,%xmm3,%xmm3
pmuludq %xmm12,%xmm7
pshufd $0xe8,%xmm7,%xmm7
punpckldq %xmm7,%xmm3
movdqa -0x30(%rsp),%xmm13
pand   %xmm13,%xmm2
pand   %xmm13,%xmm0
pand   %xmm13,%xmm4
pshufd $0xee,%xmm6,%xmm7
pshuflw $0xfe,%xmm7,%xmm1
movdqa %xmm4,%xmm5
psrld  %xmm1,%xmm5
pshuflw $0x54,%xmm7,%xmm1
movdqa %xmm4,%xmm7
psrld  %xmm1,%xmm7
punpckhqdq %xmm5,%xmm7
pshuflw $0xfe,%xmm6,%xmm1
movdqa %xmm4,%xmm5
psrld  %xmm1,%xmm5
pshuflw $0x54,%xmm6,%xmm1
psrld  %xmm1,%xmm4
punpcklqdq %xmm5,%xmm4
shufps $0xcc,%xmm7,%xmm4
pshufd $0xee,%xmm15,%xmm1
pshuflw $0xfe,%xmm1,%xmm5
movdqa %xmm0,%xmm6
psrld  %xmm5,%xmm6
pshuflw $0x54,%xmm1,%xmm1
movdqa %xmm0,%xmm5
psrld  %xmm1,%xmm5
punpckhqdq %xmm6,%xmm5
pshuflw $0xfe,%xmm15,%xmm1
movdqa %xmm0,%xmm6
psrld  %xmm1,%xmm6
pshuflw $0x54,%xmm15,%xmm1
psrld  %xmm1,%xmm0
pshufd $0xee,%xmm14,%xmm1
pshuflw $0xfe,%xmm1,%xmm15
movdqa %xmm2,%xmm7
psrld  %xmm15,%xmm7
pslld  $0x3,%xmm8
pand   %xmm13,%xmm3
punpcklqdq %xmm6,%xmm0
pshuflw $0x54,%xmm1,%xmm1
movdqa %xmm2,%xmm6
psrld  %xmm1,%xmm6
shufps $0xcc,%xmm5,%xmm0
pshuflw $0xfe,%xmm14,%xmm1
movdqa %xmm2,%xmm5
psrld  %xmm1,%xmm5
punpckhqdq %xmm7,%xmm6
pshuflw $0x54,%xmm14,%xmm1
psrld  %xmm1,%xmm2
pshufd $0xee,%xmm8,%xmm1
pshuflw $0xfe,%xmm1,%xmm14
movdqa %xmm3,%xmm7
psrld  %xmm14,%xmm7
punpcklqdq %xmm5,%xmm2
pshuflw $0x54,%xmm1,%xmm1
movdqa %xmm3,%xmm5
psrld  %xmm1,%xmm5
shufps $0xcc,%xmm6,%xmm2
pshuflw $0xfe,%xmm8,%xmm1
movdqa %xmm3,%xmm6
psrld  %xmm1,%xmm6
punpckhqdq %xmm7,%xmm5
pshuflw $0x54,%xmm8,%xmm1
psrld  %xmm1,%xmm3
punpcklqdq %xmm6,%xmm3
shufps $0xcc,%xmm5,%xmm3
andps  %xmm12,%xmm3
andps  %xmm12,%xmm2
packuswb %xmm2,%xmm3
andps  %xmm12,%xmm0
andps  %xmm12,%xmm4
packuswb %xmm4,%xmm0
packuswb %xmm0,%xmm3
movdqu %xmm3,0x10(%rdi,%r11,1)
add    $0x20,%r11
movdqa 0xc61(%rip),%xmm0
movdqa -0x10(%rsp),%xmm13
paddd  %xmm0,%xmm13
paddd  %xmm0,%xmm10
paddd  %xmm0,%xmm11
paddd  %xmm0,%xmm9
add    $0xfffffffffffffffe,%rcx
movdqa %xmm11,%xmm2
je     174a <format_int+0x64a>
movdqa %xmm9,%xmm5
movdqa %xmm2,%xmm0
movdqa %xmm10,%xmm6
movdqa %xmm13,%xmm15
test   %r9b,%r9b
je     14a0 <format_int+0x3a0>
movdqa %xmm9,%xmm5
pcmpeqd %xmm1,%xmm1
pxor   %xmm1,%xmm5
movdqa %xmm2,%xmm0
pxor   %xmm1,%xmm0
movdqa %xmm10,%xmm6
pxor   %xmm1,%xmm6
movdqa %xmm13,%xmm15
pxor   %xmm1,%xmm15
movdqa -0x40(%rsp),%xmm1
paddd  %xmm1,%xmm15
paddd  %xmm1,%xmm6
paddd  %xmm1,%xmm0
paddd  %xmm1,%xmm5
movdqa %xmm9,-0x20(%rsp)
movdqa %xmm2,%xmm9
movdqa %xmm15,%xmm7
pslld  $0x3,%xmm7
movdqa %xmm6,%xmm1
pslld  $0x3,%xmm1
movdqa %xmm0,%xmm3
pslld  $0x3,%xmm3
movdqa %xmm5,%xmm4
pslld  $0x3,%xmm4
pslld  $0x1a,%xmm5
movdqa 0xb61(%rip),%xmm11
paddd  %xmm11,%xmm5
cvttps2dq %xmm5,%xmm5
pshufd $0xf5,%xmm5,%xmm2
pmuludq %xmm12,%xmm5
pshufd $0xe8,%xmm5,%xmm14
pmuludq %xmm12,%xmm2
pshufd $0xe8,%xmm2,%xmm2
punpckldq %xmm2,%xmm14
pslld  $0x1a,%xmm0
paddd  %xmm11,%xmm0
cvttps2dq %xmm0,%xmm0
pshufd $0xf5,%xmm0,%xmm2
pmuludq %xmm12,%xmm0
pshufd $0xe8,%xmm0,%xmm0
pmuludq %xmm12,%xmm2
pshufd $0xe8,%xmm2,%xmm2
punpckldq %xmm2,%xmm0
pslld  $0x1a,%xmm6
paddd  %xmm11,%xmm6
cvttps2dq %xmm6,%xmm2
pshufd $0xf5,%xmm2,%xmm6
pmuludq %xmm12,%xmm2
pshufd $0xe8,%xmm2,%xmm8
pmuludq %xmm12,%xmm6
pshufd $0xe8,%xmm6,%xmm2
punpckldq %xmm2,%xmm8
pslld  $0x1a,%xmm15
paddd  %xmm11,%xmm15
cvttps2dq %xmm15,%xmm2
pshufd $0xf5,%xmm2,%xmm6
pmuludq %xmm12,%xmm2
pshufd $0xe8,%xmm2,%xmm2
pmuludq %xmm12,%xmm6
pshufd $0xe8,%xmm6,%xmm6
punpckldq %xmm6,%xmm2
movdqa -0x30(%rsp),%xmm5
pand   %xmm5,%xmm2
pand   %xmm5,%xmm8
pand   %xmm5,%xmm0
pand   %xmm5,%xmm14
pshufd $0xee,%xmm4,%xmm6
pshuflw $0xfe,%xmm6,%xmm15
movdqa %xmm14,%xmm5
psrld  %xmm15,%xmm5
pshuflw $0x54,%xmm6,%xmm15
movdqa %xmm14,%xmm6
psrld  %xmm15,%xmm6
punpckhqdq %xmm5,%xmm6
pshuflw $0xfe,%xmm4,%xmm15
movdqa %xmm14,%xmm5
psrld  %xmm15,%xmm5
pshuflw $0x54,%xmm4,%xmm4
psrld  %xmm4,%xmm14
punpcklqdq %xmm5,%xmm14
shufps $0xcc,%xmm6,%xmm14
pshufd $0xee,%xmm3,%xmm4
pshuflw $0xfe,%xmm4,%xmm5
movdqa %xmm0,%xmm6
psrld  %xmm5,%xmm6
pshuflw $0x54,%xmm4,%xmm4
movdqa %xmm0,%xmm5
psrld  %xmm4,%xmm5
punpckhqdq %xmm6,%xmm5
pshuflw $0xfe,%xmm3,%xmm4
movdqa %xmm0,%xmm6
psrld  %xmm4,%xmm6
pshuflw $0x54,%xmm3,%xmm3
psrld  %xmm3,%xmm0
punpcklqdq %xmm6,%xmm0
shufps $0xcc,%xmm5,%xmm0
pshufd $0xee,%xmm1,%xmm3
pshuflw $0xfe,%xmm3,%xmm4
movdqa %xmm8,%xmm5
psrld  %xmm4,%xmm5
pshuflw $0x54,%xmm3,%xmm3
movdqa %xmm8,%xmm4
psrld  %xmm3,%xmm4
punpckhqdq %xmm5,%xmm4
pshuflw $0xfe,%xmm1,%xmm3
movdqa %xmm8,%xmm5
psrld  %xmm3,%xmm5
pshuflw $0x54,%xmm1,%xmm1
psrld  %xmm1,%xmm8
punpcklqdq %xmm5,%xmm8
shufps $0xcc,%xmm4,%xmm8
pshufd $0xee,%xmm7,%xmm1
pshuflw $0xfe,%xmm1,%xmm3
movdqa %xmm2,%xmm4
psrld  %xmm3,%xmm4
pshuflw $0x54,%xmm1,%xmm1
movdqa %xmm2,%xmm3
psrld  %xmm1,%xmm3
punpckhqdq %xmm4,%xmm3
pshuflw $0xfe,%xmm7,%xmm1
movdqa %xmm2,%xmm4
psrld  %xmm1,%xmm4
pshuflw $0x54,%xmm7,%xmm1
psrld  %xmm1,%xmm2
punpcklqdq %xmm4,%xmm2
shufps $0xcc,%xmm3,%xmm2
andps  %xmm12,%xmm2
andps  %xmm12,%xmm8
packuswb %xmm8,%xmm2
andps  %xmm12,%xmm0
andps  %xmm12,%xmm14
packuswb %xmm14,%xmm0
packuswb %xmm0,%xmm2
movdqu %xmm2,(%rdi,%r11,1)
movdqa %xmm13,-0x10(%rsp)
jne    11a0 <format_int+0xa0>
movdqa %xmm13,%xmm3
movdqa 0x968(%rip),%xmm1
paddd  %xmm1,%xmm3
movdqa %xmm10,%xmm2
paddd  %xmm1,%xmm2
movdqa %xmm9,%xmm11
movdqa %xmm9,%xmm0
paddd  %xmm1,%xmm0
movdqa -0x20(%rsp),%xmm9
movdqa %xmm9,%xmm5
jmp    11e6 <format_int+0xe6>
movdqa 0x8d3(%rip),%xmm9
movdqa 0x8db(%rip),%xmm2
movdqa 0x8e2(%rip),%xmm10
movdqa 0x8e9(%rip),%xmm13
xor    %r11d,%r11d
test   $0x1,%r10b
je     19bd <format_int+0x8bd>
test   %r9b,%r9b
je     1789 <format_int+0x689>
pcmpeqd %xmm0,%xmm0
pxor   %xmm0,%xmm9
pxor   %xmm0,%xmm2
pxor   %xmm0,%xmm10
pxor   %xmm0,%xmm13
movdqa -0x40(%rsp),%xmm0
paddd  %xmm0,%xmm13
paddd  %xmm0,%xmm10
paddd  %xmm0,%xmm2
paddd  %xmm0,%xmm9
movdqa %xmm13,%xmm8
pslld  $0x3,%xmm8
movdqa %xmm10,%xmm14
pslld  $0x3,%xmm14
movdqa %xmm2,%xmm15
pslld  $0x3,%xmm15
movdqa %xmm9,%xmm5
pslld  $0x3,%xmm5
pslld  $0x1a,%xmm9
movdqa 0x87d(%rip),%xmm12
paddd  %xmm12,%xmm9
cvttps2dq %xmm9,%xmm0
movdqa 0x87a(%rip),%xmm11
pshufd $0xf5,%xmm0,%xmm1
pmuludq %xmm11,%xmm0
pshufd $0xe8,%xmm0,%xmm3
pmuludq %xmm11,%xmm1
pshufd $0xe8,%xmm1,%xmm0
punpckldq %xmm0,%xmm3
pslld  $0x1a,%xmm2
paddd  %xmm12,%xmm2
cvttps2dq %xmm2,%xmm0
pshufd $0xf5,%xmm0,%xmm1
pmuludq %xmm11,%xmm0
pshufd $0xe8,%xmm0,%xmm0
pmuludq %xmm11,%xmm1
pshufd $0xe8,%xmm1,%xmm1
punpckldq %xmm1,%xmm0
pslld  $0x1a,%xmm10
paddd  %xmm12,%xmm10
cvttps2dq %xmm10,%xmm1
pshufd $0xf5,%xmm1,%xmm2
pmuludq %xmm11,%xmm1
pshufd $0xe8,%xmm1,%xmm1
pmuludq %xmm11,%xmm2
pshufd $0xe8,%xmm2,%xmm2
punpckldq %xmm2,%xmm1
pslld  $0x1a,%xmm13
paddd  %xmm12,%xmm13
cvttps2dq %xmm13,%xmm2
pshufd $0xf5,%xmm2,%xmm4
pmuludq %xmm11,%xmm2
pshufd $0xe8,%xmm2,%xmm2
pmuludq %xmm11,%xmm4
pshufd $0xe8,%xmm4,%xmm4
punpckldq %xmm4,%xmm2
movdqa -0x30(%rsp),%xmm4
pand   %xmm4,%xmm2
pand   %xmm4,%xmm1
pand   %xmm4,%xmm0
pand   %xmm4,%xmm3
pshufd $0xee,%xmm5,%xmm4
pshuflw $0xfe,%xmm4,%xmm7
movdqa %xmm3,%xmm6
psrld  %xmm7,%xmm6
pshuflw $0x54,%xmm4,%xmm4
movdqa %xmm3,%xmm7
psrld  %xmm4,%xmm7
punpckhqdq %xmm6,%xmm7
pshuflw $0xfe,%xmm5,%xmm4
movdqa %xmm3,%xmm6
psrld  %xmm4,%xmm6
pshuflw $0x54,%xmm5,%xmm4
psrld  %xmm4,%xmm3
punpcklqdq %xmm6,%xmm3
shufps $0xcc,%xmm7,%xmm3
pshufd $0xee,%xmm15,%xmm4
pshuflw $0xfe,%xmm4,%xmm5
movdqa %xmm0,%xmm6
psrld  %xmm5,%xmm6
pshuflw $0x54,%xmm4,%xmm4
movdqa %xmm0,%xmm5
psrld  %xmm4,%xmm5
punpckhqdq %xmm6,%xmm5
pshuflw $0xfe,%xmm15,%xmm4
movdqa %xmm0,%xmm6
psrld  %xmm4,%xmm6
pshuflw $0x54,%xmm15,%xmm4
psrld  %xmm4,%xmm0
punpcklqdq %xmm6,%xmm0
shufps $0xcc,%xmm5,%xmm0
pshufd $0xee,%xmm14,%xmm4
pshuflw $0xfe,%xmm4,%xmm5
movdqa %xmm1,%xmm6
psrld  %xmm5,%xmm6
pshuflw $0x54,%xmm4,%xmm4
movdqa %xmm1,%xmm5
psrld  %xmm4,%xmm5
punpckhqdq %xmm6,%xmm5
pshuflw $0xfe,%xmm14,%xmm4
movdqa %xmm1,%xmm6
psrld  %xmm4,%xmm6
pshuflw $0x54,%xmm14,%xmm4
psrld  %xmm4,%xmm1
punpcklqdq %xmm6,%xmm1
shufps $0xcc,%xmm5,%xmm1
pshufd $0xee,%xmm8,%xmm4
pshuflw $0xfe,%xmm4,%xmm5
movdqa %xmm2,%xmm6
psrld  %xmm5,%xmm6
pshuflw $0x54,%xmm4,%xmm4
movdqa %xmm2,%xmm5
psrld  %xmm4,%xmm5
punpckhqdq %xmm6,%xmm5
pshuflw $0xfe,%xmm8,%xmm4
movdqa %xmm2,%xmm6
psrld  %xmm4,%xmm6
pshuflw $0x54,%xmm8,%xmm4
psrld  %xmm4,%xmm2
punpcklqdq %xmm6,%xmm2
shufps $0xcc,%xmm5,%xmm2
andps  %xmm11,%xmm2
andps  %xmm11,%xmm1
packuswb %xmm1,%xmm2
andps  %xmm11,%xmm0
andps  %xmm11,%xmm3
packuswb %xmm3,%xmm0
packuswb %xmm0,%xmm2
movdqu %xmm2,(%rdi,%r11,1)
cmp    %r8,%rbx
je     19f5 <format_int+0x8f5>
mov    %ebx,%eax
not    %eax
add    %edx,%eax
nopl   0x0(%rax,%rax,1)
test   %r9b,%r9b
mov    %ebx,%ecx
cmovne %eax,%ecx
shl    $0x3,%ecx
mov    $0xff,%edx
shl    %cl,%edx
and    %esi,%edx
shr    %cl,%edx
mov    %dl,(%rdi,%rbx,1)
add    $0x1,%rbx
add    $0xffffffff,%eax
cmp    %rbx,%r8
jne    19d0 <format_int+0x8d0>
pop    %rbx
ret

LLVM IR (-O0):
define void @format_int(i8* %0, i32 %1, i8 zeroext %2, i8 zeroext %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8
%8 = alloca i8
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8 %2, i8* %7
store i8 %3, i8* %8
store i32 0, i32* %9
br label %11
11: ; preds = %43, %4
%12 = load i32, i32* %9
%13 = load i8, i8* %7
%14 = zext i8 %13 to i32
%15 = icmp slt i32 %12, %14
br i1 %15, label %16, label %46
16: ; preds = %11
%17 = load i8, i8* %8
%18 = zext i8 %17 to i32
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = load i32, i32* %9
br label %28
22: ; preds = %16
%23 = load i8, i8* %7
%24 = zext i8 %23 to i32
%25 = sub nsw i32 %24, 1
%26 = load i32, i32* %9
%27 = sub nsw i32 %25, %26
br label %28
28: ; preds = %22, %20
%29 = phi i32 [ %21, %20 ], [ %27, %22 ]
store i32 %29, i32* %10
%30 = load i32, i32* %6
%31 = load i32, i32* %10
%32 = mul nsw i32 %31, 8
%33 = shl i32 255, %32
%34 = and i32 %30, %33
%35 = load i32, i32* %10
%36 = mul nsw i32 %35, 8
%37 = lshr i32 %34, %36
%38 = trunc i32 %37 to i8
%39 = load i8*, i8** %5
%40 = load i32, i32* %9
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
store i8 %38, i8* %42
br label %43
43: ; preds = %28
%44 = load i32, i32* %9
%45 = add nsw i32 %44, 1
store i32 %45, i32* %9
br label %11
46: ; preds = %11
ret void
}

LLVM IR (-O2):
define void @format_int(i8* nocapture writeonly %0, i32 %1, i8 zeroext %2, i8 zeroext %3) {
%5 = zext i8 %2 to i32
%6 = icmp eq i8 %2, 0
br i1 %6, label %87, label %7
7: ; preds = %4
%8 = icmp eq i8 %3, 0
%9 = zext i8 %2 to i64
%10 = icmp ult i8 %2, 16
br i1 %10, label %71, label %11
11: ; preds = %7
%12 = and i64 %9, 240
%13 = insertelement <16 x i32> poison, i32 %5, i64 0
%14 = shufflevector <16 x i32> %13, <16 x i32> poison, <16 x i32> zeroinitializer
%15 = insertelement <16 x i32> poison, i32 %1, i64 0
%16 = shufflevector <16 x i32> %15, <16 x i32> poison, <16 x i32> zeroinitializer
%17 = add nsw i64 %12, -16
%18 = lshr exact i64 %17, 4
%19 = add nuw nsw i64 %18, 1
%20 = and i64 %19, 1
%21 = icmp eq i64 %17, 0
br i1 %21, label %54, label %22
22: ; preds = %11
%23 = and i64 %19, 2305843009213693950
br label %24
24: ; preds = %24, %22
%25 = phi i64 [ 0, %22 ], [ %50, %24 ]
%26 = phi <16 x i32> [ <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>, %22 ], [ %51, %24 ]
%27 = phi i64 [ 0, %22 ], [ %52, %24 ]
%28 = xor <16 x i32> %26, <i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1>
%29 = add nsw <16 x i32> %14, %28
%30 = select i1 %8, <16 x i32> %26, <16 x i32> %29
%31 = shl nsw <16 x i32> %30, <i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3>
%32 = shl <16 x i32> <i32 255, i32 255, i32 255, i32 255, i32 255, i32 255, i32 255, i32 255, i32 255, i32 255, i32 255, i32 255, i32 255, i32 255, i32 255, i32 255>, %31
%33 = and <16 x i32> %32, %16
%34 = lshr <16 x i32> %33, %31
%35 = trunc <16 x i32> %34 to <16 x i8>
%36 = getelementptr inbounds i8, i8* %0, i64 %25
%37 = bitcast i8* %36 to <16 x i8>*
store <16 x i8> %35, <16 x i8>* %37
%38 = or i64 %25, 16
%39 = add <16 x i32> %26, <i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16>
%40 = sub <16 x i32> <i32 -17, i32 -17, i32 -17, i32 -17, i32 -17, i32 -17, i32 -17, i32 -17, i32 -17, i32 -17, i32 -17, i32 -17, i32 -17, i32 -17, i32 -17, i32 -17>, %26
%41 = add nsw <16 x i32> %14, %40
%42 = select i1 %8, <16 x i32> %39, <16 x i32> %41
%43 = shl nsw <16 x i32> %42, <i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3>
%44 = shl <16 x i32> <i32 255, i32 255, i32 255, i32 255, i32 255, i32 255, i32 255, i32 255, i32 255, i32 255, i32 255, i32 255, i32 255, i32 255, i32 255, i32 255>, %43
%45 = and <16 x i32> %44, %16
%46 = lshr <16 x i32> %45, %43
%47 = trunc <16 x i32> %46 to <16 x i8>
%48 = getelementptr inbounds i8, i8* %0, i64 %38
%49 = bitcast i8* %48 to <16 x i8>*
store <16 x i8> %47, <16 x i8>* %49
%50 = add nuw i64 %25, 32
%51 = add <16 x i32> %26, <i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32>
%52 = add i64 %27, 2
%53 = icmp eq i64 %52, %23
br i1 %53, label %54, label %24
54: ; preds = %24, %11
%55 = phi i64 [ 0, %11 ], [ %50, %24 ]
%56 = phi <16 x i32> [ <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>, %11 ], [ %51, %24 ]
%57 = icmp eq i64 %20, 0
br i1 %57, label %69, label %58
58: ; preds = %54
%59 = xor <16 x i32> %56, <i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1>
%60 = add nsw <16 x i32> %14, %59
%61 = select i1 %8, <16 x i32> %56, <16 x i32> %60
%62 = shl nsw <16 x i32> %61, <i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3>
%63 = shl <16 x i32> <i32 255, i32 255, i32 255, i32 255, i32 255, i32 255, i32 255, i32 255, i32 255, i32 255, i32 255, i32 255, i32 255, i32 255, i32 255, i32 255>, %62
%64 = and <16 x i32> %63, %16
%65 = lshr <16 x i32> %64, %62
%66 = trunc <16 x i32> %65 to <16 x i8>
%67 = getelementptr inbounds i8, i8* %0, i64 %55
%68 = bitcast i8* %67 to <16 x i8>*
store <16 x i8> %66, <16 x i8>* %68
br label %69
69: ; preds = %54, %58
%70 = icmp eq i64 %12, %9
br i1 %70, label %87, label %71
71: ; preds = %7, %69
%72 = phi i64 [ 0, %7 ], [ %12, %69 ]
br label %73
73: ; preds = %71, %73
%74 = phi i64 [ %85, %73 ], [ %72, %71 ]
%75 = trunc i64 %74 to i32
%76 = xor i32 %75, -1
%77 = add nsw i32 %76, %5
%78 = select i1 %8, i32 %75, i32 %77
%79 = shl nsw i32 %78, 3
%80 = shl i32 255, %79
%81 = and i32 %80, %1
%82 = lshr i32 %81, %79
%83 = trunc i32 %82 to i8
%84 = getelementptr inbounds i8, i8* %0, i64 %74
store i8 %83, i8* %84
%85 = add nuw nsw i64 %74, 1
%86 = icmp eq i64 %85, %9
br i1 %86, label %87, label %73
87: ; preds = %73, %69, %4
ret void
}