#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 */
char *bc_strdup_printf(char *, long);
char *blogc_rusage_format_memory(long mem) {
  if (mem >= 1048576)
    return bc_strdup_printf("%.3fGB", ((float)mem) / 1048576.0);
  if (mem >= 1024)
    return bc_strdup_printf("%.3fMB", ((float)mem) / 1024.0);
  return bc_strdup_printf("%dKB", mem);
}


x86 assembly (clang, -O0):
<blogc_rusage_format_memory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x100000,-0x10(%rbp)
jl     115a <blogc_rusage_format_memory+0x4a>
cvtsi2ssq -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xecc(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rsi
lea    0xec4(%rip),%rdi
call   1030 <bc_strdup_printf@plt>
mov    %rax,-0x8(%rbp)
jmp    11ac <blogc_rusage_format_memory+0x9c>
cmpq   $0x400,-0x10(%rbp)
jl     1198 <blogc_rusage_format_memory+0x88>
cvtsi2ssq -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe86(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rsi
lea    0xe8d(%rip),%rdi
call   1030 <bc_strdup_printf@plt>
mov    %rax,-0x8(%rbp)
jmp    11ac <blogc_rusage_format_memory+0x9c>
mov    -0x10(%rbp),%rsi
lea    0xe7b(%rip),%rdi
call   1030 <bc_strdup_printf@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<blogc_rusage_format_memory>:
mov    %rdi,%rsi
cmp    $0x100000,%rdi
jl     113e <blogc_rusage_format_memory+0x2e>
cvtsi2ss %rsi,%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  0xedb(%rip),%xmm0
cvttsd2si %xmm0,%rsi
lea    0xed7(%rip),%rdi
jmp    1030 <bc_strdup_printf@plt>
cmp    $0x400,%rsi
jl     1169 <blogc_rusage_format_memory+0x59>
cvtsi2ss %rsi,%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  0xea8(%rip),%xmm0
cvttsd2si %xmm0,%rsi
lea    0xeb3(%rip),%rdi
jmp    1030 <bc_strdup_printf@plt>
lea    0xeae(%rip),%rdi
jmp    1030 <bc_strdup_printf@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"%.3fGB\00"
@.str.1 = [7 x i8] c"%.3fMB\00"
@.str.2 = [5 x i8] c"%dKB\00"
define i8* @blogc_rusage_format_memory(i64 %0) {
%2 = alloca i8*
%3 = alloca i64
store i64 %0, i64* %3
%4 = load i64, i64* %3
%5 = icmp sge i64 %4, 1048576
br i1 %5, label %6, label %13
6: ; preds = %1
%7 = load i64, i64* %3
%8 = sitofp i64 %7 to float
%9 = fpext float %8 to double
%10 = fdiv double %9, 0x4130000000000000
%11 = fptosi double %10 to i64
%12 = call i8* @bc_strdup_printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %11)
store i8* %12, i8** %2
br label %26
13: ; preds = %1
%14 = load i64, i64* %3
%15 = icmp sge i64 %14, 1024
br i1 %15, label %16, label %23
16: ; preds = %13
%17 = load i64, i64* %3
%18 = sitofp i64 %17 to float
%19 = fpext float %18 to double
%20 = fdiv double %19, 1.024000e+03
%21 = fptosi double %20 to i64
%22 = call i8* @bc_strdup_printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i64 %21)
store i8* %22, i8** %2
br label %26
23: ; preds = %13
%24 = load i64, i64* %3
%25 = call i8* @bc_strdup_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %24)
store i8* %25, i8** %2
br label %26
26: ; preds = %23, %16, %6
%27 = load i8*, i8** %2
ret i8* %27
}

LLVM IR (-O2):
@.str = [7 x i8] c"%.3fGB\00"
@.str.1 = [7 x i8] c"%.3fMB\00"
@.str.2 = [5 x i8] c"%dKB\00"
define i8* @blogc_rusage_format_memory(i64 %0) {
%2 = icmp sgt i64 %0, 1048575
br i1 %2, label %3, label %9
3: ; preds = %1
%4 = sitofp i64 %0 to float
%5 = fpext float %4 to double
%6 = fmul double %5, 0x3EB0000000000000
%7 = fptosi double %6 to i64
%8 = tail call i8* @bc_strdup_printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %7)
br label %19
9: ; preds = %1
%10 = icmp sgt i64 %0, 1023
br i1 %10, label %11, label %17
11: ; preds = %9
%12 = sitofp i64 %0 to float
%13 = fpext float %12 to double
%14 = fmul double %13, 0x3F50000000000000
%15 = fptosi double %14 to i64
%16 = tail call i8* @bc_strdup_printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i64 %15)
br label %19
17: ; preds = %9
%18 = tail call i8* @bc_strdup_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 %0)
br label %19
19: ; preds = %17, %11, %3
%20 = phi i8* [ %8, %3 ], [ %16, %11 ], [ %18, %17 ]
ret i8* %20
}