#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int abs(int);
scalar_t__ malloc(int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int strlen(char *);
char *qstr_comma_number(int number) {
  char *str, *strp;
  str = strp = (char *)malloc(sizeof(char) * (14 + 1));
  if (str == NULL)
    return NULL;
  char buf[10 + 1], *bufp;
  snprintf(buf, sizeof(buf), "%d", abs(number));
  if (number < 0)
    *strp++ = '-';
  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):
<qstr_comma_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0xc(%rbp)
mov    $0xf,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1175 <qstr_comma_number+0x35>
movq   $0x0,-0x8(%rbp)
jmp    124b <qstr_comma_number+0x10b>
lea    -0x2b(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <abs@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%ecx
mov    $0xb,%esi
lea    0xe69(%rip),%rdx
call   1050 <snprintf@plt>
cmpl   $0x0,-0xc(%rbp)
jge    11b8 <qstr_comma_number+0x78>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x2d,(%rax)
lea    -0x2b(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     123c <qstr_comma_number+0xfc>
mov    -0x38(%rbp),%rax
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x38(%rbp),%rdi
call   1040 <strlen@plt>
mov    $0x3,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
jne    121a <qstr_comma_number+0xda>
mov    -0x38(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     121a <qstr_comma_number+0xda>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x2c,0x1(%rax)
jmp    121f <qstr_comma_number+0xdf>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    11c0 <qstr_comma_number+0x80>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qstr_comma_number>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%r15d
mov    $0xf,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11e1 <qstr_comma_number+0xb1>
mov    %rax,%r14
mov    %r15d,%ecx
neg    %ecx
cmovs  %r15d,%ecx
lea    0xe9d(%rip),%rdx
lea    0xd(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xb,%esi
call   1040 <snprintf@plt>
mov    %r14,%rbp
test   %r15d,%r15d
jns    1188 <qstr_comma_number+0x58>
mov    %r14,%rbp
add    $0x1,%rbp
movb   $0x2d,(%r14)
mov    0xd(%rsp),%al
jmp    119c <qstr_comma_number+0x6c>
xchg   %ax,%ax
add    $0x1,%rbp
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     11db <qstr_comma_number+0xab>
mov    %al,0x0(%rbp)
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    1190 <qstr_comma_number+0x60>
cmpb   $0x0,0x1(%rbx)
je     1190 <qstr_comma_number+0x60>
movb   $0x2c,0x1(%rbp)
add    $0x1,%rbp
jmp    1190 <qstr_comma_number+0x60>
movb   $0x0,0x0(%rbp)
jmp    11e4 <qstr_comma_number+0xb4>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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