#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 */
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ SYS_write;
char const *itoa(unsigned long long, char *);
int /*<<< orphan*/ strlen(char const *);
int /*<<< orphan*/ syscall(int /*<<< orphan*/, int /*<<< orphan*/, char const *,
                           int /*<<< orphan*/);
void iambored_sizeconvert(unsigned long long int size, char *buffer) {
  const char *units[] = {"  ", "K ", "M ", "GB", "TB", "PB"};
  int i = 0;
  if (size < 0x400) {
    syscall(SYS_write, STDOUT_FILENO, itoa(size, buffer),
            strlen(itoa(size, buffer)));
    syscall(SYS_write, STDOUT_FILENO, units[i], strlen(units[i]));
    return;
  }
  while (size > 0x400) {
    size = size >> 10;
    i++;
  }
  syscall(SYS_write, STDOUT_FILENO, itoa(size, buffer),
          strlen(itoa(size, buffer)));
  syscall(SYS_write, STDOUT_FILENO, units[i], strlen(units[i]));
}


x86 assembly (clang, -O0):
<iambored_sizeconvert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1040 <memset@plt>
lea    0xe96(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xe8e(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xe86(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xe7e(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe76(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe6e(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x44(%rbp)
cmpq   $0x400,-0x8(%rbp)
jae    1252 <iambored_sizeconvert+0x112>
mov    0x2e1f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
mov    0x2e23(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <itoa@plt>
mov    %rax,-0x60(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <itoa@plt>
mov    %rax,%rdi
call   1030 <strlen@plt>
mov    -0x68(%rbp),%edi
mov    -0x64(%rbp),%esi
mov    -0x60(%rbp),%rdx
mov    %eax,%ecx
call   1050 <syscall@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
mov    0x2dd4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
movslq -0x44(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rax
mov    %rax,-0x50(%rbp)
movslq -0x44(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rdi
call   1030 <strlen@plt>
mov    -0x58(%rbp),%edi
mov    -0x54(%rbp),%esi
mov    -0x50(%rbp),%rdx
mov    %eax,%ecx
call   1050 <syscall@plt>
jmp    131e <iambored_sizeconvert+0x1de>
jmp    1257 <iambored_sizeconvert+0x117>
cmpq   $0x400,-0x8(%rbp)
jbe    127f <iambored_sizeconvert+0x13f>
mov    -0x8(%rbp),%rax
shr    $0xa,%rax
mov    %rax,-0x8(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1257 <iambored_sizeconvert+0x117>
mov    0x2d5a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x88(%rbp)
mov    0x2d5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x84(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <itoa@plt>
mov    %rax,-0x80(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <itoa@plt>
mov    %rax,%rdi
call   1030 <strlen@plt>
mov    -0x88(%rbp),%edi
mov    -0x84(%rbp),%esi
mov    -0x80(%rbp),%rdx
mov    %eax,%ecx
call   1050 <syscall@plt>
mov    0x2cff(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x78(%rbp)
mov    0x2d03(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
movslq -0x44(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rax
mov    %rax,-0x70(%rbp)
movslq -0x44(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rdi
call   1030 <strlen@plt>
mov    -0x78(%rbp),%edi
mov    -0x74(%rbp),%esi
mov    -0x70(%rbp),%rdx
mov    %eax,%ecx
call   1050 <syscall@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iambored_sizeconvert>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xeb5(%rip),%rax
mov    %rax,(%rsp)
lea    0xead(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0xea4(%rip),%rax
mov    %rax,0x10(%rsp)
lea    0xe9b(%rip),%rax
mov    %rax,0x18(%rsp)
lea    0xe92(%rip),%rax
mov    %rax,0x20(%rsp)
lea    0xe89(%rip),%rax
mov    %rax,0x28(%rsp)
cmp    $0x400,%rdi
jae    1201 <iambored_sizeconvert+0xd1>
mov    0x2e45(%rip),%rax
mov    (%rax),%r12d
mov    0x2e4b(%rip),%r13
mov    0x0(%r13),%ebp
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <itoa@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <itoa@plt>
mov    %rax,%rdi
call   1030 <strlen@plt>
mov    %r12d,%edi
mov    %ebp,%esi
mov    %rbx,%rdx
mov    %eax,%ecx
call   1040 <syscall@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%ebx
mov    0x0(%r13),%ebp
lea    0xe13(%rip),%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %ebx,%edi
mov    %ebp,%esi
mov    %r14,%rdx
jmp    12a2 <iambored_sizeconvert+0x172>
jne    120c <iambored_sizeconvert+0xdc>
mov    $0x400,%ebx
xor    %ebp,%ebp
jmp    1234 <iambored_sizeconvert+0x104>
xor    %ebp,%ebp
mov    %r15,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
shr    $0xa,%rbx
add    $0x1,%rbp
cmp    $0x1003ff,%r15
mov    %rbx,%r15
ja     1220 <iambored_sizeconvert+0xf0>
mov    0x2da5(%rip),%rax
mov    (%rax),%r15d
mov    0x2dab(%rip),%rax
mov    (%rax),%r12d
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <itoa@plt>
mov    %rax,%r13
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <itoa@plt>
mov    %rax,%rdi
call   1030 <strlen@plt>
mov    %r15d,%edi
mov    %r12d,%esi
mov    %r13,%rdx
mov    %eax,%ecx
call   1040 <syscall@plt>
mov    0x2d60(%rip),%rax
mov    (%rax),%r14d
mov    0x2d66(%rip),%rax
mov    (%rax),%r15d
mov    (%rsp,%rbp,8),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %r14d,%edi
mov    %r15d,%esi
mov    %rbx,%rdx
mov    %eax,%ecx
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <syscall@plt>

LLVM IR (-O0):
@.str = [3 x i8] c" \00"
@.str.1 = [3 x i8] c"K \00"
@.str.2 = [3 x i8] c"M \00"
@.str.3 = [3 x i8] c"GB\00"
@.str.4 = [3 x i8] c"TB\00"
@.str.5 = [3 x i8] c"PB\00"
@SYS_write = global i32 0
@STDOUT_FILENO = global i32 0
define void @iambored_sizeconvert(i64 %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca [6 x i8*]
%6 = alloca i32
store i64 %0, i64* %3
store i8* %1, i8** %4
%7 = bitcast [6 x i8*]* %5 to i8*
%8 = bitcast i8* %7 to [6 x i8*]*
%9 = getelementptr inbounds [6 x i8*], [6 x i8*]* %8, i32 0, i32 0
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i32 0, i32 0), i8** %9
%10 = getelementptr inbounds [6 x i8*], [6 x i8*]* %8, i32 0, i32 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8** %10
%11 = getelementptr inbounds [6 x i8*], [6 x i8*]* %8, i32 0, i32 2
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0), i8** %11
%12 = getelementptr inbounds [6 x i8*], [6 x i8*]* %8, i32 0, i32 3
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i32 0, i32 0), i8** %12
%13 = getelementptr inbounds [6 x i8*], [6 x i8*]* %8, i32 0, i32 4
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i32 0, i32 0), i8** %13
%14 = getelementptr inbounds [6 x i8*], [6 x i8*]* %8, i32 0, i32 5
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i32 0, i32 0), i8** %14
store i32 0, i32* %6
%15 = load i64, i64* %3
%16 = icmp ult i64 %15, 1024
br i1 %16, label %17, label %40
17: ; preds = %2
%18 = load i32, i32* @SYS_write
%19 = load i32, i32* @STDOUT_FILENO
%20 = load i64, i64* %3
%21 = load i8*, i8** %4
%22 = call i8* @itoa(i64 %20, i8* %21)
%23 = load i64, i64* %3
%24 = load i8*, i8** %4
%25 = call i8* @itoa(i64 %23, i8* %24)
%26 = call i32 @strlen(i8* %25)
%27 = call i32 @syscall(i32 %18, i32 %19, i8* %22, i32 %26)
%28 = load i32, i32* @SYS_write
%29 = load i32, i32* @STDOUT_FILENO
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [6 x i8*], [6 x i8*]* %5, i64 0, i64 %31
%33 = load i8*, i8** %32
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [6 x i8*], [6 x i8*]* %5, i64 0, i64 %35
%37 = load i8*, i8** %36
%38 = call i32 @strlen(i8* %37)
%39 = call i32 @syscall(i32 %28, i32 %29, i8* %33, i32 %38)
br label %72
40: ; preds = %2
br label %41
41: ; preds = %44, %40
%42 = load i64, i64* %3
%43 = icmp ugt i64 %42, 1024
br i1 %43, label %44, label %49
44: ; preds = %41
%45 = load i64, i64* %3
%46 = lshr i64 %45, 10
store i64 %46, i64* %3
%47 = load i32, i32* %6
%48 = add nsw i32 %47, 1
store i32 %48, i32* %6
br label %41
49: ; preds = %41
%50 = load i32, i32* @SYS_write
%51 = load i32, i32* @STDOUT_FILENO
%52 = load i64, i64* %3
%53 = load i8*, i8** %4
%54 = call i8* @itoa(i64 %52, i8* %53)
%55 = load i64, i64* %3
%56 = load i8*, i8** %4
%57 = call i8* @itoa(i64 %55, i8* %56)
%58 = call i32 @strlen(i8* %57)
%59 = call i32 @syscall(i32 %50, i32 %51, i8* %54, i32 %58)
%60 = load i32, i32* @SYS_write
%61 = load i32, i32* @STDOUT_FILENO
%62 = load i32, i32* %6
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [6 x i8*], [6 x i8*]* %5, i64 0, i64 %63
%65 = load i8*, i8** %64
%66 = load i32, i32* %6
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [6 x i8*], [6 x i8*]* %5, i64 0, i64 %67
%69 = load i8*, i8** %68
%70 = call i32 @strlen(i8* %69)
%71 = call i32 @syscall(i32 %60, i32 %61, i8* %65, i32 %70)
br label %72
72: ; preds = %49, %17
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c" \00"
@.str.1 = [3 x i8] c"K \00"
@.str.2 = [3 x i8] c"M \00"
@.str.3 = [3 x i8] c"GB\00"
@.str.4 = [3 x i8] c"TB\00"
@.str.5 = [3 x i8] c"PB\00"
@SYS_write = global i32 0
@STDOUT_FILENO = global i32 0
define void @iambored_sizeconvert(i64 %0, i8* %1) {
%3 = alloca [6 x i8*]
%4 = bitcast [6 x i8*]* %3 to i8*
%5 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 0
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %5
%6 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %6
%7 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 2
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %7
%8 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 3
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %8
%9 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 4
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8** %9
%10 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 5
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8** %10
%11 = icmp ult i64 %0, 1024
br i1 %11, label %14, label %12
12: ; preds = %2
%13 = icmp eq i64 %0, 1024
br i1 %13, label %33, label %25
14: ; preds = %2
%15 = load i32, i32* @SYS_write
%16 = load i32, i32* @STDOUT_FILENO
%17 = tail call i8* @itoa(i64 %0, i8* %1)
%18 = tail call i8* @itoa(i64 %0, i8* %1)
%19 = tail call i32 @strlen(i8* %18)
%20 = tail call i32 @syscall(i32 %15, i32 %16, i8* %17, i32 %19)
%21 = load i32, i32* @SYS_write
%22 = load i32, i32* @STDOUT_FILENO
%23 = tail call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%24 = tail call i32 @syscall(i32 %21, i32 %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %23)
br label %48
25: ; preds = %12, %25
%26 = phi i32 [ %29, %25 ], [ 0, %12 ]
%27 = phi i64 [ %28, %25 ], [ %0, %12 ]
%28 = lshr i64 %27, 10
%29 = add nuw nsw i32 %26, 1
%30 = icmp ugt i64 %27, 1049599
br i1 %30, label %25, label %31
31: ; preds = %25
%32 = zext i32 %29 to i64
br label %33
33: ; preds = %31, %12
%34 = phi i64 [ 1024, %12 ], [ %28, %31 ]
%35 = phi i64 [ 0, %12 ], [ %32, %31 ]
%36 = load i32, i32* @SYS_write
%37 = load i32, i32* @STDOUT_FILENO
%38 = tail call i8* @itoa(i64 %34, i8* %1)
%39 = tail call i8* @itoa(i64 %34, i8* %1)
%40 = tail call i32 @strlen(i8* %39)
%41 = tail call i32 @syscall(i32 %36, i32 %37, i8* %38, i32 %40)
%42 = load i32, i32* @SYS_write
%43 = load i32, i32* @STDOUT_FILENO
%44 = getelementptr inbounds [6 x i8*], [6 x i8*]* %3, i64 0, i64 %35
%45 = load i8*, i8** %44
%46 = tail call i32 @strlen(i8* %45)
%47 = tail call i32 @syscall(i32 %42, i32 %43, i8* %45, i32 %46)
br label %48
48: ; preds = %33, %14
ret void
}