#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 cdflib_eval_pol(double const *, int const *, double *);
int /*<<< orphan*/ cdflib_ftnstop(char *);
double cdflib_gamma_log(double *);
double log(double);
double pow(double, double);
double cdflib_dstrem(double *z) {
  static const double hln2pi = 0.91893853320467274178e0;
  enum { ncoef = 10 };
  static const double coef[ncoef] = {0.0e0,
                                     0.0833333333333333333333333333333e0,
                                     -0.00277777777777777777777777777778e0,
                                     0.000793650793650793650793650793651e0,
                                     -0.000595238095238095238095238095238e0,
                                     0.000841750841750841750841750841751e0,
                                     -0.00191752691752691752691752691753e0,
                                     0.00641025641025641025641025641026e0,
                                     -0.0295506535947712418300653594771e0,
                                     0.179644372368830573164938490016e0};
  static const int K1 = 10;
  double dstrem, sterl, T2;
  if (*z <= 0.0e0) {
    cdflib_ftnstop("Zero or negative argument in DSTREM");
  }
  if (!(*z > 6.0e0)) {
    goto S10;
  }
  T2 = 1.0e0 / pow(*z, 2.0);
  dstrem = cdflib_eval_pol(coef, &K1, &T2) * *z;
  goto S20;
S10:
  sterl = hln2pi + (*z - 0.5e0) * log(*z) - *z;
  dstrem = cdflib_gamma_log(z) - sterl;
S20:
  return dstrem;
}


x86 assembly (clang, -O0):
<cdflib_dstrem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
ucomisd (%rax),%xmm0
jb     1179 <cdflib_dstrem+0x29>
lea    0xf20(%rip),%rdi
call   1030 <cdflib_ftnstop@plt>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  0xe77(%rip),%xmm1
ucomisd %xmm1,%xmm0
ja     1198 <cdflib_dstrem+0x48>
jmp    11ea <cdflib_dstrem+0x9a>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  0xe78(%rip),%xmm1
call   1060 <pow@plt>
movaps %xmm0,%xmm1
movsd  0xe60(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
lea    0xe78(%rip),%rdi
lea    0xec1(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1040 <cdflib_eval_pol@plt>
mov    -0x8(%rbp),%rax
mulsd  (%rax),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1248 <cdflib_dstrem+0xf8>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  0xe16(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
call   1050 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xde4(%rip),%xmm1
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
subsd  (%rax),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <cdflib_gamma_log@plt>
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cdflib_dstrem>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movsd  (%rdi),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jb     1166 <cdflib_dstrem+0x26>
lea    0xf17(%rip),%rdi
call   1030 <cdflib_ftnstop@plt>
movsd  (%rbx),%xmm0
ucomisd 0xe92(%rip),%xmm0
jbe    11a4 <cdflib_dstrem+0x64>
mulsd  %xmm0,%xmm0
movsd  0xe9c(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
lea    0xe93(%rip),%rdi
lea    0xedc(%rip),%rsi
lea    0x8(%rsp),%rdx
call   1040 <cdflib_eval_pol@plt>
mulsd  (%rbx),%xmm0
jmp    11dd <cdflib_dstrem+0x9d>
movsd  0xe5c(%rip),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
call   1050 <log@plt>
mulsd  (%rsp),%xmm0
addsd  0xe49(%rip),%xmm0
subsd  (%rbx),%xmm0
movsd  %xmm0,(%rsp)
mov    %rbx,%rdi
call   1060 <cdflib_gamma_log@plt>
subsd  (%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@cdflib_dstrem.hln2pi = internal constant double 0x3FED67F1C864BEB5
@cdflib_dstrem.coef = internal constant [10 x double] [double 0.000000e+00, double 0x3FB5555555555555, double 0xBF66C16C16C16C17, double 0x3F4A01A01A01A01A, double 0xBF43813813813814, double 0x3F4B951E2B18FF23, double 0xBF5F6AB0D9993C7D, double 0x3F7A41A41A41A41A, double 0xBF9E4286CB0F5398, double 0x3FC6FE96381E0680]
@cdflib_dstrem.K1 = internal constant i32 10
@.str = [36 x i8] c"Zero or negative argument in DSTREM\00"
define double @cdflib_dstrem(double* %0) {
%2 = alloca double*
%3 = alloca double
%4 = alloca double
%5 = alloca double
store double* %0, double** %2
%6 = load double*, double** %2
%7 = load double, double* %6
%8 = fcmp ole double %7, 0.000000e+00
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @cdflib_ftnstop(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %1
%12 = load double*, double** %2
%13 = load double, double* %12
%14 = fcmp ogt double %13, 6.000000e+00
br i1 %14, label %16, label %15
15: ; preds = %11
br label %25
16: ; preds = %11
%17 = load double*, double** %2
%18 = load double, double* %17
%19 = call double @pow(double %18, double 2.000000e+00)
%20 = fdiv double 1.000000e+00, %19
store double %20, double* %5
%21 = call double @cdflib_eval_pol(double* getelementptr inbounds ([10 x double], [10 x double]* @cdflib_dstrem.coef, i64 0, i64 0), i32* @cdflib_dstrem.K1, double* %5)
%22 = load double*, double** %2
%23 = load double, double* %22
%24 = fmul double %21, %23
store double %24, double* %3
br label %40
25: ; preds = %15
%26 = load double*, double** %2
%27 = load double, double* %26
%28 = fsub double %27, 5.000000e-01
%29 = load double*, double** %2
%30 = load double, double* %29
%31 = call double @log(double %30)
%32 = call double @llvm.fmuladd.f64(double %28, double %31, double 0x3FED67F1C864BEB5)
%33 = load double*, double** %2
%34 = load double, double* %33
%35 = fsub double %32, %34
store double %35, double* %4
%36 = load double*, double** %2
%37 = call double @cdflib_gamma_log(double* %36)
%38 = load double, double* %4
%39 = fsub double %37, %38
store double %39, double* %3
br label %40
40: ; preds = %25, %16
%41 = load double, double* %3
ret double %41
}

LLVM IR (-O2):
@cdflib_dstrem.coef = internal constant [10 x double] [double 0.000000e+00, double 0x3FB5555555555555, double 0xBF66C16C16C16C17, double 0x3F4A01A01A01A01A, double 0xBF43813813813814, double 0x3F4B951E2B18FF23, double 0xBF5F6AB0D9993C7D, double 0x3F7A41A41A41A41A, double 0xBF9E4286CB0F5398, double 0x3FC6FE96381E0680]
@cdflib_dstrem.K1 = internal constant i32 10
@.str = [36 x i8] c"Zero or negative argument in DSTREM\00"
define double @cdflib_dstrem(double* %0) {
%2 = alloca double
%3 = bitcast double* %2 to i8*
%4 = load double, double* %0
%5 = fcmp ugt double %4, 0.000000e+00
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = tail call i32 @cdflib_ftnstop(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%8 = load double, double* %0
br label %9
9: ; preds = %6, %1
%10 = phi double [ %8, %6 ], [ %4, %1 ]
%11 = fcmp ogt double %10, 6.000000e+00
br i1 %11, label %12, label %18
12: ; preds = %9
%13 = fmul double %10, %10
%14 = fdiv double 1.000000e+00, %13
store double %14, double* %2
%15 = call double @cdflib_eval_pol(double* getelementptr inbounds ([10 x double], [10 x double]* @cdflib_dstrem.coef, i64 0, i64 0), i32* @cdflib_dstrem.K1, double* %2)
%16 = load double, double* %0
%17 = fmul double %15, %16
br label %26
18: ; preds = %9
%19 = fadd double %10, -5.000000e-01
%20 = tail call double @log(double %10)
%21 = tail call double @llvm.fmuladd.f64(double %19, double %20, double 0x3FED67F1C864BEB5)
%22 = load double, double* %0
%23 = fsub double %21, %22
%24 = tail call double @cdflib_gamma_log(double* %0)
%25 = fsub double %24, %23
br label %26
26: ; preds = %18, %12
%27 = phi double [ %17, %12 ], [ %25, %18 ]
ret double %27
}