#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 abs(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int strlen(char *);
char *qitocomma(int value) {
  static char str[14 + 1];
  char buf[10 + 1], *strp = str, *bufp;
  if (value < 0)
    *strp++ = '-';
  sprintf(buf, "%d", abs(value));
  for (bufp = buf; *bufp != '\0'; strp++, bufp++) {
    *strp = *bufp;
    if (((strlen(bufp)) % 3 == 1) && (*(bufp + 1) != '\0'))
      *(++strp) = ',';
  }
  *strp = '\0';
  return str;
}


x86 assembly (clang, -O0):
<qitocomma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
lea    0x2ef7(%rip),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    1162 <qitocomma+0x32>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x2d,(%rax)
lea    -0xf(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <abs@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%edx
lea    0xe81(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0xf(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1208 <qitocomma+0xd8>
mov    -0x20(%rbp),%rax
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    $0x3,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
jne    11e6 <qitocomma+0xb6>
mov    -0x20(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     11e6 <qitocomma+0xb6>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x2c,0x1(%rax)
jmp    11eb <qitocomma+0xbb>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    118c <qitocomma+0x5c>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
lea    0x2e23(%rip),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qitocomma>:
push   %r14
push   %rbx
sub    $0x18,%rsp
test   %edi,%edi
js     1134 <qitocomma+0x14>
lea    0x2eff(%rip),%r14
jmp    1142 <qitocomma+0x22>
movb   $0x2d,0x2ef6(%rip)
lea    0x2ef0(%rip),%r14
mov    %edi,%edx
neg    %edx
cmovs  %edi,%edx
lea    0xeb0(%rip),%rsi
lea    0xd(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <sprintf@plt>
mov    0xd(%rsp),%al
jmp    117c <qitocomma+0x5c>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r14
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     11bc <qitocomma+0x9c>
mov    %al,(%r14)
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
imul   $0x55555556,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,2),%ecx
sub    %ecx,%eax
cmp    $0x1,%eax
jne    1170 <qitocomma+0x50>
cmpb   $0x0,0x1(%rbx)
je     1170 <qitocomma+0x50>
movb   $0x2c,0x1(%r14)
add    $0x1,%r14
jmp    1170 <qitocomma+0x50>
movb   $0x0,(%r14)
lea    0x2e6a(%rip),%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

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

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