#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 /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned int, ...);
const char *kilo_mega_ize(unsigned int val) {
  static char buf[20];
  char c = 0;
  int rest;
  if (val >= 1024) {
    rest = (val & 1023) / 102.4;
    val = val >> 10;
    c = 'k';
  }
  if (val >= 1024) {
    rest = (val & 1023) / 102.4;
    val = val >> 10;
    c = 'M';
  }
  if (c)
    snprintf(buf, sizeof(buf), "%d.%d%c", val, rest, c);
  else
    snprintf(buf, sizeof(buf), "%d", val);
  return buf;
}


x86 assembly (clang, -O0):
<kilo_mega_ize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movb   $0x0,-0x5(%rbp)
cmpl   $0x400,-0x4(%rbp)
jb     1158 <kilo_mega_ize+0x48>
mov    -0x4(%rbp),%eax
and    $0x3ff,%eax
cvtsi2sd %eax,%xmm0
movsd  0xec0(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
shr    $0xa,%eax
mov    %eax,-0x4(%rbp)
movb   $0x6b,-0x5(%rbp)
cmpl   $0x400,-0x4(%rbp)
jb     1191 <kilo_mega_ize+0x81>
mov    -0x4(%rbp),%eax
and    $0x3ff,%eax
cvtsi2sd %eax,%xmm0
movsd  0xe87(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
shr    $0xa,%eax
mov    %eax,-0x4(%rbp)
movb   $0x4d,-0x5(%rbp)
cmpb   $0x0,-0x5(%rbp)
je     11c6 <kilo_mega_ize+0xb6>
mov    -0x4(%rbp),%ecx
mov    -0xc(%rbp),%r8d
movsbl -0x5(%rbp),%r9d
lea    0x2e92(%rip),%rdi
mov    $0x14,%esi
lea    0xe4e(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    11e3 <kilo_mega_ize+0xd3>
mov    -0x4(%rbp),%ecx
lea    0x2e70(%rip),%rdi
mov    $0x14,%esi
lea    0xe34(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
lea    0x2e56(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kilo_mega_ize>:
push   %rax
mov    %edi,%eax
cmp    $0x400,%edi
jb     1172 <kilo_mega_ize+0x62>
mov    %eax,%edx
shr    $0xa,%edx
mov    %eax,%ecx
shr    $0x14,%ecx
cmp    $0x100000,%eax
cmovb  %edx,%ecx
mov    $0x4d,%esi
mov    $0x6b,%r9d
cmovae %esi,%r9d
cmovb  %eax,%edx
and    $0x3ff,%edx
cvtsi2sd %edx,%xmm0
divsd  0xeaf(%rip),%xmm0
cvttsd2si %xmm0,%r8d
lea    0x2ee3(%rip),%rdi
lea    0xea4(%rip),%rdx
mov    $0x14,%esi
xor    %eax,%eax
call   1030 <snprintf@plt>
jmp    118e <kilo_mega_ize+0x7e>
lea    0x2ec7(%rip),%rdi
lea    0xe90(%rip),%rdx
mov    $0x14,%esi
mov    %eax,%ecx
xor    %eax,%eax
call   1030 <snprintf@plt>
lea    0x2eab(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
@kilo_mega_ize.buf = internal global [20 x i8] zeroinitializer
@.str = [8 x i8] c"%d.%d%c\00"
@.str.1 = [3 x i8] c"%d\00"
define i8* @kilo_mega_ize(i32 %0) {
%2 = alloca i32
%3 = alloca i8
%4 = alloca i32
store i32 %0, i32* %2
store i8 0, i8* %3
%5 = load i32, i32* %2
%6 = icmp uge i32 %5, 1024
br i1 %6, label %7, label %15
7: ; preds = %1
%8 = load i32, i32* %2
%9 = and i32 %8, 1023
%10 = uitofp i32 %9 to double
%11 = fdiv double %10, 1.024000e+02
%12 = fptosi double %11 to i32
store i32 %12, i32* %4
%13 = load i32, i32* %2
%14 = lshr i32 %13, 10
store i32 %14, i32* %2
store i8 107, i8* %3
br label %15
15: ; preds = %7, %1
%16 = load i32, i32* %2
%17 = icmp uge i32 %16, 1024
br i1 %17, label %18, label %26
18: ; preds = %15
%19 = load i32, i32* %2
%20 = and i32 %19, 1023
%21 = uitofp i32 %20 to double
%22 = fdiv double %21, 1.024000e+02
%23 = fptosi double %22 to i32
store i32 %23, i32* %4
%24 = load i32, i32* %2
%25 = lshr i32 %24, 10
store i32 %25, i32* %2
store i8 77, i8* %3
br label %26
26: ; preds = %18, %15
%27 = load i8, i8* %3
%28 = icmp ne i8 %27, 0
br i1 %28, label %29, label %35
29: ; preds = %26
%30 = load i32, i32* %2
%31 = load i32, i32* %4
%32 = load i8, i8* %3
%33 = sext i8 %32 to i32
%34 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @kilo_mega_ize.buf, i64 0, i64 0), i32 20, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %30, i32 %31, i32 %33)
br label %38
35: ; preds = %26
%36 = load i32, i32* %2
%37 = call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @kilo_mega_ize.buf, i64 0, i64 0), i32 20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %36)
br label %38
38: ; preds = %35, %29
ret i8* getelementptr inbounds ([20 x i8], [20 x i8]* @kilo_mega_ize.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@kilo_mega_ize.buf = internal global [20 x i8] zeroinitializer
@.str = [8 x i8] c"%d.%d%c\00"
@.str.1 = [3 x i8] c"%d\00"
define i8* @kilo_mega_ize(i32 %0) {
%2 = icmp ugt i32 %0, 1023
br i1 %2, label %3, label %15
3: ; preds = %1
%4 = lshr i32 %0, 10
%5 = icmp ugt i32 %0, 1048575
%6 = lshr i32 %0, 20
%7 = select i1 %5, i32 %6, i32 %4
%8 = select i1 %5, i32 77, i32 107
%9 = select i1 %5, i32 %4, i32 %0
%10 = and i32 %9, 1023
%11 = uitofp i32 %10 to double
%12 = fdiv double %11, 1.024000e+02
%13 = fptosi double %12 to i32
%14 = tail call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @kilo_mega_ize.buf, i64 0, i64 0), i32 20, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %13, i32 %8)
br label %17
15: ; preds = %1
%16 = tail call i32 (i8*, i32, i8*, i32, ...) @snprintf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @kilo_mega_ize.buf, i64 0, i64 0), i32 20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %0)
br label %17
17: ; preds = %15, %3
ret i8* getelementptr inbounds ([20 x i8], [20 x i8]* @kilo_mega_ize.buf, i64 0, i64 0)
}