#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 fabs(double);
int /*<<< orphan*/ fatalx(char *);
scalar_t__ isnan(double);
double log(double);
scalar_t__ xlgamma(double);
double ltlg1(double a, double x) {
  double r, s, tiny = 1.0e-14;
  double yk, y1, xam;
  int k;
  s = 1.0 / a;
  r = s;
  for (k = 1; k <= 60; ++k) {
    yk = (double)k;
    r *= (x / (a + yk));
    s += r;
    if (fabs(r / s) < tiny)
      break;
  }
  xam = (a * log(x)) - x;
  y1 = xam + log(s);
  y1 -= xlgamma(a);
  y1 = exp(y1);
  if (isnan(y1))
    fatalx("bad ltlg1\n");
  return y1;
}


x86 assembly (clang, -O0):
<ltlg1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  0xe9e(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe89(%rip),%xmm0
divsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x1,-0x44(%rbp)
cmpl   $0x3c,-0x44(%rbp)
jg     120e <ltlg1+0xbe>
cvtsi2sdl -0x44(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
addsd  -0x30(%rbp),%xmm1
divsd  %xmm1,%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm1
divsd  -0x20(%rbp),%xmm1
movaps 0xe2d(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11fb <ltlg1+0xab>
jmp    120e <ltlg1+0xbe>
jmp    1200 <ltlg1+0xb0>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1192 <ltlg1+0x42>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1070 <log@plt>
movaps %xmm0,%xmm2
movsd  -0x58(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1070 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1040 <xlgamma@plt>
cvtsi2sd %rax,%xmm1
movsd  -0x38(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1050 <exp@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1060 <isnan@plt>
cmp    $0x0,%rax
je     12c4 <ltlg1+0x174>
lea    0xd61(%rip),%rdi
call   1030 <fatalx@plt>
movsd  -0x38(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ltlg1>:
sub    $0x18,%rsp
movapd %xmm1,%xmm6
movapd %xmm0,%xmm5
movsd  0xe9c(%rip),%xmm2
divsd  %xmm0,%xmm2
mov    $0x1,%eax
movapd 0xe9b(%rip),%xmm0
movsd  0xe8b(%rip),%xmm1
movapd %xmm2,%xmm7
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movapd %xmm2,%xmm3
xorps  %xmm4,%xmm4
cvtsi2sd %eax,%xmm4
addsd  %xmm5,%xmm4
movapd %xmm6,%xmm2
divsd  %xmm4,%xmm2
mulsd  %xmm3,%xmm2
addsd  %xmm2,%xmm7
movapd %xmm2,%xmm3
divsd  %xmm7,%xmm3
andpd  %xmm0,%xmm3
ucomisd %xmm3,%xmm1
ja     11cb <ltlg1+0x7b>
lea    0x1(%rax),%ecx
cmp    $0x3c,%eax
mov    %ecx,%eax
jne    1190 <ltlg1+0x40>
movapd %xmm6,%xmm0
movsd  %xmm5,(%rsp)
movsd  %xmm6,0x8(%rsp)
movsd  %xmm7,0x10(%rsp)
call   1070 <log@plt>
mulsd  (%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
call   1070 <log@plt>
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  (%rsp),%xmm0
call   1040 <xlgamma@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
movsd  0x10(%rsp),%xmm0
subsd  %xmm1,%xmm0
call   1050 <exp@plt>
movsd  %xmm0,(%rsp)
call   1060 <isnan@plt>
test   %rax,%rax
je     1249 <ltlg1+0xf9>
lea    0xddc(%rip),%rdi
call   1030 <fatalx@plt>
movsd  (%rsp),%xmm0
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
@.str = [11 x i8] c"bad ltlg1\0A\00"
define double @ltlg1(double %0, double %1) {
%3 = fdiv double 1.000000e+00, %0
br label %4
4: ; preds = %4, %2
%5 = phi i32 [ 1, %2 ], [ %16, %4 ]
%6 = phi double [ %3, %2 ], [ %11, %4 ]
%7 = phi double [ %3, %2 ], [ %12, %4 ]
%8 = sitofp i32 %5 to double
%9 = fadd double %8, %0
%10 = fdiv double %1, %9
%11 = fmul double %6, %10
%12 = fadd double %7, %11
%13 = fdiv double %11, %12
%14 = tail call double @llvm.fabs.f64(double %13)
%15 = fcmp olt double %14, 0x3D06849B86A12B9B
%16 = add nuw nsw i32 %5, 1
%17 = icmp eq i32 %16, 61
%18 = select i1 %15, i1 true, i1 %17
br i1 %18, label %19, label %4
19: ; preds = %4
%20 = tail call double @log(double %1)
%21 = fneg double %1
%22 = tail call double @llvm.fmuladd.f64(double %0, double %20, double %21)
%23 = tail call double @log(double %12)
%24 = fadd double %22, %23
%25 = tail call i64 @xlgamma(double %0)
%26 = sitofp i64 %25 to double
%27 = fsub double %24, %26
%28 = tail call double @exp(double %27)
%29 = tail call i64 @isnan(double %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %19
%32 = tail call i32 @fatalx(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %33
33: ; preds = %31, %19
ret double %28
}