#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, size_t const, ...);
void commaPrint0dp(FILE *fp, double d) {
  if (d >= 1000) {
    const size_t dd = d;
    d = 0;
    if (dd >= 1000000000) {
      fprintf(fp, "%zd,%03zd,%03zd,%03zd", (dd / 1000000000),
              (dd % 1000000000) / 1000000, (dd % 1000000) / 1000, dd % 1000);
    } else if (dd >= 1000000) {
      fprintf(fp, "%zd,%03zd,%03zd", (dd / 1000000), (dd % 1000000) / 1000,
              dd % 1000);
    } else {
      fprintf(fp, "%3zd,%03zd", dd / 1000, dd % 1000);
    }
  } else {
    fprintf(fp, "%7.0lf", d);
  }
}


x86 assembly (clang, -O0):
<commaPrint0dp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xed2(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     12a4 <commaPrint0dp+0x194>
movsd  -0x10(%rbp),%xmm0
movsd  0xec3(%rip),%xmm2
movaps %xmm0,%xmm1
subsd  %xmm2,%xmm1
cvttsd2si %xmm1,%rcx
cvttsd2si %xmm0,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
and    %rdx,%rcx
or     %rcx,%rax
mov    %rax,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
cmpq   $0x3b9aca00,-0x18(%rbp)
3b
jb     11f7 <commaPrint0dp+0xe7>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    $0x3b9aca00,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    $0x3b9aca00,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,%rax
mov    $0xf4240,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    $0xf4240,%esi
xor    %edx,%edx
div    %rsi
mov    %rdx,%rax
mov    $0x3e8,%esi
xor    %edx,%edx
div    %rsi
mov    %rax,%r8
mov    -0x18(%rbp),%rax
mov    $0x3e8,%esi
xor    %edx,%edx
div    %rsi
mov    %rdx,%r9
mov    -0x20(%rbp),%rdx
lea    0xe25(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    129f <commaPrint0dp+0x18f>
cmpq   $0xf4240,-0x18(%rbp)
jb     1261 <commaPrint0dp+0x151>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    $0xf4240,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    $0xf4240,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,%rax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    $0x3e8,%esi
xor    %edx,%edx
div    %rsi
mov    %rdx,%r8
mov    -0x28(%rbp),%rdx
lea    0xdd1(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    129a <commaPrint0dp+0x18a>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,%rcx
mov    -0x30(%rbp),%rdx
lea    0xda3(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    129f <commaPrint0dp+0x18f>
jmp    12e1 <commaPrint0dp+0x1d1>
mov    -0x8(%rbp),%rdi
movsd  -0x10(%rbp),%xmm0
movsd  0xd53(%rip),%xmm2
movaps %xmm0,%xmm1
subsd  %xmm2,%xmm1
cvttsd2si %xmm1,%rax
cvttsd2si %xmm0,%rdx
mov    %rdx,%rcx
sar    $0x3f,%rcx
and    %rcx,%rax
or     %rax,%rdx
lea    0xd67(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<commaPrint0dp>:
cvttsd2si %xmm0,%rax
mov    %rax,%rcx
movapd %xmm0,%xmm1
subsd  0xedc(%rip),%xmm1
sar    $0x3f,%rcx
cvttsd2si %xmm1,%r9
and    %rcx,%r9
or     %rax,%r9
ucomisd 0xecd(%rip),%xmm0
jae    114e <commaPrint0dp+0x3e>
lea    0xefd(%rip),%rsi
mov    %r9,%rdx
xor    %eax,%eax
jmp    1030 <fprintf@plt>
cmp    $0x3b9aca00,%r9
jb     11ed <commaPrint0dp+0xdd>
mov    %r9,%rax
shr    $0x9,%rax
movabs $0x44b82fa09b5a53,%rcx
mul    %rcx
mov    %rdx,%r10
shr    $0xb,%r10
imul   $0x3b9aca00,%r10,%rax
mov    %r9,%rcx
sub    %rax,%rcx
imul   $0x431bde83,%rcx,%rcx
shr    $0x32,%rcx
movabs $0x431bde82d7b634db,%rdx
de 1b 43
mov    %r9,%rax
mul    %rdx
shr    $0x12,%rdx
imul   $0xf4240,%rdx,%rax
mov    %r9,%rdx
sub    %rax,%rdx
imul   $0x10624dd3,%rdx,%r8
shr    $0x26,%r8
mov    %r9,%rax
shr    $0x3,%rax
movabs $0x20c49ba5e353f7cf,%rdx
9b c4 20
mul    %rdx
shr    $0x4,%rdx
imul   $0x3e8,%rdx,%rax
sub    %rax,%r9
lea    0xe2d(%rip),%rsi
mov    %r10,%rdx
xor    %eax,%eax
jmp    1030 <fprintf@plt>
mov    %r9d,%eax
cmp    $0xf4240,%r9
jb     123f <commaPrint0dp+0x12f>
imul   $0x431bde83,%rax,%rdx
shr    $0x32,%rdx
imul   $0xf4240,%edx,%ecx
mov    %r9d,%esi
sub    %ecx,%esi
imul   $0x10624dd3,%rsi,%rcx
shr    $0x26,%rcx
imul   $0x10624dd3,%rax,%rax
shr    $0x26,%rax
imul   $0x3e8,%eax,%eax
sub    %eax,%r9d
lea    0xdf1(%rip),%rsi
mov    %r9,%r8
xor    %eax,%eax
jmp    1030 <fprintf@plt>
imul   $0x10624dd3,%rax,%rdx
shr    $0x26,%rdx
imul   $0x3e8,%edx,%eax
sub    %eax,%r9d
lea    0xddc(%rip),%rsi
mov    %r9,%rcx
xor    %eax,%eax
jmp    1030 <fprintf@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"%zd,%03zd,%03zd,%03zd\00"
@.str.1 = [16 x i8] c"%zd,%03zd,%03zd\00"
@.str.2 = [11 x i8] c"%3zd,%03zd\00"
@.str.3 = [7 x i8] c"%7.0lf\00"
define void @commaPrint0dp(i32* %0, double %1) {
%3 = alloca i32*
%4 = alloca double
%5 = alloca i64
store i32* %0, i32** %3
store double %1, double* %4
%6 = load double, double* %4
%7 = fcmp oge double %6, 1.000000e+03
br i1 %7, label %8, label %48
8: ; preds = %2
%9 = load double, double* %4
%10 = fptoui double %9 to i64
store i64 %10, i64* %5
store double 0.000000e+00, double* %4
%11 = load i64, i64* %5
%12 = icmp uge i64 %11, 1000000000
br i1 %12, label %13, label %26
13: ; preds = %8
%14 = load i32*, i32** %3
%15 = load i64, i64* %5
%16 = udiv i64 %15, 1000000000
%17 = load i64, i64* %5
%18 = urem i64 %17, 1000000000
%19 = udiv i64 %18, 1000000
%20 = load i64, i64* %5
%21 = urem i64 %20, 1000000
%22 = udiv i64 %21, 1000
%23 = load i64, i64* %5
%24 = urem i64 %23, 1000
%25 = call i32 (i32*, i8*, i64, ...) @fprintf(i32* %14, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i64 %16, i64 %19, i64 %22, i64 %24)
br label %47
26: ; preds = %8
%27 = load i64, i64* %5
%28 = icmp uge i64 %27, 1000000
br i1 %28, label %29, label %39
29: ; preds = %26
%30 = load i32*, i32** %3
%31 = load i64, i64* %5
%32 = udiv i64 %31, 1000000
%33 = load i64, i64* %5
%34 = urem i64 %33, 1000000
%35 = udiv i64 %34, 1000
%36 = load i64, i64* %5
%37 = urem i64 %36, 1000
%38 = call i32 (i32*, i8*, i64, ...) @fprintf(i32* %30, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i64 %32, i64 %35, i64 %37)
br label %46
39: ; preds = %26
%40 = load i32*, i32** %3
%41 = load i64, i64* %5
%42 = udiv i64 %41, 1000
%43 = load i64, i64* %5
%44 = urem i64 %43, 1000
%45 = call i32 (i32*, i8*, i64, ...) @fprintf(i32* %40, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i64 %42, i64 %44)
br label %46
46: ; preds = %39, %29
br label %47
47: ; preds = %46, %13
br label %53
48: ; preds = %2
%49 = load i32*, i32** %3
%50 = load double, double* %4
%51 = fptoui double %50 to i64
%52 = call i32 (i32*, i8*, i64, ...) @fprintf(i32* %49, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i64 %51)
br label %53
53: ; preds = %48, %47
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"%zd,%03zd,%03zd,%03zd\00"
@.str.1 = [16 x i8] c"%zd,%03zd,%03zd\00"
@.str.2 = [11 x i8] c"%3zd,%03zd\00"
@.str.3 = [7 x i8] c"%7.0lf\00"
define void @commaPrint0dp(i32* nocapture %0, double %1) {
%3 = fcmp ult double %1, 1.000000e+03
%4 = fptoui double %1 to i64
br i1 %3, label %37, label %5
5: ; preds = %2
%6 = icmp ugt i64 %4, 999999999
br i1 %6, label %7, label %19
7: ; preds = %5
%8 = udiv i64 %4, 1000000000
%9 = urem i64 %4, 1000000000
%10 = trunc i64 %9 to i32
%11 = udiv i32 %10, 1000000
%12 = zext i32 %11 to i64
%13 = urem i64 %4, 1000000
%14 = trunc i64 %13 to i32
%15 = udiv i32 %14, 1000
%16 = zext i32 %15 to i64
%17 = urem i64 %4, 1000
%18 = tail call i32 (i32*, i8*, i64, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i64 %8, i64 %12, i64 %16, i64 %17)
br label %39
19: ; preds = %5
%20 = icmp ugt i64 %4, 999999
%21 = trunc i64 %4 to i32
br i1 %20, label %22, label %31
22: ; preds = %19
%23 = udiv i32 %21, 1000000
%24 = zext i32 %23 to i64
%25 = urem i32 %21, 1000000
%26 = udiv i32 %25, 1000
%27 = zext i32 %26 to i64
%28 = urem i32 %21, 1000
%29 = zext i32 %28 to i64
%30 = tail call i32 (i32*, i8*, i64, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i64 %24, i64 %27, i64 %29)
br label %39
31: ; preds = %19
%32 = udiv i32 %21, 1000
%33 = zext i32 %32 to i64
%34 = urem i32 %21, 1000
%35 = zext i32 %34 to i64
%36 = tail call i32 (i32*, i8*, i64, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i64 %33, i64 %35)
br label %39
37: ; preds = %2
%38 = tail call i32 (i32*, i8*, i64, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i64 %4)
br label %39
39: ; preds = %7, %31, %22, %37
ret void
}