#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 uint64_t;

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, size_t, char *, float, char const *);
const char *print_volume(uint64_t vol, char *buf, size_t len) {
  const char *suffix = "";
  float value = vol;
  if (vol < 1000000) {
    suffix = "ki";
    value = vol / 1000.0f;
  } else if (vol < 1000000000U) {
    suffix = "Mi";
    value = vol / 1000000.0f;
  } else {
    suffix = "Gi";
    value = vol / 1000000000.0f;
  }
  snprintf(buf, len, "%6.2f %s", value, suffix);
  return buf;
}


x86 assembly (clang, -O0):
<print_volume>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0xeea(%rip),%rax
mov    %rax,-0x20(%rbp)
cvtsi2ssl -0x4(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
cmpl   $0xf4240,-0x4(%rbp)
jge    116b <print_volume+0x5b>
lea    0xec0(%rip),%rax
mov    %rax,-0x20(%rbp)
cvtsi2ssl -0x4(%rbp),%xmm0
movss  0xeab(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x24(%rbp)
jmp    11c4 <print_volume+0xb4>
cmpl   $0x3b9aca00,-0x4(%rbp)
jae    119e <print_volume+0x8e>
lea    0xe90(%rip),%rax
mov    %rax,-0x20(%rbp)
cvtsi2ssl -0x4(%rbp),%xmm0
movss  0xe74(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x24(%rbp)
jmp    11bf <print_volume+0xaf>
lea    0xe6d(%rip),%rax
mov    %rax,-0x20(%rbp)
cvtsi2ssl -0x4(%rbp),%xmm0
movss  0xe4a(%rip),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x24(%rbp)
jmp    11c4 <print_volume+0xb4>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movss  -0x24(%rbp),%xmm0
mov    -0x20(%rbp),%rcx
lea    0xe39(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_volume>:
push   %rbx
mov    %rsi,%rbx
cmp    $0xf423f,%edi
jg     1131 <print_volume+0x21>
cvtsi2ss %edi,%xmm0
divss  0xee0(%rip),%xmm0
lea    0xedd(%rip),%rcx
jmp    115d <print_volume+0x4d>
cvtsi2ss %edi,%xmm0
cmp    $0x3b9ac9ff,%edi
ja     114e <print_volume+0x3e>
divss  0xebf(%rip),%xmm0
lea    0xec3(%rip),%rcx
jmp    115d <print_volume+0x4d>
divss  0xeaa(%rip),%xmm0
lea    0xeb5(%rip),%rcx
lea    0xeb1(%rip),%rax
mov    %rbx,%rdi
mov    %rdx,%rsi
mov    %rax,%rdx
call   1030 <snprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c"ki\00"
@.str.2 = [3 x i8] c"Mi\00"
@.str.3 = [3 x i8] c"Gi\00"
@.str.4 = [9 x i8] c"%6.2f %s\00"
define i8* @print_volume(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca float
store i32 %0, i32* %4
store i8* %1, i8** %5
store i64 %2, i64* %6
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %7
%9 = load i32, i32* %4
%10 = sitofp i32 %9 to float
store float %10, float* %8
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 1000000
br i1 %12, label %13, label %17
13: ; preds = %3
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %7
%14 = load i32, i32* %4
%15 = sitofp i32 %14 to float
%16 = fdiv float %15, 1.000000e+03
store float %16, float* %8
br label %29
17: ; preds = %3
%18 = load i32, i32* %4
%19 = icmp ult i32 %18, 1000000000
br i1 %19, label %20, label %24
20: ; preds = %17
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %7
%21 = load i32, i32* %4
%22 = sitofp i32 %21 to float
%23 = fdiv float %22, 1.000000e+06
store float %23, float* %8
br label %28
24: ; preds = %17
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %7
%25 = load i32, i32* %4
%26 = sitofp i32 %25 to float
%27 = fdiv float %26, 1.000000e+09
store float %27, float* %8
br label %28
28: ; preds = %24, %20
br label %29
29: ; preds = %28, %13
%30 = load i8*, i8** %5
%31 = load i64, i64* %6
%32 = load float, float* %8
%33 = load i8*, i8** %7
%34 = call i32 @snprintf(i8* %30, i64 %31, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), float %32, i8* %33)
%35 = load i8*, i8** %5
ret i8* %35
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"ki\00"
@.str.2 = [3 x i8] c"Mi\00"
@.str.3 = [3 x i8] c"Gi\00"
@.str.4 = [9 x i8] c"%6.2f %s\00"
define i8* @print_volume(i32 %0, i8* returned %1, i64 %2) {
%4 = icmp slt i32 %0, 1000000
br i1 %4, label %5, label %8
5: ; preds = %3
%6 = sitofp i32 %0 to float
%7 = fdiv float %6, 1.000000e+03
br label %15
8: ; preds = %3
%9 = icmp ult i32 %0, 1000000000
%10 = sitofp i32 %0 to float
br i1 %9, label %11, label %13
11: ; preds = %8
%12 = fdiv float %10, 1.000000e+06
br label %15
13: ; preds = %8
%14 = fdiv float %10, 1.000000e+09
br label %15
15: ; preds = %11, %13, %5
%16 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %5 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %11 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), %13 ]
%17 = phi float [ %7, %5 ], [ %12, %11 ], [ %14, %13 ]
%18 = tail call i32 @snprintf(i8* %1, i64 %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), float %17, i8* %16)
ret i8* %1
}