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

/* Variables and functions */
int /*<<< orphan*/ safef(char *, int, char *, int, double, char *);
void sprintWithGreekByte(char *s, int slength, long long size) {
  char *greek[] = {"B", "KB", "MB", "GB", "TB", "PB"};
  int maxGreek = (sizeof(greek) / sizeof(char *)) - 1;
  int i = 0;
  long long d = 1;
  while (((size / d) >= 1024) && (i != maxGreek)) {
    ++i;
    d *= 1024;
  }
  double result = ((double)size) / d;
  safef(s, slength, "%3.*f %s", result < 10 ? 1 : 0, ((double)size) / d,
        greek[i]);
}


x86 assembly (clang, -O0):
<sprintWithGreekByte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1030 <memset@plt>
lea    0xec5(%rip),%rax
mov    %rax,-0x50(%rbp)
lea    0xeb3(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    0xeab(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xea3(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xe9b(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xe93(%rip),%rax
mov    %rax,-0x28(%rbp)
movl   $0x5,-0x54(%rbp)
movl   $0x0,-0x58(%rbp)
movq   $0x1,-0x60(%rbp)
mov    -0x18(%rbp),%rax
cqto
idivq  -0x60(%rbp)
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x400,%rcx
mov    %al,-0x69(%rbp)
jl     11c6 <sprintWithGreekByte+0xa6>
mov    -0x58(%rbp),%eax
cmp    -0x54(%rbp),%eax
setne  %al
mov    %al,-0x69(%rbp)
mov    -0x69(%rbp),%al
test   $0x1,%al
jne    11d6 <sprintWithGreekByte+0xb6>
jmp    11f0 <sprintWithGreekByte+0xd0>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
mov    -0x60(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x60(%rbp)
jmp    119b <sprintWithGreekByte+0x7b>
cvtsi2sdq -0x18(%rbp),%xmm0
cvtsi2sdq -0x60(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
movsd  -0x68(%rbp),%xmm1
movsd  0xde7(%rip),%xmm0
xor    %ecx,%ecx
mov    $0x1,%eax
ucomisd %xmm1,%xmm0
cmova  %eax,%ecx
cvtsi2sdq -0x18(%rbp),%xmm0
cvtsi2sdq -0x60(%rbp),%xmm1
divsd  %xmm1,%xmm0
movslq -0x58(%rbp),%rax
mov    -0x50(%rbp,%rax,8),%r8
lea    0xdd0(%rip),%rdx
call   1040 <safef@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sprintWithGreekByte>:
lea    0xf21(%rip),%rax
mov    %rax,-0x30(%rsp)
lea    0xf18(%rip),%rax
mov    %rax,-0x28(%rsp)
lea    0xf0f(%rip),%rax
mov    %rax,-0x20(%rsp)
lea    0xf06(%rip),%rax
mov    %rax,-0x18(%rsp)
lea    0xefd(%rip),%rax
mov    %rax,-0x10(%rsp)
cmp    $0x400,%rdx
jl     119a <sprintWithGreekByte+0x8a>
cmp    $0x100000,%rdx
jl     11ab <sprintWithGreekByte+0x9b>
cmp    $0x40000000,%rdx
jl     11ba <sprintWithGreekByte+0xaa>
movabs $0x10000000000,%rax
cmp    %rax,%rdx
jl     11c9 <sprintWithGreekByte+0xb9>
movabs $0x3ffffffffffff,%rcx
xor    %eax,%eax
cmp    %rcx,%rdx
setg   %al
lea    0xe99(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm1
or     $0x4,%rax
jmp    11d6 <sprintWithGreekByte+0xc6>
movsd  0xe5e(%rip),%xmm1
lea    0xe96(%rip),%r8
jmp    11db <sprintWithGreekByte+0xcb>
movsd  0xe55(%rip),%xmm1
mov    $0x1,%eax
jmp    11d6 <sprintWithGreekByte+0xc6>
movsd  0xe4e(%rip),%xmm1
mov    $0x2,%eax
jmp    11d6 <sprintWithGreekByte+0xc6>
movsd  0xe47(%rip),%xmm1
mov    $0x3,%eax
mov    -0x38(%rsp,%rax,8),%r8
cvtsi2sd %rdx,%xmm0
divsd  %xmm1,%xmm0
movsd  0xe34(%rip),%xmm1
xor    %ecx,%ecx
ucomisd %xmm0,%xmm1
seta   %cl
lea    0xe4b(%rip),%rdx
jmp    1030 <safef@plt>

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"
@.str.4 = [3 x i8] c"TB\00"
@.str.5 = [3 x i8] c"PB\00"
@.str.6 = [9 x i8] c"%3.*f %s\00"
define void @sprintWithGreekByte(i8* %0, i32 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i64
%7 = alloca [6 x i8*]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i64
%11 = alloca double
store i8* %0, i8** %4
store i32 %1, i32* %5
store i64 %2, i64* %6
%12 = bitcast [6 x i8*]* %7 to i8*
%13 = bitcast i8* %12 to [6 x i8*]*
%14 = getelementptr inbounds [6 x i8*], [6 x i8*]* %13, i32 0, i32 0
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i32 0, i32 0), i8** %14
%15 = getelementptr inbounds [6 x i8*], [6 x i8*]* %13, i32 0, i32 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8** %15
%16 = getelementptr inbounds [6 x i8*], [6 x i8*]* %13, i32 0, i32 2
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0), i8** %16
%17 = getelementptr inbounds [6 x i8*], [6 x i8*]* %13, i32 0, i32 3
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i32 0, i32 0), i8** %17
%18 = getelementptr inbounds [6 x i8*], [6 x i8*]* %13, i32 0, i32 4
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i32 0, i32 0), i8** %18
%19 = getelementptr inbounds [6 x i8*], [6 x i8*]* %13, i32 0, i32 5
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i32 0, i32 0), i8** %19
store i32 5, i32* %8
store i32 0, i32* %9
store i64 1, i64* %10
br label %20
20: ; preds = %31, %3
%21 = load i64, i64* %6
%22 = load i64, i64* %10
%23 = sdiv i64 %21, %22
%24 = icmp sge i64 %23, 1024
br i1 %24, label %25, label %29
25: ; preds = %20
%26 = load i32, i32* %9
%27 = load i32, i32* %8
%28 = icmp ne i32 %26, %27
br label %29
29: ; preds = %25, %20
%30 = phi i1 [ false, %20 ], [ %28, %25 ]
br i1 %30, label %31, label %36
31: ; preds = %29
%32 = load i32, i32* %9
%33 = add nsw i32 %32, 1
store i32 %33, i32* %9
%34 = load i64, i64* %10
%35 = mul nsw i64 %34, 1024
store i64 %35, i64* %10
br label %20
36: ; preds = %29
%37 = load i64, i64* %6
%38 = sitofp i64 %37 to double
%39 = load i64, i64* %10
%40 = sitofp i64 %39 to double
%41 = fdiv double %38, %40
store double %41, double* %11
%42 = load i8*, i8** %4
%43 = load i32, i32* %5
%44 = load double, double* %11
%45 = fcmp olt double %44, 1.000000e+01
%46 = zext i1 %45 to i64
%47 = select i1 %45, i32 1, i32 0
%48 = load i64, i64* %6
%49 = sitofp i64 %48 to double
%50 = load i64, i64* %10
%51 = sitofp i64 %50 to double
%52 = fdiv double %49, %51
%53 = load i32, i32* %9
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [6 x i8*], [6 x i8*]* %7, i64 0, i64 %54
%56 = load i8*, i8** %55
%57 = call i32 @safef(i8* %42, i32 %43, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 %47, double %52, i8* %56)
ret void
}

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"
@.str.4 = [3 x i8] c"TB\00"
@.str.5 = [3 x i8] c"PB\00"
@.str.6 = [9 x i8] c"%3.*f %s\00"
define void @sprintWithGreekByte(i8* %0, i32 %1, i64 %2) {
%4 = alloca [6 x i8*]
%5 = bitcast [6 x i8*]* %4 to i8*
%6 = getelementptr inbounds [6 x i8*], [6 x i8*]* %4, i64 0, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %6
%7 = getelementptr inbounds [6 x i8*], [6 x i8*]* %4, i64 0, i64 2
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %7
%8 = getelementptr inbounds [6 x i8*], [6 x i8*]* %4, i64 0, i64 3
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %8
%9 = getelementptr inbounds [6 x i8*], [6 x i8*]* %4, i64 0, i64 4
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8** %9
%10 = getelementptr inbounds [6 x i8*], [6 x i8*]* %4, i64 0, i64 5
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8** %10
%11 = icmp sgt i64 %2, 1023
br i1 %11, label %12, label %27
12: ; preds = %3
%13 = icmp sgt i64 %2, 1048575
br i1 %13, label %14, label %22
14: ; preds = %12
%15 = icmp sgt i64 %2, 1073741823
br i1 %15, label %16, label %22
16: ; preds = %14
%17 = icmp sgt i64 %2, 1099511627775
br i1 %17, label %18, label %22
18: ; preds = %16
%19 = icmp sgt i64 %2, 1125899906842623
%20 = select i1 %19, i64 5, i64 4
%21 = select i1 %19, double 0x4310000000000000, double 0x4270000000000000
br label %22
22: ; preds = %18, %16, %14, %12
%23 = phi i64 [ 1, %12 ], [ 2, %14 ], [ 3, %16 ], [ %20, %18 ]
%24 = phi double [ 1.024000e+03, %12 ], [ 0x4130000000000000, %14 ], [ 0x41D0000000000000, %16 ], [ %21, %18 ]
%25 = getelementptr inbounds [6 x i8*], [6 x i8*]* %4, i64 0, i64 %23
%26 = load i8*, i8** %25
br label %27
27: ; preds = %3, %22
%28 = phi i8* [ %26, %22 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %3 ]
%29 = phi double [ %24, %22 ], [ 1.000000e+00, %3 ]
%30 = sitofp i64 %2 to double
%31 = fdiv double %30, %29
%32 = fcmp olt double %31, 1.000000e+01
%33 = zext i1 %32 to i32
%34 = tail call i32 @safef(i8* %0, i32 %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 %33, double %31, i8* %28)
ret void
}