#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 *, long long, ...);
void sprintLongWithCommas(char *s, long long l) {
  long long trillions, billions, millions, thousands;
  if (l >= 1000000000000LL) {
    trillions = l / 1000000000000LL;
    l -= trillions * 1000000000000LL;
    billions = l / 1000000000;
    l -= billions * 1000000000;
    millions = l / 1000000;
    l -= millions * 1000000;
    thousands = l / 1000;
    l -= thousands * 1000;
    sprintf(s, "%lld,%03lld,%03lld,%03lld,%03lld", trillions, billions,
            millions, thousands, l);
  } else if (l >= 1000000000) {
    billions = l / 1000000000;
    l -= billions * 1000000000;
    millions = l / 1000000;
    l -= millions * 1000000;
    thousands = l / 1000;
    l -= thousands * 1000;
    sprintf(s, "%lld,%03lld,%03lld,%03lld", billions, millions, thousands, l);
  } else if (l >= 1000000) {
    millions = l / 1000000;
    l -= millions * (long long)1000000;
    thousands = l / 1000;
    l -= thousands * 1000;
    sprintf(s, "%lld,%03lld,%03lld", millions, thousands, l);
  } else if (l >= 1000) {
    thousands = l / 1000;
    l -= thousands * 1000;
    sprintf(s, "%lld,%03lld", thousands, l);
  } else
    sprintf(s, "%lld", l);
}


x86 assembly (clang, -O0):
<sprintLongWithCommas>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movabs $0xe8d4a51000,%rax
cmp    %rax,-0x10(%rbp)
jl     1203 <sprintLongWithCommas+0xf3>
mov    -0x10(%rbp),%rax
movabs $0xe8d4a51000,%rcx
cqto
idiv   %rcx
mov    %rax,-0x18(%rbp)
movabs $0xe8d4a51000,%rcx
imul   -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x3b9aca00,%ecx
cqto
idiv   %rcx
mov    %rax,-0x20(%rbp)
imul   $0x3b9aca00,-0x20(%rbp),%rcx
3b
mov    -0x10(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    %rax,-0x28(%rbp)
imul   $0xf4240,-0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
mov    %rax,-0x30(%rbp)
imul   $0x3e8,-0x30(%rbp),%rcx
mov    -0x10(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x30(%rbp),%r9
mov    -0x10(%rbp),%rax
lea    0xe0d(%rip),%rsi
mov    %rax,(%rsp)
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1399 <sprintLongWithCommas+0x289>
cmpq   $0x3b9aca00,-0x10(%rbp)
3b
jl     12a7 <sprintLongWithCommas+0x197>
mov    -0x10(%rbp),%rax
mov    $0x3b9aca00,%ecx
cqto
idiv   %rcx
mov    %rax,-0x20(%rbp)
imul   $0x3b9aca00,-0x20(%rbp),%rcx
3b
mov    -0x10(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    %rax,-0x28(%rbp)
imul   $0xf4240,-0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
mov    %rax,-0x30(%rbp)
imul   $0x3e8,-0x30(%rbp),%rcx
mov    -0x10(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
mov    -0x10(%rbp),%r9
lea    0xd86(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1394 <sprintLongWithCommas+0x284>
cmpq   $0xf4240,-0x10(%rbp)
jl     1322 <sprintLongWithCommas+0x212>
mov    -0x10(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    %rax,-0x28(%rbp)
imul   $0xf4240,-0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
mov    %rax,-0x30(%rbp)
imul   $0x3e8,-0x30(%rbp),%rcx
mov    -0x10(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xd25(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    138f <sprintLongWithCommas+0x27f>
cmpq   $0x3e8,-0x10(%rbp)
jl     1374 <sprintLongWithCommas+0x264>
mov    -0x10(%rbp),%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
mov    %rax,-0x30(%rbp)
imul   $0x3e8,-0x30(%rbp),%rcx
mov    -0x10(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xce6(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    138a <sprintLongWithCommas+0x27a>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xcd7(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    138f <sprintLongWithCommas+0x27f>
jmp    1394 <sprintLongWithCommas+0x284>
jmp    1399 <sprintLongWithCommas+0x289>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sprintLongWithCommas>:
mov    %rsi,%r8
movabs $0xe8d4a51000,%rax
cmp    %rax,%rsi
jl     11de <sprintLongWithCommas+0xce>
push   %rax
movabs $0x232f33025bd42233,%rcx
33 2f 23
mov    %r8,%rax
mul    %rcx
mov    %rdx,%r11
shr    $0x25,%r11
movabs $0xffffff172b5af000,%rsi
ff ff ff
imul   %r11,%rsi
add    %r8,%rsi
movabs $0x112e0be826d694b3,%rcx
0b 2e 11
mov    %rsi,%rax
imul   %rcx
mov    %rdx,%rcx
shr    $0x3f,%rcx
sar    $0x1a,%rdx
add    %rdx,%rcx
imul   $0xffffffffc4653600,%rcx,%r10
add    %rsi,%r10
movabs $0x431bde82d7b634db,%rdx
de 1b 43
mov    %r10,%rax
imul   %rdx
mov    %rdx,%r8
shr    $0x3f,%r8
sar    $0x12,%rdx
add    %rdx,%r8
imul   $0xfffffffffff0bdc0,%r8,%rsi
add    %r10,%rsi
movabs $0x20c49ba5e353f7cf,%rdx
9b c4 20
mov    %rsi,%rax
imul   %rdx
mov    %rdx,%r9
shr    $0x3f,%r9
sar    $0x7,%rdx
add    %rdx,%r9
imul   $0xfffffffffffffc18,%r9,%rax
add    %rsi,%rax
mov    %rax,(%rsp)
lea    0xe2e(%rip),%rsi
mov    %r11,%rdx
xor    %eax,%eax
call   1030 <sprintf@plt>
pop    %rax
ret
cmp    $0x3b9aca00,%r8
jl     1271 <sprintLongWithCommas+0x161>
mov    %r8,%rax
shr    $0x9,%rax
movabs $0x44b82fa09b5a53,%rcx
mul    %rcx
mov    %rdx,%r10
shr    $0xb,%r10
imul   $0xffffffffc4653600,%r10,%rsi
add    %r8,%rsi
movabs $0x431bde82d7b634db,%rcx
de 1b 43
mov    %rsi,%rax
imul   %rcx
mov    %rdx,%rcx
shr    $0x3f,%rcx
sar    $0x12,%rdx
add    %rdx,%rcx
imul   $0xfffffffffff0bdc0,%rcx,%r11
add    %rsi,%r11
movabs $0x20c49ba5e353f7cf,%rdx
9b c4 20
mov    %r11,%rax
imul   %rdx
mov    %rdx,%r8
shr    $0x3f,%r8
sar    $0x7,%rdx
add    %rdx,%r8
imul   $0xfffffffffffffc18,%r8,%r9
add    %r11,%r9
lea    0xdba(%rip),%rsi
mov    %r10,%rdx
xor    %eax,%eax
jmp    1030 <sprintf@plt>
cmp    $0xf4240,%r8
jl     12c4 <sprintLongWithCommas+0x1b4>
mov    %r8d,%eax
imul   $0x431bde83,%rax,%rdx
shr    $0x32,%rdx
imul   $0xfffffffffff0bdc0,%rdx,%rax
add    %r8,%rax
movslq %eax,%rcx
imul   $0x10624dd3,%rcx,%rcx
mov    %rcx,%rsi
shr    $0x3f,%rsi
sar    $0x26,%rcx
add    %esi,%ecx
movslq %ecx,%rcx
imul   $0xfffffffffffffc18,%rcx,%r8
add    %rax,%r8
lea    0xd7e(%rip),%rsi
xor    %eax,%eax
jmp    1030 <sprintf@plt>
cmp    $0x3e8,%r8
jl     12f3 <sprintLongWithCommas+0x1e3>
mov    %r8d,%eax
imul   $0x10624dd3,%rax,%rdx
shr    $0x26,%rdx
imul   $0xfffffffffffffc18,%rdx,%rcx
add    %r8,%rcx
lea    0xd62(%rip),%rsi
xor    %eax,%eax
jmp    1030 <sprintf@plt>
lea    0xd60(%rip),%rsi
mov    %r8,%rdx
xor    %eax,%eax
jmp    1030 <sprintf@plt>

LLVM IR (-O0):
@.str = [33 x i8] c"%lld,%03lld,%03lld,%03lld,%03lld\00"
@.str.1 = [26 x i8] c"%lld,%03lld,%03lld,%03lld\00"
@.str.2 = [19 x i8] c"%lld,%03lld,%03lld\00"
@.str.3 = [12 x i8] c"%lld,%03lld\00"
@.str.4 = [5 x i8] c"%lld\00"
define void @sprintLongWithCommas(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
%9 = load i64, i64* %4
%10 = icmp sge i64 %9, 1000000000000
br i1 %10, label %11, label %43
11: ; preds = %2
%12 = load i64, i64* %4
%13 = sdiv i64 %12, 1000000000000
store i64 %13, i64* %5
%14 = load i64, i64* %5
%15 = mul nsw i64 %14, 1000000000000
%16 = load i64, i64* %4
%17 = sub nsw i64 %16, %15
store i64 %17, i64* %4
%18 = load i64, i64* %4
%19 = sdiv i64 %18, 1000000000
store i64 %19, i64* %6
%20 = load i64, i64* %6
%21 = mul nsw i64 %20, 1000000000
%22 = load i64, i64* %4
%23 = sub nsw i64 %22, %21
store i64 %23, i64* %4
%24 = load i64, i64* %4
%25 = sdiv i64 %24, 1000000
store i64 %25, i64* %7
%26 = load i64, i64* %7
%27 = mul nsw i64 %26, 1000000
%28 = load i64, i64* %4
%29 = sub nsw i64 %28, %27
store i64 %29, i64* %4
%30 = load i64, i64* %4
%31 = sdiv i64 %30, 1000
store i64 %31, i64* %8
%32 = load i64, i64* %8
%33 = mul nsw i64 %32, 1000
%34 = load i64, i64* %4
%35 = sub nsw i64 %34, %33
store i64 %35, i64* %4
%36 = load i8*, i8** %3
%37 = load i64, i64* %5
%38 = load i64, i64* %6
%39 = load i64, i64* %7
%40 = load i64, i64* %8
%41 = load i64, i64* %4
%42 = call i32 (i8*, i8*, i64, ...) @sprintf(i8* %36, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i64 %37, i64 %38, i64 %39, i64 %40, i64 %41)
br label %113
43: ; preds = %2
%44 = load i64, i64* %4
%45 = icmp sge i64 %44, 1000000000
br i1 %45, label %46, label %71
46: ; preds = %43
%47 = load i64, i64* %4
%48 = sdiv i64 %47, 1000000000
store i64 %48, i64* %6
%49 = load i64, i64* %6
%50 = mul nsw i64 %49, 1000000000
%51 = load i64, i64* %4
%52 = sub nsw i64 %51, %50
store i64 %52, i64* %4
%53 = load i64, i64* %4
%54 = sdiv i64 %53, 1000000
store i64 %54, i64* %7
%55 = load i64, i64* %7
%56 = mul nsw i64 %55, 1000000
%57 = load i64, i64* %4
%58 = sub nsw i64 %57, %56
store i64 %58, i64* %4
%59 = load i64, i64* %4
%60 = sdiv i64 %59, 1000
store i64 %60, i64* %8
%61 = load i64, i64* %8
%62 = mul nsw i64 %61, 1000
%63 = load i64, i64* %4
%64 = sub nsw i64 %63, %62
store i64 %64, i64* %4
%65 = load i8*, i8** %3
%66 = load i64, i64* %6
%67 = load i64, i64* %7
%68 = load i64, i64* %8
%69 = load i64, i64* %4
%70 = call i32 (i8*, i8*, i64, ...) @sprintf(i8* %65, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i64 %66, i64 %67, i64 %68, i64 %69)
br label %112
71: ; preds = %43
%72 = load i64, i64* %4
%73 = icmp sge i64 %72, 1000000
br i1 %73, label %74, label %92
74: ; preds = %71
%75 = load i64, i64* %4
%76 = sdiv i64 %75, 1000000
store i64 %76, i64* %7
%77 = load i64, i64* %7
%78 = mul nsw i64 %77, 1000000
%79 = load i64, i64* %4
%80 = sub nsw i64 %79, %78
store i64 %80, i64* %4
%81 = load i64, i64* %4
%82 = sdiv i64 %81, 1000
store i64 %82, i64* %8
%83 = load i64, i64* %8
%84 = mul nsw i64 %83, 1000
%85 = load i64, i64* %4
%86 = sub nsw i64 %85, %84
store i64 %86, i64* %4
%87 = load i8*, i8** %3
%88 = load i64, i64* %7
%89 = load i64, i64* %8
%90 = load i64, i64* %4
%91 = call i32 (i8*, i8*, i64, ...) @sprintf(i8* %87, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i64 %88, i64 %89, i64 %90)
br label %111
92: ; preds = %71
%93 = load i64, i64* %4
%94 = icmp sge i64 %93, 1000
br i1 %94, label %95, label %106
95: ; preds = %92
%96 = load i64, i64* %4
%97 = sdiv i64 %96, 1000
store i64 %97, i64* %8
%98 = load i64, i64* %8
%99 = mul nsw i64 %98, 1000
%100 = load i64, i64* %4
%101 = sub nsw i64 %100, %99
store i64 %101, i64* %4
%102 = load i8*, i8** %3
%103 = load i64, i64* %8
%104 = load i64, i64* %4
%105 = call i32 (i8*, i8*, i64, ...) @sprintf(i8* %102, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i64 %103, i64 %104)
br label %110
106: ; preds = %92
%107 = load i8*, i8** %3
%108 = load i64, i64* %4
%109 = call i32 (i8*, i8*, i64, ...) @sprintf(i8* %107, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i64 %108)
br label %110
110: ; preds = %106, %95
br label %111
111: ; preds = %110, %74
br label %112
112: ; preds = %111, %46
br label %113
113: ; preds = %112, %11
ret void
}

LLVM IR (-O2):
@.str = [33 x i8] c"%lld,%03lld,%03lld,%03lld,%03lld\00"
@.str.1 = [26 x i8] c"%lld,%03lld,%03lld,%03lld\00"
@.str.2 = [19 x i8] c"%lld,%03lld,%03lld\00"
@.str.3 = [12 x i8] c"%lld,%03lld\00"
@.str.4 = [5 x i8] c"%lld\00"
define void @sprintLongWithCommas(i8* nocapture writeonly %0, i64 %1) {
%3 = icmp sgt i64 %1, 999999999999
br i1 %3, label %4, label %18
4: ; preds = %2
%5 = udiv i64 %1, 1000000000000
%6 = mul nsw i64 %5, -1000000000000
%7 = add nsw i64 %6, %1
%8 = sdiv i64 %7, 1000000000
%9 = mul nsw i64 %8, -1000000000
%10 = add i64 %9, %7
%11 = sdiv i64 %10, 1000000
%12 = mul nsw i64 %11, -1000000
%13 = add i64 %12, %10
%14 = sdiv i64 %13, 1000
%15 = mul nsw i64 %14, -1000
%16 = add i64 %15, %13
%17 = tail call i32 (i8*, i8*, i64, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i64 %5, i64 %8, i64 %11, i64 %14, i64 %16)
br label %56
18: ; preds = %2
%19 = icmp sgt i64 %1, 999999999
br i1 %19, label %20, label %31
20: ; preds = %18
%21 = udiv i64 %1, 1000000000
%22 = mul nsw i64 %21, -1000000000
%23 = add nsw i64 %22, %1
%24 = sdiv i64 %23, 1000000
%25 = mul nsw i64 %24, -1000000
%26 = add nsw i64 %25, %23
%27 = sdiv i64 %26, 1000
%28 = mul nsw i64 %27, -1000
%29 = add nsw i64 %28, %26
%30 = tail call i32 (i8*, i8*, i64, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i64 %21, i64 %24, i64 %27, i64 %29)
br label %56
31: ; preds = %18
%32 = icmp sgt i64 %1, 999999
br i1 %32, label %33, label %45
33: ; preds = %31
%34 = trunc i64 %1 to i32
%35 = udiv i32 %34, 1000000
%36 = zext i32 %35 to i64
%37 = mul nsw i64 %36, -1000000
%38 = add nsw i64 %37, %1
%39 = trunc i64 %38 to i32
%40 = sdiv i32 %39, 1000
%41 = sext i32 %40 to i64
%42 = mul nsw i64 %41, -1000
%43 = add nsw i64 %42, %38
%44 = tail call i32 (i8*, i8*, i64, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i64 %36, i64 %41, i64 %43)
br label %56
45: ; preds = %31
%46 = icmp sgt i64 %1, 999
br i1 %46, label %47, label %54
47: ; preds = %45
%48 = trunc i64 %1 to i32
%49 = udiv i32 %48, 1000
%50 = zext i32 %49 to i64
%51 = mul nsw i64 %50, -1000
%52 = add nsw i64 %51, %1
%53 = tail call i32 (i8*, i8*, i64, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i64 %50, i64 %52)
br label %56
54: ; preds = %45
%55 = tail call i32 (i8*, i8*, i64, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i64 %1)
br label %56
56: ; preds = %20, %47, %54, %33, %4
ret void
}