#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_int;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int);
void print_size(u_int i) {
  if (i < 1024)
    printf("%ubits", i);
  else if (i < 1024 * 1024)
    printf("%ukb", i / 1024);
  else
    printf("%uMb", i / (1024 * 1024));
}


x86 assembly (clang, -O0):
<print_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x400,-0x4(%rbp)
jge    113c <print_size+0x2c>
mov    -0x4(%rbp),%esi
lea    0xece(%rip),%rdi
call   1030 <printf@plt>
jmp    1185 <print_size+0x75>
cmpl   $0x100000,-0x4(%rbp)
jge    1167 <print_size+0x57>
mov    -0x4(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xeaa(%rip),%rdi
call   1030 <printf@plt>
jmp    1180 <print_size+0x70>
mov    -0x4(%rbp),%eax
mov    $0x100000,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xe91(%rip),%rdi
call   1030 <printf@plt>
jmp    1185 <print_size+0x75>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_size>:
mov    %edi,%esi
cmp    $0x3ff,%edi
jg     1126 <print_size+0x16>
lea    0xedf(%rip),%rdi
jmp    1030 <printf@plt>
cmp    $0xfffff,%esi
ja     113d <print_size+0x2d>
shr    $0xa,%esi
lea    0xecf(%rip),%rdi
jmp    1030 <printf@plt>
shr    $0x14,%esi
lea    0xec5(%rip),%rdi
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"%ubits\00"
@.str.1 = [5 x i8] c"%ukb\00"
@.str.2 = [5 x i8] c"%uMb\00"
define void @print_size(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = icmp slt i32 %3, 1024
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = load i32, i32* %2
%7 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %6)
br label %20
8: ; preds = %1
%9 = load i32, i32* %2
%10 = icmp slt i32 %9, 1048576
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = load i32, i32* %2
%13 = sdiv i32 %12, 1024
%14 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %13)
br label %19
15: ; preds = %8
%16 = load i32, i32* %2
%17 = sdiv i32 %16, 1048576
%18 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %15, %11
br label %20
20: ; preds = %19, %5
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%ubits\00"
@.str.1 = [5 x i8] c"%ukb\00"
@.str.2 = [5 x i8] c"%uMb\00"
define void @print_size(i32 %0) {
%2 = icmp slt i32 %0, 1024
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %13
5: ; preds = %1
%6 = icmp ult i32 %0, 1048576
br i1 %6, label %7, label %10
7: ; preds = %5
%8 = lshr i32 %0, 10
%9 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %8)
br label %13
10: ; preds = %5
%11 = lshr i32 %0, 20
%12 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %11)
br label %13
13: ; preds = %7, %10, %3
ret void
}