#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 INFINITY;
double M_PI;
double TH_polevl(double, double *, int);
double floor(double);
double log(double);
double tan(double);
double TH_digamma(double x) {
  static double PSI_10 = 2.25175258906672110764;
  if (x == 0) {
    return INFINITY;
  }
  int x_is_integer = x == floor(x);
  if (x < 0) {
    if (x_is_integer) {
      return INFINITY;
    }
    return TH_digamma(1 - x) - M_PI / tan(M_PI * x);
  }
  double result = 0;
  while (x < 10) {
    result -= 1 / x;
    x += 1;
  }
  if (x == 10) {
    return result + PSI_10;
  }
  static double A[] = {
      8.33333333333333333333E-2, -2.10927960927960927961E-2,
      7.57575757575757575758E-3, -4.16666666666666666667E-3,
      3.96825396825396825397E-3, -8.33333333333333333333E-3,
      8.33333333333333333333E-2,
  };
  double y = 0;
  if (x < 1.0e17) {
    double z = 1.0 / (x * x);
    y = z * TH_polevl(z, A, 6);
  }
  return result + log(x) - (0.5 / x) - y;
}


x86 assembly (clang, -O0):
<TH_digamma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    118a <TH_digamma+0x3a>
jp     118a <TH_digamma+0x3a>
mov    0x2e6c(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1365 <TH_digamma+0x215>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1070 <floor@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
ucomisd %xmm1,%xmm0
sete   %al
setnp  %cl
and    %cl,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x14(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1242 <TH_digamma+0xf2>
cmpl   $0x0,-0x14(%rbp)
je     11e7 <TH_digamma+0x97>
mov    0x2e0f(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1365 <TH_digamma+0x215>
movsd  0xe21(%rip),%xmm0
subsd  -0x10(%rbp),%xmm0
call   1060 <TH_digamma@plt>
movsd  %xmm0,-0x40(%rbp)
mov    0x2ddb(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    0x2dcb(%rip),%rax
movsd  (%rax),%xmm0
mulsd  -0x10(%rbp),%xmm0
call   1040 <tan@plt>
movsd  -0x48(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x40(%rbp),%xmm0
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1365 <TH_digamma+0x215>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xdae(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    128f <TH_digamma+0x13f>
movsd  0xdab(%rip),%xmm1
divsd  -0x10(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xd90(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    124a <TH_digamma+0xfa>
movsd  -0x10(%rbp),%xmm0
movsd  0xd64(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    12c3 <TH_digamma+0x173>
jp     12c3 <TH_digamma+0x173>
movsd  -0x20(%rbp),%xmm0
addsd  0x2d97(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1365 <TH_digamma+0x215>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xd35(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    132a <TH_digamma+0x1da>
movsd  -0x10(%rbp),%xmm1
mulsd  -0x10(%rbp),%xmm1
movsd  0xd20(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x30(%rbp),%xmm0
lea    0x2d51(%rip),%rdi
mov    $0x6,%esi
call   1030 <TH_polevl@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  0xcc6(%rip),%xmm1
divsd  -0x10(%rbp),%xmm1
subsd  %xmm1,%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TH_digamma>:
sub    $0x18,%rsp
movapd %xmm0,%xmm3
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm3
jne    1174 <TH_digamma+0x24>
jp     1174 <TH_digamma+0x24>
mov    0x2e7d(%rip),%rax
movsd  (%rax),%xmm0
add    $0x18,%rsp
ret
ucomisd %xmm3,%xmm0
jbe    11e5 <TH_digamma+0x95>
movapd %xmm3,%xmm0
movsd  %xmm3,0x8(%rsp)
call   1070 <floor@plt>
movsd  0x8(%rsp),%xmm1
ucomisd %xmm1,%xmm0
jne    1197 <TH_digamma+0x47>
jnp    1164 <TH_digamma+0x14>
movsd  0xe69(%rip),%xmm0
subsd  %xmm1,%xmm0
call   1060 <TH_digamma@plt>
movsd  %xmm0,0x10(%rsp)
mov    0x2e2b(%rip),%rax
movsd  (%rax),%xmm1
movsd  %xmm1,(%rsp)
movsd  0x8(%rsp),%xmm0
mulsd  %xmm1,%xmm0
call   1040 <tan@plt>
movsd  (%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  0x10(%rsp),%xmm0
subsd  %xmm1,%xmm0
add    $0x18,%rsp
ret
xorpd  %xmm4,%xmm4
movsd  0xe0f(%rip),%xmm0
ucomisd %xmm3,%xmm0
jbe    1226 <TH_digamma+0xd6>
xorpd  %xmm4,%xmm4
movsd  0xe05(%rip),%xmm1
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movapd %xmm1,%xmm2
divsd  %xmm3,%xmm2
subsd  %xmm2,%xmm4
addsd  %xmm1,%xmm3
ucomisd %xmm3,%xmm0
ja     1210 <TH_digamma+0xc0>
ucomisd 0xdd2(%rip),%xmm3
jne    1243 <TH_digamma+0xf3>
jp     1243 <TH_digamma+0xf3>
addsd  0xde6(%rip),%xmm4
movapd %xmm4,%xmm0
add    $0x18,%rsp
ret
movsd  %xmm4,0x10(%rsp)
xorpd  %xmm0,%xmm0
movsd  0xdbb(%rip),%xmm1
ucomisd %xmm3,%xmm1
movsd  %xmm3,0x8(%rsp)
jbe    1296 <TH_digamma+0x146>
movapd %xmm3,%xmm1
mulsd  %xmm3,%xmm1
movsd  0xd97(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
lea    0x2dcf(%rip),%rdi
mov    $0x6,%esi
call   1030 <TH_polevl@plt>
movsd  0x8(%rsp),%xmm3
mulsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
movapd %xmm3,%xmm0
call   1050 <log@plt>
movsd  0x10(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  0xd62(%rip),%xmm0
divsd  0x8(%rsp),%xmm0
addsd  %xmm1,%xmm0
subsd  (%rsp),%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
@TH_digamma.PSI_10 = internal global double 0x40020396DC85CC95
@INFINITY = global double 0.000000e+00
@M_PI = global double 0.000000e+00
@TH_digamma.A = internal global [7 x double] [double 0x3FB5555555555555, double 0xBF95995995995996, double 0x3F7F07C1F07C1F08, double 0xBF71111111111111, double 0x3F70410410410410, double 0xBF81111111111111, double 0x3FB5555555555555]
define double @TH_digamma(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double
store double %0, double* %3
%8 = load double, double* %3
%9 = fcmp oeq double %8, 0.000000e+00
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = load double, double* @INFINITY
store double %11, double* %2
br label %76
12: ; preds = %1
%13 = load double, double* %3
%14 = load double, double* %3
%15 = call double @llvm.floor.f64(double %14)
%16 = fcmp oeq double %13, %15
%17 = zext i1 %16 to i32
store i32 %17, i32* %4
%18 = load double, double* %3
%19 = fcmp olt double %18, 0.000000e+00
br i1 %19, label %20, label %36
20: ; preds = %12
%21 = load i32, i32* %4
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = load double, double* @INFINITY
store double %24, double* %2
br label %76
25: ; preds = %20
%26 = load double, double* %3
%27 = fsub double 1.000000e+00, %26
%28 = call double @TH_digamma(double %27)
%29 = load double, double* @M_PI
%30 = load double, double* @M_PI
%31 = load double, double* %3
%32 = fmul double %30, %31
%33 = call double @tan(double %32)
%34 = fdiv double %29, %33
%35 = fsub double %28, %34
store double %35, double* %2
br label %76
36: ; preds = %12
store double 0.000000e+00, double* %5
br label %37
37: ; preds = %40, %36
%38 = load double, double* %3
%39 = fcmp olt double %38, 1.000000e+01
br i1 %39, label %40, label %47
40: ; preds = %37
%41 = load double, double* %3
%42 = fdiv double 1.000000e+00, %41
%43 = load double, double* %5
%44 = fsub double %43, %42
store double %44, double* %5
%45 = load double, double* %3
%46 = fadd double %45, 1.000000e+00
store double %46, double* %3
br label %37
47: ; preds = %37
%48 = load double, double* %3
%49 = fcmp oeq double %48, 1.000000e+01
br i1 %49, label %50, label %54
50: ; preds = %47
%51 = load double, double* %5
%52 = load double, double* @TH_digamma.PSI_10
%53 = fadd double %51, %52
store double %53, double* %2
br label %76
54: ; preds = %47
store double 0.000000e+00, double* %6
%55 = load double, double* %3
%56 = fcmp olt double %55, 1.000000e+17
br i1 %56, label %57, label %66
57: ; preds = %54
%58 = load double, double* %3
%59 = load double, double* %3
%60 = fmul double %58, %59
%61 = fdiv double 1.000000e+00, %60
store double %61, double* %7
%62 = load double, double* %7
%63 = load double, double* %7
%64 = call double @TH_polevl(double %63, double* getelementptr inbounds ([7 x double], [7 x double]* @TH_digamma.A, i64 0, i64 0), i32 6)
%65 = fmul double %62, %64
store double %65, double* %6
br label %66
66: ; preds = %57, %54
%67 = load double, double* %5
%68 = load double, double* %3
%69 = call double @log(double %68)
%70 = fadd double %67, %69
%71 = load double, double* %3
%72 = fdiv double 5.000000e-01, %71
%73 = fsub double %70, %72
%74 = load double, double* %6
%75 = fsub double %73, %74
store double %75, double* %2
br label %76
76: ; preds = %66, %50, %25, %23, %10
%77 = load double, double* %2
ret double %77
}

LLVM IR (-O2):
@INFINITY = global double 0.000000e+00
@M_PI = global double 0.000000e+00
@TH_digamma.A = internal global [7 x double] [double 0x3FB5555555555555, double 0xBF95995995995996, double 0x3F7F07C1F07C1F08, double 0xBF71111111111111, double 0x3F70410410410410, double 0xBF81111111111111, double 0x3FB5555555555555]
define double @TH_digamma(double %0) {
%2 = fcmp oeq double %0, 0.000000e+00
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = load double, double* @INFINITY
br label %14
5: ; preds = %1
%6 = fcmp olt double %0, 0.000000e+00
br i1 %6, label %9, label %7
7: ; preds = %5
%8 = fcmp olt double %0, 1.000000e+01
br i1 %8, label %24, label %31
9: ; preds = %5
%10 = tail call double @llvm.floor.f64(double %0)
%11 = fcmp oeq double %10, %0
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = load double, double* @INFINITY
br label %14
14: ; preds = %3, %35, %44, %12, %16
%15 = phi double [ %23, %16 ], [ %4, %3 ], [ %13, %12 ], [ %36, %35 ], [ %50, %44 ]
ret double %15
16: ; preds = %9
%17 = fsub double 1.000000e+00, %0
%18 = tail call double @TH_digamma(double %17)
%19 = load double, double* @M_PI
%20 = fmul double %19, %0
%21 = tail call double @tan(double %20)
%22 = fdiv double %19, %21
%23 = fsub double %18, %22
br label %14
24: ; preds = %7, %24
%25 = phi double [ %28, %24 ], [ 0.000000e+00, %7 ]
%26 = phi double [ %29, %24 ], [ %0, %7 ]
%27 = fdiv double 1.000000e+00, %26
%28 = fsub double %25, %27
%29 = fadd double %26, 1.000000e+00
%30 = fcmp olt double %29, 1.000000e+01
br i1 %30, label %24, label %31
31: ; preds = %24, %7
%32 = phi double [ %0, %7 ], [ %29, %24 ]
%33 = phi double [ 0.000000e+00, %7 ], [ %28, %24 ]
%34 = fcmp oeq double %32, 1.000000e+01
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = fadd double %33, 0x40020396DC85CC95
br label %14
37: ; preds = %31
%38 = fcmp olt double %32, 1.000000e+17
br i1 %38, label %39, label %44
39: ; preds = %37
%40 = fmul double %32, %32
%41 = fdiv double 1.000000e+00, %40
%42 = tail call double @TH_polevl(double %41, double* getelementptr inbounds ([7 x double], [7 x double]* @TH_digamma.A, i64 0, i64 0), i32 6)
%43 = fmul double %41, %42
br label %44
44: ; preds = %39, %37
%45 = phi double [ %43, %39 ], [ 0.000000e+00, %37 ]
%46 = tail call double @log(double %32)
%47 = fadd double %33, %46
%48 = fdiv double 5.000000e-01, %32
%49 = fsub double %47, %48
%50 = fsub double %49, %45
br label %14
}