#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 *malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, float, char);
void df_human(unsigned long long value) {
  char *string = malloc(100);
  int mult = 1;
  char z = 'k';
  if (value > 1024) {
    z = 'M';
    mult *= 1024;
  }
  if (value > 1024 * 1024) {
    z = 'G';
    mult *= 1024;
  }
  sprintf(string, "%3.1f%c", (float)value / mult, z);
  printf("%-13s ", string);
}


x86 assembly (clang, -O0):
<df_human>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x64,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
movb   $0x6b,-0x15(%rbp)
cmpq   $0x400,-0x8(%rbp)
jbe    1170 <df_human+0x40>
movb   $0x4d,-0x15(%rbp)
mov    -0x14(%rbp),%eax
shl    $0xa,%eax
mov    %eax,-0x14(%rbp)
cmpq   $0x100000,-0x8(%rbp)
jbe    118b <df_human+0x5b>
movb   $0x47,-0x15(%rbp)
mov    -0x14(%rbp),%eax
shl    $0xa,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
shr    %rdx
mov    %eax,%ecx
and    $0x1,%ecx
or     %rdx,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %rax,%xmm1
movss  %xmm1,-0x20(%rbp)
test   %rax,%rax
movss  %xmm0,-0x1c(%rbp)
js     11d0 <df_human+0xa0>
movss  -0x20(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
movss  -0x1c(%rbp),%xmm0
cvtsi2ssl -0x14(%rbp),%xmm1
divss  %xmm1,%xmm0
lea    0xe17(%rip),%rsi
movsbl -0x15(%rbp),%edx
call   1050 <sprintf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe0b(%rip),%rdi
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<df_human>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x64,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
cmp    $0x401,%rbx
mov    $0x400,%eax
mov    $0x1,%ecx
cmovae %eax,%ecx
mov    $0x4d,%eax
mov    $0x6b,%esi
cmovae %eax,%esi
mov    %ecx,%eax
shl    $0xa,%eax
cmp    $0x100001,%rbx
cmovb  %ecx,%eax
mov    $0x47,%edx
cmovb  %esi,%edx
test   %rbx,%rbx
js     1188 <df_human+0x58>
cvtsi2ss %rbx,%xmm0
jmp    119d <df_human+0x6d>
mov    %rbx,%rcx
shr    %rcx
and    $0x1,%ebx
or     %rcx,%rbx
cvtsi2ss %rbx,%xmm0
addss  %xmm0,%xmm0
cvtsi2ss %eax,%xmm1
divss  %xmm1,%xmm0
lea    0xe54(%rip),%rsi
mov    %r14,%rdi
call   1050 <sprintf@plt>
lea    0xe4d(%rip),%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"%3.1f%c\00"
@.str.1 = [7 x i8] c"%-13s \00"
define void @df_human(i64 %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8
store i64 %0, i64* %2
%6 = call i8* @malloc(i32 100)
store i8* %6, i8** %3
store i32 1, i32* %4
store i8 107, i8* %5
%7 = load i64, i64* %2
%8 = icmp ugt i64 %7, 1024
br i1 %8, label %9, label %12
9: ; preds = %1
store i8 77, i8* %5
%10 = load i32, i32* %4
%11 = mul nsw i32 %10, 1024
store i32 %11, i32* %4
br label %12
12: ; preds = %9, %1
%13 = load i64, i64* %2
%14 = icmp ugt i64 %13, 1048576
br i1 %14, label %15, label %18
15: ; preds = %12
store i8 71, i8* %5
%16 = load i32, i32* %4
%17 = mul nsw i32 %16, 1024
store i32 %17, i32* %4
br label %18
18: ; preds = %15, %12
%19 = load i8*, i8** %3
%20 = load i64, i64* %2
%21 = uitofp i64 %20 to float
%22 = load i32, i32* %4
%23 = sitofp i32 %22 to float
%24 = fdiv float %21, %23
%25 = load i8, i8* %5
%26 = call i32 @sprintf(i8* %19, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), float %24, i8 signext %25)
%27 = load i8*, i8** %3
%28 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %27)
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"%3.1f%c\00"
@.str.1 = [7 x i8] c"%-13s \00"
define void @df_human(i64 %0) {
%2 = tail call dereferenceable_or_null(100) i8* @malloc(i32 100)
%3 = icmp ugt i64 %0, 1024
%4 = select i1 %3, i32 1024, i32 1
%5 = select i1 %3, i8 77, i8 107
%6 = icmp ugt i64 %0, 1048576
%7 = shl nuw nsw i32 %4, 10
%8 = select i1 %6, i32 %7, i32 %4
%9 = select i1 %6, i8 71, i8 %5
%10 = uitofp i64 %0 to float
%11 = sitofp i32 %8 to float
%12 = fdiv float %10, %11
%13 = tail call i32 @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), float %12, i8 signext %9)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %2)
ret void
}