#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(long int n) {
  if (n < 0) {
    printf("-");
    printfcomma(-n);
    return;
  }
  if (n < 1000) {
    printf("%ld", n);
    return;
  }
  printfcomma(n / 1000);
  printf(",%03ld", n % 1000);
}


x86 assembly (clang, -O0):
<printfcomma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jge    1157 <printfcomma+0x37>
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
sub    -0x8(%rbp),%rdi
call   1040 <printfcomma@plt>
jmp    11b1 <printfcomma+0x91>
cmpq   $0x3e8,-0x8(%rbp)
jge    117c <printfcomma+0x5c>
mov    -0x8(%rbp),%rsi
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b1 <printfcomma+0x91>
mov    -0x8(%rbp),%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
mov    %rax,%rdi
call   1040 <printfcomma@plt>
mov    -0x8(%rbp),%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
mov    %rdx,%rsi
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printfcomma>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
test   %rdi,%rdi
js     1141 <printfcomma+0x11>
mov    %r14,%rbx
jmp    1165 <printfcomma+0x35>
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x2d,%edi
call   1030 <putchar@plt>
neg    %rbx
test   %r14,%r14
mov    %rbx,%r14
jg     1150 <printfcomma+0x20>
cmp    $0x3e7,%rbx
ja     1177 <printfcomma+0x47>
lea    0xe8b(%rip),%rdi
jmp    11ab <printfcomma+0x7b>
mov    %rbx,%rax
shr    $0x3,%rax
movabs $0x20c49ba5e353f7cf,%rcx
9b c4 20
mul    %rcx
mov    %rdx,%r14
shr    $0x4,%r14
mov    %r14,%rdi
call   1050 <printfcomma@plt>
imul   $0x3e8,%r14,%rax
sub    %rax,%rbx
lea    0xe59(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <printf@plt>

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

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