#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*/ printf(char *, long long);
void print_mem(long long get_mem_size) {
  if (get_mem_size > 1023 * 1024 * 1024) {
    printf("%.2gPB\n", ((double)get_mem_size) / (1024.0 * 1024.0 * 1024.0));
  } else if (get_mem_size > 1023 * 1024 * 10) {
    printf("%.3gTB\n", ((double)get_mem_size) / (1024.0 * 1024.0));
  } else if (get_mem_size > 1023 * 1024) {
    printf("%.2gTB\n", ((double)get_mem_size) / (1024.0 * 1024.0));
  } else if (get_mem_size > 1023 * 10) {
    printf("%.3gGB\n", ((double)get_mem_size / 1024.0));
  } else if (get_mem_size > 1023) {
    printf("%.2gGB\n", ((double)get_mem_size / 1024.0));
  } else {
    printf("%lldM\n", get_mem_size);
  }
}


x86 assembly (clang, -O0):
<print_mem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x3ff00000,-0x8(%rbp)
3f
jle    1152 <print_mem+0x42>
cvtsi2sdq -0x8(%rbp),%xmm0
movsd  0xed8(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rsi
lea    0xed0(%rip),%rdi
call   1030 <printf@plt>
jmp    124e <print_mem+0x13e>
cmpq   $0x9fd800,-0x8(%rbp)
jle    1188 <print_mem+0x78>
cvtsi2sdq -0x8(%rbp),%xmm0
movsd  0xe9a(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rsi
lea    0xea2(%rip),%rdi
call   1030 <printf@plt>
jmp    1249 <print_mem+0x139>
cmpq   $0xffc00,-0x8(%rbp)
jle    11be <print_mem+0xae>
cvtsi2sdq -0x8(%rbp),%xmm0
movsd  0xe64(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rsi
lea    0xe74(%rip),%rdi
call   1030 <printf@plt>
jmp    1244 <print_mem+0x134>
cmpq   $0x27f6,-0x8(%rbp)
jle    11f4 <print_mem+0xe4>
cvtsi2sdq -0x8(%rbp),%xmm0
movsd  0xe26(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rsi
lea    0xe46(%rip),%rdi
call   1030 <printf@plt>
jmp    123f <print_mem+0x12f>
cmpq   $0x3ff,-0x8(%rbp)
jle    122a <print_mem+0x11a>
cvtsi2sdq -0x8(%rbp),%xmm0
movsd  0xdf0(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rsi
lea    0xe18(%rip),%rdi
call   1030 <printf@plt>
jmp    123a <print_mem+0x12a>
mov    -0x8(%rbp),%rsi
lea    0xe0b(%rip),%rdi
call   1030 <printf@plt>
jmp    123f <print_mem+0x12f>
jmp    1244 <print_mem+0x134>
jmp    1249 <print_mem+0x139>
jmp    124e <print_mem+0x13e>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_mem>:
mov    %rdi,%rsi
cmp    $0x3ff00001,%rdi
jl     113a <print_mem+0x2a>
cvtsi2sd %rsi,%xmm0
mulsd  0xee7(%rip),%xmm0
cvttsd2si %xmm0,%rsi
lea    0xee3(%rip),%rdi
jmp    1030 <printf@plt>
cmp    $0x9fd801,%rsi
jl     1161 <print_mem+0x51>
cvtsi2sd %rsi,%xmm0
mulsd  0xeb8(%rip),%xmm0
cvttsd2si %xmm0,%rsi
lea    0xec4(%rip),%rdi
jmp    1030 <printf@plt>
cmp    $0xffc01,%rsi
jl     1188 <print_mem+0x78>
cvtsi2sd %rsi,%xmm0
mulsd  0xe91(%rip),%xmm0
cvttsd2si %xmm0,%rsi
lea    0xea5(%rip),%rdi
jmp    1030 <printf@plt>
cmp    $0x27f7,%rsi
jl     11af <print_mem+0x9f>
cvtsi2sd %rsi,%xmm0
mulsd  0xe62(%rip),%xmm0
cvttsd2si %xmm0,%rsi
lea    0xe86(%rip),%rdi
jmp    1030 <printf@plt>
cmp    $0x400,%rsi
jl     11d6 <print_mem+0xc6>
cvtsi2sd %rsi,%xmm0
mulsd  0xe3b(%rip),%xmm0
cvttsd2si %xmm0,%rsi
lea    0xe67(%rip),%rdi
jmp    1030 <printf@plt>
lea    0xe63(%rip),%rdi
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"%.2gPB\0A\00"
@.str.1 = [8 x i8] c"%.3gTB\0A\00"
@.str.2 = [8 x i8] c"%.2gTB\0A\00"
@.str.3 = [8 x i8] c"%.3gGB\0A\00"
@.str.4 = [8 x i8] c"%.2gGB\0A\00"
@.str.5 = [7 x i8] c"%lldM\0A\00"
define void @print_mem(i64 %0) {
%2 = alloca i64
store i64 %0, i64* %2
%3 = load i64, i64* %2
%4 = icmp sgt i64 %3, 1072693248
br i1 %4, label %5, label %11
5: ; preds = %1
%6 = load i64, i64* %2
%7 = sitofp i64 %6 to double
%8 = fdiv double %7, 0x41D0000000000000
%9 = fptosi double %8 to i64
%10 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64 %9)
br label %54
11: ; preds = %1
%12 = load i64, i64* %2
%13 = icmp sgt i64 %12, 10475520
br i1 %13, label %14, label %20
14: ; preds = %11
%15 = load i64, i64* %2
%16 = sitofp i64 %15 to double
%17 = fdiv double %16, 0x4130000000000000
%18 = fptosi double %17 to i64
%19 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i64 %18)
br label %53
20: ; preds = %11
%21 = load i64, i64* %2
%22 = icmp sgt i64 %21, 1047552
br i1 %22, label %23, label %29
23: ; preds = %20
%24 = load i64, i64* %2
%25 = sitofp i64 %24 to double
%26 = fdiv double %25, 0x4130000000000000
%27 = fptosi double %26 to i64
%28 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i64 %27)
br label %52
29: ; preds = %20
%30 = load i64, i64* %2
%31 = icmp sgt i64 %30, 10230
br i1 %31, label %32, label %38
32: ; preds = %29
%33 = load i64, i64* %2
%34 = sitofp i64 %33 to double
%35 = fdiv double %34, 1.024000e+03
%36 = fptosi double %35 to i64
%37 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i64 %36)
br label %51
38: ; preds = %29
%39 = load i64, i64* %2
%40 = icmp sgt i64 %39, 1023
br i1 %40, label %41, label %47
41: ; preds = %38
%42 = load i64, i64* %2
%43 = sitofp i64 %42 to double
%44 = fdiv double %43, 1.024000e+03
%45 = fptosi double %44 to i64
%46 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i64 %45)
br label %50
47: ; preds = %38
%48 = load i64, i64* %2
%49 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i64 %48)
br label %50
50: ; preds = %47, %41
br label %51
51: ; preds = %50, %32
br label %52
52: ; preds = %51, %23
br label %53
53: ; preds = %52, %14
br label %54
54: ; preds = %53, %5
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"%.2gPB\0A\00"
@.str.1 = [8 x i8] c"%.3gTB\0A\00"
@.str.2 = [8 x i8] c"%.2gTB\0A\00"
@.str.3 = [8 x i8] c"%.3gGB\0A\00"
@.str.4 = [8 x i8] c"%.2gGB\0A\00"
@.str.5 = [7 x i8] c"%lldM\0A\00"
define void @print_mem(i64 %0) {
%2 = icmp sgt i64 %0, 1072693248
br i1 %2, label %3, label %8
3: ; preds = %1
%4 = sitofp i64 %0 to double
%5 = fmul double %4, 0x3E10000000000000
%6 = fptosi double %5 to i64
%7 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64 %6)
br label %38
8: ; preds = %1
%9 = icmp sgt i64 %0, 10475520
br i1 %9, label %10, label %15
10: ; preds = %8
%11 = sitofp i64 %0 to double
%12 = fmul double %11, 0x3EB0000000000000
%13 = fptosi double %12 to i64
%14 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i64 %13)
br label %38
15: ; preds = %8
%16 = icmp sgt i64 %0, 1047552
br i1 %16, label %17, label %22
17: ; preds = %15
%18 = sitofp i64 %0 to double
%19 = fmul double %18, 0x3EB0000000000000
%20 = fptosi double %19 to i64
%21 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i64 %20)
br label %38
22: ; preds = %15
%23 = icmp sgt i64 %0, 10230
br i1 %23, label %24, label %29
24: ; preds = %22
%25 = sitofp i64 %0 to double
%26 = fmul double %25, 0x3F50000000000000
%27 = fptosi double %26 to i64
%28 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i64 %27)
br label %38
29: ; preds = %22
%30 = icmp sgt i64 %0, 1023
br i1 %30, label %31, label %36
31: ; preds = %29
%32 = sitofp i64 %0 to double
%33 = fmul double %32, 0x3F50000000000000
%34 = fptosi double %33 to i64
%35 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i64 %34)
br label %38
36: ; preds = %29
%37 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i64 %0)
br label %38
38: ; preds = %10, %24, %36, %31, %17, %3
ret void
}