#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 *, long, ...);
void print_size(long size, char human) {
  int i;
  if (size < 1024 || !human) {
    printf("%ld\n", size);
    return;
  }
  i = 0;
  do {
    i++;
    size /= 1024;
  } while (size > 1024 && i < 6);
  printf("%ld%c\n", size, "\0kMGTP"[i]);
}


x86 assembly (clang, -O0):
<print_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
cmpq   $0x400,-0x8(%rbp)
jl     113a <print_size+0x2a>
cmpb   $0x0,-0x9(%rbp)
jne    1151 <print_size+0x41>
mov    -0x8(%rbp),%rsi
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11bc <print_size+0xac>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x400,%ecx
cqto
idiv   %rcx
mov    %rax,-0x8(%rbp)
xor    %eax,%eax
cmpq   $0x400,-0x8(%rbp)
mov    %al,-0x11(%rbp)
jle    1190 <print_size+0x80>
cmpl   $0x6,-0x10(%rbp)
setl   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1158 <print_size+0x48>
mov    -0x8(%rbp),%rsi
movslq -0x10(%rbp),%rcx
lea    0xe62(%rip),%rax
movsbl (%rax,%rcx,1),%edx
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_size>:
mov    %rdi,%rax
cmp    $0x400,%rdi
jl     11e3 <print_size+0xd3>
test   %sil,%sil
je     11e3 <print_size+0xd3>
lea    0x3ff(%rax),%rsi
test   %rax,%rax
cmovns %rax,%rsi
cmp    $0x100400,%rax
jl     11f4 <print_size+0xe4>
lea    0xfffff(%rax),%rsi
test   %rax,%rax
cmovns %rax,%rsi
cmp    $0x40100000,%rax
jl     11ff <print_size+0xef>
lea    0x3fffffff(%rax),%rsi
test   %rax,%rax
cmovns %rax,%rsi
movabs $0x10040000000,%rcx
cmp    %rcx,%rax
jl     120a <print_size+0xfa>
movabs $0xffffffffff,%rsi
add    %rax,%rsi
test   %rax,%rax
cmovns %rax,%rsi
movabs $0x4010000000000,%rcx
cmp    %rcx,%rax
jl     1215 <print_size+0x105>
movabs $0x3ffffffffffff,%rsi
add    %rax,%rsi
test   %rax,%rax
cmovns %rax,%rsi
movabs $0x1004000000000000,%rcx
cmp    %rcx,%rax
jl     1220 <print_size+0x110>
movabs $0xfffffffffffffff,%rsi
ff ff 0f
add    %rax,%rsi
test   %rax,%rax
cmovns %rax,%rsi
sar    $0x3c,%rsi
mov    $0x6,%eax
jmp    1229 <print_size+0x119>
lea    0xe16(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
jmp    1030 <printf@plt>
sar    $0xa,%rsi
mov    $0x1,%eax
jmp    1229 <print_size+0x119>
sar    $0x14,%rsi
mov    $0x2,%eax
jmp    1229 <print_size+0x119>
sar    $0x1e,%rsi
mov    $0x3,%eax
jmp    1229 <print_size+0x119>
sar    $0x28,%rsi
mov    $0x4,%eax
jmp    1229 <print_size+0x119>
sar    $0x32,%rsi
mov    $0x5,%eax
lea    0xddc(%rip),%rcx
movsbl (%rax,%rcx,1),%edx
lea    0xdca(%rip),%rdi
xor    %eax,%eax
jmp    1030 <printf@plt>

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

LLVM IR (-O2):
@.str = [5 x i8] c"%ld\0A\00"
@.str.1 = [7 x i8] c"%ld%c\0A\00"
@.str.2 = [7 x i8] c"\00kMGTP\00"
define void @print_size(i64 %0, i8 signext %1) {
%3 = icmp sgt i64 %0, 1023
%4 = icmp ne i8 %1, 0
%5 = and i1 %3, %4
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %0)
br label %32
8: ; preds = %2
%9 = sdiv i64 %0, 1024
%10 = icmp sgt i64 %0, 1049599
br i1 %10, label %11, label %25
11: ; preds = %8
%12 = sdiv i64 %0, 1048576
%13 = icmp sgt i64 %0, 1074790399
br i1 %13, label %14, label %25
14: ; preds = %11
%15 = sdiv i64 %0, 1073741824
%16 = icmp sgt i64 %0, 1100585369599
br i1 %16, label %17, label %25
17: ; preds = %14
%18 = sdiv i64 %0, 1099511627776
%19 = icmp sgt i64 %0, 1126999418470399
br i1 %19, label %20, label %25
20: ; preds = %17
%21 = sdiv i64 %0, 1125899906842624
%22 = icmp sgt i64 %0, 1154047404513689599
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = sdiv i64 %0, 1152921504606846976
br label %25
25: ; preds = %23, %20, %17, %14, %11, %8
%26 = phi i64 [ 1, %8 ], [ 2, %11 ], [ 3, %14 ], [ 4, %17 ], [ 5, %20 ], [ 6, %23 ]
%27 = phi i64 [ %9, %8 ], [ %12, %11 ], [ %15, %14 ], [ %18, %17 ], [ %21, %20 ], [ %24, %23 ]
%28 = getelementptr inbounds [7 x i8], [7 x i8]* @.str.2, i64 0, i64 %26
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = tail call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i64 %27, i32 %30)
br label %32
32: ; preds = %25, %6
ret void
}