#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 */
typedef int u_int32_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int, ...);
void printsize(u_int32_t x) {
  int i;
  static const char *flags = "KMGT";
  printf("%u ", x);
  for (i = 0; x >= 1024 && flags[i] != '\0'; i++)
    x /= 1024;
  i--;
  if (i >= 0)
    printf("(%u%c)", x, flags[i]);
}


x86 assembly (clang, -O0):
<printsize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xee0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
xor    %eax,%eax
cmpl   $0x400,-0x4(%rbp)
mov    %al,-0x9(%rbp)
jl     115d <printsize+0x4d>
mov    0x2edc(%rip),%rax
movslq -0x8(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
test   $0x1,%al
jne    116d <printsize+0x5d>
jmp    1189 <printsize+0x79>
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    1133 <printsize+0x23>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     11bc <printsize+0xac>
mov    -0x4(%rbp),%esi
mov    0x2e82(%rip),%rax
movslq -0x8(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printsize>:
push   %rbx
mov    %edi,%ebx
lea    0xeeb(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
cmp    $0x400,%ebx
jge    112d <printsize+0x1d>
pop    %rbx
ret
cmp    $0x100000,%ebx
jae    113c <printsize+0x2c>
shr    $0xa,%ebx
xor    %eax,%eax
jmp    1160 <printsize+0x50>
mov    %ebx,%ecx
shr    $0x14,%ecx
mov    %ebx,%edx
shr    $0x1e,%edx
cmp    $0x40000000,%ebx
mov    $0x2,%eax
sbb    $0x0,%rax
cmp    $0x40000000,%ebx
cmovb  %ecx,%edx
mov    %edx,%ebx
lea    0xe99(%rip),%rcx
movsbl (%rax,%rcx,1),%edx
lea    0xe97(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
pop    %rbx
jmp    1030 <printf@plt>

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

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