#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);
char *human_size_brief(long long bytes) {
  static char buf[30];
  if (bytes < 5000 * 1024)
    snprintf(buf, sizeof(buf), "%ld.%02ldKiB", (long)(bytes >> 10),
             (long)(((bytes & 1023) * 100 + 512) / 1024));
  else if (bytes < 2 * 1024LL * 1024LL * 1024LL)
    snprintf(buf, sizeof(buf), "%ld.%02ldMiB", (long)(bytes >> 20),
             (long)((bytes & 0xfffff) + 0x100000 / 200) / (0x100000 / 100));
  else
    snprintf(buf, sizeof(buf), "%ld.%02ldGiB", (long)(bytes >> 30),
             (long)(((bytes >> 10) & 0xfffff) + 0x100000 / 200) /
                 (0x100000 / 100));
  return buf;
}


x86 assembly (clang, -O0):
<human_size_brief>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x4e2000,-0x8(%rbp)
jge    1170 <human_size_brief+0x60>
mov    -0x8(%rbp),%rcx
sar    $0xa,%rcx
mov    -0x8(%rbp),%rax
and    $0x3ff,%rax
imul   $0x64,%rax,%rax
add    $0x200,%rax
mov    $0x400,%esi
cqto
idiv   %rsi
mov    %rax,%r8
lea    0x2ee6(%rip),%rdi
mov    $0x1e,%esi
lea    0xe9a(%rip),%rdx
call   1030 <snprintf@plt>
jmp    1207 <human_size_brief+0xf7>
mov    $0x80000000,%eax
cmp    %rax,-0x8(%rbp)
jge    11c1 <human_size_brief+0xb1>
mov    -0x8(%rbp),%rcx
sar    $0x14,%rcx
mov    -0x8(%rbp),%rax
and    $0xfffff,%rax
add    $0x147a,%rax
mov    $0x28f5,%esi
cqto
idiv   %rsi
mov    %rax,%r8
lea    0x2e95(%rip),%rdi
mov    $0x1e,%esi
lea    0xe56(%rip),%rdx
call   1030 <snprintf@plt>
jmp    1202 <human_size_brief+0xf2>
mov    -0x8(%rbp),%rcx
sar    $0x1e,%rcx
mov    -0x8(%rbp),%rax
sar    $0xa,%rax
and    $0xfffff,%rax
add    $0x147a,%rax
mov    $0x28f5,%esi
cqto
idiv   %rsi
mov    %rax,%r8
lea    0x2e4f(%rip),%rdi
mov    $0x1e,%esi
lea    0xe1d(%rip),%rdx
call   1030 <snprintf@plt>
jmp    1207 <human_size_brief+0xf7>
lea    0x2e32(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<human_size_brief>:
push   %rax
mov    %rdi,%rcx
cmp    $0x4e1fff,%rdi
jg     1146 <human_size_brief+0x36>
sar    $0xa,%rcx
and    $0x3ff,%edi
imul   $0x64,%rdi,%r8
add    $0x200,%r8
shr    $0xa,%r8
lea    0x2f03(%rip),%rdi
lea    0xebc(%rip),%rdx
jmp    11a6 <human_size_brief+0x96>
cmp    $0x7fffffff,%rdi
ja     117a <human_size_brief+0x6a>
shr    $0x14,%rcx
and    $0xfffff,%edi
add    $0x147a,%edi
imul   $0x6401db09,%rdi,%r8
shr    $0x2c,%r8
lea    0x2ecf(%rip),%rdi
lea    0xe95(%rip),%rdx
jmp    11a6 <human_size_brief+0x96>
shr    $0x1e,%rcx
shr    $0xa,%edi
and    $0xfffff,%edi
add    $0x147a,%edi
imul   $0x6401db09,%rdi,%r8
shr    $0x2c,%r8
lea    0x2ea1(%rip),%rdi
lea    0xe74(%rip),%rdx
mov    $0x1e,%esi
call   1030 <snprintf@plt>
lea    0x2e89(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
@human_size_brief.buf = internal global [30 x i8] zeroinitializer
@.str = [13 x i8] c"%ld.%02ldKiB\00"
@.str.1 = [13 x i8] c"%ld.%02ldMiB\00"
@.str.2 = [13 x i8] c"%ld.%02ldGiB\00"
define i8* @human_size_brief(i64 %0) {
%2 = alloca i64
store i64 %0, i64* %2
%3 = load i64, i64* %2
%4 = icmp slt i64 %3, 5120000
br i1 %4, label %5, label %14
5: ; preds = %1
%6 = load i64, i64* %2
%7 = ashr i64 %6, 10
%8 = load i64, i64* %2
%9 = and i64 %8, 1023
%10 = mul nsw i64 %9, 100
%11 = add nsw i64 %10, 512
%12 = sdiv i64 %11, 1024
%13 = call i32 @snprintf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @human_size_brief.buf, i64 0, i64 0), i32 30, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i64 %7, i64 %12)
br label %35
14: ; preds = %1
%15 = load i64, i64* %2
%16 = icmp slt i64 %15, 2147483648
br i1 %16, label %17, label %25
17: ; preds = %14
%18 = load i64, i64* %2
%19 = ashr i64 %18, 20
%20 = load i64, i64* %2
%21 = and i64 %20, 1048575
%22 = add nsw i64 %21, 5242
%23 = sdiv i64 %22, 10485
%24 = call i32 @snprintf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @human_size_brief.buf, i64 0, i64 0), i32 30, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i64 %19, i64 %23)
br label %34
25: ; preds = %14
%26 = load i64, i64* %2
%27 = ashr i64 %26, 30
%28 = load i64, i64* %2
%29 = ashr i64 %28, 10
%30 = and i64 %29, 1048575
%31 = add nsw i64 %30, 5242
%32 = sdiv i64 %31, 10485
%33 = call i32 @snprintf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @human_size_brief.buf, i64 0, i64 0), i32 30, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i64 %27, i64 %32)
br label %34
34: ; preds = %25, %17
br label %35
35: ; preds = %34, %5
ret i8* getelementptr inbounds ([30 x i8], [30 x i8]* @human_size_brief.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@human_size_brief.buf = internal global [30 x i8] zeroinitializer
@.str = [13 x i8] c"%ld.%02ldKiB\00"
@.str.1 = [13 x i8] c"%ld.%02ldMiB\00"
@.str.2 = [13 x i8] c"%ld.%02ldGiB\00"
define i8* @human_size_brief(i64 %0) {
%2 = icmp slt i64 %0, 5120000
br i1 %2, label %3, label %10
3: ; preds = %1
%4 = ashr i64 %0, 10
%5 = and i64 %0, 1023
%6 = mul nuw nsw i64 %5, 100
%7 = add nuw nsw i64 %6, 512
%8 = lshr i64 %7, 10
%9 = tail call i32 @snprintf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @human_size_brief.buf, i64 0, i64 0), i32 30, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i64 %4, i64 %8)
br label %29
10: ; preds = %1
%11 = icmp ult i64 %0, 2147483648
br i1 %11, label %12, label %20
12: ; preds = %10
%13 = lshr i64 %0, 20
%14 = trunc i64 %0 to i32
%15 = and i32 %14, 1048575
%16 = add nuw nsw i32 %15, 5242
%17 = udiv i32 %16, 10485
%18 = zext i32 %17 to i64
%19 = tail call i32 @snprintf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @human_size_brief.buf, i64 0, i64 0), i32 30, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i64 %13, i64 %18)
br label %29
20: ; preds = %10
%21 = lshr i64 %0, 30
%22 = trunc i64 %0 to i32
%23 = lshr i32 %22, 10
%24 = and i32 %23, 1048575
%25 = add nuw nsw i32 %24, 5242
%26 = udiv i32 %25, 10485
%27 = zext i32 %26 to i64
%28 = tail call i32 @snprintf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @human_size_brief.buf, i64 0, i64 0), i32 30, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i64 %21, i64 %27)
br label %29
29: ; preds = %12, %20, %3
ret i8* getelementptr inbounds ([30 x i8], [30 x i8]* @human_size_brief.buf, i64 0, i64 0)
}