#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 /*<<< orphan*/ postfix;

/* Variables and functions */
char *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, unsigned long, ...);
unsigned int strlen(char *);
char *num2str(unsigned long num, int maxlen, int base, int pow2,
              int unit_base) {
  const char *postfix[] = {"", "K", "M", "G", "P", "E"};
  const char *byte_postfix[] = {"", "B", "bit"};
  const unsigned int thousand[] = {1000, 1024};
  unsigned int modulo, decimals;
  int byte_post_index = 0, post_index, carry = 0;
  char tmp[32];
  char *buf;
  buf = malloc(128);
  for (post_index = 0; base > 1; post_index++)
    base /= thousand[!!pow2];
  switch (unit_base) {
  case 1:
    byte_post_index = 2;
    num *= 8;
    break;
  case 8:
    byte_post_index = 1;
    break;
  }
  modulo = -1U;
  while (post_index < sizeof(postfix)) {
    sprintf(tmp, "%lu", num);
    if (strlen(tmp) <= maxlen)
      break;
    modulo = num % thousand[!!pow2];
    num /= thousand[!!pow2];
    carry = modulo >= thousand[!!pow2] / 2;
    post_index++;
  }
  if (modulo == -1U) {
  done:
    sprintf(buf, "%lu%s%s", num, postfix[post_index],
            byte_postfix[byte_post_index]);
    return buf;
  }
  sprintf(tmp, "%lu", num);
  decimals = maxlen - strlen(tmp);
  if (decimals <= 1) {
    if (carry)
      num++;
    goto done;
  }
  do {
    sprintf(tmp, "%u", modulo);
    if (strlen(tmp) <= decimals - 1)
      break;
    modulo = (modulo + 9) / 10;
  } while (1);
  sprintf(buf, "%lu.%u%s%s", num, modulo, postfix[post_index],
          byte_postfix[byte_post_index]);
  return buf;
}


x86 assembly (clang, -O0):
<num2str>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1040 <memset@plt>
lea    0xe98(%rip),%rax
mov    %rax,-0x50(%rbp)
lea    0xe82(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    0xe79(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xe70(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xe67(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xe5e(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2c4b(%rip),%rax
mov    %rax,-0x70(%rbp)
mov    0x2c48(%rip),%rax
mov    %rax,-0x68(%rbp)
mov    0x2c45(%rip),%rax
mov    %rax,-0x60(%rbp)
mov    0xe56(%rip),%rax
mov    %rax,-0x78(%rbp)
movl   $0x0,-0x84(%rbp)
movl   $0x0,-0x8c(%rbp)
mov    $0x80,%edi
call   1050 <malloc@plt>
mov    %rax,-0xb8(%rbp)
movl   $0x0,-0x88(%rbp)
cmpl   $0x1,-0x18(%rbp)
jle    1247 <num2str+0x107>
cmpl   $0x0,-0x1c(%rbp)
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
cltq
mov    -0x78(%rbp,%rax,4),%ecx
mov    -0x18(%rbp),%eax
xor    %edx,%edx
div    %ecx
mov    %eax,-0x18(%rbp)
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    1209 <num2str+0xc9>
mov    -0x20(%rbp),%eax
mov    %eax,-0xbc(%rbp)
sub    $0x1,%eax
je     1272 <num2str+0x132>
jmp    125e <num2str+0x11e>
mov    -0xbc(%rbp),%eax
sub    $0x8,%eax
je     128d <num2str+0x14d>
jmp    1297 <num2str+0x157>
movl   $0x2,-0x84(%rbp)
mov    -0x10(%rbp),%rax
shl    $0x3,%rax
mov    %rax,-0x10(%rbp)
jmp    1297 <num2str+0x157>
movl   $0x1,-0x84(%rbp)
movl   $0xffffffff,-0x7c(%rbp)
movslq -0x88(%rbp),%rax
cmp    $0x30,%rax
jae    1373 <num2str+0x233>
lea    -0xb0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xd4f(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
lea    -0xb0(%rbp),%rdi
call   1030 <strlen@plt>
cmp    -0x14(%rbp),%eax
ja     12e2 <num2str+0x1a2>
jmp    1373 <num2str+0x233>
mov    -0x10(%rbp),%rax
cmpl   $0x0,-0x1c(%rbp)
setne  %cl
xor    $0xff,%cl
xor    $0xff,%cl
and    $0x1,%cl
movzbl %cl,%ecx
movslq %ecx,%rcx
mov    -0x78(%rbp,%rcx,4),%ecx
xor    %edx,%edx
div    %rcx
mov    %edx,%eax
mov    %eax,-0x7c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
cltq
mov    -0x78(%rbp,%rax,4),%eax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
xor    %edx,%edx
div    %rcx
mov    %rax,-0x10(%rbp)
mov    -0x7c(%rbp),%eax
cmpl   $0x0,-0x1c(%rbp)
setne  %cl
xor    $0xff,%cl
xor    $0xff,%cl
and    $0x1,%cl
movzbl %cl,%ecx
movslq %ecx,%rcx
mov    -0x78(%rbp,%rcx,4),%ecx
shr    $0x1,%ecx
cmp    %ecx,%eax
setae  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x8c(%rbp)
mov    -0x88(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x88(%rbp)
jmp    129e <num2str+0x15e>
cmpl   $0xffffffff,-0x7c(%rbp)
jne    13c3 <num2str+0x283>
jmp    1382 <num2str+0x242>
mov    -0xb8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
movslq -0x88(%rbp),%rax
mov    -0x50(%rbp,%rax,8),%rcx
movslq -0x84(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%r8
lea    0xc68(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    -0xb8(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    14c4 <num2str+0x384>
lea    -0xb0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xc3b(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0xc0(%rbp)
lea    -0xb0(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0xc0(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x80(%rbp)
cmpl   $0x1,-0x80(%rbp)
ja     1426 <num2str+0x2e6>
cmpl   $0x0,-0x8c(%rbp)
je     1421 <num2str+0x2e1>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1382 <num2str+0x242>
jmp    142b <num2str+0x2eb>
lea    -0xb0(%rbp),%rdi
mov    -0x7c(%rbp),%eax
mov    %eax,%edx
lea    0xbde(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
lea    -0xb0(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x80(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
ja     1464 <num2str+0x324>
jmp    1485 <num2str+0x345>
mov    -0x7c(%rbp),%eax
add    $0x9,%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x7c(%rbp)
mov    $0x1,%al
test   $0x1,%al
jne    142b <num2str+0x2eb>
jmp    1485 <num2str+0x345>
mov    -0xb8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x7c(%rbp),%ecx
movslq -0x88(%rbp),%rax
mov    -0x50(%rbp,%rax,8),%r8
movslq -0x84(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%r9
lea    0xb6d(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    -0xb8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<num2str>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %r8d,%ebx
mov    %ecx,%r15d
mov    %edx,%ebp
mov    %esi,%r12d
mov    %rdi,%r13
lea    0xeb8(%rip),%rax
mov    %rax,0x20(%rsp)
lea    0xea1(%rip),%rax
mov    %rax,0x28(%rsp)
lea    0xe97(%rip),%rax
mov    %rax,0x30(%rsp)
lea    0xe8d(%rip),%rax
mov    %rax,0x38(%rsp)
lea    0xe83(%rip),%rax
mov    %rax,0x40(%rsp)
lea    0xe79(%rip),%rax
mov    %rax,0x48(%rsp)
mov    $0x80,%edi
call   1040 <malloc@plt>
mov    %rax,%rsi
xor    %r14d,%r14d
cmp    $0x2,%ebp
jl     11d1 <num2str+0xa1>
xor    %eax,%eax
test   %r15d,%r15d
setne  %al
lea    0xe74(%rip),%rcx
mov    (%rcx,%rax,4),%ecx
xor    %r14d,%r14d
xchg   %ax,%ax
mov    %ebp,%eax
xor    %edx,%edx
div    %ecx
add    $0x1,%r14d
mov    %eax,%ebp
cmp    $0x1,%eax
ja     11c0 <num2str+0x90>
cmp    $0x8,%ebx
mov    %rsi,0x10(%rsp)
je     11f1 <num2str+0xc1>
cmp    $0x1,%ebx
jne    1204 <num2str+0xd4>
shl    $0x3,%r13
mov    $0x2,%edx
cmp    $0x30,%r14d
jae    11fc <num2str+0xcc>
jmp    120c <num2str+0xdc>
mov    $0x1,%edx
cmp    $0x30,%r14d
jb     120c <num2str+0xdc>
mov    %r14d,%r15d
jmp    135e <num2str+0x22e>
xor    %edx,%edx
cmp    $0x30,%r14d
jae    11fc <num2str+0xcc>
mov    %rdx,(%rsp)
xor    %ebp,%ebp
test   %r15d,%r15d
setne  %r15b
lea    0xdf0(%rip),%rsi
lea    0x50(%rsp),%rbx
mov    %rbx,%rdi
mov    %r13,%rdx
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %r12d,0xc(%rsp)
cmp    %r12d,%eax
jbe    12c9 <num2str+0x199>
mov    %r15b,%bpl
lea    0xdda(%rip),%rax
mov    (%rax,%rbp,4),%r15d
lea    0x50(%rsp),%rbp
nopl   0x0(%rax,%rax,1)
mov    %r13,%r12
mov    %r13,%rbx
shr    $0x20,%rbx
je     1280 <num2str+0x150>
mov    %r12,%rax
xor    %edx,%edx
div    %r15
mov    %rax,%r13
cmp    $0x2f,%r14d
jne    1291 <num2str+0x161>
jmp    12d7 <num2str+0x1a7>
nop
mov    %r12d,%eax
xor    %edx,%edx
div    %r15d
mov    %eax,%r13d
cmp    $0x2f,%r14d
je     12d7 <num2str+0x1a7>
mov    %rbp,%rdi
lea    0xd75(%rip),%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    %rbp,%rdi
call   1030 <strlen@plt>
add    $0x1,%r14d
cmp    0xc(%rsp),%eax
ja     1260 <num2str+0x130>
test   %rbx,%rbx
je     1308 <num2str+0x1d8>
mov    %r12,%rax
xor    %edx,%edx
div    %r15
mov    %rdx,%rbp
jmp    1312 <num2str+0x1e2>
mov    $0xffffffff,%ebp
mov    (%rsp),%rdx
xor    %r12d,%r12d
jmp    1323 <num2str+0x1f3>
test   %rbx,%rbx
je     12e9 <num2str+0x1b9>
mov    %r12,%rax
xor    %edx,%edx
div    %r15
mov    %rdx,%rbp
jmp    12f3 <num2str+0x1c3>
mov    %r12d,%eax
xor    %edx,%edx
div    %r15d
mov    %edx,%ebp
shr    %r15d
xor    %r12d,%r12d
cmp    %ebp,%r15d
setbe  %r12b
mov    $0x30,%r15d
jmp    132b <num2str+0x1fb>
mov    %r12d,%eax
xor    %edx,%edx
div    %r15d
mov    %edx,%ebp
mov    (%rsp),%rdx
shr    %r15d
xor    %r12d,%r12d
cmp    %ebp,%r15d
setbe  %r12b
mov    %r14d,%r15d
cmp    $0xffffffff,%ebp
je     135e <num2str+0x22e>
lea    0xcde(%rip),%rsi
lea    0x50(%rsp),%rbx
mov    %rbx,%rdi
mov    %r13,%rdx
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    0xc(%rsp),%ebx
sub    %eax,%ebx
cmp    $0x2,%ebx
jae    1399 <num2str+0x269>
add    %r12,%r13
mov    (%rsp),%rdx
mov    0x20(%rsp,%r15,8),%rcx
lea    0x2a96(%rip),%rax
mov    (%rax,%rdx,8),%r8
lea    0xc9f(%rip),%rsi
mov    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %r13,%rdx
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    %rbx,%rax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebp,%edx
lea    0xc7a(%rip),%rsi
lea    0x50(%rsp),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
add    $0xffffffff,%ebx
cmp    %ebx,%eax
mov    %r15,0x18(%rsp)
jbe    1408 <num2str+0x2d8>
mov    %ebx,%r14d
mov    $0xcccccccd,%r12d
lea    0xc47(%rip),%r15
lea    0x50(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
add    $0x9,%ebp
imul   %r12,%rbp
shr    $0x23,%rbp
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    %r14d,%eax
ja     13e0 <num2str+0x2b0>
mov    0x18(%rsp),%rax
mov    0x20(%rsp,%rax,8),%r8
lea    0x29e7(%rip),%rax
mov    (%rsp),%rcx
mov    (%rax,%rcx,8),%r9
lea    0xbf7(%rip),%rsi
mov    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %r13,%rdx
mov    %ebp,%ecx
xor    %eax,%eax
call   1050 <sprintf@plt>
jmp    1387 <num2str+0x257>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c"K\00"
@.str.2 = [2 x i8] c"M\00"
@.str.3 = [2 x i8] c"G\00"
@.str.4 = [2 x i8] c"P\00"
@.str.5 = [2 x i8] c"E\00"
@.str.6 = [2 x i8] c"B\00"
@.str.7 = [4 x i8] c"bit\00"
@__const.num2str.byte_postfix = [3 x i8*] [i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i32 0, i32 0)]
@__const.num2str.thousand = [2 x i32] [i32 1000, i32 1024]
@.str.8 = [4 x i8] c"%lu\00"
@.str.9 = [8 x i8] c"%lu%s%s\00"
@.str.10 = [3 x i8] c"%u\00"
@.str.11 = [11 x i8] c"%lu.%u%s%s\00"
define i8* @num2str(i64 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [6 x i8*]
%13 = alloca [3 x i8*]
%14 = alloca [2 x i32]
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca [32 x i8]
%21 = alloca i8*
store i64 %0, i64* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%22 = bitcast [6 x i8*]* %12 to i8*
%23 = bitcast i8* %22 to [6 x i8*]*
%24 = getelementptr inbounds [6 x i8*], [6 x i8*]* %23, i32 0, i32 0
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i32 0, i32 0), i8** %24
%25 = getelementptr inbounds [6 x i8*], [6 x i8*]* %23, i32 0, i32 1
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i32 0, i32 0), i8** %25
%26 = getelementptr inbounds [6 x i8*], [6 x i8*]* %23, i32 0, i32 2
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i32 0, i32 0), i8** %26
%27 = getelementptr inbounds [6 x i8*], [6 x i8*]* %23, i32 0, i32 3
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i32 0, i32 0), i8** %27
%28 = getelementptr inbounds [6 x i8*], [6 x i8*]* %23, i32 0, i32 4
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i32 0, i32 0), i8** %28
%29 = getelementptr inbounds [6 x i8*], [6 x i8*]* %23, i32 0, i32 5
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i32 0, i32 0), i8** %29
%30 = bitcast [3 x i8*]* %13 to i8*
%31 = bitcast [2 x i32]* %14 to i8*
store i32 0, i32* %17
store i32 0, i32* %19
%32 = call i8* @malloc(i32 128)
store i8* %32, i8** %21
store i32 0, i32* %18
br label %33
33: ; preds = %47, %5
%34 = load i32, i32* %9
%35 = icmp sgt i32 %34, 1
br i1 %35, label %36, label %50
36: ; preds = %33
%37 = load i32, i32* %10
%38 = icmp ne i32 %37, 0
%39 = xor i1 %38, true
%40 = xor i1 %39, true
%41 = zext i1 %40 to i32
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [2 x i32], [2 x i32]* %14, i64 0, i64 %42
%44 = load i32, i32* %43
%45 = load i32, i32* %9
%46 = udiv i32 %45, %44
store i32 %46, i32* %9
br label %47
47: ; preds = %36
%48 = load i32, i32* %18
%49 = add nsw i32 %48, 1
store i32 %49, i32* %18
br label %33
50: ; preds = %33
%51 = load i32, i32* %11
switch i32 %51, label %56 [
i32 1, label %52
i32 8, label %55
]
52: ; preds = %50
store i32 2, i32* %17
%53 = load i64, i64* %7
%54 = mul i64 %53, 8
store i64 %54, i64* %7
br label %56
55: ; preds = %50
store i32 1, i32* %17
br label %56
56: ; preds = %50, %55, %52
store i32 -1, i32* %15
br label %57
57: ; preds = %70, %56
%58 = load i32, i32* %18
%59 = sext i32 %58 to i64
%60 = icmp ult i64 %59, 48
br i1 %60, label %61, label %108
61: ; preds = %57
%62 = getelementptr inbounds [32 x i8], [32 x i8]* %20, i64 0, i64 0
%63 = load i64, i64* %7
%64 = call i32 (i8*, i8*, i64, ...) @sprintf(i8* %62, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i64 %63)
%65 = getelementptr inbounds [32 x i8], [32 x i8]* %20, i64 0, i64 0
%66 = call i32 @strlen(i8* %65)
%67 = load i32, i32* %8
%68 = icmp ule i32 %66, %67
br i1 %68, label %69, label %70
69: ; preds = %61
br label %108
70: ; preds = %61
%71 = load i64, i64* %7
%72 = load i32, i32* %10
%73 = icmp ne i32 %72, 0
%74 = xor i1 %73, true
%75 = xor i1 %74, true
%76 = zext i1 %75 to i32
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds [2 x i32], [2 x i32]* %14, i64 0, i64 %77
%79 = load i32, i32* %78
%80 = zext i32 %79 to i64
%81 = urem i64 %71, %80
%82 = trunc i64 %81 to i32
store i32 %82, i32* %15
%83 = load i32, i32* %10
%84 = icmp ne i32 %83, 0
%85 = xor i1 %84, true
%86 = xor i1 %85, true
%87 = zext i1 %86 to i32
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds [2 x i32], [2 x i32]* %14, i64 0, i64 %88
%90 = load i32, i32* %89
%91 = zext i32 %90 to i64
%92 = load i64, i64* %7
%93 = udiv i64 %92, %91
store i64 %93, i64* %7
%94 = load i32, i32* %15
%95 = load i32, i32* %10
%96 = icmp ne i32 %95, 0
%97 = xor i1 %96, true
%98 = xor i1 %97, true
%99 = zext i1 %98 to i32
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds [2 x i32], [2 x i32]* %14, i64 0, i64 %100
%102 = load i32, i32* %101
%103 = udiv i32 %102, 2
%104 = icmp uge i32 %94, %103
%105 = zext i1 %104 to i32
store i32 %105, i32* %19
%106 = load i32, i32* %18
%107 = add nsw i32 %106, 1
store i32 %107, i32* %18
br label %57
108: ; preds = %69, %57
%109 = load i32, i32* %15
%110 = icmp eq i32 %109, -1
br i1 %110, label %111, label %125
111: ; preds = %108
br label %112
112: ; preds = %141, %111
%113 = load i8*, i8** %21
%114 = load i64, i64* %7
%115 = load i32, i32* %18
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds [6 x i8*], [6 x i8*]* %12, i64 0, i64 %116
%118 = load i8*, i8** %117
%119 = load i32, i32* %17
%120 = sext i32 %119 to i64
%121 = getelementptr inbounds [3 x i8*], [3 x i8*]* %13, i64 0, i64 %120
%122 = load i8*, i8** %121
%123 = call i32 (i8*, i8*, i64, ...) @sprintf(i8* %113, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0), i64 %114, i8* %118, i8* %122)
%124 = load i8*, i8** %21
store i8* %124, i8** %6
br label %173
125: ; preds = %108
%126 = getelementptr inbounds [32 x i8], [32 x i8]* %20, i64 0, i64 0
%127 = load i64, i64* %7
%128 = call i32 (i8*, i8*, i64, ...) @sprintf(i8* %126, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i64 %127)
%129 = load i32, i32* %8
%130 = getelementptr inbounds [32 x i8], [32 x i8]* %20, i64 0, i64 0
%131 = call i32 @strlen(i8* %130)
%132 = sub i32 %129, %131
store i32 %132, i32* %16
%133 = load i32, i32* %16
%134 = icmp ule i32 %133, 1
br i1 %134, label %135, label %142
135: ; preds = %125
%136 = load i32, i32* %19
%137 = icmp ne i32 %136, 0
br i1 %137, label %138, label %141
138: ; preds = %135
%139 = load i64, i64* %7
%140 = add i64 %139, 1
store i64 %140, i64* %7
br label %141
141: ; preds = %138, %135
br label %112
142: ; preds = %125
br label %143
143: ; preds = %158, %142
%144 = getelementptr inbounds [32 x i8], [32 x i8]* %20, i64 0, i64 0
%145 = load i32, i32* %15
%146 = zext i32 %145 to i64
%147 = call i32 (i8*, i8*, i64, ...) @sprintf(i8* %144, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i64 %146)
%148 = getelementptr inbounds [32 x i8], [32 x i8]* %20, i64 0, i64 0
%149 = call i32 @strlen(i8* %148)
%150 = load i32, i32* %16
%151 = sub i32 %150, 1
%152 = icmp ule i32 %149, %151
br i1 %152, label %153, label %154
153: ; preds = %143
br label %159
154: ; preds = %143
%155 = load i32, i32* %15
%156 = add i32 %155, 9
%157 = udiv i32 %156, 10
store i32 %157, i32* %15
br label %158
158: ; preds = %154
br i1 true, label %143, label %159
159: ; preds = %158, %153
%160 = load i8*, i8** %21
%161 = load i64, i64* %7
%162 = load i32, i32* %15
%163 = load i32, i32* %18
%164 = sext i32 %163 to i64
%165 = getelementptr inbounds [6 x i8*], [6 x i8*]* %12, i64 0, i64 %164
%166 = load i8*, i8** %165
%167 = load i32, i32* %17
%168 = sext i32 %167 to i64
%169 = getelementptr inbounds [3 x i8*], [3 x i8*]* %13, i64 0, i64 %168
%170 = load i8*, i8** %169
%171 = call i32 (i8*, i8*, i64, ...) @sprintf(i8* %160, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.11, i64 0, i64 0), i64 %161, i32 %162, i8* %166, i8* %170)
%172 = load i8*, i8** %21
store i8* %172, i8** %6
br label %173
173: ; preds = %159, %112
%174 = load i8*, i8** %6
ret i8* %174
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [2 x i8] c"K\00"
@.str.2 = [2 x i8] c"M\00"
@.str.3 = [2 x i8] c"G\00"
@.str.4 = [2 x i8] c"P\00"
@.str.5 = [2 x i8] c"E\00"
@.str.6 = [2 x i8] c"B\00"
@.str.7 = [4 x i8] c"bit\00"
@__const.num2str.byte_postfix = [3 x i8*] [i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i32 0, i32 0)]
@__const.num2str.thousand = [2 x i32] [i32 1000, i32 1024]
@.str.8 = [4 x i8] c"%lu\00"
@.str.9 = [8 x i8] c"%lu%s%s\00"
@.str.10 = [3 x i8] c"%u\00"
@.str.11 = [11 x i8] c"%lu.%u%s%s\00"
define noalias i8* @num2str(i64 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca [6 x i8*]
%7 = alloca [32 x i8]
%8 = bitcast [6 x i8*]* %6 to i8*
%9 = getelementptr inbounds [6 x i8*], [6 x i8*]* %6, i64 0, i64 0
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %9
%10 = getelementptr inbounds [6 x i8*], [6 x i8*]* %6, i64 0, i64 1
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %10
%11 = getelementptr inbounds [6 x i8*], [6 x i8*]* %6, i64 0, i64 2
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %11
%12 = getelementptr inbounds [6 x i8*], [6 x i8*]* %6, i64 0, i64 3
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8** %12
%13 = getelementptr inbounds [6 x i8*], [6 x i8*]* %6, i64 0, i64 4
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8** %13
%14 = getelementptr inbounds [6 x i8*], [6 x i8*]* %6, i64 0, i64 5
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8** %14
%15 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%16 = tail call dereferenceable_or_null(128) i8* @malloc(i32 128)
%17 = icmp sgt i32 %2, 1
br i1 %17, label %18, label %29
18: ; preds = %5
%19 = icmp ne i32 %3, 0
%20 = zext i1 %19 to i64
%21 = getelementptr inbounds [2 x i32], [2 x i32]* @__const.num2str.thousand, i64 0, i64 %20
%22 = load i32, i32* %21
br label %23
23: ; preds = %18, %23
%24 = phi i32 [ 0, %18 ], [ %27, %23 ]
%25 = phi i32 [ %2, %18 ], [ %26, %23 ]
%26 = udiv i32 %25, %22
%27 = add nuw nsw i32 %24, 1
%28 = icmp ugt i32 %26, 1
br i1 %28, label %23, label %29
29: ; preds = %23, %5
%30 = phi i32 [ 0, %5 ], [ %27, %23 ]
switch i32 %4, label %34 [
i32 1, label %31
i32 8, label %33
]
31: ; preds = %29
%32 = shl i64 %0, 3
br label %34
33: ; preds = %29
br label %34
34: ; preds = %29, %33, %31
%35 = phi i64 [ %0, %29 ], [ %0, %33 ], [ %32, %31 ]
%36 = phi i64 [ 0, %29 ], [ 1, %33 ], [ 2, %31 ]
%37 = icmp ult i32 %30, 48
br i1 %37, label %40, label %38
38: ; preds = %34
%39 = zext i32 %30 to i64
br label %74
40: ; preds = %34
%41 = icmp ne i32 %3, 0
%42 = zext i1 %41 to i64
%43 = getelementptr inbounds [2 x i32], [2 x i32]* @__const.num2str.thousand, i64 0, i64 %42
%44 = call i32 (i8*, i8*, i64, ...) @sprintf(i8* %15, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i64 %35)
%45 = call i32 @strlen(i8* %15)
%46 = icmp ugt i32 %45, %1
br i1 %46, label %47, label %67
47: ; preds = %40
%48 = load i32, i32* %43
%49 = zext i32 %48 to i64
br label %54
50: ; preds = %54
%51 = call i32 (i8*, i8*, i64, ...) @sprintf(i8* %15, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i64 %57)
%52 = call i32 @strlen(i8* %15)
%53 = icmp ugt i32 %52, %1
br i1 %53, label %54, label %60
54: ; preds = %47, %50
%55 = phi i64 [ %57, %50 ], [ %35, %47 ]
%56 = phi i32 [ %58, %50 ], [ %30, %47 ]
%57 = udiv i64 %55, %49
%58 = add i32 %56, 1
%59 = icmp eq i32 %58, 48
br i1 %59, label %82, label %50
60: ; preds = %50
%61 = zext i32 %48 to i64
%62 = urem i64 %55, %61
%63 = trunc i64 %62 to i32
%64 = lshr i32 %48, 1
%65 = icmp ule i32 %64, %63
%66 = zext i1 %65 to i64
br label %67
67: ; preds = %60, %40
%68 = phi i64 [ 0, %40 ], [ %66, %60 ]
%69 = phi i32 [ %30, %40 ], [ %58, %60 ]
%70 = phi i64 [ %35, %40 ], [ %57, %60 ]
%71 = phi i32 [ -1, %40 ], [ %63, %60 ]
%72 = zext i32 %69 to i64
%73 = icmp eq i32 %71, -1
br i1 %73, label %74, label %90
74: ; preds = %38, %105, %67
%75 = phi i64 [ %72, %67 ], [ %91, %105 ], [ %39, %38 ]
%76 = phi i64 [ %70, %67 ], [ %106, %105 ], [ %35, %38 ]
%77 = getelementptr inbounds [6 x i8*], [6 x i8*]* %6, i64 0, i64 %75
%78 = load i8*, i8** %77
%79 = getelementptr inbounds [3 x i8*], [3 x i8*]* @__const.num2str.byte_postfix, i64 0, i64 %36
%80 = load i8*, i8** %79
%81 = call i32 (i8*, i8*, i64, ...) @sprintf(i8* dereferenceable(1) %16, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0), i64 %76, i8* %78, i8* %80)
br label %122
82: ; preds = %54
%83 = zext i32 %48 to i64
%84 = urem i64 %55, %83
%85 = trunc i64 %84 to i32
%86 = lshr i32 %48, 1
%87 = icmp ule i32 %86, %85
%88 = zext i1 %87 to i64
%89 = trunc i64 %84 to i32
br label %90
90: ; preds = %82, %67
%91 = phi i64 [ %72, %67 ], [ 48, %82 ]
%92 = phi i64 [ %68, %67 ], [ %88, %82 ]
%93 = phi i64 [ %70, %67 ], [ %57, %82 ]
%94 = phi i32 [ %71, %67 ], [ %89, %82 ]
%95 = call i32 (i8*, i8*, i64, ...) @sprintf(i8* %15, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i64 %93)
%96 = call i32 @strlen(i8* %15)
%97 = sub i32 %1, %96
%98 = icmp ult i32 %97, 2
br i1 %98, label %105, label %99
99: ; preds = %90
%100 = zext i32 %94 to i64
%101 = call i32 (i8*, i8*, i64, ...) @sprintf(i8* %15, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i64 %100)
%102 = call i32 @strlen(i8* %15)
%103 = add i32 %97, -1
%104 = icmp ugt i32 %102, %103
br i1 %104, label %107, label %115
105: ; preds = %90
%106 = add i64 %92, %93
br label %74
107: ; preds = %99, %107
%108 = phi i32 [ %110, %107 ], [ %94, %99 ]
%109 = add i32 %108, 9
%110 = udiv i32 %109, 10
%111 = zext i32 %110 to i64
%112 = call i32 (i8*, i8*, i64, ...) @sprintf(i8* %15, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i64 %111)
%113 = call i32 @strlen(i8* %15)
%114 = icmp ugt i32 %113, %103
br i1 %114, label %107, label %115
115: ; preds = %107, %99
%116 = phi i32 [ %94, %99 ], [ %110, %107 ]
%117 = getelementptr inbounds [6 x i8*], [6 x i8*]* %6, i64 0, i64 %91
%118 = load i8*, i8** %117
%119 = getelementptr inbounds [3 x i8*], [3 x i8*]* @__const.num2str.byte_postfix, i64 0, i64 %36
%120 = load i8*, i8** %119
%121 = call i32 (i8*, i8*, i64, ...) @sprintf(i8* dereferenceable(1) %16, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.11, i64 0, i64 0), i64 %93, i32 %116, i8* %118, i8* %120)
br label %122
122: ; preds = %115, %74
ret i8* %16
}