#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*/ printf(char *, int, ...);
void fancy_int(int a) {
  if (a < 1000)
    printf("%d\n", a);
  else if (a >= 1000 && a < 1000000)
    printf("%d,%03d\n", a / 1000, a % 1000);
  else if (a >= 1000000 && a < 1000000000)
    printf("%d,%03d,%03d\n", a / 1000000, (a % 1000000) / 1000, a % 1000);
  else if (a >= 1000000000)
    printf("%d,%03d,%03d,%03d\n", a / 1000000000, (a % 1000000000) / 1000000,
           (a % 1000000) / 1000, a % 1000);
  else
    printf("%d\n", a);
}


x86 assembly (clang, -O0):
<fancy_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x3e8,-0x4(%rbp)
jge    113e <fancy_int+0x2e>
mov    -0x4(%rbp),%esi
lea    0xece(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1272 <fancy_int+0x162>
cmpl   $0x3e8,-0x4(%rbp)
jl     1183 <fancy_int+0x73>
cmpl   $0xf4240,-0x4(%rbp)
jge    1183 <fancy_int+0x73>
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    126d <fancy_int+0x15d>
cmpl   $0xf4240,-0x4(%rbp)
jl     11e5 <fancy_int+0xd5>
cmpl   $0x3b9aca00,-0x4(%rbp)
jge    11e5 <fancy_int+0xd5>
mov    -0x4(%rbp),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x4(%rbp),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %edx,%ecx
mov    -0x8(%rbp),%edx
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1268 <fancy_int+0x158>
cmpl   $0x3b9aca00,-0x4(%rbp)
jl     1252 <fancy_int+0x142>
mov    -0x4(%rbp),%eax
mov    $0x3b9aca00,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x4(%rbp),%eax
mov    $0x3b9aca00,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x4(%rbp),%eax
mov    $0x3e8,%edi
cltd
idiv   %edi
mov    %edx,%r8d
mov    -0xc(%rbp),%edx
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1263 <fancy_int+0x153>
mov    -0x4(%rbp),%esi
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1268 <fancy_int+0x158>
jmp    126d <fancy_int+0x15d>
jmp    1272 <fancy_int+0x162>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fancy_int>:
mov    %edi,%r8d
cmp    $0x3e7,%edi
jg     112c <fancy_int+0x1c>
lea    0xede(%rip),%rdi
mov    %r8d,%esi
xor    %eax,%eax
jmp    1030 <printf@plt>
cmp    $0xf423f,%r8d
ja     115d <fancy_int+0x4d>
mov    %r8d,%eax
imul   $0x10624dd3,%rax,%rsi
shr    $0x26,%rsi
imul   $0x3e8,%esi,%eax
sub    %eax,%r8d
lea    0xeb1(%rip),%rdi
mov    %r8d,%edx
xor    %eax,%eax
jmp    1030 <printf@plt>
cmp    $0x3b9ac9ff,%r8d
ja     11af <fancy_int+0x9f>
mov    %r8d,%eax
imul   $0x431bde83,%rax,%rsi
shr    $0x32,%rsi
imul   $0xf4240,%esi,%ecx
mov    %r8d,%edx
sub    %ecx,%edx
imul   $0x10624dd3,%rdx,%rdx
shr    $0x26,%rdx
imul   $0x10624dd3,%rax,%rax
shr    $0x26,%rax
imul   $0x3e8,%eax,%eax
sub    %eax,%r8d
lea    0xe68(%rip),%rdi
mov    %r8d,%ecx
xor    %eax,%eax
jmp    1030 <printf@plt>
mov    %r8d,%eax
shr    $0x9,%eax
imul   $0x44b83,%rax,%rsi
shr    $0x27,%rsi
imul   $0x3b9aca00,%esi,%eax
mov    %r8d,%ecx
sub    %eax,%ecx
imul   $0x431bde83,%rcx,%rdx
shr    $0x32,%rdx
mov    %r8d,%eax
imul   $0x431bde83,%rax,%rcx
shr    $0x32,%rcx
imul   $0xf4240,%ecx,%ecx
mov    %r8d,%edi
sub    %ecx,%edi
imul   $0x10624dd3,%rdi,%rcx
shr    $0x26,%rcx
imul   $0x10624dd3,%rax,%rax
shr    $0x26,%rax
imul   $0x3e8,%eax,%eax
sub    %eax,%r8d
lea    0xe06(%rip),%rdi
xor    %eax,%eax
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [9 x i8] c"%d,%03d\0A\00"
@.str.2 = [14 x i8] c"%d,%03d,%03d\0A\00"
@.str.3 = [19 x i8] c"%d,%03d,%03d,%03d\0A\00"
define void @fancy_int(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = icmp slt i32 %3, 1000
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = load i32, i32* %2
%7 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %6)
br label %56
8: ; preds = %1
%9 = load i32, i32* %2
%10 = icmp sge i32 %9, 1000
br i1 %10, label %11, label %20
11: ; preds = %8
%12 = load i32, i32* %2
%13 = icmp slt i32 %12, 1000000
br i1 %13, label %14, label %20
14: ; preds = %11
%15 = load i32, i32* %2
%16 = sdiv i32 %15, 1000
%17 = load i32, i32* %2
%18 = srem i32 %17, 1000
%19 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %18)
br label %55
20: ; preds = %11, %8
%21 = load i32, i32* %2
%22 = icmp sge i32 %21, 1000000
br i1 %22, label %23, label %35
23: ; preds = %20
%24 = load i32, i32* %2
%25 = icmp slt i32 %24, 1000000000
br i1 %25, label %26, label %35
26: ; preds = %23
%27 = load i32, i32* %2
%28 = sdiv i32 %27, 1000000
%29 = load i32, i32* %2
%30 = srem i32 %29, 1000000
%31 = sdiv i32 %30, 1000
%32 = load i32, i32* %2
%33 = srem i32 %32, 1000
%34 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %28, i32 %31, i32 %33)
br label %54
35: ; preds = %23, %20
%36 = load i32, i32* %2
%37 = icmp sge i32 %36, 1000000000
br i1 %37, label %38, label %50
38: ; preds = %35
%39 = load i32, i32* %2
%40 = sdiv i32 %39, 1000000000
%41 = load i32, i32* %2
%42 = srem i32 %41, 1000000000
%43 = sdiv i32 %42, 1000000
%44 = load i32, i32* %2
%45 = srem i32 %44, 1000000
%46 = sdiv i32 %45, 1000
%47 = load i32, i32* %2
%48 = srem i32 %47, 1000
%49 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %40, i32 %43, i32 %46, i32 %48)
br label %53
50: ; preds = %35
%51 = load i32, i32* %2
%52 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %51)
br label %53
53: ; preds = %50, %38
br label %54
54: ; preds = %53, %26
br label %55
55: ; preds = %54, %14
br label %56
56: ; preds = %55, %5
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [9 x i8] c"%d,%03d\0A\00"
@.str.2 = [14 x i8] c"%d,%03d,%03d\0A\00"
@.str.3 = [19 x i8] c"%d,%03d,%03d,%03d\0A\00"
define void @fancy_int(i32 %0) {
%2 = icmp slt i32 %0, 1000
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %27
5: ; preds = %1
%6 = icmp ult i32 %0, 1000000
br i1 %6, label %7, label %11
7: ; preds = %5
%8 = udiv i32 %0, 1000
%9 = urem i32 %0, 1000
%10 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %8, i32 %9)
br label %27
11: ; preds = %5
%12 = icmp ult i32 %0, 1000000000
br i1 %12, label %13, label %19
13: ; preds = %11
%14 = udiv i32 %0, 1000000
%15 = urem i32 %0, 1000000
%16 = udiv i32 %15, 1000
%17 = urem i32 %0, 1000
%18 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %14, i32 %16, i32 %17)
br label %27
19: ; preds = %11
%20 = udiv i32 %0, 1000000000
%21 = urem i32 %0, 1000000000
%22 = udiv i32 %21, 1000000
%23 = urem i32 %0, 1000000
%24 = udiv i32 %23, 1000
%25 = urem i32 %0, 1000
%26 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %20, i32 %22, i32 %24, i32 %25)
br label %27
27: ; preds = %7, %19, %13, %3
ret void
}