#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 */
char *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, long);
char *bytes_to_size(long bytes) {
  char *ret = malloc(5);
  if (bytes >= 1073741824L)
    sprintf(ret, "%ldGB", bytes / (1024 * 1024 * 1024));
  else if (bytes >= 1048576L)
    sprintf(ret, "%ldMB", bytes / (1024 * 1024));
  else if (bytes >= 1024)
    sprintf(ret, "%ldKB", bytes / 1024);
  else
    sprintf(ret, "%ldB", bytes);
  return ret;
}


x86 assembly (clang, -O0):
<bytes_to_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x5,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x40000000,-0x8(%rbp)
40
jl     116e <bytes_to_size+0x4e>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    $0x40000000,%ecx
cqto
idiv   %rcx
mov    %rax,%rdx
lea    0xe9c(%rip),%rsi
call   1040 <sprintf@plt>
jmp    11f4 <bytes_to_size+0xd4>
cmpq   $0x100000,-0x8(%rbp)
jl     11a2 <bytes_to_size+0x82>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    $0x100000,%ecx
cqto
idiv   %rcx
mov    %rax,%rdx
lea    0xe6e(%rip),%rsi
call   1040 <sprintf@plt>
jmp    11ef <bytes_to_size+0xcf>
cmpq   $0x400,-0x8(%rbp)
jl     11d6 <bytes_to_size+0xb6>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    $0x400,%ecx
cqto
idiv   %rcx
mov    %rax,%rdx
lea    0xe40(%rip),%rsi
call   1040 <sprintf@plt>
jmp    11ea <bytes_to_size+0xca>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe2d(%rip),%rsi
call   1040 <sprintf@plt>
jmp    11ef <bytes_to_size+0xcf>
jmp    11f4 <bytes_to_size+0xd4>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bytes_to_size>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x5,%edi
call   1030 <malloc@plt>
mov    %rax,%r14
cmp    $0x40000000,%rbx
jl     114a <bytes_to_size+0x2a>
shr    $0x1e,%rbx
lea    0xeb8(%rip),%rsi
jmp    117d <bytes_to_size+0x5d>
cmp    $0x100000,%rbx
jl     1160 <bytes_to_size+0x40>
shr    $0x14,%rbx
lea    0xea8(%rip),%rsi
jmp    117d <bytes_to_size+0x5d>
cmp    $0x400,%rbx
jl     1176 <bytes_to_size+0x56>
shr    $0xa,%rbx
lea    0xe98(%rip),%rsi
jmp    117d <bytes_to_size+0x5d>
lea    0xe95(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1040 <sprintf@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%ldGB\00"
@.str.1 = [6 x i8] c"%ldMB\00"
@.str.2 = [6 x i8] c"%ldKB\00"
@.str.3 = [5 x i8] c"%ldB\00"
define i8* @bytes_to_size(i64 %0) {
%2 = alloca i64
%3 = alloca i8*
store i64 %0, i64* %2
%4 = call i8* @malloc(i32 5)
store i8* %4, i8** %3
%5 = load i64, i64* %2
%6 = icmp sge i64 %5, 1073741824
br i1 %6, label %7, label %12
7: ; preds = %1
%8 = load i8*, i8** %3
%9 = load i64, i64* %2
%10 = sdiv i64 %9, 1073741824
%11 = call i32 @sprintf(i8* %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %10)
br label %34
12: ; preds = %1
%13 = load i64, i64* %2
%14 = icmp sge i64 %13, 1048576
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = load i8*, i8** %3
%17 = load i64, i64* %2
%18 = sdiv i64 %17, 1048576
%19 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %18)
br label %33
20: ; preds = %12
%21 = load i64, i64* %2
%22 = icmp sge i64 %21, 1024
br i1 %22, label %23, label %28
23: ; preds = %20
%24 = load i8*, i8** %3
%25 = load i64, i64* %2
%26 = sdiv i64 %25, 1024
%27 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %26)
br label %32
28: ; preds = %20
%29 = load i8*, i8** %3
%30 = load i64, i64* %2
%31 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 %30)
br label %32
32: ; preds = %28, %23
br label %33
33: ; preds = %32, %15
br label %34
34: ; preds = %33, %7
%35 = load i8*, i8** %3
ret i8* %35
}

LLVM IR (-O2):
@.str = [6 x i8] c"%ldGB\00"
@.str.1 = [6 x i8] c"%ldMB\00"
@.str.2 = [6 x i8] c"%ldKB\00"
@.str.3 = [5 x i8] c"%ldB\00"
define noalias i8* @bytes_to_size(i64 %0) {
%2 = tail call dereferenceable_or_null(5) i8* @malloc(i32 5)
%3 = icmp sgt i64 %0, 1073741823
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = lshr i64 %0, 30
%6 = tail call i32 @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %5)
br label %19
7: ; preds = %1
%8 = icmp sgt i64 %0, 1048575
br i1 %8, label %9, label %12
9: ; preds = %7
%10 = lshr i64 %0, 20
%11 = tail call i32 @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %10)
br label %19
12: ; preds = %7
%13 = icmp sgt i64 %0, 1023
br i1 %13, label %14, label %17
14: ; preds = %12
%15 = lshr i64 %0, 10
%16 = tail call i32 @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %15)
br label %19
17: ; preds = %12
%18 = tail call i32 @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 %0)
br label %19
19: ; preds = %9, %17, %14, %4
ret i8* %2
}