#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*/ printf(char *, ...);
void printfcomma(int n) {
  if (n < 0) {
    printf("-");
    printfcomma(-n);
    return;
  }
  if (n < 1000) {
    printf("%d", n);
    return;
  }
  printfcomma(n / 1000);
  printf(",%03d", n % 1000);
}


x86 assembly (clang, -O0):
<printfcomma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    1152 <printfcomma+0x32>
lea    0xec4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
sub    -0x4(%rbp),%edi
call   1040 <printfcomma@plt>
jmp    11a2 <printfcomma+0x82>
cmpl   $0x3e8,-0x4(%rbp)
jge    1175 <printfcomma+0x55>
mov    -0x4(%rbp),%esi
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a2 <printfcomma+0x82>
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1040 <printfcomma@plt>
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %edx,%esi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printfcomma>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
test   %edi,%edi
js     113d <printfcomma+0xd>
mov    %ebp,%ebx
jmp    1152 <printfcomma+0x22>
mov    %ebp,%ebx
nop
mov    $0x2d,%edi
call   1030 <putchar@plt>
neg    %ebx
test   %ebp,%ebp
mov    %ebx,%ebp
jg     1140 <printfcomma+0x10>
cmp    $0x3e7,%ebx
ja     1163 <printfcomma+0x33>
lea    0xe9f(%rip),%rdi
jmp    1186 <printfcomma+0x56>
mov    %ebx,%eax
imul   $0x10624dd3,%rax,%rbp
shr    $0x26,%rbp
mov    %ebp,%edi
call   1050 <printfcomma@plt>
imul   $0x3e8,%ebp,%eax
sub    %eax,%ebx
lea    0xe7d(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"-\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [6 x i8] c",%03d\00"
define void @printfcomma(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* %2
%8 = sub nsw i32 0, %7
br label %21
9: ; preds = %1
%10 = load i32, i32* %2
%11 = icmp slt i32 %10, 1000
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i32, i32* %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %13)
br label %21
15: ; preds = %9
%16 = load i32, i32* %2
%17 = sdiv i32 %16, 1000
%18 = load i32, i32* %2
%19 = srem i32 %18, 1000
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %15, %12, %5
ret void
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [6 x i8] c",%03d\00"
define void @printfcomma(i32 %0) {
%2 = icmp slt i32 %0, 0
br i1 %2, label %3, label %8
3: ; preds = %1, %3
%4 = phi i32 [ %6, %3 ], [ %0, %1 ]
%5 = tail call i32 @putchar(i32 45)
%6 = sub nsw i32 0, %4
%7 = icmp sgt i32 %4, 0
br i1 %7, label %3, label %8
8: ; preds = %3, %1
%9 = phi i32 [ %0, %1 ], [ %6, %3 ]
%10 = icmp ult i32 %9, 1000
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %9)
br label %13
13: ; preds = %11, %14
ret void
14: ; preds = %8
%15 = udiv i32 %9, 1000
tail call void @printfcomma(i32 %15)
%16 = urem i32 %9, 1000
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %16)
br label %13
}