#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 */
int /*<<< orphan*/ M_PI;
double compute_1F1_1d(int, double, int);
double exp(double);
int fabs(double);
double lfact(int);
double lgamma(int);
double log(double);
int sqrt(int /*<<< orphan*/);
double surface_area_sphere(int);
double compute_d1F1_dz_1d(int dim, double z, int iter) {
  if (fabs(z) < 1e-8)
    return surface_area_sphere(dim) / (double)(dim + 1);
  if (z < 0)
    return compute_1F1_1d(dim, z, iter) -
           exp(z) * compute_d1F1_dz_1d(dim, -z, iter);
  int i;
  double g, F = 0.0, logz = log(z);
  double a = .5, b = .5 * (dim + 1);
  for (i = 1; i < iter; i++) {
    g = lgamma(i + a) - lgamma(i + b) + (i - 1) * logz - lfact(i - 1);
    if (i > z && exp(g) < 1e-8 * F)
      break;
    F += exp(g);
  }
  return 2 * sqrt(M_PI) * F;
}


x86 assembly (clang, -O0):
<compute_d1F1_dz_1d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <fabs@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe47(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11e3 <compute_d1F1_dz_1d+0x53>
mov    -0xc(%rbp),%edi
call   1060 <surface_area_sphere@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    13aa <compute_d1F1_dz_1d+0x21a>
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1272 <compute_d1F1_dz_1d+0xe2>
mov    -0xc(%rbp),%edi
movsd  -0x18(%rbp),%xmm0
mov    -0x1c(%rbp),%esi
call   10b0 <compute_1F1_1d@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1050 <exp@plt>
movsd  %xmm0,-0x50(%rbp)
mov    -0xc(%rbp),%edi
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mov    -0x1c(%rbp),%esi
call   1080 <compute_d1F1_dz_1d@plt>
movsd  -0x58(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x50(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    13aa <compute_d1F1_dz_1d+0x21a>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1090 <log@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  0xd77(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm1
movsd  0xd60(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    138b <compute_d1F1_dz_1d+0x1fb>
cvtsi2sdl -0x20(%rbp),%xmm0
addsd  -0x40(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1070 <lgamma@plt>
movsd  %xmm0,-0x68(%rbp)
cvtsi2sdl -0x20(%rbp),%xmm0
addsd  -0x48(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1070 <lgamma@plt>
movsd  -0x68(%rbp),%xmm1
subsd  %xmm0,%xmm1
mov    -0x20(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  -0x38(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x20(%rbp),%edi
sub    $0x1,%edi
call   1030 <lfact@plt>
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
cvtsi2sdl -0x20(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1369 <compute_d1F1_dz_1d+0x1d9>
movsd  -0x28(%rbp),%xmm0
call   1050 <exp@plt>
movaps %xmm0,%xmm1
movsd  0xcab(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1369 <compute_d1F1_dz_1d+0x1d9>
jmp    138b <compute_d1F1_dz_1d+0x1fb>
movsd  -0x28(%rbp),%xmm0
call   1050 <exp@plt>
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    12b8 <compute_d1F1_dz_1d+0x128>
mov    0x2c56(%rip),%rax
mov    (%rax),%edi
call   10a0 <sqrt@plt>
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute_d1F1_dz_1d>:
push   %rbp
push   %rbx
sub    $0x48,%rsp
mov    %esi,%ebx
mov    %edi,%ebp
movapd %xmm0,0x20(%rsp)
call   1040 <fabs@plt>
test   %eax,%eax
jle    120c <compute_d1F1_dz_1d+0x7c>
xorpd  %xmm0,%xmm0
movapd 0x20(%rsp),%xmm1
ucomisd %xmm1,%xmm0
movapd %xmm1,%xmm0
jbe    1223 <compute_d1F1_dz_1d+0x93>
mov    %ebp,%edi
mov    %ebx,%esi
call   10b0 <compute_1F1_1d@plt>
movsd  %xmm0,0x8(%rsp)
movaps 0x20(%rsp),%xmm0
call   1050 <exp@plt>
movsd  %xmm0,0x18(%rsp)
movapd 0x20(%rsp),%xmm0
xorpd  0xe26(%rip),%xmm0
mov    %ebp,%edi
mov    %ebx,%esi
call   1080 <compute_d1F1_dz_1d@plt>
mulsd  0x18(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
jmp    135e <compute_d1F1_dz_1d+0x1ce>
mov    %ebp,%edi
call   1060 <surface_area_sphere@plt>
add    $0x1,%ebp
cvtsi2sd %ebp,%xmm1
divsd  %xmm1,%xmm0
jmp    135e <compute_d1F1_dz_1d+0x1ce>
xorpd  %xmm1,%xmm1
movsd  %xmm1,0x10(%rsp)
call   1090 <log@plt>
movsd  %xmm0,0x40(%rsp)
cmp    $0x2,%ebx
jl     1341 <compute_d1F1_dz_1d+0x1b1>
add    $0x1,%ebp
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  0xdad(%rip),%xmm0
movsd  %xmm0,0x38(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
mov    $0x1,%ebp
jmp    1294 <compute_d1F1_dz_1d+0x104>
nopw   0x0(%rax,%rax,1)
movapd %xmm1,%xmm0
call   1050 <exp@plt>
movsd  0x10(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
add    $0x2,%ebp
cmp    %ebx,%ebp
je     1341 <compute_d1F1_dz_1d+0x1b1>
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
movsd  %xmm0,0x18(%rsp)
addsd  0xd57(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1070 <lgamma@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x38(%rsp),%xmm0
addsd  0x18(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1070 <lgamma@plt>
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
add    $0xffffffff,%ebp
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  0x40(%rsp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %ebp,%edi
call   1030 <lfact@plt>
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  0x18(%rsp),%xmm0
ucomisd 0x20(%rsp),%xmm0
jbe    1270 <compute_d1F1_dz_1d+0xe0>
movapd %xmm1,%xmm0
movsd  %xmm1,0x8(%rsp)
call   1050 <exp@plt>
movsd  0x10(%rsp),%xmm1
mulsd  0xcd7(%rip),%xmm1
ucomisd %xmm0,%xmm1
movsd  0x8(%rsp),%xmm1
jbe    1270 <compute_d1F1_dz_1d+0xe0>
mov    0x2ca0(%rip),%rax
mov    (%rax),%edi
call   10a0 <sqrt@plt>
add    %eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0x10(%rsp),%xmm0
add    $0x48,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@M_PI = global i32 0
define double @compute_d1F1_dz_1d(i32 %0, double %1, i32 %2) {
%4 = alloca double
%5 = alloca i32
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
store i32 %0, i32* %5
store double %1, double* %6
store i32 %2, i32* %7
%14 = load double, double* %6
%15 = call i32 @fabs(double %14)
%16 = sitofp i32 %15 to double
%17 = fcmp olt double %16, 1.000000e-08
br i1 %17, label %18, label %25
18: ; preds = %3
%19 = load i32, i32* %5
%20 = call double @surface_area_sphere(i32 %19)
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
%23 = sitofp i32 %22 to double
%24 = fdiv double %20, %23
store double %24, double* %4
br label %102
25: ; preds = %3
%26 = load double, double* %6
%27 = fcmp olt double %26, 0.000000e+00
br i1 %27, label %28, label %42
28: ; preds = %25
%29 = load i32, i32* %5
%30 = load double, double* %6
%31 = load i32, i32* %7
%32 = call double @compute_1F1_1d(i32 %29, double %30, i32 %31)
%33 = load double, double* %6
%34 = call double @exp(double %33)
%35 = load i32, i32* %5
%36 = load double, double* %6
%37 = fneg double %36
%38 = load i32, i32* %7
%39 = call double @compute_d1F1_dz_1d(i32 %35, double %37, i32 %38)
%40 = fneg double %34
%41 = call double @llvm.fmuladd.f64(double %40, double %39, double %32)
store double %41, double* %4
br label %102
42: ; preds = %25
store double 0.000000e+00, double* %10
%43 = load double, double* %6
%44 = call double @log(double %43)
store double %44, double* %11
store double 5.000000e-01, double* %12
%45 = load i32, i32* %5
%46 = add nsw i32 %45, 1
%47 = sitofp i32 %46 to double
%48 = fmul double 5.000000e-01, %47
store double %48, double* %13
store i32 1, i32* %8
br label %49
49: ; preds = %92, %42
%50 = load i32, i32* %8
%51 = load i32, i32* %7
%52 = icmp slt i32 %50, %51
br i1 %52, label %53, label %95
53: ; preds = %49
%54 = load i32, i32* %8
%55 = sitofp i32 %54 to double
%56 = load double, double* %12
%57 = fadd double %55, %56
%58 = fptosi double %57 to i32
%59 = call double @lgamma(i32 %58)
%60 = load i32, i32* %8
%61 = sitofp i32 %60 to double
%62 = load double, double* %13
%63 = fadd double %61, %62
%64 = fptosi double %63 to i32
%65 = call double @lgamma(i32 %64)
%66 = fsub double %59, %65
%67 = load i32, i32* %8
%68 = sub nsw i32 %67, 1
%69 = sitofp i32 %68 to double
%70 = load double, double* %11
%71 = call double @llvm.fmuladd.f64(double %69, double %70, double %66)
%72 = load i32, i32* %8
%73 = sub nsw i32 %72, 1
%74 = call double @lfact(i32 %73)
%75 = fsub double %71, %74
store double %75, double* %9
%76 = load i32, i32* %8
%77 = sitofp i32 %76 to double
%78 = load double, double* %6
%79 = fcmp ogt double %77, %78
br i1 %79, label %80, label %87
80: ; preds = %53
%81 = load double, double* %9
%82 = call double @exp(double %81)
%83 = load double, double* %10
%84 = fmul double 1.000000e-08, %83
%85 = fcmp olt double %82, %84
br i1 %85, label %86, label %87
86: ; preds = %80
br label %95
87: ; preds = %80, %53
%88 = load double, double* %9
%89 = call double @exp(double %88)
%90 = load double, double* %10
%91 = fadd double %90, %89
store double %91, double* %10
br label %92
92: ; preds = %87
%93 = load i32, i32* %8
%94 = add nsw i32 %93, 1
store i32 %94, i32* %8
br label %49
95: ; preds = %86, %49
%96 = load i32, i32* @M_PI
%97 = call i32 @sqrt(i32 %96)
%98 = mul nsw i32 2, %97
%99 = sitofp i32 %98 to double
%100 = load double, double* %10
%101 = fmul double %99, %100
store double %101, double* %4
br label %102
102: ; preds = %95, %28, %18
%103 = load double, double* %4
ret double %103
}

LLVM IR (-O2):
@M_PI = global i32 0
define double @compute_d1F1_dz_1d(i32 %0, double %1, i32 %2) {
%4 = tail call i32 @fabs(double %1)
%5 = icmp slt i32 %4, 1
br i1 %5, label %6, label %11
6: ; preds = %3
%7 = tail call double @surface_area_sphere(i32 %0)
%8 = add nsw i32 %0, 1
%9 = sitofp i32 %8 to double
%10 = fdiv double %7, %9
br label %13
11: ; preds = %3
%12 = fcmp olt double %1, 0.000000e+00
br i1 %12, label %15, label %22
13: ; preds = %6, %54, %15
%14 = phi double [ %21, %15 ], [ %10, %6 ], [ %60, %54 ]
ret double %14
15: ; preds = %11
%16 = tail call double @compute_1F1_1d(i32 %0, double %1, i32 %2)
%17 = tail call double @exp(double %1)
%18 = fneg double %1
%19 = tail call double @compute_d1F1_dz_1d(i32 %0, double %18, i32 %2)
%20 = fneg double %17
%21 = tail call double @llvm.fmuladd.f64(double %20, double %19, double %16)
br label %13
22: ; preds = %11
%23 = tail call double @log(double %1)
%24 = add nsw i32 %0, 1
%25 = sitofp i32 %24 to double
%26 = fmul double %25, 5.000000e-01
%27 = icmp sgt i32 %2, 1
br i1 %27, label %28, label %54
28: ; preds = %22, %49
%29 = phi i32 [ %52, %49 ], [ 1, %22 ]
%30 = phi double [ %51, %49 ], [ 0.000000e+00, %22 ]
%31 = sitofp i32 %29 to double
%32 = fadd double %31, 5.000000e-01
%33 = fptosi double %32 to i32
%34 = tail call double @lgamma(i32 %33)
%35 = fadd double %26, %31
%36 = fptosi double %35 to i32
%37 = tail call double @lgamma(i32 %36)
%38 = fsub double %34, %37
%39 = add nsw i32 %29, -1
%40 = sitofp i32 %39 to double
%41 = tail call double @llvm.fmuladd.f64(double %40, double %23, double %38)
%42 = tail call double @lfact(i32 %39)
%43 = fsub double %41, %42
%44 = fcmp ogt double %31, %1
br i1 %44, label %45, label %49
45: ; preds = %28
%46 = tail call double @exp(double %43)
%47 = fmul double %30, 1.000000e-08
%48 = fcmp olt double %46, %47
br i1 %48, label %54, label %49
49: ; preds = %45, %28
%50 = tail call double @exp(double %43)
%51 = fadd double %30, %50
%52 = add nuw nsw i32 %29, 1
%53 = icmp eq i32 %52, %2
br i1 %53, label %54, label %28
54: ; preds = %49, %45, %22
%55 = phi double [ 0.000000e+00, %22 ], [ %30, %45 ], [ %51, %49 ]
%56 = load i32, i32* @M_PI
%57 = tail call i32 @sqrt(i32 %56)
%58 = shl nsw i32 %57, 1
%59 = sitofp i32 %58 to double
%60 = fmul double %55, %59
br label %13
}