#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*/ snprintf(char *, int, char *, unsigned long);
void n2h(unsigned long n, char *str, int maxlen) {
  if (n >= 1000 * 1000 * 1000) {
    snprintf(str, maxlen, "%.1fG", n / (float)(1000 * 1000 * 1000));
  } else if (n >= 1000 * 1000) {
    snprintf(str, maxlen, "%.1fM", n / (float)(1000 * 1000));
  } else if (n >= 1000) {
    snprintf(str, maxlen, "%.1fK", n / (float)1000);
  } else {
    snprintf(str, maxlen, "%lu", n);
  }
}


x86 assembly (clang, -O0):
<n2h>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpq   $0x3b9aca00,-0x8(%rbp)
3b
jb     11cb <n2h+0xbb>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%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,-0x1c(%rbp)
test   %rax,%rax
movss  %xmm0,-0x18(%rbp)
js     117c <n2h+0x6c>
movss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
mov    -0x20(%rbp),%esi
mov    -0x28(%rbp),%rdi
movss  -0x18(%rbp),%xmm0
movss  0xe7c(%rip),%xmm1
divss  %xmm1,%xmm0
movaps %xmm0,%xmm1
cvttss2si %xmm1,%rcx
mov    %rcx,%rdx
sar    $0x3f,%rdx
movss  0xe59(%rip),%xmm1
subss  %xmm1,%xmm0
cvttss2si %xmm0,%rax
and    %rdx,%rax
or     %rax,%rcx
lea    0xe4f(%rip),%rdx
call   1030 <snprintf@plt>
jmp    133c <n2h+0x22c>
cmpq   $0xf4240,-0x8(%rbp)
jb     1273 <n2h+0x163>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%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,-0x30(%rbp)
test   %rax,%rax
movss  %xmm0,-0x2c(%rbp)
js     1224 <n2h+0x114>
movss  -0x30(%rbp),%xmm0
movss  %xmm0,-0x2c(%rbp)
mov    -0x34(%rbp),%esi
mov    -0x40(%rbp),%rdi
movss  -0x2c(%rbp),%xmm0
movss  0xdd0(%rip),%xmm1
divss  %xmm1,%xmm0
movaps %xmm0,%xmm1
cvttss2si %xmm1,%rcx
mov    %rcx,%rdx
sar    $0x3f,%rdx
movss  0xdb1(%rip),%xmm1
subss  %xmm1,%xmm0
cvttss2si %xmm0,%rax
and    %rdx,%rax
or     %rax,%rcx
lea    0xdad(%rip),%rdx
call   1030 <snprintf@plt>
jmp    1337 <n2h+0x227>
cmpq   $0x3e8,-0x8(%rbp)
jb     131b <n2h+0x20b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4c(%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,-0x48(%rbp)
test   %rax,%rax
movss  %xmm0,-0x44(%rbp)
js     12cc <n2h+0x1bc>
movss  -0x48(%rbp),%xmm0
movss  %xmm0,-0x44(%rbp)
mov    -0x4c(%rbp),%esi
mov    -0x58(%rbp),%rdi
movss  -0x44(%rbp),%xmm0
movss  0xd20(%rip),%xmm1
divss  %xmm1,%xmm0
movaps %xmm0,%xmm1
cvttss2si %xmm1,%rcx
mov    %rcx,%rdx
sar    $0x3f,%rdx
movss  0xd09(%rip),%xmm1
subss  %xmm1,%xmm0
cvttss2si %xmm0,%rax
and    %rdx,%rax
or     %rax,%rcx
lea    0xd0b(%rip),%rdx
call   1030 <snprintf@plt>
jmp    1332 <n2h+0x222>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%rcx
lea    0xcf5(%rip),%rdx
call   1030 <snprintf@plt>
jmp    1337 <n2h+0x227>
jmp    133c <n2h+0x22c>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<n2h>:
mov    %rdi,%rcx
cmp    $0x3b9aca00,%rdi
jb     1128 <n2h+0x18>
test   %rcx,%rcx
js     113d <n2h+0x2d>
cvtsi2ss %rcx,%xmm0
jmp    1152 <n2h+0x42>
cmp    $0xf4240,%rcx
jb     1185 <n2h+0x75>
test   %rcx,%rcx
js     119a <n2h+0x8a>
cvtsi2ss %rcx,%xmm0
jmp    11af <n2h+0x9f>
mov    %rcx,%rax
shr    %rax
and    $0x1,%ecx
or     %rax,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
divss  0xeb2(%rip),%xmm0
cvttss2si %xmm0,%rax
mov    %rax,%rdi
subss  0xe9a(%rip),%xmm0
cvttss2si %xmm0,%rcx
sar    $0x3f,%rdi
and    %rdi,%rcx
or     %rax,%rcx
lea    0xe90(%rip),%rax
jmp    122b <n2h+0x11b>
cmp    $0x3e8,%rcx
jb     11df <n2h+0xcf>
test   %rcx,%rcx
js     11e8 <n2h+0xd8>
cvtsi2ss %rcx,%xmm0
jmp    11fd <n2h+0xed>
mov    %rcx,%rax
shr    %rax
and    $0x1,%ecx
or     %rax,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
divss  0xe51(%rip),%xmm0
cvttss2si %xmm0,%rax
mov    %rax,%rdi
subss  0xe3d(%rip),%xmm0
cvttss2si %xmm0,%rcx
sar    $0x3f,%rdi
and    %rdi,%rcx
or     %rax,%rcx
lea    0xe39(%rip),%rax
jmp    122b <n2h+0x11b>
lea    0xe3c(%rip),%rax
jmp    122b <n2h+0x11b>
mov    %rcx,%rax
shr    %rax
and    $0x1,%ecx
or     %rax,%rcx
cvtsi2ss %rcx,%xmm0
addss  %xmm0,%xmm0
divss  0xdfb(%rip),%xmm0
cvttss2si %xmm0,%rax
mov    %rax,%rdi
subss  0xdef(%rip),%xmm0
cvttss2si %xmm0,%rcx
sar    $0x3f,%rdi
and    %rdi,%rcx
or     %rax,%rcx
lea    0xdf1(%rip),%rax
mov    %rsi,%rdi
mov    %edx,%esi
mov    %rax,%rdx
jmp    1030 <snprintf@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"%.1fG\00"
@.str.1 = [6 x i8] c"%.1fM\00"
@.str.2 = [6 x i8] c"%.1fK\00"
@.str.3 = [4 x i8] c"%lu\00"
define void @n2h(i64 %0, i8* %1, i32 %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32
store i64 %0, i64* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%7 = load i64, i64* %4
%8 = icmp uge i64 %7, 1000000000
br i1 %8, label %9, label %17
9: ; preds = %3
%10 = load i8*, i8** %5
%11 = load i32, i32* %6
%12 = load i64, i64* %4
%13 = uitofp i64 %12 to float
%14 = fdiv float %13, 1.000000e+09
%15 = fptoui float %14 to i64
%16 = call i32 @snprintf(i8* %10, i32 %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %15)
br label %46
17: ; preds = %3
%18 = load i64, i64* %4
%19 = icmp uge i64 %18, 1000000
br i1 %19, label %20, label %28
20: ; preds = %17
%21 = load i8*, i8** %5
%22 = load i32, i32* %6
%23 = load i64, i64* %4
%24 = uitofp i64 %23 to float
%25 = fdiv float %24, 1.000000e+06
%26 = fptoui float %25 to i64
%27 = call i32 @snprintf(i8* %21, i32 %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %26)
br label %45
28: ; preds = %17
%29 = load i64, i64* %4
%30 = icmp uge i64 %29, 1000
br i1 %30, label %31, label %39
31: ; preds = %28
%32 = load i8*, i8** %5
%33 = load i32, i32* %6
%34 = load i64, i64* %4
%35 = uitofp i64 %34 to float
%36 = fdiv float %35, 1.000000e+03
%37 = fptoui float %36 to i64
%38 = call i32 @snprintf(i8* %32, i32 %33, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %37)
br label %44
39: ; preds = %28
%40 = load i8*, i8** %5
%41 = load i32, i32* %6
%42 = load i64, i64* %4
%43 = call i32 @snprintf(i8* %40, i32 %41, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64 %42)
br label %44
44: ; preds = %39, %31
br label %45
45: ; preds = %44, %20
br label %46
46: ; preds = %45, %9
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"%.1fG\00"
@.str.1 = [6 x i8] c"%.1fM\00"
@.str.2 = [6 x i8] c"%.1fK\00"
@.str.3 = [4 x i8] c"%lu\00"
define void @n2h(i64 %0, i8* %1, i32 %2) {
%4 = icmp ugt i64 %0, 999999999
br i1 %4, label %5, label %10
5: ; preds = %3
%6 = uitofp i64 %0 to float
%7 = fdiv float %6, 1.000000e+09
%8 = fptoui float %7 to i64
%9 = tail call i32 @snprintf(i8* %1, i32 %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %8)
br label %26
10: ; preds = %3
%11 = icmp ugt i64 %0, 999999
br i1 %11, label %12, label %17
12: ; preds = %10
%13 = uitofp i64 %0 to float
%14 = fdiv float %13, 1.000000e+06
%15 = fptoui float %14 to i64
%16 = tail call i32 @snprintf(i8* %1, i32 %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %15)
br label %26
17: ; preds = %10
%18 = icmp ugt i64 %0, 999
br i1 %18, label %19, label %24
19: ; preds = %17
%20 = uitofp i64 %0 to float
%21 = fdiv float %20, 1.000000e+03
%22 = fptoui float %21 to i64
%23 = tail call i32 @snprintf(i8* %1, i32 %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 %22)
br label %26
24: ; preds = %17
%25 = tail call i32 @snprintf(i8* %1, i32 %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64 %0)
br label %26
26: ; preds = %12, %24, %19, %5
ret void
}