#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 *, float, char const *);
void printsize(size_t size) {
  static const char *SIZES[] = {"B", "kB", "MB", "GB"};
  size_t div = 0;
  size_t rem = 0;
  while (size >= 1024 && div < (sizeof SIZES / sizeof *SIZES)) {
    rem = (size % 1024);
    div++;
    size /= 1024;
  }
  printf("%.1f %s\n", (float)size + (float)rem / 1024.0, SIZES[div]);
}


x86 assembly (clang, -O0):
<printsize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
xor    %eax,%eax
cmpq   $0x400,-0x8(%rbp)
mov    %al,-0x19(%rbp)
jb     114a <printsize+0x3a>
cmpq   $0x4,-0x10(%rbp)
setb   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    115a <printsize+0x4a>
jmp    1185 <printsize+0x75>
mov    -0x8(%rbp),%rax
and    $0x3ff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
shr    $0xa,%rax
mov    %rax,-0x8(%rbp)
jmp    112c <printsize+0x1c>
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x24(%rbp)
test   %rax,%rax
movss  %xmm0,-0x20(%rbp)
js     11c2 <printsize+0xb2>
movss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x2c(%rbp)
test   %rax,%rax
movss  %xmm0,-0x28(%rbp)
js     120d <printsize+0xfd>
movss  -0x2c(%rbp),%xmm0
movss  %xmm0,-0x28(%rbp)
movsd  -0x38(%rbp),%xmm0
movss  -0x28(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
movsd  0xddd(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
mov    -0x10(%rbp),%rcx
lea    0x2df6(%rip),%rax
mov    (%rax,%rcx,8),%rsi
lea    0xdcc(%rip),%rdi
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printsize>:
cmp    $0x400,%rdi
jb     115f <printsize+0x4f>
mov    %rdi,%rsi
shr    $0xa,%rsi
mov    $0x1,%eax
cmp    $0x100000,%rdi
jb     1181 <printsize+0x71>
mov    %rdi,%rdx
shr    $0x14,%rdx
mov    $0x2,%eax
cmp    $0x40000000,%rdi
jb     1186 <printsize+0x76>
mov    %rdi,%rsi
shr    $0x1e,%rsi
shr    $0x28,%rdi
mov    $0x3,%eax
je     118e <printsize+0x7e>
mov    $0x4,%eax
mov    %rsi,%rcx
jmp    1194 <printsize+0x84>
xorpd  %xmm0,%xmm0
xor    %eax,%eax
test   %rdi,%rdi
jns    11af <printsize+0x9f>
mov    %rdi,%rcx
shr    %rcx
and    $0x1,%edi
or     %rcx,%rdi
cvtsi2ss %rdi,%xmm1
addss  %xmm1,%xmm1
jmp    11b4 <printsize+0xa4>
mov    %rdi,%rcx
jmp    1191 <printsize+0x81>
mov    %rsi,%rcx
mov    %rdx,%rdi
jmp    1194 <printsize+0x84>
mov    %rdx,%rcx
mov    %rsi,%rdi
and    $0x3ff,%ecx
cvtsi2ss %ecx,%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  0xe56(%rip),%xmm0
test   %rdi,%rdi
js     116a <printsize+0x5a>
cvtsi2ss %rdi,%xmm1
cvtss2sd %xmm1,%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
lea    0xe41(%rip),%rcx
movslq (%rcx,%rax,4),%rsi
add    %rcx,%rsi
lea    0xe4c(%rip),%rdi
jmp    1030 <printf@plt>

LLVM IR (-O0):
@printsize.SIZES = internal global [4 x i8*] [i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i32 0, i32 0)]
@.str = [2 x i8] c"B\00"
@.str.1 = [3 x i8] c"kB\00"
@.str.2 = [3 x i8] c"MB\00"
@.str.3 = [3 x i8] c"GB\00"
@.str.4 = [9 x i8] c"%.1f %s\0A\00"
define void @printsize(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
store i64 %0, i64* %2
store i64 0, i64* %3
store i64 0, i64* %4
br label %5
5: ; preds = %13, %1
%6 = load i64, i64* %2
%7 = icmp uge i64 %6, 1024
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = load i64, i64* %3
%10 = icmp ult i64 %9, 4
br label %11
11: ; preds = %8, %5
%12 = phi i1 [ false, %5 ], [ %10, %8 ]
br i1 %12, label %13, label %20
13: ; preds = %11
%14 = load i64, i64* %2
%15 = urem i64 %14, 1024
store i64 %15, i64* %4
%16 = load i64, i64* %3
%17 = add i64 %16, 1
store i64 %17, i64* %3
%18 = load i64, i64* %2
%19 = udiv i64 %18, 1024
store i64 %19, i64* %2
br label %5
20: ; preds = %11
%21 = load i64, i64* %2
%22 = uitofp i64 %21 to float
%23 = fpext float %22 to double
%24 = load i64, i64* %4
%25 = uitofp i64 %24 to float
%26 = fpext float %25 to double
%27 = fdiv double %26, 1.024000e+03
%28 = fadd double %23, %27
%29 = fptrunc double %28 to float
%30 = load i64, i64* %3
%31 = getelementptr inbounds [4 x i8*], [4 x i8*]* @printsize.SIZES, i64 0, i64 %30
%32 = load i8*, i8** %31
%33 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), float %29, i8* %32)
ret void
}

LLVM IR (-O2):
@reltable.printsize = internal unnamed_addr constant [4 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([2 x i8]* @.str to i64), i64 ptrtoint ([4 x i32]* @reltable.printsize to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.1 to i64), i64 ptrtoint ([4 x i32]* @reltable.printsize to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.2 to i64), i64 ptrtoint ([4 x i32]* @reltable.printsize to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.3 to i64), i64 ptrtoint ([4 x i32]* @reltable.printsize to i64)) to i32)]
@.str = [2 x i8] c"B\00"
@.str.1 = [3 x i8] c"kB\00"
@.str.2 = [3 x i8] c"MB\00"
@.str.3 = [3 x i8] c"GB\00"
@.str.4 = [9 x i8] c"%.1f %s\0A\00"
define void @printsize(i64 %0) {
%2 = icmp ugt i64 %0, 1023
br i1 %2, label %3, label %22
3: ; preds = %1
%4 = lshr i64 %0, 10
%5 = icmp ugt i64 %0, 1048575
br i1 %5, label %6, label %14
6: ; preds = %3
%7 = lshr i64 %0, 20
%8 = icmp ugt i64 %0, 1073741823
br i1 %8, label %9, label %14
9: ; preds = %6
%10 = lshr i64 %0, 30
%11 = icmp ugt i64 %0, 1099511627775
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = lshr i64 %0, 40
br label %14
14: ; preds = %12, %9, %6, %3
%15 = phi i64 [ %0, %3 ], [ %4, %6 ], [ %7, %9 ], [ %10, %12 ]
%16 = phi i64 [ 1, %3 ], [ 2, %6 ], [ 3, %9 ], [ 4, %12 ]
%17 = phi i64 [ %4, %3 ], [ %7, %6 ], [ %10, %9 ], [ %13, %12 ]
%18 = and i64 %15, 1023
%19 = uitofp i64 %18 to float
%20 = fpext float %19 to double
%21 = fmul double %20, 0x3F50000000000000
br label %22
22: ; preds = %14, %1
%23 = phi i64 [ %17, %14 ], [ %0, %1 ]
%24 = phi i64 [ %16, %14 ], [ 0, %1 ]
%25 = phi double [ %21, %14 ], [ 0.000000e+00, %1 ]
%26 = uitofp i64 %23 to float
%27 = fpext float %26 to double
%28 = fadd double %25, %27
%29 = fptrunc double %28 to float
%30 = shl i64 %24, 2
%31 = call i8* @llvm.load.relative.i64(i8* bitcast ([4 x i32]* @reltable.printsize to i8*), i64 %30)
%32 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), float %29, i8* %31)
ret void
}