#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*/ const mpf_t;

/* Variables and functions */
int /*<<< orphan*/ fp_gamma(int /*<<< orphan*/ const, int /*<<< orphan*/ const,
                            int);
int /*<<< orphan*/ mpf_eq(int /*<<< orphan*/ const, int /*<<< orphan*/ const,
                          int);
int /*<<< orphan*/ mpf_init(int /*<<< orphan*/ const);
int /*<<< orphan*/ mpf_set(int /*<<< orphan*/ const, int /*<<< orphan*/ const);
int /*<<< orphan*/ mpf_set_prec(int /*<<< orphan*/ const, double);
void mpf_gamma_cache(mpf_t gam, const mpf_t z, int prec) {
  static mpf_t cache_z, cache_gam;
  static int precision = 0;
  int redo = 0;
  if (!precision) {
    mpf_init(cache_z);
    mpf_init(cache_gam);
  }
  if (precision < prec) {
    mpf_set_prec(cache_z, 3.322 * prec + 50);
    mpf_set_prec(cache_gam, 3.322 * prec + 50);
    precision = prec;
    redo = 1;
  }
  if (redo || !mpf_eq(z, cache_z, prec * 3.322)) {
    mpf_set(cache_z, z);
    fp_gamma(gam, z, prec);
    mpf_set(cache_gam, gam);
  } else {
    mpf_set(gam, cache_gam);
  }
}


x86 assembly (clang, -O0):
<mpf_gamma_cache>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x0,0x2edd(%rip)
jne    118b <mpf_gamma_cache+0x3b>
mov    0xe95(%rip),%edi
call   1050 <mpf_init@plt>
mov    0xe8e(%rip),%edi
call   1050 <mpf_init@plt>
mov    0x2ebb(%rip),%eax
cmp    -0xc(%rbp),%eax
jge    11fa <mpf_gamma_cache+0xaa>
mov    0xe70(%rip),%edi
cvtsi2sdl -0xc(%rbp),%xmm0
movsd  0xe53(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe4f(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1040 <mpf_set_prec@plt>
mov    0xe4c(%rip),%edi
cvtsi2sdl -0xc(%rbp),%xmm0
movsd  0xe2b(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe27(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1040 <mpf_set_prec@plt>
mov    -0xc(%rbp),%eax
mov    %eax,0x2e59(%rip)
movl   $0x1,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    1230 <mpf_gamma_cache+0xe0>
mov    -0x8(%rbp),%edi
mov    0xe03(%rip),%esi
cvtsi2sdl -0xc(%rbp),%xmm0
movsd  0xde6(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edx
call   1030 <mpf_eq@plt>
cmp    $0x0,%eax
jne    125f <mpf_gamma_cache+0x10f>
mov    0xdda(%rip),%edi
mov    -0x8(%rbp),%esi
call   1070 <mpf_set@plt>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1060 <fp_gamma@plt>
mov    0xdc2(%rip),%edi
mov    -0x4(%rbp),%esi
call   1070 <mpf_set@plt>
jmp    126d <mpf_gamma_cache+0x11d>
mov    -0x4(%rbp),%edi
mov    0xdac(%rip),%esi
call   1070 <mpf_set@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mpf_gamma_cache>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebp
mov    %esi,%ebx
mov    %edi,%r14d
mov    0x2ee7(%rip),%eax
test   %eax,%eax
jne    117d <mpf_gamma_cache+0x2d>
xor    %edi,%edi
call   1050 <mpf_init@plt>
xor    %edi,%edi
call   1050 <mpf_init@plt>
mov    0x2ecf(%rip),%eax
cvtsi2sd %ebp,%xmm0
mulsd  0xe77(%rip),%xmm0
cmp    %ebp,%eax
jge    11b7 <mpf_gamma_cache+0x67>
addsd  0xe73(%rip),%xmm0
xor    %edi,%edi
movsd  %xmm0,0x8(%rsp)
call   1040 <mpf_set_prec@plt>
xor    %edi,%edi
movsd  0x8(%rsp),%xmm0
call   1040 <mpf_set_prec@plt>
mov    %ebp,0x2e97(%rip)
jmp    11cf <mpf_gamma_cache+0x7f>
cvttsd2si %xmm0,%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1030 <mpf_eq@plt>
test   %eax,%eax
je     11cf <mpf_gamma_cache+0x7f>
mov    %r14d,%edi
xor    %esi,%esi
jmp    11e9 <mpf_gamma_cache+0x99>
xor    %edi,%edi
mov    %ebx,%esi
call   1070 <mpf_set@plt>
mov    %r14d,%edi
mov    %ebx,%esi
mov    %ebp,%edx
call   1060 <fp_gamma@plt>
xor    %edi,%edi
mov    %r14d,%esi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1070 <mpf_set@plt>

LLVM IR (-O0):
@mpf_gamma_cache.cache_z = internal constant i32 0
@mpf_gamma_cache.cache_gam = internal constant i32 0
@mpf_gamma_cache.precision = internal global i32 0
define void @mpf_gamma_cache(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
%8 = load i32, i32* @mpf_gamma_cache.precision
%9 = icmp ne i32 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %3
%11 = load i32, i32* @mpf_gamma_cache.cache_z
%12 = call i32 @mpf_init(i32 %11)
%13 = load i32, i32* @mpf_gamma_cache.cache_gam
%14 = call i32 @mpf_init(i32 %13)
br label %15
15: ; preds = %10, %3
%16 = load i32, i32* @mpf_gamma_cache.precision
%17 = load i32, i32* %6
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %31
19: ; preds = %15
%20 = load i32, i32* @mpf_gamma_cache.cache_z
%21 = load i32, i32* %6
%22 = sitofp i32 %21 to double
%23 = call double @llvm.fmuladd.f64(double 3.322000e+00, double %22, double 5.000000e+01)
%24 = call i32 @mpf_set_prec(i32 %20, double %23)
%25 = load i32, i32* @mpf_gamma_cache.cache_gam
%26 = load i32, i32* %6
%27 = sitofp i32 %26 to double
%28 = call double @llvm.fmuladd.f64(double 3.322000e+00, double %27, double 5.000000e+01)
%29 = call i32 @mpf_set_prec(i32 %25, double %28)
%30 = load i32, i32* %6
store i32 %30, i32* @mpf_gamma_cache.precision
store i32 1, i32* %7
br label %31
31: ; preds = %19, %15
%32 = load i32, i32* %7
%33 = icmp ne i32 %32, 0
br i1 %33, label %43, label %34
34: ; preds = %31
%35 = load i32, i32* %5
%36 = load i32, i32* @mpf_gamma_cache.cache_z
%37 = load i32, i32* %6
%38 = sitofp i32 %37 to double
%39 = fmul double %38, 3.322000e+00
%40 = fptosi double %39 to i32
%41 = call i32 @mpf_eq(i32 %35, i32 %36, i32 %40)
%42 = icmp ne i32 %41, 0
br i1 %42, label %54, label %43
43: ; preds = %34, %31
%44 = load i32, i32* @mpf_gamma_cache.cache_z
%45 = load i32, i32* %5
%46 = call i32 @mpf_set(i32 %44, i32 %45)
%47 = load i32, i32* %4
%48 = load i32, i32* %5
%49 = load i32, i32* %6
%50 = call i32 @fp_gamma(i32 %47, i32 %48, i32 %49)
%51 = load i32, i32* @mpf_gamma_cache.cache_gam
%52 = load i32, i32* %4
%53 = call i32 @mpf_set(i32 %51, i32 %52)
br label %58
54: ; preds = %34
%55 = load i32, i32* %4
%56 = load i32, i32* @mpf_gamma_cache.cache_gam
%57 = call i32 @mpf_set(i32 %55, i32 %56)
br label %58
58: ; preds = %54, %43
ret void
}

LLVM IR (-O2):
@mpf_gamma_cache.precision = internal unnamed_addr global i32 0
define void @mpf_gamma_cache(i32 %0, i32 %1, i32 %2) {
%4 = load i32, i32* @mpf_gamma_cache.precision
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = tail call i32 @mpf_init(i32 0)
%8 = tail call i32 @mpf_init(i32 0)
%9 = load i32, i32* @mpf_gamma_cache.precision
br label %10
10: ; preds = %6, %3
%11 = phi i32 [ %9, %6 ], [ %4, %3 ]
%12 = icmp slt i32 %11, %2
%13 = sitofp i32 %2 to double
br i1 %12, label %14, label %18
14: ; preds = %10
%15 = tail call double @llvm.fmuladd.f64(double %13, double 3.322000e+00, double 5.000000e+01)
%16 = tail call i32 @mpf_set_prec(i32 0, double %15)
%17 = tail call i32 @mpf_set_prec(i32 0, double %15)
store i32 %2, i32* @mpf_gamma_cache.precision
br label %23
18: ; preds = %10
%19 = fmul double %13, 3.322000e+00
%20 = fptosi double %19 to i32
%21 = tail call i32 @mpf_eq(i32 %1, i32 0, i32 %20)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %14, %18
%24 = tail call i32 @mpf_set(i32 0, i32 %1)
%25 = tail call i32 @fp_gamma(i32 %0, i32 %1, i32 %2)
%26 = tail call i32 @mpf_set(i32 0, i32 %0)
br label %29
27: ; preds = %18
%28 = tail call i32 @mpf_set(i32 %0, i32 0)
br label %29
29: ; preds = %27, %23
ret void
}