#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*/ printf(char *, int, ...);
void print_file_size(int size) {
  int unit = 0;
  char units[] = " KMGT";
  while (size > 1024 && unit < 5) {
    size /= 1024;
    unit++;
  }
  if (!unit)
    printf("%dB", size);
  else
    printf("%d%cB", size, units[unit]);
}


x86 assembly (clang, -O0):
<print_file_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    0xed8(%rip),%eax
mov    %eax,-0xe(%rbp)
mov    0xed2(%rip),%ax
mov    %ax,-0xa(%rbp)
xor    %eax,%eax
cmpl   $0x400,-0x4(%rbp)
mov    %al,-0xf(%rbp)
jle    1152 <print_file_size+0x42>
cmpl   $0x5,-0x8(%rbp)
setl   %al
mov    %al,-0xf(%rbp)
mov    -0xf(%rbp),%al
test   $0x1,%al
jne    1162 <print_file_size+0x52>
jmp    117e <print_file_size+0x6e>
mov    -0x4(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1136 <print_file_size+0x26>
cmpl   $0x0,-0x8(%rbp)
jne    119e <print_file_size+0x8e>
mov    -0x4(%rbp),%esi
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b8 <print_file_size+0xa8>
mov    -0x4(%rbp),%esi
movslq -0x8(%rbp),%rax
movsbl -0xe(%rbp,%rax,1),%edx
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_file_size>:
mov    %edi,%esi
cmp    $0x401,%edi
jl     1142 <print_file_size+0x32>
cmp    $0x100400,%esi
jb     1150 <print_file_size+0x40>
mov    %esi,%ecx
shr    $0x14,%ecx
mov    %esi,%edx
shr    $0x1e,%edx
xor    %eax,%eax
cmp    $0x40100000,%esi
setae  %al
cmovb  %ecx,%edx
or     $0x2,%rax
mov    %edx,%esi
jmp    1158 <print_file_size+0x48>
lea    0xebd(%rip),%rdi
xor    %eax,%eax
jmp    1030 <printf@plt>
shr    $0xa,%esi
mov    $0x1,%eax
lea    0xea1(%rip),%rcx
movsbl (%rax,%rcx,1),%edx
lea    0xea0(%rip),%rdi
xor    %eax,%eax
jmp    1030 <printf@plt>

LLVM IR (-O0):
@__const.print_file_size.units = [6 x i8] c" KMGT\00"
@.str = [4 x i8] c"%dB\00"
@.str.1 = [6 x i8] c"%d%cB\00"
define void @print_file_size(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [6 x i8]
store i32 %0, i32* %2
store i32 0, i32* %3
%5 = bitcast [6 x i8]* %4 to i8*
br label %6
6: ; preds = %14, %1
%7 = load i32, i32* %2
%8 = icmp sgt i32 %7, 1024
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = load i32, i32* %3
%11 = icmp slt i32 %10, 5
br label %12
12: ; preds = %9, %6
%13 = phi i1 [ false, %6 ], [ %11, %9 ]
br i1 %13, label %14, label %19
14: ; preds = %12
%15 = load i32, i32* %2
%16 = sdiv i32 %15, 1024
store i32 %16, i32* %2
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %3
br label %6
19: ; preds = %12
%20 = load i32, i32* %3
%21 = icmp ne i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = load i32, i32* %2
%24 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %23)
br label %33
25: ; preds = %19
%26 = load i32, i32* %2
%27 = load i32, i32* %3
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %26, i32 %31)
br label %33
33: ; preds = %25, %22
ret void
}

LLVM IR (-O2):
@__const.print_file_size.units = [6 x i8] c" KMGT\00"
@.str = [4 x i8] c"%dB\00"
@.str.1 = [6 x i8] c"%d%cB\00"
define void @print_file_size(i32 %0) {
%2 = icmp sgt i32 %0, 1024
br i1 %2, label %3, label %12
3: ; preds = %1
%4 = lshr i32 %0, 10
%5 = icmp ugt i32 %0, 1049599
br i1 %5, label %6, label %14
6: ; preds = %3
%7 = lshr i32 %0, 20
%8 = icmp ugt i32 %0, 1074790399
%9 = lshr i32 %0, 30
%10 = select i1 %8, i32 %9, i32 %7
%11 = select i1 %8, i64 3, i64 2
br label %14
12: ; preds = %1
%13 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %21
14: ; preds = %6, %3
%15 = phi i32 [ %4, %3 ], [ %10, %6 ]
%16 = phi i64 [ 1, %3 ], [ %11, %6 ]
%17 = getelementptr inbounds [6 x i8], [6 x i8]* @__const.print_file_size.units, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %15, i32 %19)
br label %21
21: ; preds = %14, %12
ret void
}