#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 *, unsigned int);
void display_size(unsigned v) {
  if (v > 1024 * 1024) {
    printf("%8.1f Gbytes", v / ((double)(1024 * 1024)));
  } else if (v > 1024) {
    printf("%8.1f Mbytes", v / ((double)(1024)));
  } else {
    printf("%8u Kbytes", v);
  }
}


x86 assembly (clang, -O0):
<display_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x100000,-0x4(%rbp)
jbe    1154 <display_size+0x44>
mov    -0x4(%rbp),%eax
cvtsi2sd %rax,%xmm0
movsd  0xed0(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %eax,%esi
lea    0xec6(%rip),%rdi
call   1030 <printf@plt>
jmp    11a1 <display_size+0x91>
cmpl   $0x400,-0x4(%rbp)
jbe    118d <display_size+0x7d>
mov    -0x4(%rbp),%eax
cvtsi2sd %rax,%xmm0
movsd  0xe8f(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %eax,%esi
lea    0xe9a(%rip),%rdi
call   1030 <printf@plt>
jmp    119c <display_size+0x8c>
mov    -0x4(%rbp),%esi
lea    0xe93(%rip),%rdi
call   1030 <printf@plt>
jmp    11a1 <display_size+0x91>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<display_size>:
mov    %edi,%esi
cmp    $0x100001,%edi
jb     113a <display_size+0x2a>
mov    %esi,%eax
cvtsi2sd %rax,%xmm0
mulsd  0xedf(%rip),%xmm0
cvttsd2si %xmm0,%rsi
lea    0xedb(%rip),%rdi
jmp    1030 <printf@plt>
cmp    $0x401,%esi
jb     1162 <display_size+0x52>
mov    %esi,%eax
cvtsi2sd %rax,%xmm0
mulsd  0xeaf(%rip),%xmm0
cvttsd2si %xmm0,%rsi
lea    0xec0(%rip),%rdi
jmp    1030 <printf@plt>
lea    0xec1(%rip),%rdi
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"%8.1f Gbytes\00"
@.str.1 = [13 x i8] c"%8.1f Mbytes\00"
@.str.2 = [11 x i8] c"%8u Kbytes\00"
define void @display_size(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = icmp ugt i32 %3, 1048576
br i1 %4, label %5, label %11
5: ; preds = %1
%6 = load i32, i32* %2
%7 = uitofp i32 %6 to double
%8 = fdiv double %7, 0x4130000000000000
%9 = fptoui double %8 to i32
%10 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %24
11: ; preds = %1
%12 = load i32, i32* %2
%13 = icmp ugt i32 %12, 1024
br i1 %13, label %14, label %20
14: ; preds = %11
%15 = load i32, i32* %2
%16 = uitofp i32 %15 to double
%17 = fdiv double %16, 1.024000e+03
%18 = fptoui double %17 to i32
%19 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %18)
br label %23
20: ; preds = %11
%21 = load i32, i32* %2
%22 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %20, %14
br label %24
24: ; preds = %23, %5
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"%8.1f Gbytes\00"
@.str.1 = [13 x i8] c"%8.1f Mbytes\00"
@.str.2 = [11 x i8] c"%8u Kbytes\00"
define void @display_size(i32 %0) {
%2 = icmp ugt i32 %0, 1048576
br i1 %2, label %3, label %8
3: ; preds = %1
%4 = uitofp i32 %0 to double
%5 = fmul double %4, 0x3EB0000000000000
%6 = fptoui double %5 to i32
%7 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %6)
br label %17
8: ; preds = %1
%9 = icmp ugt i32 %0, 1024
br i1 %9, label %10, label %15
10: ; preds = %8
%11 = uitofp i32 %0 to double
%12 = fmul double %11, 0x3F50000000000000
%13 = fptoui double %12 to i32
%14 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %13)
br label %17
15: ; preds = %8
%16 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %0)
br label %17
17: ; preds = %10, %15, %3
ret void
}