#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 */
char *get_buffer();
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned long, ...);
char *print_big_number(unsigned long val) {
  char *buf = get_buffer();
  if (val < 1000UL)
    snprintf(buf, 32, "%ld", val);
  else if (val < 1000000UL)
    snprintf(buf, 32, "%ld %03ld", val / 1000, val % 1000);
  else
    snprintf(buf, 32, "%ld %03ld %03ld", val / 1000000UL, (val / 1000) % 1000,
             val % 1000);
  return buf;
}


x86 assembly (clang, -O0):
<print_big_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1040 <get_buffer@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x3e8,-0x8(%rbp)
jae    1165 <print_big_number+0x45>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x20,%esi
lea    0xea7(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    120a <print_big_number+0xea>
cmpq   $0xf4240,-0x8(%rbp)
jae    11b1 <print_big_number+0x91>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    $0x3e8,%esi
xor    %edx,%edx
div    %rsi
mov    %rdx,%r8
mov    $0x20,%esi
lea    0xe5f(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    1205 <print_big_number+0xe5>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    $0xf4240,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    $0x3e8,%esi
xor    %edx,%edx
div    %rsi
mov    $0x3e8,%esi
xor    %edx,%edx
div    %rsi
mov    %rdx,%r8
mov    -0x8(%rbp),%rax
mov    $0x3e8,%esi
xor    %edx,%edx
div    %rsi
mov    %rdx,%r9
mov    $0x20,%esi
lea    0xe10(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    120a <print_big_number+0xea>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_big_number>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <get_buffer@plt>
mov    %rax,%r14
cmp    $0x3e7,%rbx
ja     1158 <print_big_number+0x38>
lea    0xebf(%rip),%rdx
mov    %r14,%rdi
mov    $0x20,%esi
mov    %rbx,%rcx
xor    %eax,%eax
call   1030 <snprintf@plt>
jmp    11fe <print_big_number+0xde>
cmp    $0xf423f,%rbx
ja     1191 <print_big_number+0x71>
mov    %ebx,%eax
imul   $0x10624dd3,%rax,%rcx
shr    $0x26,%rcx
imul   $0x3e8,%ecx,%eax
sub    %eax,%ebx
lea    0xe87(%rip),%rdx
mov    %r14,%rdi
mov    $0x20,%esi
mov    %rbx,%r8
xor    %eax,%eax
call   1030 <snprintf@plt>
jmp    11fe <print_big_number+0xde>
movabs $0x431bde82d7b634db,%rcx
de 1b 43
mov    %rbx,%rax
mul    %rcx
mov    %rdx,%rcx
shr    $0x12,%rcx
mov    %rbx,%rax
shr    $0x3,%rax
movabs $0x20c49ba5e353f7cf,%rsi
9b c4 20
mul    %rsi
mov    %rdx,%r8
mov    %rdx,%rax
shr    $0x7,%rax
mul    %rsi
shr    $0x4,%rdx
imul   $0x3e8,%rdx,%rax
shr    $0x4,%r8
imul   $0x3e8,%r8,%rdx
sub    %rax,%r8
sub    %rdx,%rbx
lea    0xe22(%rip),%rdx
mov    %r14,%rdi
mov    $0x20,%esi
mov    %rbx,%r9
xor    %eax,%eax
call   1030 <snprintf@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%ld\00"
@.str.1 = [10 x i8] c"%ld %03ld\00"
@.str.2 = [16 x i8] c"%ld %03ld %03ld\00"
define i8* @print_big_number(i64 %0) {
%2 = tail call i8* (...) @get_buffer()
%3 = icmp ult i64 %0, 1000
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 (i8*, i32, i8*, i64, ...) @snprintf(i8* %2, i32 32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %0)
br label %21
6: ; preds = %1
%7 = icmp ult i64 %0, 1000000
br i1 %7, label %8, label %15
8: ; preds = %6
%9 = trunc i64 %0 to i32
%10 = udiv i32 %9, 1000
%11 = zext i32 %10 to i64
%12 = urem i32 %9, 1000
%13 = zext i32 %12 to i64
%14 = tail call i32 (i8*, i32, i8*, i64, ...) @snprintf(i8* %2, i32 32, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i64 %11, i64 %13)
br label %21
15: ; preds = %6
%16 = udiv i64 %0, 1000000
%17 = udiv i64 %0, 1000
%18 = urem i64 %17, 1000
%19 = urem i64 %0, 1000
%20 = tail call i32 (i8*, i32, i8*, i64, ...) @snprintf(i8* %2, i32 32, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i64 %16, i64 %18, i64 %19)
br label %21
21: ; preds = %8, %15, %4
ret i8* %2
}