int factorial(double a, double *f) {
  double b = 0;
  if (a == 0) {
    *f = a;
    return 0;
  }
  if ((a - ((int)a) != 0.0) || (a < 0)) {
    {
      do {
      } while (0);
    };
    return -1;
  }
  b = a;
  while (a > 1) {
    a -= 1.0;
    {
      do {
      } while (0);
    };
    b = b * a;
  }
  *f = b;
  return 0;
}


x86 assembly (clang, -O0):
<factorial>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x10(%rbp)
mov    %rdi,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1146 <factorial+0x46>
jp     1146 <factorial+0x46>
movsd  -0x10(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11f3 <factorial+0xf3>
movsd  -0x10(%rbp),%xmm0
cvttsd2si -0x10(%rbp),%eax
cvtsi2sd %eax,%xmm1
subsd  %xmm1,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1179 <factorial+0x79>
jp     1179 <factorial+0x79>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    118f <factorial+0x8f>
jmp    117e <factorial+0x7e>
jmp    1183 <factorial+0x83>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f3 <factorial+0xf3>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe5a(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11df <factorial+0xdf>
movsd  -0x10(%rbp),%xmm0
movsd  0xe43(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11cb <factorial+0xcb>
movsd  -0x20(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    1199 <factorial+0x99>
movsd  -0x20(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<factorial>:
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1113 <factorial+0x13>
jp     1113 <factorial+0x13>
movsd  %xmm0,(%rdi)
xor    %eax,%eax
ret
ucomisd %xmm0,%xmm1
mov    $0xffffffff,%eax
ja     1112 <factorial+0x12>
cvttpd2dq %xmm0,%xmm1
cvtdq2pd %xmm1,%xmm1
movapd %xmm0,%xmm2
subsd  %xmm1,%xmm2
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm2
jne    1112 <factorial+0x12>
jp     1112 <factorial+0x12>
ucomisd 0xebe(%rip),%xmm0
jbe    110c <factorial+0xc>
movsd  0xebc(%rip),%xmm1
movsd  0xeac(%rip),%xmm2
movapd %xmm0,%xmm3
nopl   0x0(%rax,%rax,1)
addsd  %xmm1,%xmm3
mulsd  %xmm3,%xmm0
ucomisd %xmm2,%xmm3
ja     1160 <factorial+0x60>
jmp    110c <factorial+0xc>

LLVM IR (-O0):
define i32 @factorial(double %0, double* %1) {
%3 = alloca i32
%4 = alloca double
%5 = alloca double*
%6 = alloca double
store double %0, double* %4
store double* %1, double** %5
store double 0.000000e+00, double* %6
%7 = load double, double* %4
%8 = fcmp oeq double %7, 0.000000e+00
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load double, double* %4
%11 = load double*, double** %5
store double %10, double* %11
store i32 0, i32* %3
br label %41
12: ; preds = %2
%13 = load double, double* %4
%14 = load double, double* %4
%15 = fptosi double %14 to i32
%16 = sitofp i32 %15 to double
%17 = fsub double %13, %16
%18 = fcmp une double %17, 0.000000e+00
br i1 %18, label %22, label %19
19: ; preds = %12
%20 = load double, double* %4
%21 = fcmp olt double %20, 0.000000e+00
br i1 %21, label %22, label %25
22: ; preds = %19, %12
br label %23
23: ; preds = %22
br label %24
24: ; preds = %23
store i32 -1, i32* %3
br label %41
25: ; preds = %19
%26 = load double, double* %4
store double %26, double* %6
br label %27
27: ; preds = %34, %25
%28 = load double, double* %4
%29 = fcmp ogt double %28, 1.000000e+00
br i1 %29, label %30, label %38
30: ; preds = %27
%31 = load double, double* %4
%32 = fsub double %31, 1.000000e+00
store double %32, double* %4
br label %33
33: ; preds = %30
br label %34
34: ; preds = %33
%35 = load double, double* %6
%36 = load double, double* %4
%37 = fmul double %35, %36
store double %37, double* %6
br label %27
38: ; preds = %27
%39 = load double, double* %6
%40 = load double*, double** %5
store double %39, double* %40
store i32 0, i32* %3
br label %41
41: ; preds = %38, %24, %9
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
define i32 @factorial(double %0, double* nocapture writeonly %1) {
%3 = fcmp oeq double %0, 0.000000e+00
br i1 %3, label %19, label %4
4: ; preds = %2
%5 = fptosi double %0 to i32
%6 = sitofp i32 %5 to double
%7 = fsub double %0, %6
%8 = fcmp une double %7, 0.000000e+00
%9 = fcmp olt double %0, 0.000000e+00
%10 = or i1 %9, %8
br i1 %10, label %21, label %11
11: ; preds = %4
%12 = fcmp ogt double %0, 1.000000e+00
br i1 %12, label %13, label %19
13: ; preds = %11, %13
%14 = phi double [ %17, %13 ], [ %0, %11 ]
%15 = phi double [ %16, %13 ], [ %0, %11 ]
%16 = fadd double %15, -1.000000e+00
%17 = fmul double %14, %16
%18 = fcmp ogt double %16, 1.000000e+00
br i1 %18, label %13, label %19
19: ; preds = %13, %11, %2
%20 = phi double [ %0, %2 ], [ %0, %11 ], [ %17, %13 ]
store double %20, double* %1
br label %21
21: ; preds = %19, %4
%22 = phi i32 [ -1, %4 ], [ 0, %19 ]
ret i32 %22
}