#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 */
typedef int /*<<< orphan*/ mpf_t;

/* Variables and functions */
int /*<<< orphan*/ fp_epsilon(int /*<<< orphan*/, int);
int /*<<< orphan*/ fp_euler_mascheroni(int /*<<< orphan*/, int);
int /*<<< orphan*/ fp_zeta(int /*<<< orphan*/, int, int);
int /*<<< orphan*/ mpf_abs(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpf_add(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpf_clear(int /*<<< orphan*/);
scalar_t__ mpf_cmp(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpf_div_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ mpf_init(int /*<<< orphan*/);
int /*<<< orphan*/ mpf_mul(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpf_set(int /*<<< orphan*/, int /*<<< orphan*/ const);
int /*<<< orphan*/ mpf_set_ui(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ mpf_sub(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int /*<<< orphan*/ mpf_sub_ui(int /*<<< orphan*/, int /*<<< orphan*/, int);
void reduced_lngamma(mpf_t gam, const mpf_t ex, int prec) {
  int n;
  mpf_t z, zn, term;
  mpf_init(z);
  mpf_init(zn);
  mpf_init(term);
  mpf_set(z, ex);
  mpf_set_ui(gam, 0);
  mpf_sub_ui(z, z, 2);
  mpf_mul(zn, z, z);
  mpf_t maxterm;
  mpf_init(maxterm);
  fp_epsilon(maxterm, prec);
  n = 2;
  while (1) {
    fp_zeta(term, n, prec);
    mpf_sub_ui(term, term, 1);
    mpf_mul(term, term, zn);
    mpf_div_ui(term, term, n);
    if (n % 2) {
      mpf_sub(gam, gam, term);
    } else {
      mpf_add(gam, gam, term);
    }
    mpf_abs(term, term);
    if (mpf_cmp(term, maxterm) < 0)
      break;
    mpf_mul(zn, zn, z);
    n++;
  }
  fp_euler_mascheroni(term, prec);
  mpf_sub_ui(term, term, 1);
  mpf_mul(term, term, z);
  mpf_sub(gam, gam, term);
  mpf_clear(z);
  mpf_clear(zn);
  mpf_clear(term);
  mpf_clear(maxterm);
}


x86 assembly (clang, -O0):
<reduced_lngamma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x14(%rbp),%edi
call   1080 <mpf_init@plt>
mov    -0x18(%rbp),%edi
call   1080 <mpf_init@plt>
mov    -0x1c(%rbp),%edi
call   1080 <mpf_init@plt>
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%esi
call   10a0 <mpf_set@plt>
mov    -0x4(%rbp),%edi
xor    %esi,%esi
call   10c0 <mpf_set_ui@plt>
mov    -0x14(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    $0x2,%edx
call   1060 <mpf_sub_ui@plt>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x14(%rbp),%edx
call   10f0 <mpf_mul@plt>
mov    -0x20(%rbp),%edi
call   1080 <mpf_init@plt>
mov    -0x20(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1050 <fp_epsilon@plt>
movl   $0x2,-0x10(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1100 <fp_zeta@plt>
mov    -0x1c(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    $0x1,%edx
call   1060 <mpf_sub_ui@plt>
mov    -0x1c(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%edx
call   10f0 <mpf_mul@plt>
mov    -0x1c(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%edx
call   10b0 <mpf_div_ui@plt>
mov    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     12b7 <reduced_lngamma+0xd7>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   10e0 <mpf_sub@plt>
jmp    12c5 <reduced_lngamma+0xe5>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1070 <mpf_add@plt>
mov    -0x1c(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1030 <mpf_abs@plt>
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1040 <mpf_cmp@plt>
cmp    $0x0,%rax
jge    12ea <reduced_lngamma+0x10a>
jmp    1306 <reduced_lngamma+0x126>
mov    -0x18(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
call   10f0 <mpf_mul@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1256 <reduced_lngamma+0x76>
mov    -0x1c(%rbp),%edi
mov    -0xc(%rbp),%esi
call   10d0 <fp_euler_mascheroni@plt>
mov    -0x1c(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    $0x1,%edx
call   1060 <mpf_sub_ui@plt>
mov    -0x1c(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x14(%rbp),%edx
call   10f0 <mpf_mul@plt>
mov    -0x4(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   10e0 <mpf_sub@plt>
mov    -0x14(%rbp),%edi
call   1090 <mpf_clear@plt>
mov    -0x18(%rbp),%edi
call   1090 <mpf_clear@plt>
mov    -0x1c(%rbp),%edi
call   1090 <mpf_clear@plt>
mov    -0x20(%rbp),%edi
call   1090 <mpf_clear@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reduced_lngamma>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%ebx
call   1080 <mpf_init@plt>
call   1080 <mpf_init@plt>
call   1080 <mpf_init@plt>
mov    %ebp,%esi
call   10a0 <mpf_set@plt>
mov    %ebx,%edi
xor    %esi,%esi
call   10c0 <mpf_set_ui@plt>
mov    $0x2,%ebp
mov    $0x2,%edx
call   1060 <mpf_sub_ui@plt>
call   10f0 <mpf_mul@plt>
call   1080 <mpf_init@plt>
mov    %r14d,%esi
call   1050 <fp_epsilon@plt>
nopl   0x0(%rax,%rax,1)
mov    %ebp,%esi
mov    %r14d,%edx
call   1100 <fp_zeta@plt>
mov    $0x1,%edx
call   1060 <mpf_sub_ui@plt>
call   10f0 <mpf_mul@plt>
mov    %ebp,%edx
call   10b0 <mpf_div_ui@plt>
mov    %ebx,%edi
mov    %ebx,%esi
test   $0x1,%bpl
jne    1270 <reduced_lngamma+0x90>
call   1070 <mpf_add@plt>
jmp    1275 <reduced_lngamma+0x95>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
call   10e0 <mpf_sub@plt>
call   1030 <mpf_abs@plt>
call   1040 <mpf_cmp@plt>
test   %rax,%rax
js     128e <reduced_lngamma+0xae>
call   10f0 <mpf_mul@plt>
add    $0x1,%ebp
jmp    1230 <reduced_lngamma+0x50>
mov    %r14d,%esi
call   10d0 <fp_euler_mascheroni@plt>
mov    $0x1,%edx
call   1060 <mpf_sub_ui@plt>
call   10f0 <mpf_mul@plt>
mov    %ebx,%edi
mov    %ebx,%esi
call   10e0 <mpf_sub@plt>
call   1090 <mpf_clear@plt>
call   1090 <mpf_clear@plt>
call   1090 <mpf_clear@plt>
pop    %rbx
pop    %r14
pop    %rbp
jmp    1090 <mpf_clear@plt>

LLVM IR (-O0):
define void @reduced_lngamma(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%12 = load i32, i32* %8
%13 = call i32 @mpf_init(i32 %12)
%14 = load i32, i32* %9
%15 = call i32 @mpf_init(i32 %14)
%16 = load i32, i32* %10
%17 = call i32 @mpf_init(i32 %16)
%18 = load i32, i32* %8
%19 = load i32, i32* %5
%20 = call i32 @mpf_set(i32 %18, i32 %19)
%21 = load i32, i32* %4
%22 = call i32 @mpf_set_ui(i32 %21, i32 0)
%23 = load i32, i32* %8
%24 = load i32, i32* %8
%25 = call i32 @mpf_sub_ui(i32 %23, i32 %24, i32 2)
%26 = load i32, i32* %9
%27 = load i32, i32* %8
%28 = load i32, i32* %8
%29 = call i32 @mpf_mul(i32 %26, i32 %27, i32 %28)
%30 = load i32, i32* %11
%31 = call i32 @mpf_init(i32 %30)
%32 = load i32, i32* %11
%33 = load i32, i32* %6
%34 = call i32 @fp_epsilon(i32 %32, i32 %33)
store i32 2, i32* %7
br label %35
35: ; preds = %3, %73
%36 = load i32, i32* %10
%37 = load i32, i32* %7
%38 = load i32, i32* %6
%39 = call i32 @fp_zeta(i32 %36, i32 %37, i32 %38)
%40 = load i32, i32* %10
%41 = load i32, i32* %10
%42 = call i32 @mpf_sub_ui(i32 %40, i32 %41, i32 1)
%43 = load i32, i32* %10
%44 = load i32, i32* %10
%45 = load i32, i32* %9
%46 = call i32 @mpf_mul(i32 %43, i32 %44, i32 %45)
%47 = load i32, i32* %10
%48 = load i32, i32* %10
%49 = load i32, i32* %7
%50 = call i32 @mpf_div_ui(i32 %47, i32 %48, i32 %49)
%51 = load i32, i32* %7
%52 = srem i32 %51, 2
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %59
54: ; preds = %35
%55 = load i32, i32* %4
%56 = load i32, i32* %4
%57 = load i32, i32* %10
%58 = call i32 @mpf_sub(i32 %55, i32 %56, i32 %57)
br label %64
59: ; preds = %35
%60 = load i32, i32* %4
%61 = load i32, i32* %4
%62 = load i32, i32* %10
%63 = call i32 @mpf_add(i32 %60, i32 %61, i32 %62)
br label %64
64: ; preds = %59, %54
%65 = load i32, i32* %10
%66 = load i32, i32* %10
%67 = call i32 @mpf_abs(i32 %65, i32 %66)
%68 = load i32, i32* %10
%69 = load i32, i32* %11
%70 = call i64 @mpf_cmp(i32 %68, i32 %69)
%71 = icmp slt i64 %70, 0
br i1 %71, label %72, label %73
72: ; preds = %64
br label %80
73: ; preds = %64
%74 = load i32, i32* %9
%75 = load i32, i32* %9
%76 = load i32, i32* %8
%77 = call i32 @mpf_mul(i32 %74, i32 %75, i32 %76)
%78 = load i32, i32* %7
%79 = add nsw i32 %78, 1
store i32 %79, i32* %7
br label %35
80: ; preds = %72
%81 = load i32, i32* %10
%82 = load i32, i32* %6
%83 = call i32 @fp_euler_mascheroni(i32 %81, i32 %82)
%84 = load i32, i32* %10
%85 = load i32, i32* %10
%86 = call i32 @mpf_sub_ui(i32 %84, i32 %85, i32 1)
%87 = load i32, i32* %10
%88 = load i32, i32* %10
%89 = load i32, i32* %8
%90 = call i32 @mpf_mul(i32 %87, i32 %88, i32 %89)
%91 = load i32, i32* %4
%92 = load i32, i32* %4
%93 = load i32, i32* %10
%94 = call i32 @mpf_sub(i32 %91, i32 %92, i32 %93)
%95 = load i32, i32* %8
%96 = call i32 @mpf_clear(i32 %95)
%97 = load i32, i32* %9
%98 = call i32 @mpf_clear(i32 %97)
%99 = load i32, i32* %10
%100 = call i32 @mpf_clear(i32 %99)
%101 = load i32, i32* %11
%102 = call i32 @mpf_clear(i32 %101)
ret void
}

LLVM IR (-O2):
define void @reduced_lngamma(i32 %0, i32 %1, i32 %2) {
%4 = tail call i32 @mpf_init(i32 undef)
%5 = tail call i32 @mpf_init(i32 undef)
%6 = tail call i32 @mpf_init(i32 undef)
%7 = tail call i32 @mpf_set(i32 undef, i32 %1)
%8 = tail call i32 @mpf_set_ui(i32 %0, i32 0)
%9 = tail call i32 @mpf_sub_ui(i32 undef, i32 undef, i32 2)
%10 = tail call i32 @mpf_mul(i32 undef, i32 undef, i32 undef)
%11 = tail call i32 @mpf_init(i32 undef)
%12 = tail call i32 @fp_epsilon(i32 undef, i32 %2)
br label %13
13: ; preds = %29, %3
%14 = phi i32 [ 2, %3 ], [ %31, %29 ]
%15 = tail call i32 @fp_zeta(i32 undef, i32 %14, i32 %2)
%16 = tail call i32 @mpf_sub_ui(i32 undef, i32 undef, i32 1)
%17 = tail call i32 @mpf_mul(i32 undef, i32 undef, i32 undef)
%18 = tail call i32 @mpf_div_ui(i32 undef, i32 undef, i32 %14)
%19 = and i32 %14, 1
%20 = icmp eq i32 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %13
%22 = tail call i32 @mpf_sub(i32 %0, i32 %0, i32 undef)
br label %25
23: ; preds = %13
%24 = tail call i32 @mpf_add(i32 %0, i32 %0, i32 undef)
br label %25
25: ; preds = %23, %21
%26 = tail call i32 @mpf_abs(i32 undef, i32 undef)
%27 = tail call i64 @mpf_cmp(i32 undef, i32 undef)
%28 = icmp slt i64 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %25
%30 = tail call i32 @mpf_mul(i32 undef, i32 undef, i32 undef)
%31 = add nuw nsw i32 %14, 1
br label %13
32: ; preds = %25
%33 = tail call i32 @fp_euler_mascheroni(i32 undef, i32 %2)
%34 = tail call i32 @mpf_sub_ui(i32 undef, i32 undef, i32 1)
%35 = tail call i32 @mpf_mul(i32 undef, i32 undef, i32 undef)
%36 = tail call i32 @mpf_sub(i32 %0, i32 %0, i32 undef)
%37 = tail call i32 @mpf_clear(i32 undef)
%38 = tail call i32 @mpf_clear(i32 undef)
%39 = tail call i32 @mpf_clear(i32 undef)
%40 = tail call i32 @mpf_clear(i32 undef)
ret void
}