#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 */
double DBL_EPSILON;
int /*<<< orphan*/ NOT_USED(int);
int /*<<< orphan*/ comma_number(int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
void comma_double(double num, char *buf, int bufsz) {
  int intnum;
  NOT_USED(bufsz);
  intnum = (int)num;
  comma_number(intnum, buf, sizeof(buf));
  num -= intnum;
  if (num > DBL_EPSILON) {
    char buf2[8];
    sprintf(buf2, ".%02d", (int)(num * 100.0));
    strcat(buf, buf2);
  }
}


x86 assembly (clang, -O0):
<comma_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <NOT_USED@plt>
cvttsd2si -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x8,%edx
call   1040 <comma_number@plt>
cvtsi2sdl -0x18(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
mov    0x2e54(%rip),%rax
ucomisd (%rax),%xmm0
jbe    11cc <comma_double+0x8c>
lea    -0x20(%rbp),%rdi
movsd  0xe56(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
cvttsd2si %xmm0,%edx
lea    0xe4e(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <strcat@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<comma_double>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
movaps %xmm0,(%rsp)
mov    %esi,%edi
call   1060 <NOT_USED@plt>
cvttsd2si (%rsp),%edi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1040 <comma_number@plt>
movapd (%rsp),%xmm1
cvttpd2dq %xmm1,%xmm0
cvtdq2pd %xmm0,%xmm0
subsd  %xmm0,%xmm1
mov    0x2e69(%rip),%rax
ucomisd (%rax),%xmm1
jbe    11b4 <comma_double+0x74>
movapd %xmm1,%xmm0
mulsd  0xe6f(%rip),%xmm0
cvttsd2si %xmm0,%edx
lea    0xe6c(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1050 <sprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcat@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@DBL_EPSILON = global double 0.000000e+00
@.str = [6 x i8] c".%02d\00"
define void @comma_double(double %0, i8* %1, i32 %2) {
%4 = alloca double
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [8 x i8]
store double %0, double* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i32, i32* %6
%10 = call i32 @NOT_USED(i32 %9)
%11 = load double, double* %4
%12 = fptosi double %11 to i32
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = load i8*, i8** %5
%15 = call i32 @comma_number(i32 %13, i8* %14, i32 8)
%16 = load i32, i32* %7
%17 = sitofp i32 %16 to double
%18 = load double, double* %4
%19 = fsub double %18, %17
store double %19, double* %4
%20 = load double, double* %4
%21 = load double, double* @DBL_EPSILON
%22 = fcmp ogt double %20, %21
br i1 %22, label %23, label %32
23: ; preds = %3
%24 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%25 = load double, double* %4
%26 = fmul double %25, 1.000000e+02
%27 = fptosi double %26 to i32
%28 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %27)
%29 = load i8*, i8** %5
%30 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%31 = call i32 @strcat(i8* %29, i8* %30)
br label %32
32: ; preds = %23, %3
ret void
}

LLVM IR (-O2):
@DBL_EPSILON = global double 0.000000e+00
@.str = [6 x i8] c".%02d\00"
define void @comma_double(double %0, i8* %1, i32 %2) {
%4 = alloca [8 x i8]
%5 = tail call i32 @NOT_USED(i32 %2)
%6 = fptosi double %0 to i32
%7 = tail call i32 @comma_number(i32 %6, i8* %1, i32 8)
%8 = sitofp i32 %6 to double
%9 = fsub double %0, %8
%10 = load double, double* @DBL_EPSILON
%11 = fcmp ogt double %9, %10
br i1 %11, label %12, label %18
12: ; preds = %3
%13 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%14 = fmul double %9, 1.000000e+02
%15 = fptosi double %14 to i32
%16 = call i32 @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = call i32 @strcat(i8* %1, i8* %13)
br label %18
18: ; preds = %12, %3
ret void
}