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


x86 assembly (clang, -O0):
<fancy_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x3e8,-0x8(%rbp)
jge    1141 <fancy_int+0x31>
mov    -0x8(%rbp),%rsi
lea    0xecb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12a8 <fancy_int+0x198>
cmpq   $0x3e8,-0x8(%rbp)
jl     118f <fancy_int+0x7f>
cmpq   $0xf4240,-0x8(%rbp)
jge    118f <fancy_int+0x7f>
mov    -0x8(%rbp),%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
mov    %rax,%rsi
mov    -0x8(%rbp),%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12a3 <fancy_int+0x193>
cmpq   $0xf4240,-0x8(%rbp)
jl     1203 <fancy_int+0xf3>
cmpq   $0x3b9aca00,-0x8(%rbp)
3b
jge    1203 <fancy_int+0xf3>
mov    -0x8(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    %rax,%rsi
mov    -0x8(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    %rdx,%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
mov    %rdx,%rcx
mov    -0x10(%rbp),%rdx
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    129e <fancy_int+0x18e>
cmpq   $0x3b9aca00,-0x8(%rbp)
3b
jl     1287 <fancy_int+0x177>
mov    -0x8(%rbp),%rax
mov    $0x3b9aca00,%ecx
cqto
idiv   %rcx
mov    %rax,%rsi
mov    -0x8(%rbp),%rax
mov    $0x3b9aca00,%ecx
cqto
idiv   %rcx
mov    %rdx,%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    %rdx,%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    $0x3e8,%edi
cqto
idiv   %rdi
mov    %rdx,%r8
mov    -0x18(%rbp),%rdx
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1299 <fancy_int+0x189>
mov    -0x8(%rbp),%rsi
lea    0xd6e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    129e <fancy_int+0x18e>
jmp    12a3 <fancy_int+0x193>
jmp    12a8 <fancy_int+0x198>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fancy_int>:
mov    %rdi,%r8
cmp    $0x3e7,%rdi
jg     112d <fancy_int+0x1d>
lea    0xedd(%rip),%rdi
mov    %r8,%rsi
xor    %eax,%eax
jmp    1030 <printf@plt>
cmp    $0xf423f,%r8
ja     115e <fancy_int+0x4e>
mov    %r8d,%eax
imul   $0x10624dd3,%rax,%rsi
shr    $0x26,%rsi
imul   $0x3e8,%esi,%eax
sub    %eax,%r8d
lea    0xeb1(%rip),%rdi
mov    %r8,%rdx
xor    %eax,%eax
jmp    1030 <printf@plt>
cmp    $0x3b9ac9ff,%r8
ja     11b0 <fancy_int+0xa0>
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    0xe6a(%rip),%rdi
mov    %r8,%rcx
xor    %eax,%eax
jmp    1030 <printf@plt>
mov    %r8,%rax
shr    $0x9,%rax
movabs $0x44b82fa09b5a53,%rcx
mul    %rcx
mov    %rdx,%rsi
shr    $0xb,%rsi
imul   $0x3b9aca00,%rsi,%rax
mov    %r8,%rcx
sub    %rax,%rcx
imul   $0x431bde83,%rcx,%r9
shr    $0x32,%r9
movabs $0x431bde82d7b634db,%rcx
de 1b 43
mov    %r8,%rax
mul    %rcx
shr    $0x12,%rdx
imul   $0xf4240,%rdx,%rax
mov    %r8,%rcx
sub    %rax,%rcx
imul   $0x10624dd3,%rcx,%rcx
shr    $0x26,%rcx
mov    %r8,%rax
shr    $0x3,%rax
movabs $0x20c49ba5e353f7cf,%rdx
9b c4 20
mul    %rdx
shr    $0x4,%rdx
imul   $0x3e8,%rdx,%rax
sub    %rax,%r8
lea    0xde9(%rip),%rdi
mov    %r9,%rdx
xor    %eax,%eax
jmp    1030 <printf@plt>

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