#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 alogam(double *, int *);
double exp(double);
double log(double);
double gammds(double *y, double *p, int *ifault) {
  static double a, c, f, g;
  static int ifail;
  *ifault = 1;
  g = 0.;
  if (*y <= 0. || *p <= 0.) {
    return g;
  }
  *ifault = 2;
  a = *p + 1.;
  f = exp(*p * log(*y) - alogam(&a, &ifail) - *y);
  if (f == 0.) {
    return g;
  }
  *ifault = 0;
  c = 1.;
  g = 1.;
  a = *p;
L10:
  a += 1.;
  c = c * *y / a;
  g += c;
  if (c / g > 1e-6) {
    goto L10;
  }
  g *= f;
  return g;
}


x86 assembly (clang, -O0):
<gammds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movl   $0x1,(%rax)
xorps  %xmm0,%xmm0
movsd  %xmm0,0x2eff(%rip)
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
ucomisd (%rax),%xmm0
jae    117b <gammds+0x4b>
mov    -0x18(%rbp),%rax
xorps  %xmm0,%xmm0
ucomisd (%rax),%xmm0
jb     118d <gammds+0x5d>
movsd  0x2ed5(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1325 <gammds+0x1f5>
mov    -0x20(%rbp),%rax
movl   $0x2,(%rax)
mov    -0x18(%rbp),%rax
movsd  0xe5d(%rip),%xmm0
addsd  (%rax),%xmm0
movsd  %xmm0,0x2e91(%rip)
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
call   1050 <log@plt>
movsd  %xmm0,-0x30(%rbp)
lea    0x2e6b(%rip),%rdi
lea    0x2e84(%rip),%rsi
call   1040 <alogam@plt>
movsd  -0x30(%rbp),%xmm2
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
subsd  (%rax),%xmm0
call   1030 <exp@plt>
movsd  %xmm0,0x2e2e(%rip)
movsd  0x2e26(%rip),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    124f <gammds+0x11f>
jp     124f <gammds+0x11f>
movsd  0x2e13(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1325 <gammds+0x1f5>
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
movsd  0xd9f(%rip),%xmm0
movsd  %xmm0,0x2ddf(%rip)
movsd  0xd8f(%rip),%xmm0
movsd  %xmm0,0x2ddf(%rip)
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,0x2db7(%rip)
movsd  0xd6f(%rip),%xmm0
addsd  0x2da7(%rip),%xmm0
movsd  %xmm0,0x2d9f(%rip)
movsd  0x2d9f(%rip),%xmm0
mov    -0x10(%rbp),%rax
mulsd  (%rax),%xmm0
divsd  0x2d87(%rip),%xmm0
movsd  %xmm0,0x2d87(%rip)
movsd  0x2d7f(%rip),%xmm0
addsd  0x2d87(%rip),%xmm0
movsd  %xmm0,0x2d7f(%rip)
movsd  0x2d67(%rip),%xmm0
divsd  0x2d6f(%rip),%xmm0
movsd  0xd17(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1300 <gammds+0x1d0>
jmp    1289 <gammds+0x159>
movsd  0x2d48(%rip),%xmm0
mulsd  0x2d48(%rip),%xmm0
movsd  %xmm0,0x2d40(%rip)
movsd  0x2d38(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gammds>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
movl   $0x1,(%rdx)
movq   $0x0,0x2efc(%rip)
xorpd  %xmm0,%xmm0
ucomisd (%rdi),%xmm0
jae    1252 <gammds+0x122>
mov    %rsi,%r14
movsd  (%rsi),%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jae    1252 <gammds+0x122>
mov    %rdx,%r15
mov    %rdi,%rbx
movl   $0x2,(%rdx)
addsd  0xe7d(%rip),%xmm1
movsd  %xmm1,0x2eb5(%rip)
lea    0x2eae(%rip),%r12
movsd  (%r14),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  (%rdi),%xmm0
call   1050 <log@plt>
movsd  %xmm0,0x8(%rsp)
lea    0x2e9d(%rip),%rsi
mov    %r12,%rdi
call   1040 <alogam@plt>
movsd  0x8(%rsp),%xmm1
mulsd  0x10(%rsp),%xmm1
subsd  %xmm0,%xmm1
subsd  (%rbx),%xmm1
movapd %xmm1,%xmm0
call   1030 <exp@plt>
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11ee <gammds+0xbe>
jp     11ee <gammds+0xbe>
movsd  0x2e5c(%rip),%xmm0
jmp    1252 <gammds+0x122>
movl   $0x0,(%r15)
movsd  (%r14),%xmm1
movsd  0xdfe(%rip),%xmm2
movsd  0xdfe(%rip),%xmm4
movapd %xmm2,%xmm3
movapd %xmm2,%xmm5
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
addsd  %xmm2,%xmm1
movsd  %xmm1,0x2e14(%rip)
mulsd  (%rbx),%xmm5
divsd  %xmm1,%xmm5
addsd  %xmm5,%xmm3
movapd %xmm5,%xmm6
divsd  %xmm3,%xmm6
ucomisd %xmm4,%xmm6
ja     1220 <gammds+0xf0>
mulsd  %xmm3,%xmm0
movsd  %xmm0,0x2df6(%rip)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@gammds.a = internal global double 0.000000e+00
@gammds.c = internal global double 0.000000e+00
@gammds.f = internal global double 0.000000e+00
@gammds.g = internal global double 0.000000e+00
@gammds.ifail = internal global i32 0
define double @gammds(double* %0, double* %1, i32* %2) {
%4 = alloca double
%5 = alloca double*
%6 = alloca double*
%7 = alloca i32*
store double* %0, double** %5
store double* %1, double** %6
store i32* %2, i32** %7
%8 = load i32*, i32** %7
store i32 1, i32* %8
store double 0.000000e+00, double* @gammds.g
%9 = load double*, double** %5
%10 = load double, double* %9
%11 = fcmp ole double %10, 0.000000e+00
br i1 %11, label %16, label %12
12: ; preds = %3
%13 = load double*, double** %6
%14 = load double, double* %13
%15 = fcmp ole double %14, 0.000000e+00
br i1 %15, label %16, label %18
16: ; preds = %12, %3
%17 = load double, double* @gammds.g
store double %17, double* %4
br label %65
18: ; preds = %12
%19 = load i32*, i32** %7
store i32 2, i32* %19
%20 = load double*, double** %6
%21 = load double, double* %20
%22 = fadd double %21, 1.000000e+00
store double %22, double* @gammds.a
%23 = load double*, double** %6
%24 = load double, double* %23
%25 = load double*, double** %5
%26 = load double, double* %25
%27 = call double @log(double %26)
%28 = call double @alogam(double* @gammds.a, i32* @gammds.ifail)
%29 = fneg double %28
%30 = call double @llvm.fmuladd.f64(double %24, double %27, double %29)
%31 = load double*, double** %5
%32 = load double, double* %31
%33 = fsub double %30, %32
%34 = call double @exp(double %33)
store double %34, double* @gammds.f
%35 = load double, double* @gammds.f
%36 = fcmp oeq double %35, 0.000000e+00
br i1 %36, label %37, label %39
37: ; preds = %18
%38 = load double, double* @gammds.g
store double %38, double* %4
br label %65
39: ; preds = %18
%40 = load i32*, i32** %7
store i32 0, i32* %40
store double 1.000000e+00, double* @gammds.c
store double 1.000000e+00, double* @gammds.g
%41 = load double*, double** %6
%42 = load double, double* %41
store double %42, double* @gammds.a
br label %43
43: ; preds = %59, %39
%44 = load double, double* @gammds.a
%45 = fadd double %44, 1.000000e+00
store double %45, double* @gammds.a
%46 = load double, double* @gammds.c
%47 = load double*, double** %5
%48 = load double, double* %47
%49 = fmul double %46, %48
%50 = load double, double* @gammds.a
%51 = fdiv double %49, %50
store double %51, double* @gammds.c
%52 = load double, double* @gammds.c
%53 = load double, double* @gammds.g
%54 = fadd double %53, %52
store double %54, double* @gammds.g
%55 = load double, double* @gammds.c
%56 = load double, double* @gammds.g
%57 = fdiv double %55, %56
%58 = fcmp ogt double %57, 0x3EB0C6F7A0B5ED8D
br i1 %58, label %59, label %60
59: ; preds = %43
br label %43
60: ; preds = %43
%61 = load double, double* @gammds.f
%62 = load double, double* @gammds.g
%63 = fmul double %62, %61
store double %63, double* @gammds.g
%64 = load double, double* @gammds.g
store double %64, double* %4
br label %65
65: ; preds = %60, %37, %16
%66 = load double, double* %4
ret double %66
}

LLVM IR (-O2):
@gammds.a = internal global double 0.000000e+00
@gammds.g = internal unnamed_addr global double 0.000000e+00
@gammds.ifail = internal global i32 0
define double @gammds(double* nocapture %0, double* nocapture %1, i32* nocapture writeonly %2) {
store i32 1, i32* %2
store double 0.000000e+00, double* @gammds.g
%4 = load double, double* %0
%5 = fcmp ugt double %4, 0.000000e+00
br i1 %5, label %6, label %38
6: ; preds = %3
%7 = load double, double* %1
%8 = fcmp ugt double %7, 0.000000e+00
br i1 %8, label %9, label %38
9: ; preds = %6
store i32 2, i32* %2
%10 = fadd double %7, 1.000000e+00
store double %10, double* @gammds.a
%11 = load double, double* %1
%12 = load double, double* %0
%13 = tail call double @log(double %12)
%14 = tail call double @alogam(double* @gammds.a, i32* @gammds.ifail)
%15 = fneg double %14
%16 = tail call double @llvm.fmuladd.f64(double %11, double %13, double %15)
%17 = load double, double* %0
%18 = fsub double %16, %17
%19 = tail call double @exp(double %18)
%20 = fcmp oeq double %19, 0.000000e+00
br i1 %20, label %21, label %23
21: ; preds = %9
%22 = load double, double* @gammds.g
br label %38
23: ; preds = %9
store i32 0, i32* %2
%24 = load double, double* %1
br label %25
25: ; preds = %25, %23
%26 = phi double [ %29, %25 ], [ %24, %23 ]
%27 = phi double [ %33, %25 ], [ 1.000000e+00, %23 ]
%28 = phi double [ %32, %25 ], [ 1.000000e+00, %23 ]
%29 = fadd double %26, 1.000000e+00
store double %29, double* @gammds.a
%30 = load double, double* %0
%31 = fmul double %28, %30
%32 = fdiv double %31, %29
%33 = fadd double %27, %32
%34 = fdiv double %32, %33
%35 = fcmp ogt double %34, 0x3EB0C6F7A0B5ED8D
br i1 %35, label %25, label %36
36: ; preds = %25
%37 = fmul double %19, %33
store double %37, double* @gammds.g
br label %38
38: ; preds = %3, %6, %36, %21
%39 = phi double [ %22, %21 ], [ %37, %36 ], [ 0.000000e+00, %6 ], [ 0.000000e+00, %3 ]
ret double %39
}