#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);
  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     1152 <snprintf_units+0x42>
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>
cmpl   $0x3e8,-0x14(%rbp)
jb     1186 <snprintf_units+0x76>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%eax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,%ecx
lea    0xe89(%rip),%rdx
call   1030 <snprintf@plt>
jmp    119d <snprintf_units+0x8d>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%ecx
lea    0xe72(%rip),%rdx
call   1030 <snprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<snprintf_units>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %edx,%ebx
cmp    $0xf4240,%edx
jb     1144 <snprintf_units+0x34>
imul   $0x431bde83,%rbx,%rcx
shr    $0x32,%rcx
lea    0xec9(%rip),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <snprintf@plt>
jmp    114e <snprintf_units+0x3e>
mov    %edx,%ecx
cmp    $0x3e8,%edx
jb     1168 <snprintf_units+0x58>
imul   $0x10624dd3,%rbx,%rcx
shr    $0x26,%rcx
lea    0xea5(%rip),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
jmp    1175 <snprintf_units+0x65>
lea    0xe9b(%rip),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %r15
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 %15
15: ; preds = %9, %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
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 %10
8: ; preds = %3
%9 = icmp ugt i32 %2, 999
br i1 %9, label %10, label %13
10: ; preds = %5, %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 = %13, %10
ret void
}