#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);
int /*<<< orphan*/ fatalx(char *);
scalar_t__ isnan(double);
double log(double);
scalar_t__ xlgamma(double);
double rtlg2(double a, double x) {
  double y1, y2;
  double yk, top, bot, t0, xam;
  int k;
  t0 = 0.0;
  for (k = 60; k >= 1; --k) {
    yk = (double)k;
    top = yk - a;
    bot = yk / (x + t0);
    ++bot;
    t0 = top / bot;
  }
  xam = (a * log(x)) - x;
  y1 = xam - log(x + t0);
  y1 -= xlgamma(a);
  y1 = exp(y1);
  if (isnan(y1))
    fatalx("bad rtlg2\n");
  return y1;
}


x86 assembly (clang, -O0):
<rtlg2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x3c,-0x4c(%rbp)
cmpl   $0x1,-0x4c(%rbp)
jl     11db <rtlg2+0x8b>
cvtsi2sdl -0x4c(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
addsd  -0x40(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xe4c(%rip),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
divsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x4c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4c(%rbp)
jmp    1171 <rtlg2+0x21>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1070 <log@plt>
movaps %xmm0,%xmm2
movsd  -0x60(%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,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x10(%rbp),%xmm0
addsd  -0x40(%rbp),%xmm0
call   1070 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1040 <xlgamma@plt>
cvtsi2sd %rax,%xmm1
movsd  -0x18(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1050 <exp@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1060 <isnan@plt>
cmp    $0x0,%rax
je     1296 <rtlg2+0x146>
lea    0xd77(%rip),%rdi
call   1030 <fatalx@plt>
movsd  -0x18(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rtlg2>:
sub    $0x28,%rsp
movapd %xmm1,%xmm5
movapd %xmm0,%xmm4
xorpd  %xmm6,%xmm6
mov    $0x3c,%eax
movsd  0xe93(%rip),%xmm0
nopl   (%rax)
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
movapd %xmm1,%xmm2
subsd  %xmm4,%xmm2
addsd  %xmm5,%xmm6
divsd  %xmm6,%xmm1
addsd  %xmm0,%xmm1
lea    -0x1(%rax),%ecx
xorps  %xmm3,%xmm3
cvtsi2sd %ecx,%xmm3
divsd  %xmm1,%xmm2
movapd %xmm3,%xmm6
subsd  %xmm4,%xmm6
addsd  %xmm5,%xmm2
divsd  %xmm2,%xmm3
addsd  %xmm0,%xmm3
divsd  %xmm3,%xmm6
add    $0xfffffffe,%eax
cmp    $0x1,%ecx
jne    1170 <rtlg2+0x20>
movapd %xmm5,%xmm0
movsd  %xmm4,0x10(%rsp)
movsd  %xmm5,0x18(%rsp)
movsd  %xmm6,0x20(%rsp)
call   1070 <log@plt>
mulsd  0x10(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x20(%rsp),%xmm0
addsd  %xmm1,%xmm0
call   1070 <log@plt>
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x10(%rsp),%xmm0
call   1040 <xlgamma@plt>
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
movsd  0x8(%rsp),%xmm0
subsd  %xmm1,%xmm0
call   1050 <exp@plt>
movsd  %xmm0,0x8(%rsp)
call   1060 <isnan@plt>
test   %rax,%rax
je     1247 <rtlg2+0xf7>
lea    0xdc6(%rip),%rdi
call   1030 <fatalx@plt>
movsd  0x8(%rsp),%xmm0
add    $0x28,%rsp
ret

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

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