#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 */
double exp(double);
double log(double);
double q_gamma(double, double, double);
int /*<<< orphan*/ rhoRubyFPrintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
double p_gamma(double a, double x, double loggamma_a) {
  int k;
  double result, term, previous;
  if (x >= 1 + a)
    return 1 - q_gamma(a, x, loggamma_a);
  if (x == 0)
    return 0;
  result = term = exp(a * log(x) - x - loggamma_a) / a;
  for (k = 1; k < 1000; k++) {
    term *= x / (a + k);
    previous = result;
    result += term;
    if (result == previous)
      return result;
  }
  rhoRubyFPrintf(stderr, "erf.c:%d:p_gamma() could not converge.", 46);
  return result;
}


x86 assembly (clang, -O0):
<p_gamma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe9c(%rip),%xmm1
addsd  -0x10(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jb     11a0 <p_gamma+0x60>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
call   1030 <q_gamma@plt>
movaps %xmm0,%xmm1
movsd  0xe6e(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12c8 <p_gamma+0x188>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11c5 <p_gamma+0x85>
jp     11c5 <p_gamma+0x85>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12c8 <p_gamma+0x188>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1050 <log@plt>
movaps %xmm0,%xmm2
movsd  -0x48(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
subsd  -0x20(%rbp),%xmm0
call   1040 <exp@plt>
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  %xmm0,-0x30(%rbp)
movl   $0x1,-0x24(%rbp)
cmpl   $0x3e8,-0x24(%rbp)
jge    12a4 <p_gamma+0x164>
movsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
cvtsi2sdl -0x24(%rbp),%xmm2
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
ucomisd -0x40(%rbp),%xmm0
jne    1291 <p_gamma+0x151>
jp     1291 <p_gamma+0x151>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12c8 <p_gamma+0x188>
jmp    1296 <p_gamma+0x156>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1225 <p_gamma+0xe5>
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
lea    0xd54(%rip),%rsi
mov    $0x2e,%edx
call   1060 <rhoRubyFPrintf@plt>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<p_gamma>:
sub    $0x18,%rsp
movapd %xmm0,%xmm4
movsd  0xeb0(%rip),%xmm0
addsd  %xmm4,%xmm0
ucomisd %xmm0,%xmm1
jae    1221 <p_gamma+0xe1>
xorpd  %xmm3,%xmm3
ucomisd %xmm3,%xmm1
jne    116e <p_gamma+0x2e>
jnp    1236 <p_gamma+0xf6>
movapd %xmm1,%xmm0
movsd  %xmm1,(%rsp)
movsd  %xmm4,0x8(%rsp)
movsd  %xmm2,0x10(%rsp)
call   1050 <log@plt>
mulsd  0x8(%rsp),%xmm0
subsd  (%rsp),%xmm0
subsd  0x10(%rsp),%xmm0
call   1040 <exp@plt>
movsd  0x8(%rsp),%xmm5
movsd  (%rsp),%xmm4
divsd  %xmm5,%xmm0
mov    $0x1,%eax
movapd %xmm0,%xmm1
cs nopw 0x0(%rax,%rax,1)
movapd %xmm0,%xmm2
xorps  %xmm3,%xmm3
cvtsi2sd %eax,%xmm3
addsd  %xmm5,%xmm3
movapd %xmm4,%xmm0
divsd  %xmm3,%xmm0
mulsd  %xmm2,%xmm0
movapd %xmm1,%xmm3
addsd  %xmm0,%xmm3
ucomisd %xmm1,%xmm3
jne    11eb <p_gamma+0xab>
jnp    1236 <p_gamma+0xf6>
add    $0x1,%eax
cmp    $0x3e8,%eax
je     123f <p_gamma+0xff>
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
addsd  %xmm5,%xmm1
movapd %xmm4,%xmm2
divsd  %xmm1,%xmm2
mulsd  %xmm2,%xmm0
movapd %xmm3,%xmm1
addsd  %xmm0,%xmm1
ucomisd %xmm3,%xmm1
jne    121c <p_gamma+0xdc>
jnp    1265 <p_gamma+0x125>
add    $0x1,%eax
jmp    11c0 <p_gamma+0x80>
movapd %xmm4,%xmm0
call   1030 <q_gamma@plt>
movsd  0xdce(%rip),%xmm3
subsd  %xmm0,%xmm3
movapd %xmm3,%xmm0
add    $0x18,%rsp
ret
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
lea    0xdb9(%rip),%rsi
mov    $0x2e,%edx
movsd  %xmm3,(%rsp)
call   1060 <rhoRubyFPrintf@plt>
movsd  (%rsp),%xmm3
jmp    1236 <p_gamma+0xf6>
movapd %xmm1,%xmm3
jmp    1236 <p_gamma+0xf6>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [39 x i8] c"erf.c:%d:p_gamma() could not converge.\00"
define double @p_gamma(double %0, double %1, double %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
%12 = load double, double* %6
%13 = load double, double* %5
%14 = fadd double 1.000000e+00, %13
%15 = fcmp oge double %12, %14
br i1 %15, label %16, label %22
16: ; preds = %3
%17 = load double, double* %5
%18 = load double, double* %6
%19 = load double, double* %7
%20 = call double @q_gamma(double %17, double %18, double %19)
%21 = fsub double 1.000000e+00, %20
store double %21, double* %4
br label %67
22: ; preds = %3
%23 = load double, double* %6
%24 = fcmp oeq double %23, 0.000000e+00
br i1 %24, label %25, label %26
25: ; preds = %22
store double 0.000000e+00, double* %4
br label %67
26: ; preds = %22
%27 = load double, double* %5
%28 = load double, double* %6
%29 = call double @log(double %28)
%30 = load double, double* %6
%31 = fneg double %30
%32 = call double @llvm.fmuladd.f64(double %27, double %29, double %31)
%33 = load double, double* %7
%34 = fsub double %32, %33
%35 = call double @exp(double %34)
%36 = load double, double* %5
%37 = fdiv double %35, %36
store double %37, double* %10
store double %37, double* %9
store i32 1, i32* %8
br label %38
38: ; preds = %60, %26
%39 = load i32, i32* %8
%40 = icmp slt i32 %39, 1000
br i1 %40, label %41, label %63
41: ; preds = %38
%42 = load double, double* %6
%43 = load double, double* %5
%44 = load i32, i32* %8
%45 = sitofp i32 %44 to double
%46 = fadd double %43, %45
%47 = fdiv double %42, %46
%48 = load double, double* %10
%49 = fmul double %48, %47
store double %49, double* %10
%50 = load double, double* %9
store double %50, double* %11
%51 = load double, double* %10
%52 = load double, double* %9
%53 = fadd double %52, %51
store double %53, double* %9
%54 = load double, double* %9
%55 = load double, double* %11
%56 = fcmp oeq double %54, %55
br i1 %56, label %57, label %59
57: ; preds = %41
%58 = load double, double* %9
store double %58, double* %4
br label %67
59: ; preds = %41
br label %60
60: ; preds = %59
%61 = load i32, i32* %8
%62 = add nsw i32 %61, 1
store i32 %62, i32* %8
br label %38
63: ; preds = %38
%64 = load i32, i32* @stderr
%65 = call i32 @rhoRubyFPrintf(i32 %64, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 46)
%66 = load double, double* %9
store double %66, double* %4
br label %67
67: ; preds = %63, %57, %25, %16
%68 = load double, double* %4
ret double %68
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [39 x i8] c"erf.c:%d:p_gamma() could not converge.\00"
define double @p_gamma(double %0, double %1, double %2) {
%4 = fadd double %0, 1.000000e+00
%5 = fcmp ugt double %4, %1
br i1 %5, label %9, label %6
6: ; preds = %3
%7 = tail call double @q_gamma(double %0, double %1, double %2)
%8 = fsub double 1.000000e+00, %7
br label %43
9: ; preds = %3
%10 = fcmp oeq double %1, 0.000000e+00
br i1 %10, label %43, label %11
11: ; preds = %9
%12 = tail call double @log(double %1)
%13 = fneg double %1
%14 = tail call double @llvm.fmuladd.f64(double %0, double %12, double %13)
%15 = fsub double %14, %2
%16 = tail call double @exp(double %15)
%17 = fdiv double %16, %0
br label %30
18: ; preds = %30
%19 = add nuw nsw i32 %33, 1
%20 = icmp eq i32 %19, 1000
br i1 %20, label %40, label %21
21: ; preds = %18
%22 = sitofp i32 %19 to double
%23 = fadd double %22, %0
%24 = fdiv double %1, %23
%25 = fmul double %37, %24
%26 = fadd double %38, %25
%27 = fcmp oeq double %26, %38
br i1 %27, label %43, label %28
28: ; preds = %21
%29 = add nuw nsw i32 %33, 2
br label %30
30: ; preds = %28, %11
%31 = phi double [ %17, %11 ], [ %25, %28 ]
%32 = phi double [ %17, %11 ], [ %26, %28 ]
%33 = phi i32 [ 1, %11 ], [ %29, %28 ]
%34 = sitofp i32 %33 to double
%35 = fadd double %34, %0
%36 = fdiv double %1, %35
%37 = fmul double %31, %36
%38 = fadd double %32, %37
%39 = fcmp oeq double %38, %32
br i1 %39, label %43, label %18
40: ; preds = %18
%41 = load i32, i32* @stderr
%42 = tail call i32 @rhoRubyFPrintf(i32 %41, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 46)
br label %43
43: ; preds = %30, %21, %9, %40, %6
%44 = phi double [ %8, %6 ], [ %38, %40 ], [ 0.000000e+00, %9 ], [ %38, %30 ], [ %26, %21 ]
ret double %44
}