#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 *, size_t, char *, unsigned int);
void snprintf_units(char *buf, size_t n, unsigned int val) {
  if (val >= 1000000)
    snprintf(buf, n, "%3dM", val / 1000000);
  else if (val >= 1000)
    snprintf(buf, n, "%3dK", val / 1000);
  else
    snprintf(buf, n, "%3d", val);
}


x86 assembly (clang, -O0):
<snprintf_units>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0xf4240,-0x14(%rbp)
jb     1157 <snprintf_units+0x47>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%eax
mov    $0xf4240,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,%ecx
lea    0xeb3(%rip),%rdx
call   1030 <snprintf@plt>
jmp    11a7 <snprintf_units+0x97>
cmpl   $0x3e8,-0x14(%rbp)
jb     118b <snprintf_units+0x7b>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%eax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,%ecx
lea    0xe84(%rip),%rdx
call   1030 <snprintf@plt>
jmp    11a2 <snprintf_units+0x92>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%ecx
lea    0xe6d(%rip),%rdx
call   1030 <snprintf@plt>
jmp    11a7 <snprintf_units+0x97>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<snprintf_units>:
mov    %edx,%ecx
cmp    $0xf4240,%edx
jb     1133 <snprintf_units+0x23>
mov    %ecx,%eax
imul   $0x431bde83,%rax,%rcx
shr    $0x32,%rcx
lea    0xed2(%rip),%rdx
jmp    1030 <snprintf@plt>
cmp    $0x3e8,%ecx
jb     1154 <snprintf_units+0x44>
mov    %ecx,%eax
imul   $0x10624dd3,%rax,%rcx
shr    $0x26,%rcx
lea    0xeb6(%rip),%rdx
jmp    1030 <snprintf@plt>
lea    0xeaf(%rip),%rdx
jmp    1030 <snprintf@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"%3dM\00"
@.str.1 = [5 x i8] c"%3dK\00"
@.str.2 = [4 x i8] c"%3d\00"
define void @snprintf_units(i8* %0, i64 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
store i32 %2, i32* %6
%7 = load i32, i32* %6
%8 = icmp uge i32 %7, 1000000
br i1 %8, label %9, label %15
9: ; preds = %3
%10 = load i8*, i8** %4
%11 = load i64, i64* %5
%12 = load i32, i32* %6
%13 = udiv i32 %12, 1000000
%14 = call i32 @snprintf(i8* %10, i64 %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %13)
br label %30
15: ; preds = %3
%16 = load i32, i32* %6
%17 = icmp uge i32 %16, 1000
br i1 %17, label %18, label %24
18: ; preds = %15
%19 = load i8*, i8** %4
%20 = load i64, i64* %5
%21 = load i32, i32* %6
%22 = udiv i32 %21, 1000
%23 = call i32 @snprintf(i8* %19, i64 %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %22)
br label %29
24: ; preds = %15
%25 = load i8*, i8** %4
%26 = load i64, i64* %5
%27 = load i32, i32* %6
%28 = call i32 @snprintf(i8* %25, i64 %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %24, %18
br label %30
30: ; preds = %29, %9
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%3dM\00"
@.str.1 = [5 x i8] c"%3dK\00"
@.str.2 = [4 x i8] c"%3d\00"
define void @snprintf_units(i8* %0, i64 %1, i32 %2) {
%4 = icmp ugt i32 %2, 999999
br i1 %4, label %5, label %8
5: ; preds = %3
%6 = udiv i32 %2, 1000000
%7 = tail call i32 @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %6)
br label %15
8: ; preds = %3
%9 = icmp ugt i32 %2, 999
br i1 %9, label %10, label %13
10: ; preds = %8
%11 = udiv i32 %2, 1000
%12 = tail call i32 @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %11)
br label %15
13: ; preds = %8
%14 = tail call i32 @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %2)
br label %15
15: ; preds = %10, %13, %5
ret void
}