#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 uint64_t;

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, unsigned int, int, char const *);
char *size_str(uint64_t nsect, char *buf) {
  static const char *suffix[] = {"kb", "mb", "gb", "tb", "pb", 0};
  int i;
  unsigned int rem;
  nsect /= 2;
  for (i = 0; nsect >= 1024 && suffix[i + 1]; i++) {
    rem = nsect % 1024;
    nsect /= 1024;
  }
  sprintf(buf, "%u.%u%s", (unsigned int)nsect, 100 * rem / 1024, suffix[i]);
  return buf;
}


x86 assembly (clang, -O0):
<size_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0x400,-0x4(%rbp)
mov    %al,-0x19(%rbp)
jl     1161 <size_str+0x51>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
movslq %eax,%rcx
lea    0x2eda(%rip),%rax
cmpq   $0x0,(%rax,%rcx,8)
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1171 <size_str+0x61>
jmp    119b <size_str+0x8b>
mov    -0x4(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1134 <size_str+0x24>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
imul   $0x64,-0x18(%rbp),%ecx
shr    $0xa,%ecx
movslq -0x14(%rbp),%rsi
lea    0x2e7c(%rip),%rax
mov    (%rax,%rsi,8),%r8
lea    0xe50(%rip),%rsi
call   1030 <sprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<size_str>:
push   %rbx
mov    %rsi,%rbx
mov    %edi,%edx
shr    $0x1f,%edx
add    %edi,%edx
sar    %edx
cmp    $0x800,%edi
jl     1157 <size_str+0x47>
mov    %edx,%esi
shr    $0xa,%esi
cmp    $0x100000,%edx
jb     115d <size_str+0x4d>
mov    %edx,%edi
shr    $0x14,%edi
cmp    $0x40000000,%edx
jb     1172 <size_str+0x62>
and    $0x3ff,%edi
imul   $0x64,%edi,%ecx
shr    $0xa,%ecx
mov    $0x3,%eax
mov    $0x3,%edx
jmp    1185 <size_str+0x75>
xor    %eax,%eax
xor    %ecx,%ecx
jmp    1185 <size_str+0x75>
and    $0x3ff,%edx
imul   $0x64,%edx,%ecx
shr    $0xa,%ecx
mov    $0x1,%eax
mov    %esi,%edx
jmp    1185 <size_str+0x75>
and    $0x3ff,%esi
imul   $0x64,%esi,%ecx
shr    $0xa,%ecx
mov    $0x2,%eax
mov    %edi,%edx
lea    0x2c64(%rip),%rsi
mov    (%rsi,%rax,8),%r8
lea    0xe78(%rip),%rsi
mov    %rbx,%rdi
call   1030 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@size_str.suffix = internal global [6 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 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), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i32 0, i32 0), i8* null]
@.str = [3 x i8] c"kb\00"
@.str.1 = [3 x i8] c"mb\00"
@.str.2 = [3 x i8] c"gb\00"
@.str.3 = [3 x i8] c"tb\00"
@.str.4 = [3 x i8] c"pb\00"
@.str.5 = [8 x i8] c"%u.%u%s\00"
define i8* @size_str(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%7 = load i32, i32* %3
%8 = sdiv i32 %7, 2
store i32 %8, i32* %3
store i32 0, i32* %5
br label %9
9: ; preds = %26, %2
%10 = load i32, i32* %3
%11 = icmp sge i32 %10, 1024
br i1 %11, label %12, label %19
12: ; preds = %9
%13 = load i32, i32* %5
%14 = add nsw i32 %13, 1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [6 x i8*], [6 x i8*]* @size_str.suffix, i64 0, i64 %15
%17 = load i8*, i8** %16
%18 = icmp ne i8* %17, null
br label %19
19: ; preds = %12, %9
%20 = phi i1 [ false, %9 ], [ %18, %12 ]
br i1 %20, label %21, label %29
21: ; preds = %19
%22 = load i32, i32* %3
%23 = srem i32 %22, 1024
store i32 %23, i32* %6
%24 = load i32, i32* %3
%25 = sdiv i32 %24, 1024
store i32 %25, i32* %3
br label %26
26: ; preds = %21
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
br label %9
29: ; preds = %19
%30 = load i8*, i8** %4
%31 = load i32, i32* %3
%32 = load i32, i32* %6
%33 = mul i32 100, %32
%34 = udiv i32 %33, 1024
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [6 x i8*], [6 x i8*]* @size_str.suffix, i64 0, i64 %36
%38 = load i8*, i8** %37
%39 = call i32 @sprintf(i8* %30, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %31, i32 %34, i8* %38)
%40 = load i8*, i8** %4
ret i8* %40
}

LLVM IR (-O2):
@size_str.suffix = internal unnamed_addr constant [6 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 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), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i32 0, i32 0), i8* null]
@.str = [3 x i8] c"kb\00"
@.str.1 = [3 x i8] c"mb\00"
@.str.2 = [3 x i8] c"gb\00"
@.str.3 = [3 x i8] c"tb\00"
@.str.4 = [3 x i8] c"pb\00"
@.str.5 = [8 x i8] c"%u.%u%s\00"
define i8* @size_str(i32 %0, i8* returned writeonly %1) {
%3 = sdiv i32 %0, 2
%4 = icmp sgt i32 %0, 2047
br i1 %4, label %5, label %21
5: ; preds = %2
%6 = and i32 %3, 1023
%7 = lshr i32 %3, 10
%8 = mul nuw nsw i32 %6, 100
%9 = lshr i32 %8, 10
%10 = icmp ugt i32 %3, 1048575
br i1 %10, label %11, label %21
11: ; preds = %5
%12 = and i32 %7, 1023
%13 = lshr i32 %3, 20
%14 = mul nuw nsw i32 %12, 100
%15 = lshr i32 %14, 10
%16 = icmp ugt i32 %3, 1073741823
br i1 %16, label %17, label %21
17: ; preds = %11
%18 = and i32 %13, 1023
%19 = mul nuw nsw i32 %18, 100
%20 = lshr i32 %19, 10
br label %21
21: ; preds = %5, %11, %17, %2
%22 = phi i32 [ %3, %2 ], [ %7, %5 ], [ %13, %11 ], [ 3, %17 ]
%23 = phi i64 [ 0, %2 ], [ 1, %5 ], [ 2, %11 ], [ 3, %17 ]
%24 = phi i32 [ 0, %2 ], [ %9, %5 ], [ %15, %11 ], [ %20, %17 ]
%25 = getelementptr inbounds [6 x i8*], [6 x i8*]* @size_str.suffix, i64 0, i64 %23
%26 = load i8*, i8** %25
%27 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %22, i32 %24, i8* %26)
ret i8* %1
}