#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 io_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)((unsigned long long)size / div), unit);
  len = strlen(res);
  if (len > maxlen)
    len = maxlen;
  memset(sizestr, 0, maxlen);
  strncpy(sizestr, res, len);
  return len;
}


x86 assembly (clang, -O0):
<io_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 <io_get_size+0x55>
movl   $0x40000000,-0x68(%rbp)
movl   $0x47,-0x6c(%rbp)
jmp    11e8 <io_get_size+0xa8>
cmpq   $0x100000,-0x8(%rbp)
jbe    11b6 <io_get_size+0x76>
movl   $0x100000,-0x68(%rbp)
movl   $0x4d,-0x6c(%rbp)
jmp    11e3 <io_get_size+0xa3>
cmpq   $0x400,-0x8(%rbp)
jbe    11d7 <io_get_size+0x97>
movl   $0x400,-0x68(%rbp)
movl   $0x6b,-0x6c(%rbp)
jmp    11de <io_get_size+0x9e>
movl   $0x1,-0x68(%rbp)
jmp    11e3 <io_get_size+0xa3>
jmp    11e8 <io_get_size+0xa8>
cmpl   $0x0,-0xc(%rbp)
jg     1222 <io_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    1274 <io_get_size+0x134>
lea    -0x60(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq -0x68(%rbp),%rsi
xor    %edx,%edx
div    %rsi
movq   %rax,%xmm0
movaps 0xdbe(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xdc2(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
mov    -0x6c(%rbp),%r8d
mov    $0x40,%esi
lea    0xdbc(%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    1292 <io_get_size+0x152>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
xor    %esi,%esi
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):
<io_get_size>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %ecx,%r15d
mov    %rdx,%r14
mov    %esi,%ecx
mov    %rdi,%rax
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
cmp    $0x40000000,%rdi
jbe    1181 <io_get_size+0x41>
mov    $0x47,%r8d
mov    $0x40000000,%esi
jmp    11b9 <io_get_size+0x79>
cmp    $0x100000,%rax
jbe    1196 <io_get_size+0x56>
mov    $0x4d,%r8d
mov    $0x100000,%esi
jmp    11b9 <io_get_size+0x79>
cmp    $0x401,%rax
mov    $0x400,%edx
mov    $0x1,%esi
cmovae %rdx,%rsi
mov    $0x6b,%edx
mov    $0x20,%r8d
cmovae %edx,%r8d
mov    %rax,%rdx
shr    $0x20,%rdx
je     1204 <io_get_size+0xc4>
xor    %edx,%edx
div    %rsi
test   %ecx,%ecx
jle    120c <io_get_size+0xcc>
movq   %rax,%xmm1
punpckldq 0xe28(%rip),%xmm1
subpd  0xe30(%rip),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
lea    0xe36(%rip),%rdx
mov    %rsp,%rdi
mov    $0x40,%esi
mov    $0x1,%al
call   1050 <snprintf@plt>
jmp    122c <io_get_size+0xec>
xor    %edx,%edx
div    %esi
test   %ecx,%ecx
jg     11cb <io_get_size+0x8b>
xorps  %xmm0,%xmm0
cvtsi2sd %r8d,%xmm0
lea    0xe05(%rip),%rdx
mov    %rsp,%rdi
mov    $0x40,%esi
mov    %eax,%ecx
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    %r15d,%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 @io_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 = load i32, i32* %11
%46 = sext i32 %45 to i64
%47 = udiv i64 %44, %46
%48 = uitofp i64 %47 to double
%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 = load i32, i32* %8
%62 = call i32 @memset(i8* %60, i32 0, i32 %61)
%63 = load i8*, i8** %7
%64 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%65 = load i32, i32* %10
%66 = call i32 @strncpy(i8* %63, i8* %64, i32 %65)
%67 = load i32, i32* %10
ret i32 %67
}

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