#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 M_PI;
double sin(double);
double TH_trigamma(double x) {
  double sign = +1;
  double result = 0;
  if (x < 0.5) {
    sign = -1;
    const double sin_pi_x = sin(M_PI * x);
    result -= (M_PI * M_PI) / (sin_pi_x * sin_pi_x);
    x = 1 - x;
  }
  for (int i = 0; i < 6; ++i) {
    result += 1 / (x * x);
    x += 1;
  }
  const double ixx = 1 / (x * x);
  result +=
      (1 + 1 / (2 * x) + ixx * (1. / 6 - ixx * (1. / 30 - ixx * (1. / 42)))) /
      x;
  return sign * result;
}


x86 assembly (clang, -O0):
<TH_trigamma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  0xee3(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xec6(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    11b0 <TH_trigamma+0xa0>
movsd  0xec3(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    0x2e8f(%rip),%rax
movsd  (%rax),%xmm0
mulsd  -0x8(%rbp),%xmm0
call   1030 <sin@plt>
movsd  %xmm0,-0x20(%rbp)
mov    0x2e75(%rip),%rax
movsd  (%rax),%xmm1
mov    0x2e6a(%rip),%rax
mulsd  (%rax),%xmm1
movsd  -0x20(%rbp),%xmm0
mulsd  -0x20(%rbp),%xmm0
divsd  %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe62(%rip),%xmm0
subsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x6,-0x24(%rbp)
jge    1201 <TH_trigamma+0xf1>
movsd  -0x8(%rbp),%xmm1
mulsd  -0x8(%rbp),%xmm1
movsd  0xe35(%rip),%xmm0
divsd  %xmm1,%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe1f(%rip),%xmm0
addsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11b7 <TH_trigamma+0xa7>
movsd  -0x8(%rbp),%xmm1
mulsd  -0x8(%rbp),%xmm1
movsd  0xdf5(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xe0c(%rip),%xmm1
mulsd  -0x8(%rbp),%xmm1
movsd  0xdd7(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  0xdcb(%rip),%xmm1
addsd  %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm3
movq   %xmm3,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm3
movsd  0xdb1(%rip),%xmm4
mulsd  %xmm4,%xmm3
movsd  0xdad(%rip),%xmm4
addsd  %xmm4,%xmm3
movq   %xmm2,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm2
mulsd  %xmm3,%xmm2
movsd  0xd76(%rip),%xmm3
addsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
divsd  -0x8(%rbp),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<TH_trigamma>:
push   %rbx
sub    $0x10,%rsp
movapd %xmm0,%xmm5
movsd  0xedf(%rip),%xmm6
xorpd  %xmm0,%xmm0
movsd  0xedb(%rip),%xmm1
ucomisd %xmm5,%xmm1
jbe    1183 <TH_trigamma+0x73>
mov    0x2eae(%rip),%rbx
movsd  (%rbx),%xmm0
mulsd  %xmm5,%xmm0
movapd %xmm5,(%rsp)
call   1030 <sin@plt>
movsd  0xeac(%rip),%xmm6
movsd  (%rbx),%xmm1
mulsd  %xmm1,%xmm1
mulsd  %xmm0,%xmm0
divsd  %xmm0,%xmm1
xorpd  %xmm0,%xmm0
subsd  %xmm1,%xmm0
movsd  0xe8c(%rip),%xmm5
subsd  (%rsp),%xmm5
movsd  0xe8f(%rip),%xmm1
jmp    1187 <TH_trigamma+0x77>
movapd %xmm6,%xmm1
movapd %xmm5,%xmm2
mulsd  %xmm5,%xmm2
movapd %xmm6,%xmm3
divsd  %xmm2,%xmm3
addsd  %xmm0,%xmm3
addsd  %xmm6,%xmm5
movapd %xmm5,%xmm0
addsd  %xmm6,%xmm0
unpcklpd %xmm0,%xmm5
mulpd  %xmm5,%xmm5
movapd 0xe79(%rip),%xmm2
movapd %xmm2,%xmm4
divpd  %xmm5,%xmm4
addsd  %xmm4,%xmm3
unpckhpd %xmm4,%xmm4
addsd  %xmm3,%xmm4
addsd  %xmm6,%xmm0
movapd %xmm0,%xmm3
addsd  %xmm6,%xmm3
unpcklpd %xmm3,%xmm0
mulpd  %xmm0,%xmm0
divpd  %xmm0,%xmm2
addsd  %xmm2,%xmm4
unpckhpd %xmm2,%xmm2
addsd  %xmm4,%xmm2
addsd  %xmm6,%xmm3
movapd %xmm3,%xmm0
unpcklpd %xmm3,%xmm0
movapd 0xe3d(%rip),%xmm4
movsd  %xmm3,%xmm4
addpd  %xmm0,%xmm4
mulpd  %xmm3,%xmm3
shufpd $0x2,%xmm4,%xmm3
unpckhpd %xmm4,%xmm4
movapd %xmm4,%xmm0
mulsd  %xmm4,%xmm0
movapd %xmm6,%xmm5
divsd  %xmm0,%xmm5
addsd  %xmm4,%xmm4
movapd %xmm6,%xmm0
divsd  %xmm4,%xmm0
addsd  %xmm6,%xmm0
movsd  0xdd8(%rip),%xmm4
mulsd  %xmm5,%xmm4
addsd  0xdd4(%rip),%xmm4
mulsd  %xmm5,%xmm4
movsd  0xdd0(%rip),%xmm6
subsd  %xmm4,%xmm6
mulsd  %xmm5,%xmm6
addsd  %xmm0,%xmm6
movapd 0xde4(%rip),%xmm0
unpcklpd %xmm6,%xmm0
divpd  %xmm3,%xmm0
addsd  %xmm0,%xmm2
unpckhpd %xmm0,%xmm0
addsd  %xmm2,%xmm0
mulsd  %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@M_PI = global double 0.000000e+00
define double @TH_trigamma(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca i32
%7 = alloca double
store double %0, double* %2
store double 1.000000e+00, double* %3
store double 0.000000e+00, double* %4
%8 = load double, double* %2
%9 = fcmp olt double %8, 5.000000e-01
br i1 %9, label %10, label %26
10: ; preds = %1
store double -1.000000e+00, double* %3
%11 = load double, double* @M_PI
%12 = load double, double* %2
%13 = fmul double %11, %12
%14 = call double @sin(double %13)
store double %14, double* %5
%15 = load double, double* @M_PI
%16 = load double, double* @M_PI
%17 = fmul double %15, %16
%18 = load double, double* %5
%19 = load double, double* %5
%20 = fmul double %18, %19
%21 = fdiv double %17, %20
%22 = load double, double* %4
%23 = fsub double %22, %21
store double %23, double* %4
%24 = load double, double* %2
%25 = fsub double 1.000000e+00, %24
store double %25, double* %2
br label %26
26: ; preds = %10, %1
store i32 0, i32* %6
br label %27
27: ; preds = %39, %26
%28 = load i32, i32* %6
%29 = icmp slt i32 %28, 6
br i1 %29, label %30, label %42
30: ; preds = %27
%31 = load double, double* %2
%32 = load double, double* %2
%33 = fmul double %31, %32
%34 = fdiv double 1.000000e+00, %33
%35 = load double, double* %4
%36 = fadd double %35, %34
store double %36, double* %4
%37 = load double, double* %2
%38 = fadd double %37, 1.000000e+00
store double %38, double* %2
br label %39
39: ; preds = %30
%40 = load i32, i32* %6
%41 = add nsw i32 %40, 1
store i32 %41, i32* %6
br label %27
42: ; preds = %27
%43 = load double, double* %2
%44 = load double, double* %2
%45 = fmul double %43, %44
%46 = fdiv double 1.000000e+00, %45
store double %46, double* %7
%47 = load double, double* %2
%48 = fmul double 2.000000e+00, %47
%49 = fdiv double 1.000000e+00, %48
%50 = fadd double 1.000000e+00, %49
%51 = load double, double* %7
%52 = load double, double* %7
%53 = load double, double* %7
%54 = fneg double %53
%55 = call double @llvm.fmuladd.f64(double %54, double 0x3F98618618618618, double 0x3FA1111111111111)
%56 = fneg double %52
%57 = call double @llvm.fmuladd.f64(double %56, double %55, double 0x3FC5555555555555)
%58 = call double @llvm.fmuladd.f64(double %51, double %57, double %50)
%59 = load double, double* %2
%60 = fdiv double %58, %59
%61 = load double, double* %4
%62 = fadd double %61, %60
store double %62, double* %4
%63 = load double, double* %3
%64 = load double, double* %4
%65 = fmul double %63, %64
ret double %65
}

LLVM IR (-O2):
@M_PI = global double 0.000000e+00
define double @TH_trigamma(double %0) {
%2 = fcmp olt double %0, 5.000000e-01
br i1 %2, label %3, label %13
3: ; preds = %1
%4 = load double, double* @M_PI
%5 = fmul double %4, %0
%6 = tail call double @sin(double %5)
%7 = load double, double* @M_PI
%8 = fmul double %7, %7
%9 = fmul double %6, %6
%10 = fdiv double %8, %9
%11 = fsub double 0.000000e+00, %10
%12 = fsub double 1.000000e+00, %0
br label %13
13: ; preds = %3, %1
%14 = phi double [ %11, %3 ], [ 0.000000e+00, %1 ]
%15 = phi double [ -1.000000e+00, %3 ], [ 1.000000e+00, %1 ]
%16 = phi double [ %12, %3 ], [ %0, %1 ]
%17 = fmul double %16, %16
%18 = fdiv double 1.000000e+00, %17
%19 = fadd double %14, %18
%20 = fadd double %16, 1.000000e+00
%21 = fadd double %20, 1.000000e+00
%22 = insertelement <2 x double> poison, double %20, i64 0
%23 = insertelement <2 x double> %22, double %21, i64 1
%24 = fmul <2 x double> %23, %23
%25 = fdiv <2 x double> <double 1.000000e+00, double 1.000000e+00>, %24
%26 = extractelement <2 x double> %25, i64 0
%27 = fadd double %19, %26
%28 = extractelement <2 x double> %25, i64 1
%29 = fadd double %27, %28
%30 = fadd double %21, 1.000000e+00
%31 = fadd double %30, 1.000000e+00
%32 = insertelement <2 x double> poison, double %30, i64 0
%33 = insertelement <2 x double> %32, double %31, i64 1
%34 = fmul <2 x double> %33, %33
%35 = fdiv <2 x double> <double 1.000000e+00, double 1.000000e+00>, %34
%36 = extractelement <2 x double> %35, i64 0
%37 = fadd double %29, %36
%38 = extractelement <2 x double> %35, i64 1
%39 = fadd double %37, %38
%40 = fadd double %31, 1.000000e+00
%41 = insertelement <2 x double> poison, double %40, i64 0
%42 = shufflevector <2 x double> %41, <2 x double> poison, <2 x i32> zeroinitializer
%43 = insertelement <2 x double> <double poison, double 1.000000e+00>, double %40, i64 0
%44 = fmul <2 x double> %42, %43
%45 = fadd <2 x double> %42, %43
%46 = shufflevector <2 x double> %44, <2 x double> %45, <2 x i32> <i32 0, i32 3>
%47 = extractelement <2 x double> %45, i64 1
%48 = fmul double %47, %47
%49 = fdiv double 1.000000e+00, %48
%50 = fmul double %47, 2.000000e+00
%51 = fdiv double 1.000000e+00, %50
%52 = fadd double %51, 1.000000e+00
%53 = fneg double %49
%54 = tail call double @llvm.fmuladd.f64(double %53, double 0x3F98618618618618, double 0x3FA1111111111111)
%55 = tail call double @llvm.fmuladd.f64(double %53, double %54, double 0x3FC5555555555555)
%56 = tail call double @llvm.fmuladd.f64(double %49, double %55, double %52)
%57 = insertelement <2 x double> <double 1.000000e+00, double poison>, double %56, i64 1
%58 = fdiv <2 x double> %57, %46
%59 = extractelement <2 x double> %58, i64 0
%60 = fadd double %39, %59
%61 = extractelement <2 x double> %58, i64 1
%62 = fadd double %60, %61
%63 = fmul double %15, %62
ret double %63
}