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

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int, double, ...);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int ixo_get_size(unsigned long long size, int prec, char *sizestr, int maxlen) {
  char res[64] = {0};
  int len, div = 1, unit = ' ';
  if (size > (1 << 30)) {
    div = (1 << 30);
    unit = 'G';
  } else if (size > (1 << 20)) {
    div = (1 << 20);
    unit = 'M';
  } else if (size > (1 << 10)) {
    div = (1 << 10);
    unit = 'k';
  } else
    div = 1;
  if (prec <= 0)
    snprintf(res, sizeof(res), "%lld %cB", (unsigned long long)size / div,
             unit);
  else
    snprintf(res, sizeof(res), "%.*f %cB", prec, (double)size / div, unit);
  len = strlen(res);
  if (len > maxlen)
    len = maxlen;
  memset(sizestr, 0, 16);
  strncpy(sizestr, res, len);
  return len;
}


x86 assembly (clang, -O0):
<ixo_get_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1060 <memset@plt>
movl   $0x1,-0x68(%rbp)
movl   $0x20,-0x6c(%rbp)
cmpq   $0x40000000,-0x8(%rbp)
40
jbe    1195 <ixo_get_size+0x55>
movl   $0x40000000,-0x68(%rbp)
movl   $0x47,-0x6c(%rbp)
jmp    11e8 <ixo_get_size+0xa8>
cmpq   $0x100000,-0x8(%rbp)
jbe    11b6 <ixo_get_size+0x76>
movl   $0x100000,-0x68(%rbp)
movl   $0x4d,-0x6c(%rbp)
jmp    11e3 <ixo_get_size+0xa3>
cmpq   $0x400,-0x8(%rbp)
jbe    11d7 <ixo_get_size+0x97>
movl   $0x400,-0x68(%rbp)
movl   $0x6b,-0x6c(%rbp)
jmp    11de <ixo_get_size+0x9e>
movl   $0x1,-0x68(%rbp)
jmp    11e3 <ixo_get_size+0xa3>
jmp    11e8 <ixo_get_size+0xa8>
cmpl   $0x0,-0xc(%rbp)
jg     1222 <ixo_get_size+0xe2>
lea    -0x60(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x68(%rbp),%rcx
xor    %edx,%edx
div    %rcx
mov    %eax,%ecx
cvtsi2sdl -0x6c(%rbp),%xmm0
mov    $0x40,%esi
lea    0xe0a(%rip),%rdx
mov    $0x1,%al
call   1050 <snprintf@plt>
jmp    1270 <ixo_get_size+0x130>
lea    -0x60(%rbp),%rdi
mov    -0xc(%rbp),%ecx
movaps 0xdd0(%rip),%xmm1
movq   -0x8(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xdcf(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
cvtsi2sdl -0x68(%rbp),%xmm1
divsd  %xmm1,%xmm0
mov    -0x6c(%rbp),%r8d
mov    $0x40,%esi
lea    0xdc0(%rip),%rdx
mov    $0x1,%al
call   1050 <snprintf@plt>
lea    -0x60(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    128e <ixo_get_size+0x14e>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
mov    -0x18(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    -0x64(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x64(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ixo_get_size>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %ecx,%r15d
mov    %rdx,%r14
mov    %esi,%ecx
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
cmp    $0x40000000,%rdi
jbe    1185 <ixo_get_size+0x45>
mov    $0x47,%r8d
mov    $0x40000000,%eax
test   %ecx,%ecx
jg     119d <ixo_get_size+0x5d>
jmp    1208 <ixo_get_size+0xc8>
cmp    $0x100000,%rdi
jbe    11e1 <ixo_get_size+0xa1>
mov    $0x4d,%r8d
mov    $0x100000,%eax
test   %ecx,%ecx
jle    1208 <ixo_get_size+0xc8>
movq   %rdi,%xmm1
punpckldq 0xe56(%rip),%xmm1
subpd  0xe5e(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
lea    0xe59(%rip),%rdx
mov    %rsp,%rdi
mov    $0x40,%esi
mov    $0x1,%al
call   1050 <snprintf@plt>
jmp    1246 <ixo_get_size+0x106>
cmp    $0x401,%rdi
mov    $0x400,%edx
mov    $0x1,%eax
cmovae %edx,%eax
mov    $0x6b,%edx
mov    $0x20,%r8d
cmovae %edx,%r8d
test   %ecx,%ecx
jg     119d <ixo_get_size+0x5d>
mov    %eax,%ecx
mov    %rdi,%rax
shr    $0x20,%rax
je     1220 <ixo_get_size+0xe0>
mov    %rdi,%rax
xor    %edx,%edx
div    %rcx
mov    %rax,%rcx
jmp    1228 <ixo_get_size+0xe8>
mov    %edi,%eax
xor    %edx,%edx
div    %ecx
mov    %eax,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %r8d,%xmm0
lea    0xde9(%rip),%rdx
mov    %rsp,%rdi
mov    $0x40,%esi
mov    $0x1,%al
call   1050 <snprintf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
cmp    %r15d,%eax
cmovg  %r15d,%ebp
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
mov    %ebp,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%lld %cB\00"
@.str.1 = [9 x i8] c"%.*f %cB\00"
define i32 @ixo_get_size(i64 %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i64
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca [64 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i64 %0, i64* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%13 = bitcast [64 x i8]* %9 to i8*
store i32 1, i32* %11
store i32 32, i32* %12
%14 = load i64, i64* %5
%15 = icmp ugt i64 %14, 1073741824
br i1 %15, label %16, label %17
16: ; preds = %4
store i32 1073741824, i32* %11
store i32 71, i32* %12
br label %28
17: ; preds = %4
%18 = load i64, i64* %5
%19 = icmp ugt i64 %18, 1048576
br i1 %19, label %20, label %21
20: ; preds = %17
store i32 1048576, i32* %11
store i32 77, i32* %12
br label %27
21: ; preds = %17
%22 = load i64, i64* %5
%23 = icmp ugt i64 %22, 1024
br i1 %23, label %24, label %25
24: ; preds = %21
store i32 1024, i32* %11
store i32 107, i32* %12
br label %26
25: ; preds = %21
store i32 1, i32* %11
br label %26
26: ; preds = %25, %24
br label %27
27: ; preds = %26, %20
br label %28
28: ; preds = %27, %16
%29 = load i32, i32* %6
%30 = icmp sle i32 %29, 0
br i1 %30, label %31, label %41
31: ; preds = %28
%32 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%33 = load i64, i64* %5
%34 = load i32, i32* %11
%35 = sext i32 %34 to i64
%36 = udiv i64 %33, %35
%37 = trunc i64 %36 to i32
%38 = load i32, i32* %12
%39 = sitofp i32 %38 to double
%40 = call i32 (i8*, i32, i8*, i32, double, ...) @snprintf(i8* %32, i32 64, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %37, double %39)
br label %51
41: ; preds = %28
%42 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%43 = load i32, i32* %6
%44 = load i64, i64* %5
%45 = uitofp i64 %44 to double
%46 = load i32, i32* %11
%47 = sitofp i32 %46 to double
%48 = fdiv double %45, %47
%49 = load i32, i32* %12
%50 = call i32 (i8*, i32, i8*, i32, double, ...) @snprintf(i8* %42, i32 64, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %43, double %48, i32 %49)
br label %51
51: ; preds = %41, %31
%52 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%53 = call i32 @strlen(i8* %52)
store i32 %53, i32* %10
%54 = load i32, i32* %10
%55 = load i32, i32* %8
%56 = icmp sgt i32 %54, %55
br i1 %56, label %57, label %59
57: ; preds = %51
%58 = load i32, i32* %8
store i32 %58, i32* %10
br label %59
59: ; preds = %57, %51
%60 = load i8*, i8** %7
%61 = call i32 @memset(i8* %60, i32 0, i32 16)
%62 = load i8*, i8** %7
%63 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%64 = load i32, i32* %10
%65 = call i32 @strncpy(i8* %62, i8* %63, i32 %64)
%66 = load i32, i32* %10
ret i32 %66
}

LLVM IR (-O2):
@.str = [9 x i8] c"%lld %cB\00"
@.str.1 = [9 x i8] c"%.*f %cB\00"
define i32 @ixo_get_size(i64 %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca [64 x i8]
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%7 = icmp ugt i64 %0, 1073741824
br i1 %7, label %14, label %8
8: ; preds = %4
%9 = icmp ugt i64 %0, 1048576
br i1 %9, label %14, label %10
10: ; preds = %8
%11 = icmp ugt i64 %0, 1024
%12 = select i1 %11, i32 1024, i32 1
%13 = select i1 %11, i32 107, i32 32
br label %14
14: ; preds = %10, %8, %4
%15 = phi i32 [ 1073741824, %4 ], [ 1048576, %8 ], [ %12, %10 ]
%16 = phi i32 [ 71, %4 ], [ 77, %8 ], [ %13, %10 ]
%17 = icmp slt i32 %1, 1
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = zext i32 %15 to i64
%20 = udiv i64 %0, %19
%21 = trunc i64 %20 to i32
%22 = sitofp i32 %16 to double
%23 = call i32 (i8*, i32, i8*, i32, double, ...) @snprintf(i8* %6, i32 64, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %21, double %22)
br label %29
24: ; preds = %14
%25 = uitofp i64 %0 to double
%26 = sitofp i32 %15 to double
%27 = fdiv double %25, %26
%28 = call i32 (i8*, i32, i8*, i32, double, ...) @snprintf(i8* %6, i32 64, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %1, double %27, i32 %16)
br label %29
29: ; preds = %24, %18
%30 = call i32 @strlen(i8* %6)
%31 = icmp sgt i32 %30, %3
%32 = select i1 %31, i32 %3, i32 %30
%33 = call i32 @memset(i8* %2, i32 0, i32 16)
%34 = call i32 @strncpy(i8* %2, i8* %6, i32 %32)
ret i32 %32
}