#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 /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, long, long, long, long);
char *human_size(long long bytes) {
  static char buf[30];
  if (bytes < 5000 * 1024)
    buf[0] = 0;
  else if (bytes < 2 * 1024LL * 1024LL * 1024LL) {
    long cMiB = (bytes / ((1LL << 20) / 200LL) + 1) / 2;
    long cMB = (bytes / (1000000LL / 200LL) + 1) / 2;
    snprintf(buf, sizeof(buf), " (%ld.%02ld MiB %ld.%02ld MB)", cMiB / 100,
             cMiB % 100, cMB / 100, cMB % 100);
  } else {
    long cGiB = (bytes / ((1LL << 30) / 200LL) + 1) / 2;
    long cGB = (bytes / (1000000000LL / 200LL) + 1) / 2;
    snprintf(buf, sizeof(buf), " (%ld.%02ld GiB %ld.%02ld GB)", cGiB / 100,
             cGiB % 100, cGB / 100, cGB % 100);
  }
  return buf;
}


x86 assembly (clang, -O0):
<human_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x4e2000,-0x8(%rbp)
jge    1136 <human_size+0x26>
movb   $0x0,0x2f0f(%rip)
jmp    128f <human_size+0x17f>
mov    $0x80000000,%eax
cmp    %rax,-0x8(%rbp)
jge    11ea <human_size+0xda>
mov    -0x8(%rbp),%rax
mov    $0x147a,%ecx
cqto
idiv   %rcx
add    $0x1,%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x1388,%ecx
cqto
idiv   %rcx
add    $0x1,%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x64,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    $0x64,%esi
cqto
idiv   %rsi
mov    %rdx,%r8
mov    -0x18(%rbp),%rax
mov    $0x64,%esi
cqto
idiv   %rsi
mov    %rax,%r9
mov    -0x18(%rbp),%rax
mov    $0x64,%esi
cqto
idiv   %rsi
mov    %rdx,%rax
lea    0x2e70(%rip),%rdi
mov    $0x1e,%esi
lea    0xe24(%rip),%rdx
mov    %rax,(%rsp)
call   1030 <snprintf@plt>
jmp    128a <human_size+0x17a>
mov    -0x8(%rbp),%rax
mov    $0x51eb85,%ecx
cqto
idiv   %rcx
add    $0x1,%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x4c4b40,%ecx
cqto
idiv   %rcx
add    $0x1,%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    $0x64,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    $0x64,%esi
cqto
idiv   %rsi
mov    %rdx,%r8
mov    -0x28(%rbp),%rax
mov    $0x64,%esi
cqto
idiv   %rsi
mov    %rax,%r9
mov    -0x28(%rbp),%rax
mov    $0x64,%esi
cqto
idiv   %rsi
mov    %rdx,%rax
lea    0x2dcb(%rip),%rdi
mov    $0x1e,%esi
lea    0xd9d(%rip),%rdx
mov    %rax,(%rsp)
call   1030 <snprintf@plt>
jmp    128f <human_size+0x17f>
lea    0x2daa(%rip),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<human_size>:
push   %rax
cmp    $0x4e1fff,%rdi
jg     1126 <human_size+0x16>
movb   $0x0,0x2f1f(%rip)
jmp    1244 <human_size+0x134>
cmp    $0x7fffffff,%rdi
ja     11a6 <human_size+0x96>
mov    %edi,%eax
mov    $0xc808985f,%r8d
imul   %rax,%r8
shr    $0x2c,%r8
add    $0x1,%r8d
imul   $0x51eb851f,%r8,%rcx
shr    %r8d
mov    $0xd1b71759,%edx
imul   %rax,%rdx
shr    $0x2c,%rdx
add    $0x1,%edx
imul   $0x51eb851f,%rdx,%r9
shr    %edx
shr    $0x26,%rcx
imul   $0x51eb851f,%r8,%rax
shr    $0x25,%rax
imul   $0x64,%eax,%eax
sub    %eax,%r8d
shr    $0x26,%r9
imul   $0x51eb851f,%rdx,%rax
shr    $0x25,%rax
imul   $0x64,%eax,%eax
sub    %eax,%edx
mov    %rdx,(%rsp)
lea    0x2ea6(%rip),%rdi
lea    0xe5f(%rip),%rdx
jmp    123a <human_size+0x12a>
movabs $0x9000009600003841,%rcx
mov    %rdi,%rax
mul    %rcx
mov    %rdi,%rcx
sub    %rdx,%rcx
shr    %rcx
add    %rdx,%rcx
shr    $0x16,%rcx
add    $0x1,%rcx
mov    %rcx,%r8
shr    %r8
movabs $0xd6bf94d5e57a42bd,%rdx
94 bf d6
mov    %rdi,%rax
mul    %rdx
shr    $0x16,%rdx
lea    0x1(%rdx),%rsi
mov    %rsi,%rdi
shr    %rdi
shr    $0x3,%rcx
movabs $0x28f5c28f5c28f5c3,%r9
c2 f5 28
mov    %rcx,%rax
mul    %r9
mov    %rdx,%rcx
shr    $0x2,%rcx
imul   $0x64,%rcx,%r10
shr    $0x3,%rsi
mov    %rsi,%rax
mul    %r9
mov    %rdx,%r9
sub    %r10,%r8
shr    $0x2,%r9
imul   $0x64,%r9,%rax
sub    %rax,%rdi
mov    %rdi,(%rsp)
lea    0x2e0d(%rip),%rdi
lea    0xde4(%rip),%rdx
mov    $0x1e,%esi
call   1030 <snprintf@plt>
lea    0x2df5(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
@human_size.buf = internal global [30 x i8] zeroinitializer
@.str = [30 x i8] c" (%ld.%02ld MiB %ld.%02ld MB)\00"
@.str.1 = [30 x i8] c" (%ld.%02ld GiB %ld.%02ld GB)\00"
define i8* @human_size(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store i64 %0, i64* %2
%7 = load i64, i64* %2
%8 = icmp slt i64 %7, 5120000
br i1 %8, label %9, label %10
9: ; preds = %1
store i8 0, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @human_size.buf, i64 0, i64 0)
br label %50
10: ; preds = %1
%11 = load i64, i64* %2
%12 = icmp slt i64 %11, 2147483648
br i1 %12, label %13, label %31
13: ; preds = %10
%14 = load i64, i64* %2
%15 = sdiv i64 %14, 5242
%16 = add nsw i64 %15, 1
%17 = sdiv i64 %16, 2
store i64 %17, i64* %3
%18 = load i64, i64* %2
%19 = sdiv i64 %18, 5000
%20 = add nsw i64 %19, 1
%21 = sdiv i64 %20, 2
store i64 %21, i64* %4
%22 = load i64, i64* %3
%23 = sdiv i64 %22, 100
%24 = load i64, i64* %3
%25 = srem i64 %24, 100
%26 = load i64, i64* %4
%27 = sdiv i64 %26, 100
%28 = load i64, i64* %4
%29 = srem i64 %28, 100
%30 = call i32 @snprintf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @human_size.buf, i64 0, i64 0), i32 30, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i64 %23, i64 %25, i64 %27, i64 %29)
br label %49
31: ; preds = %10
%32 = load i64, i64* %2
%33 = sdiv i64 %32, 5368709
%34 = add nsw i64 %33, 1
%35 = sdiv i64 %34, 2
store i64 %35, i64* %5
%36 = load i64, i64* %2
%37 = sdiv i64 %36, 5000000
%38 = add nsw i64 %37, 1
%39 = sdiv i64 %38, 2
store i64 %39, i64* %6
%40 = load i64, i64* %5
%41 = sdiv i64 %40, 100
%42 = load i64, i64* %5
%43 = srem i64 %42, 100
%44 = load i64, i64* %6
%45 = sdiv i64 %44, 100
%46 = load i64, i64* %6
%47 = srem i64 %46, 100
%48 = call i32 @snprintf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @human_size.buf, i64 0, i64 0), i32 30, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i64 %41, i64 %43, i64 %45, i64 %47)
br label %49
49: ; preds = %31, %13
br label %50
50: ; preds = %49, %9
ret i8* getelementptr inbounds ([30 x i8], [30 x i8]* @human_size.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@human_size.buf = internal global [30 x i8] zeroinitializer
@.str = [30 x i8] c" (%ld.%02ld MiB %ld.%02ld MB)\00"
@.str.1 = [30 x i8] c" (%ld.%02ld GiB %ld.%02ld GB)\00"
define i8* @human_size(i64 %0) {
%2 = icmp slt i64 %0, 5120000
br i1 %2, label %3, label %4
3: ; preds = %1
store i8 0, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @human_size.buf, i64 0, i64 0)
br label %35
4: ; preds = %1
%5 = icmp ult i64 %0, 2147483648
br i1 %5, label %6, label %23
6: ; preds = %4
%7 = trunc i64 %0 to i32
%8 = udiv i32 %7, 5242
%9 = add nuw nsw i32 %8, 1
%10 = lshr i32 %9, 1
%11 = udiv i32 %7, 5000
%12 = add nuw nsw i32 %11, 1
%13 = lshr i32 %12, 1
%14 = udiv i32 %9, 200
%15 = zext i32 %14 to i64
%16 = urem i32 %10, 100
%17 = zext i32 %16 to i64
%18 = udiv i32 %12, 200
%19 = zext i32 %18 to i64
%20 = urem i32 %13, 100
%21 = zext i32 %20 to i64
%22 = tail call i32 @snprintf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @human_size.buf, i64 0, i64 0), i32 30, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i64 %15, i64 %17, i64 %19, i64 %21)
br label %35
23: ; preds = %4
%24 = udiv i64 %0, 5368709
%25 = add nuw nsw i64 %24, 1
%26 = lshr i64 %25, 1
%27 = udiv i64 %0, 5000000
%28 = add nuw nsw i64 %27, 1
%29 = lshr i64 %28, 1
%30 = udiv i64 %25, 200
%31 = urem i64 %26, 100
%32 = udiv i64 %28, 200
%33 = urem i64 %29, 100
%34 = tail call i32 @snprintf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @human_size.buf, i64 0, i64 0), i32 30, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i64 %30, i64 %31, i64 %32, i64 %33)
br label %35
35: ; preds = %6, %23, %3
ret i8* getelementptr inbounds ([30 x i8], [30 x i8]* @human_size.buf, i64 0, i64 0)
}