#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 *, int, size_t, char const *);
char *readable_fs(size_t size, char *buf) {
  int i = 0;
  const char *units[] = {"B", "KB", "MB", "GB"};
  while (size > 1024) {
    size /= 1024;
    i++;
  }
  sprintf(buf, "%.*zu %s", i, size, units[i]);
  return buf;
}


x86 assembly (clang, -O0):
<readable_fs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    0x2cd2(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0x2ccf(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0x2ccc(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2cc9(%rip),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x400,-0x8(%rbp)
jbe    117b <readable_fs+0x6b>
mov    -0x8(%rbp),%rax
shr    $0xa,%rax
mov    %rax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1153 <readable_fs+0x43>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%rcx
movslq -0x14(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%r8
lea    0xe73(%rip),%rsi
call   1030 <sprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readable_fs>:
push   %rbx
mov    %rsi,%rbx
xor    %edx,%edx
cmp    $0x401,%rdi
jb     1145 <readable_fs+0x35>
xor    %edx,%edx
mov    %rdi,%rcx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
shr    $0xa,%rcx
add    $0x1,%edx
cmp    $0x1003ff,%rdi
mov    %rcx,%rdi
ja     1130 <readable_fs+0x20>
jmp    1148 <readable_fs+0x38>
mov    %rdi,%rcx
mov    %edx,%eax
lea    0xec3(%rip),%rsi
movslq (%rsi,%rax,4),%r8
add    %rsi,%r8
lea    0xeaa(%rip),%rsi
mov    %rbx,%rdi
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c"B\00"
@.str.1 = [3 x i8] c"KB\00"
@.str.2 = [3 x i8] c"MB\00"
@.str.3 = [3 x i8] c"GB\00"
@__const.readable_fs.units = [4 x i8*] [i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i32 0, i32 0)]
@.str.4 = [9 x i8] c"%.*zu %s\00"
define i8* @readable_fs(i64 %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [4 x i8*]
store i64 %0, i64* %3
store i8* %1, i8** %4
store i32 0, i32* %5
%7 = bitcast [4 x i8*]* %6 to i8*
br label %8
8: ; preds = %11, %2
%9 = load i64, i64* %3
%10 = icmp ugt i64 %9, 1024
br i1 %10, label %11, label %16
11: ; preds = %8
%12 = load i64, i64* %3
%13 = udiv i64 %12, 1024
store i64 %13, i64* %3
%14 = load i32, i32* %5
%15 = add nsw i32 %14, 1
store i32 %15, i32* %5
br label %8
16: ; preds = %8
%17 = load i8*, i8** %4
%18 = load i32, i32* %5
%19 = load i64, i64* %3
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [4 x i8*], [4 x i8*]* %6, i64 0, i64 %21
%23 = load i8*, i8** %22
%24 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %18, i64 %19, i8* %23)
%25 = load i8*, i8** %4
ret i8* %25
}

LLVM IR (-O2):
@.str = [2 x i8] c"B\00"
@.str.1 = [3 x i8] c"KB\00"
@.str.2 = [3 x i8] c"MB\00"
@.str.3 = [3 x i8] c"GB\00"
@reltable.readable_fs = [4 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([2 x i8]* @.str to i64), i64 ptrtoint ([4 x i32]* @reltable.readable_fs to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.1 to i64), i64 ptrtoint ([4 x i32]* @reltable.readable_fs to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.2 to i64), i64 ptrtoint ([4 x i32]* @reltable.readable_fs to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([3 x i8]* @.str.3 to i64), i64 ptrtoint ([4 x i32]* @reltable.readable_fs to i64)) to i32)]
@.str.4 = [9 x i8] c"%.*zu %s\00"
define i8* @readable_fs(i64 %0, i8* returned writeonly %1) {
%3 = icmp ugt i64 %0, 1024
br i1 %3, label %4, label %10
4: ; preds = %2, %4
%5 = phi i32 [ %8, %4 ], [ 0, %2 ]
%6 = phi i64 [ %7, %4 ], [ %0, %2 ]
%7 = lshr i64 %6, 10
%8 = add nuw nsw i32 %5, 1
%9 = icmp ugt i64 %6, 1049599
br i1 %9, label %4, label %10
10: ; preds = %4, %2
%11 = phi i64 [ %0, %2 ], [ %7, %4 ]
%12 = phi i32 [ 0, %2 ], [ %8, %4 ]
%13 = zext i32 %12 to i64
%14 = shl i64 %13, 2
%15 = call i8* @llvm.load.relative.i64(i8* bitcast ([4 x i32]* @reltable.readable_fs to i8*), i64 %14)
%16 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %12, i64 %11, i8* %15)
ret i8* %1
}