#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*/ snprintf(char *, size_t const, char *, unsigned int, char);
void human_readable(unsigned int bytes, char *out, const size_t str_size) {
  static char units[] = "BKMGTPE";
  unsigned int remainder = bytes;
  int unit = 0;
  while (remainder > 1024) {
    remainder = remainder / 1024;
    unit++;
  }
  snprintf(out, str_size, "%d%c", remainder, units[unit]);
}


x86 assembly (clang, -O0):
<human_readable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x400,-0x1c(%rbp)
jbe    1154 <human_readable+0x44>
mov    -0x1c(%rbp),%eax
shr    $0xa,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1130 <human_readable+0x20>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%ecx
movslq -0x20(%rbp),%r8
lea    0xe96(%rip),%rdx
lea    0x2eb7(%rip),%rax
movsbl (%rax,%r8,1),%r8d
call   1030 <snprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<human_readable>:
mov    %edi,%ecx
xor    %eax,%eax
cmp    $0x401,%edi
jb     1131 <human_readable+0x21>
mov    %ecx,%edi
xchg   %ax,%ax
shr    $0xa,%ecx
add    $0x1,%rax
cmp    $0x1003ff,%edi
mov    %ecx,%edi
ja     1120 <human_readable+0x10>
lea    0xec8(%rip),%rdi
movsbl (%rax,%rdi,1),%r8d
lea    0xec4(%rip),%rax
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    %rax,%rdx
jmp    1030 <snprintf@plt>

LLVM IR (-O0):
@human_readable.units = internal global [8 x i8] c"BKMGTPE\00"
@.str = [5 x i8] c"%d%c\00"
define void @human_readable(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%9 = load i32, i32* %4
store i32 %9, i32* %7
store i32 0, i32* %8
br label %10
10: ; preds = %13, %3
%11 = load i32, i32* %7
%12 = icmp ugt i32 %11, 1024
br i1 %12, label %13, label %18
13: ; preds = %10
%14 = load i32, i32* %7
%15 = udiv i32 %14, 1024
store i32 %15, i32* %7
%16 = load i32, i32* %8
%17 = add nsw i32 %16, 1
store i32 %17, i32* %8
br label %10
18: ; preds = %10
%19 = load i8*, i8** %5
%20 = load i64, i64* %6
%21 = load i32, i32* %7
%22 = load i32, i32* %8
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [8 x i8], [8 x i8]* @human_readable.units, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = call i32 @snprintf(i8* %19, i64 %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %21, i8 signext %25)
ret void
}

LLVM IR (-O2):
@human_readable.units = internal unnamed_addr constant [8 x i8] c"BKMGTPE\00"
@.str = [5 x i8] c"%d%c\00"
define void @human_readable(i32 %0, i8* %1, i64 %2) {
%4 = icmp ugt i32 %0, 1024
br i1 %4, label %5, label %13
5: ; preds = %3, %5
%6 = phi i32 [ %9, %5 ], [ 0, %3 ]
%7 = phi i32 [ %8, %5 ], [ %0, %3 ]
%8 = lshr i32 %7, 10
%9 = add nuw nsw i32 %6, 1
%10 = icmp ugt i32 %7, 1049599
br i1 %10, label %5, label %11
11: ; preds = %5
%12 = zext i32 %9 to i64
br label %13
13: ; preds = %11, %3
%14 = phi i32 [ %0, %3 ], [ %8, %11 ]
%15 = phi i64 [ 0, %3 ], [ %12, %11 ]
%16 = getelementptr inbounds [8 x i8], [8 x i8]* @human_readable.units, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = tail call i32 @snprintf(i8* %1, i64 %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %14, i8 signext %17)
ret void
}