#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*/ sprintf(char *, char *, unsigned long);
char *show_size64(char *buf, unsigned long long size) {
  char *format;
  unsigned long x = 0;
  if (size < (10 * 1024UL)) {
    format = "%lu bytes";
    x = size;
  } else if (size < (10 * 1024UL * 1024UL)) {
    format = "%lu kB";
    x = size / 1024UL;
  } else if (size < (10 * 1024UL * 1024UL * 1024UL)) {
    format = "%lu MB";
    x = size / (1024UL * 1024UL);
  } else {
    format = "%lu GB";
    x = size / (1024UL * 1024UL * 1024UL);
  }
  sprintf(buf, format, x);
  return buf;
}


x86 assembly (clang, -O0):
<show_size64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x2800,-0x10(%rbp)
jae    114e <show_size64+0x3e>
lea    0xec3(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    11c9 <show_size64+0xb9>
cmpq   $0xa00000,-0x10(%rbp)
jae    1178 <show_size64+0x68>
lea    0xea7(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
shr    $0xa,%rax
mov    %rax,-0x20(%rbp)
jmp    11c4 <show_size64+0xb4>
movabs $0x280000000,%rax
cmp    %rax,-0x10(%rbp)
jae    11a8 <show_size64+0x98>
lea    0xe7e(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
shr    $0x14,%rax
mov    %rax,-0x20(%rbp)
jmp    11bf <show_size64+0xaf>
lea    0xe69(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
shr    $0x1e,%rax
mov    %rax,-0x20(%rbp)
jmp    11c4 <show_size64+0xb4>
jmp    11c9 <show_size64+0xb9>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <sprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_size64>:
push   %rbx
mov    %rsi,%rdx
mov    %rdi,%rbx
cmp    $0x2800,%rsi
jae    1129 <show_size64+0x19>
lea    0xed9(%rip),%rsi
jmp    1164 <show_size64+0x54>
cmp    $0x9fffff,%rdx
ja     113f <show_size64+0x2f>
shr    $0xa,%rdx
lea    0xecd(%rip),%rsi
jmp    1164 <show_size64+0x54>
mov    %rdx,%rax
shr    $0x1f,%rax
cmp    $0x4,%rax
ja     1159 <show_size64+0x49>
shr    $0x14,%rdx
lea    0xeba(%rip),%rsi
jmp    1164 <show_size64+0x54>
shr    $0x1e,%rdx
lea    0xeb4(%rip),%rsi
mov    %rbx,%rdi
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [10 x i8] c"%lu bytes\00"
@.str.1 = [7 x i8] c"%lu kB\00"
@.str.2 = [7 x i8] c"%lu MB\00"
@.str.3 = [7 x i8] c"%lu GB\00"
define i8* @show_size64(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
store i64 0, i64* %6
%7 = load i64, i64* %4
%8 = icmp ult i64 %7, 10240
br i1 %8, label %9, label %11
9: ; preds = %2
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %5
%10 = load i64, i64* %4
store i64 %10, i64* %6
br label %28
11: ; preds = %2
%12 = load i64, i64* %4
%13 = icmp ult i64 %12, 10485760
br i1 %13, label %14, label %17
14: ; preds = %11
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8** %5
%15 = load i64, i64* %4
%16 = udiv i64 %15, 1024
store i64 %16, i64* %6
br label %27
17: ; preds = %11
%18 = load i64, i64* %4
%19 = icmp ult i64 %18, 10737418240
br i1 %19, label %20, label %23
20: ; preds = %17
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8** %5
%21 = load i64, i64* %4
%22 = udiv i64 %21, 1048576
store i64 %22, i64* %6
br label %26
23: ; preds = %17
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8** %5
%24 = load i64, i64* %4
%25 = udiv i64 %24, 1073741824
store i64 %25, i64* %6
br label %26
26: ; preds = %23, %20
br label %27
27: ; preds = %26, %14
br label %28
28: ; preds = %27, %9
%29 = load i8*, i8** %3
%30 = load i8*, i8** %5
%31 = load i64, i64* %6
%32 = call i32 @sprintf(i8* %29, i8* %30, i64 %31)
%33 = load i8*, i8** %3
ret i8* %33
}

LLVM IR (-O2):
@.str = [10 x i8] c"%lu bytes\00"
@.str.1 = [7 x i8] c"%lu kB\00"
@.str.2 = [7 x i8] c"%lu MB\00"
@.str.3 = [7 x i8] c"%lu GB\00"
define i8* @show_size64(i8* returned writeonly %0, i64 %1) {
%3 = icmp ult i64 %1, 10240
br i1 %3, label %14, label %4
4: ; preds = %2
%5 = icmp ult i64 %1, 10485760
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = lshr i64 %1, 10
br label %14
8: ; preds = %4
%9 = icmp ult i64 %1, 10737418240
br i1 %9, label %10, label %12
10: ; preds = %8
%11 = lshr i64 %1, 20
br label %14
12: ; preds = %8
%13 = lshr i64 %1, 30
br label %14
14: ; preds = %2, %6, %12, %10
%15 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), %6 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), %10 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), %12 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %2 ]
%16 = phi i64 [ %7, %6 ], [ %11, %10 ], [ %13, %12 ], [ %1, %2 ]
%17 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) %15, i64 %16)
ret i8* %0
}