#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*/ sprintf(char *, char *, unsigned int);
char *number(unsigned int n) {
  unsigned int k = 1000000000UL;
  static char s[16];
  char *cp = s;
  while (n < k && k > 1)
    k /= 1000UL;
  sprintf(cp, "%u", n / k);
  n %= k;
  k /= 1000UL;
  while (k) {
    while (*++cp)
      ;
    sprintf(cp, ",%03u", n / k);
    n %= k;
    k /= 1000UL;
  }
  return s;
}


x86 assembly (clang, -O0):
<number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x3b9aca00,-0x8(%rbp)
lea    0x2f17(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%ecx
xor    %eax,%eax
cmp    -0x8(%rbp),%ecx
mov    %al,-0x11(%rbp)
jae    1148 <number+0x38>
cmpl   $0x1,-0x8(%rbp)
seta   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1158 <number+0x48>
jmp    116d <number+0x5d>
mov    -0x8(%rbp),%eax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %rcx
mov    %eax,-0x8(%rbp)
jmp    112d <number+0x1d>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%eax
xor    %edx,%edx
divl   -0x8(%rbp)
mov    %eax,%edx
lea    0xe7e(%rip),%rsi
call   1030 <sprintf@plt>
mov    -0x8(%rbp),%ecx
mov    -0x4(%rbp),%eax
xor    %edx,%edx
div    %ecx
mov    %edx,-0x4(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %rcx
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     120d <number+0xfd>
jmp    11b3 <number+0xa3>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
cmpb   $0x0,0x1(%rax)
je     11d1 <number+0xc1>
jmp    11b3 <number+0xa3>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%eax
xor    %edx,%edx
divl   -0x8(%rbp)
mov    %eax,%edx
lea    0xe1d(%rip),%rsi
call   1030 <sprintf@plt>
mov    -0x8(%rbp),%ecx
mov    -0x4(%rbp),%eax
xor    %edx,%edx
div    %ecx
mov    %edx,-0x4(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %rcx
mov    %eax,-0x8(%rbp)
jmp    11a4 <number+0x94>
lea    0x2e2c(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<number>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%ebx
cmp    $0x3b9aca00,%edi
jae    1149 <number+0x39>
cmp    $0xf423f,%ebx
ja     1174 <number+0x64>
cmp    $0x3e8,%ebx
sbb    %ebp,%ebp
cmp    $0x3e8,%ebx
mov    $0x1,%eax
mov    $0x3e8,%r15d
cmovb  %eax,%r15d
jmp    117c <number+0x6c>
mov    %ebx,%eax
shr    $0x9,%eax
imul   $0x44b83,%rax,%rdx
shr    $0x27,%rdx
lea    0x2ee0(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1030 <sprintf@plt>
mov    $0x3b9aca00,%r15d
jmp    119e <number+0x8e>
mov    $0xf4240,%r15d
xor    %ebp,%ebp
mov    %ebx,%eax
xor    %edx,%edx
div    %r15d
lea    0x2eb6(%rip),%rdi
lea    0xe6f(%rip),%rsi
mov    %eax,%edx
call   1030 <sprintf@plt>
test   $0x1,%bpl
jne    11fb <number+0xeb>
mov    %ebx,%eax
xor    %edx,%edx
div    %r15d
mov    %edx,%r12d
lea    0x2e91(%rip),%rbx
lea    0xe4d(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
cmpb   $0x0,0x1(%rbx)
lea    0x1(%rbx),%rbx
jne    11c0 <number+0xb0>
mov    %r15d,%eax
imul   $0x10624dd3,%rax,%rbp
shr    $0x26,%rbp
mov    %r12d,%eax
xor    %edx,%edx
div    %ebp
mov    %edx,%r12d
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <sprintf@plt>
cmp    $0xf423f,%r15d
mov    %ebp,%r15d
ja     11c0 <number+0xb0>
lea    0x2e3e(%rip),%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@number.s = internal global [16 x i8] zeroinitializer
@.str = [3 x i8] c"%u\00"
@.str.1 = [6 x i8] c",%03u\00"
define i8* @number(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %2
store i32 1000000000, i32* %3
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @number.s, i64 0, i64 0), i8** %4
br label %5
5: ; preds = %14, %1
%6 = load i32, i32* %2
%7 = load i32, i32* %3
%8 = icmp ult i32 %6, %7
br i1 %8, label %9, label %12
9: ; preds = %5
%10 = load i32, i32* %3
%11 = icmp ugt i32 %10, 1
br label %12
12: ; preds = %9, %5
%13 = phi i1 [ false, %5 ], [ %11, %9 ]
br i1 %13, label %14, label %19
14: ; preds = %12
%15 = load i32, i32* %3
%16 = zext i32 %15 to i64
%17 = udiv i64 %16, 1000
%18 = trunc i64 %17 to i32
store i32 %18, i32* %3
br label %5
19: ; preds = %12
%20 = load i8*, i8** %4
%21 = load i32, i32* %2
%22 = load i32, i32* %3
%23 = udiv i32 %21, %22
%24 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %3
%26 = load i32, i32* %2
%27 = urem i32 %26, %25
store i32 %27, i32* %2
%28 = load i32, i32* %3
%29 = zext i32 %28 to i64
%30 = udiv i64 %29, 1000
%31 = trunc i64 %30 to i32
store i32 %31, i32* %3
br label %32
32: ; preds = %42, %19
%33 = load i32, i32* %3
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %55
35: ; preds = %32
br label %36
36: ; preds = %41, %35
%37 = load i8*, i8** %4
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %4
%39 = load i8, i8* %38
%40 = icmp ne i8 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %36
br label %36
42: ; preds = %36
%43 = load i8*, i8** %4
%44 = load i32, i32* %2
%45 = load i32, i32* %3
%46 = udiv i32 %44, %45
%47 = call i32 @sprintf(i8* %43, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %46)
%48 = load i32, i32* %3
%49 = load i32, i32* %2
%50 = urem i32 %49, %48
store i32 %50, i32* %2
%51 = load i32, i32* %3
%52 = zext i32 %51 to i64
%53 = udiv i64 %52, 1000
%54 = trunc i64 %53 to i32
store i32 %54, i32* %3
br label %32
55: ; preds = %32
ret i8* getelementptr inbounds ([16 x i8], [16 x i8]* @number.s, i64 0, i64 0)
}

LLVM IR (-O2):
@number.s = internal global [16 x i8] zeroinitializer
@.str = [3 x i8] c"%u\00"
@.str.1 = [6 x i8] c",%03u\00"
define i8* @number(i32 %0) {
%2 = icmp ult i32 %0, 1000000000
br i1 %2, label %6, label %3
3: ; preds = %1
%4 = udiv i32 %0, 1000000000
%5 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @number.s, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %4)
br label %17
6: ; preds = %1
%7 = icmp ult i32 %0, 1000000
br i1 %7, label %8, label %12
8: ; preds = %6
%9 = icmp ult i32 %0, 1000
%10 = select i1 %9, i1 true, i1 false
%11 = select i1 %9, i32 1, i32 1000
br label %12
12: ; preds = %8, %6
%13 = phi i1 [ false, %6 ], [ %10, %8 ]
%14 = phi i32 [ 1000000, %6 ], [ %11, %8 ]
%15 = udiv i32 %0, %14
%16 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @number.s, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %15)
br i1 %13, label %35, label %17
17: ; preds = %3, %12
%18 = phi i32 [ 1000000000, %3 ], [ %14, %12 ]
%19 = urem i32 %0, %18
br label %20
20: ; preds = %17, %29
%21 = phi i32 [ %30, %29 ], [ %18, %17 ]
%22 = phi i8* [ %26, %29 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @number.s, i64 0, i64 0), %17 ]
%23 = phi i32 [ %33, %29 ], [ %19, %17 ]
br label %24
24: ; preds = %20, %24
%25 = phi i8* [ %26, %24 ], [ %22, %20 ]
%26 = getelementptr inbounds i8, i8* %25, i64 1
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 0
br i1 %28, label %29, label %24
29: ; preds = %24
%30 = udiv i32 %21, 1000
%31 = udiv i32 %23, %30
%32 = tail call i32 @sprintf(i8* %26, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %31)
%33 = urem i32 %23, %30
%34 = icmp ult i32 %21, 1000000
br i1 %34, label %35, label %20
35: ; preds = %29, %12
ret i8* getelementptr inbounds ([16 x i8], [16 x i8]* @number.s, i64 0, i64 0)
}