#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 *, int);
int strlen(char *);
char *int_to_text(int nr) {
  char tmpbuf[12];
  static char buf[20];
  char *to = buf;
  char *from = tmpbuf;
  sprintf(tmpbuf, "%d", nr);
  while (*from) {
    *to++ = *from++;
    if (strlen(from) % 3 == 0 && *from)
      *to++ = ',';
  }
  *to = 0;
  return buf;
}


x86 assembly (clang, -O0):
<int_to_text>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    0x2f0e(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xeb4(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     11c1 <int_to_text+0xa1>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    $0x3,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11bc <int_to_text+0x9c>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11bc <int_to_text+0x9c>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x2c,(%rax)
jmp    1151 <int_to_text+0x31>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
lea    0x2e71(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<int_to_text>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%edx
lea    0xece(%rip),%rsi
lea    0x4(%rsp),%rdi
call   1040 <sprintf@plt>
mov    0x4(%rsp),%al
test   %al,%al
je     11a3 <int_to_text+0x83>
lea    0x5(%rsp),%rbx
lea    0x2ef0(%rip),%r14
jmp    116b <int_to_text+0x4b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%r14
add    $0x1,%rbx
test   %al,%al
je     11aa <int_to_text+0x8a>
lea    0x1(%r14),%r15
mov    %al,(%r14)
mov    %rbx,%rdi
call   1030 <strlen@plt>
imul   $0xaaaaaaab,%eax,%ecx
add    $0x2aaaaaaa,%ecx
movzbl (%rbx),%eax
cmp    $0x55555554,%ecx
ja     1160 <int_to_text+0x40>
test   %al,%al
je     11aa <int_to_text+0x8a>
movb   $0x2c,0x1(%r14)
add    $0x2,%r14
mov    %r14,%r15
jmp    1163 <int_to_text+0x43>
lea    0x2e96(%rip),%r15
movb   $0x0,(%r15)
lea    0x2e8b(%rip),%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@int_to_text.buf = internal global [20 x i8] zeroinitializer
@.str = [3 x i8] c"%d\00"
define i8* @int_to_text(i32 %0) {
%2 = alloca i32
%3 = alloca [12 x i8]
%4 = alloca i8*
%5 = alloca i8*
store i32 %0, i32* %2
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @int_to_text.buf, i64 0, i64 0), i8** %4
%6 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
store i8* %6, i8** %5
%7 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%8 = load i32, i32* %2
%9 = call i32 @sprintf(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %10
10: ; preds = %32, %1
%11 = load i8*, i8** %5
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
br i1 %13, label %14, label %33
14: ; preds = %10
%15 = load i8*, i8** %5
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %5
%17 = load i8, i8* %15
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %4
store i8 %17, i8* %18
%20 = load i8*, i8** %5
%21 = call i32 @strlen(i8* %20)
%22 = srem i32 %21, 3
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %32
24: ; preds = %14
%25 = load i8*, i8** %5
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %4
store i8 44, i8* %30
br label %32
32: ; preds = %29, %24, %14
br label %10
33: ; preds = %10
%34 = load i8*, i8** %4
store i8 0, i8* %34
ret i8* getelementptr inbounds ([20 x i8], [20 x i8]* @int_to_text.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@int_to_text.buf = internal global [20 x i8] zeroinitializer
@.str = [3 x i8] c"%d\00"
define i8* @int_to_text(i32 %0) {
%2 = alloca [12 x i8]
%3 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%4 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %0)
%5 = load i8, i8* %3
%6 = icmp eq i8 %5, 0
br i1 %6, label %24, label %7
7: ; preds = %1, %21
%8 = phi i8 [ %16, %21 ], [ %5, %1 ]
%9 = phi i8* [ %11, %21 ], [ %3, %1 ]
%10 = phi i8* [ %22, %21 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @int_to_text.buf, i64 0, i64 0), %1 ]
%11 = getelementptr inbounds i8, i8* %9, i64 1
%12 = getelementptr inbounds i8, i8* %10, i64 1
store i8 %8, i8* %10
%13 = call i32 @strlen(i8* %11)
%14 = srem i32 %13, 3
%15 = icmp eq i32 %14, 0
%16 = load i8, i8* %11
br i1 %15, label %17, label %21
17: ; preds = %7
%18 = icmp eq i8 %16, 0
br i1 %18, label %24, label %19
19: ; preds = %17
%20 = getelementptr inbounds i8, i8* %10, i64 2
store i8 44, i8* %12
br label %21
21: ; preds = %7, %19
%22 = phi i8* [ %20, %19 ], [ %12, %7 ]
%23 = icmp eq i8 %16, 0
br i1 %23, label %24, label %7
24: ; preds = %17, %21, %1
%25 = phi i8* [ getelementptr inbounds ([20 x i8], [20 x i8]* @int_to_text.buf, i64 0, i64 0), %1 ], [ %12, %17 ], [ %22, %21 ]
store i8 0, i8* %25
ret i8* getelementptr inbounds ([20 x i8], [20 x i8]* @int_to_text.buf, i64 0, i64 0)
}