#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 */

/* Variables and functions */
char *malloc(int);
scalar_t__ pow(int, int);
int snprintf(int /*<<< orphan*/ *, int /*<<< orphan*/, char *, int, char *);
int /*<<< orphan*/ sprintf(char *, char *, int, char *);
char *getSizeStr(int size) {
  char *cat;
  char *out;
  int i, len;
  int s = size;
  for (i = 9; !(s / (int)pow(10, i)) && i; i -= 3)
    ;
  switch (i) {
  case 24:
    cat = "YB";
    break;
  case 21:
    cat = "ZB";
    break;
  case 18:
    cat = "EB";
    break;
  case 15:
    cat = "PB";
    break;
  case 12:
    cat = "TB";
    break;
  case 9:
    cat = "GB";
    break;
  case 6:
    cat = "MB";
    break;
  case 3:
    cat = "KB";
    break;
  case 0:
    cat = "B";
    break;
  }
  len = snprintf(NULL, 0, "%d%s", s / (int)pow(10, i), cat);
  out = malloc(len);
  if (!out)
    return NULL;
  sprintf(out, "%d%s", s / (int)pow(10, i), cat);
  return out;
}


x86 assembly (clang, -O0):
<getSizeStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movl   $0x9,-0x24(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x24(%rbp),%esi
mov    $0xa,%edi
call   1050 <pow@plt>
mov    %rax,%rcx
mov    -0x34(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x2d(%rbp)
jne    118e <getSizeStr+0x4e>
cmpl   $0x0,-0x24(%rbp)
setne  %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    119e <getSizeStr+0x5e>
jmp    11b1 <getSizeStr+0x71>
jmp    11a3 <getSizeStr+0x63>
mov    -0x24(%rbp),%eax
sub    $0x3,%eax
mov    %eax,-0x24(%rbp)
jmp    1158 <getSizeStr+0x18>
mov    -0x24(%rbp),%eax
mov    %rax,-0x40(%rbp)
sub    $0x18,%rax
ja     1261 <getSizeStr+0x121>
mov    -0x40(%rbp),%rax
lea    0xe33(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe87(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1261 <getSizeStr+0x121>
lea    0xe7a(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1261 <getSizeStr+0x121>
lea    0xe6d(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1261 <getSizeStr+0x121>
lea    0xe60(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1261 <getSizeStr+0x121>
lea    0xe53(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1261 <getSizeStr+0x121>
lea    0xe46(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1261 <getSizeStr+0x121>
lea    0xe39(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1261 <getSizeStr+0x121>
lea    0xe2c(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1261 <getSizeStr+0x121>
lea    0xe0e(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x24(%rbp),%esi
mov    $0xa,%edi
call   1050 <pow@plt>
mov    %rax,%rcx
mov    -0x44(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x18(%rbp),%r8
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
lea    0xdec(%rip),%rdx
call   1030 <snprintf@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12bc <getSizeStr+0x17c>
movq   $0x0,-0x8(%rbp)
jmp    12fe <getSizeStr+0x1be>
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x24(%rbp),%esi
mov    $0xa,%edi
call   1050 <pow@plt>
mov    -0x50(%rbp),%rdi
mov    %rax,%rcx
mov    -0x48(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,%edx
mov    -0x18(%rbp),%rcx
lea    0xd8b(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getSizeStr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
mov    $0x9,%ebp
mov    $0xa,%edi
mov    $0x9,%esi
call   1050 <pow@plt>
mov    %rax,%rcx
mov    %r14d,%eax
cltd
idiv   %ecx
test   %eax,%eax
jne    11bb <getSizeStr+0x7b>
mov    $0x6,%ebp
mov    $0xa,%edi
mov    $0x6,%esi
call   1050 <pow@plt>
mov    %rax,%rcx
mov    %r14d,%eax
cltd
idiv   %ecx
test   %eax,%eax
jne    11bb <getSizeStr+0x7b>
mov    $0x3,%ebp
mov    $0xa,%edi
mov    $0x3,%esi
call   1050 <pow@plt>
mov    %rax,%rcx
mov    %r14d,%eax
cltd
idiv   %ecx
test   %eax,%eax
jne    11bb <getSizeStr+0x7b>
xor    %ebp,%ebp
mov    $0xa,%edi
xor    %esi,%esi
call   1050 <pow@plt>
lea    0xe7e(%rip),%r15
cmp    $0xf,%ebp
ja     120d <getSizeStr+0xcd>
mov    %ebp,%eax
lea    0xe30(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe6a(%rip),%r15
jmp    120d <getSizeStr+0xcd>
lea    0xe66(%rip),%r15
jmp    120d <getSizeStr+0xcd>
lea    0xe5a(%rip),%r15
jmp    120d <getSizeStr+0xcd>
lea    0xe4e(%rip),%r15
jmp    120d <getSizeStr+0xcd>
lea    0xe42(%rip),%r15
jmp    120d <getSizeStr+0xcd>
lea    0xe36(%rip),%r15
mov    $0xa,%edi
mov    %ebp,%esi
call   1050 <pow@plt>
mov    %rax,%rcx
mov    %r14d,%eax
cltd
idiv   %ecx
lea    0xe29(%rip),%rdx
xor    %edi,%edi
xor    %esi,%esi
mov    %eax,%ecx
mov    %r15,%r8
call   1030 <snprintf@plt>
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     126f <getSizeStr+0x12f>
mov    $0xa,%edi
mov    %ebp,%esi
call   1050 <pow@plt>
mov    %rax,%rcx
mov    %r14d,%eax
cltd
idiv   %ecx
lea    0xdf0(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
mov    %r15,%rcx
call   1060 <sprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"YB\00"
@.str.1 = [3 x i8] c"ZB\00"
@.str.2 = [3 x i8] c"EB\00"
@.str.3 = [3 x i8] c"PB\00"
@.str.4 = [3 x i8] c"TB\00"
@.str.5 = [3 x i8] c"GB\00"
@.str.6 = [3 x i8] c"MB\00"
@.str.7 = [3 x i8] c"KB\00"
@.str.8 = [2 x i8] c"B\00"
@.str.9 = [5 x i8] c"%d%s\00"
define i8* @getSizeStr(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
%9 = load i32, i32* %3
store i32 %9, i32* %8
store i32 9, i32* %6
br label %10
10: ; preds = %23, %1
%11 = load i32, i32* %8
%12 = load i32, i32* %6
%13 = call i64 @pow(i32 10, i32 %12)
%14 = trunc i64 %13 to i32
%15 = sdiv i32 %11, %14
%16 = icmp ne i32 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %10
%18 = load i32, i32* %6
%19 = icmp ne i32 %18, 0
br label %20
20: ; preds = %17, %10
%21 = phi i1 [ false, %10 ], [ %19, %17 ]
br i1 %21, label %22, label %26
22: ; preds = %20
br label %23
23: ; preds = %22
%24 = load i32, i32* %6
%25 = sub nsw i32 %24, 3
store i32 %25, i32* %6
br label %10
26: ; preds = %20
%27 = load i32, i32* %6
switch i32 %27, label %37 [
i32 24, label %28
i32 21, label %29
i32 18, label %30
i32 15, label %31
i32 12, label %32
i32 9, label %33
i32 6, label %34
i32 3, label %35
i32 0, label %36
]
28: ; preds = %26
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %4
br label %37
29: ; preds = %26
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %4
br label %37
30: ; preds = %26
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %4
br label %37
31: ; preds = %26
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %4
br label %37
32: ; preds = %26
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8** %4
br label %37
33: ; preds = %26
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8** %4
br label %37
34: ; preds = %26
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8** %4
br label %37
35: ; preds = %26
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8** %4
br label %37
36: ; preds = %26
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i8** %4
br label %37
37: ; preds = %26, %36, %35, %34, %33, %32, %31, %30, %29, %28
%38 = load i32, i32* %8
%39 = load i32, i32* %6
%40 = call i64 @pow(i32 10, i32 %39)
%41 = trunc i64 %40 to i32
%42 = sdiv i32 %38, %41
%43 = load i8*, i8** %4
%44 = call i32 @snprintf(i32* null, i32 0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i32 %42, i8* %43)
store i32 %44, i32* %7
%45 = load i32, i32* %7
%46 = call i8* @malloc(i32 %45)
store i8* %46, i8** %5
%47 = load i8*, i8** %5
%48 = icmp ne i8* %47, null
br i1 %48, label %50, label %49
49: ; preds = %37
store i8* null, i8** %2
br label %60
50: ; preds = %37
%51 = load i8*, i8** %5
%52 = load i32, i32* %8
%53 = load i32, i32* %6
%54 = call i64 @pow(i32 10, i32 %53)
%55 = trunc i64 %54 to i32
%56 = sdiv i32 %52, %55
%57 = load i8*, i8** %4
%58 = call i32 @sprintf(i8* %51, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i32 %56, i8* %57)
%59 = load i8*, i8** %5
store i8* %59, i8** %2
br label %60
60: ; preds = %50, %49
%61 = load i8*, i8** %2
ret i8* %61
}

LLVM IR (-O2):
@.str = [3 x i8] c"YB\00"
@.str.3 = [3 x i8] c"PB\00"
@.str.4 = [3 x i8] c"TB\00"
@.str.5 = [3 x i8] c"GB\00"
@.str.6 = [3 x i8] c"MB\00"
@.str.7 = [3 x i8] c"KB\00"
@.str.8 = [2 x i8] c"B\00"
@.str.9 = [5 x i8] c"%d%s\00"
define noalias i8* @getSizeStr(i32 %0) {
%2 = tail call i64 @pow(i32 10, i32 9)
%3 = trunc i64 %2 to i32
%4 = sdiv i32 %0, %3
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %18
6: ; preds = %1
%7 = tail call i64 @pow(i32 10, i32 6)
%8 = trunc i64 %7 to i32
%9 = sdiv i32 %0, %8
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %6
%12 = tail call i64 @pow(i32 10, i32 3)
%13 = trunc i64 %12 to i32
%14 = sdiv i32 %0, %13
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = tail call i64 @pow(i32 10, i32 0)
br label %18
18: ; preds = %16, %11, %6, %1
%19 = phi i32 [ 9, %1 ], [ 6, %6 ], [ 3, %11 ], [ 0, %16 ]
switch i32 %19, label %26 [
i32 0, label %25
i32 3, label %24
i32 6, label %23
i32 15, label %20
i32 12, label %21
i32 9, label %22
]
20: ; preds = %18
br label %26
21: ; preds = %18
br label %26
22: ; preds = %18
br label %26
23: ; preds = %18
br label %26
24: ; preds = %18
br label %26
25: ; preds = %18
br label %26
26: ; preds = %18, %25, %24, %23, %22, %21, %20
%27 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), %25 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), %24 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), %23 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), %22 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), %21 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), %20 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %18 ]
%28 = tail call i64 @pow(i32 10, i32 %19)
%29 = trunc i64 %28 to i32
%30 = sdiv i32 %0, %29
%31 = tail call i32 @snprintf(i32* null, i32 0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i32 %30, i8* %27)
%32 = tail call i8* @malloc(i32 %31)
%33 = icmp eq i8* %32, null
br i1 %33, label %39, label %34
34: ; preds = %26
%35 = tail call i64 @pow(i32 10, i32 %19)
%36 = trunc i64 %35 to i32
%37 = sdiv i32 %0, %36
%38 = tail call i32 @sprintf(i8* %32, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i32 %37, i8* %27)
br label %39
39: ; preds = %26, %34
ret i8* %32
}