#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 BESSI0(double);
double BESSI1(double);
double fabs(double);
int floor(int /*<<< orphan*/);
int /*<<< orphan*/ sqrt(int);
double BESSI(int N, double X) {
  int IACC = 40;
  double BIGNO = 1e10, BIGNI = 1e-10;
  double TOX, BIM, BI, BIP, BSI;
  int J, M;
  if (N == 0)
    return (BESSI0(X));
  if (N == 1)
    return (BESSI1(X));
  if (X == 0.0)
    return 0.0;
  TOX = 2.0 / X;
  BIP = 0.0;
  BI = 1.0;
  BSI = 0.0;
  M = (int)(2 * ((N + floor(sqrt(IACC * N)))));
  for (J = M; J > 0; J--) {
    BIM = BIP + J * TOX * BI;
    BIP = BI;
    BI = BIM;
    if (fabs(BI) > BIGNO) {
      BI = BI * BIGNI;
      BIP = BIP * BIGNI;
      BSI = BSI * BIGNI;
    }
    if (J == N)
      BSI = BIP;
  }
  return (BSI * BESSI0(X) / BI);
}


x86 assembly (clang, -O0):
<BESSI>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
movl   $0x28,-0x1c(%rbp)
movsd  0xea9(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe94(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    118f <BESSI+0x4f>
movsd  -0x18(%rbp),%xmm0
call   1050 <BESSI0@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    1307 <BESSI+0x1c7>
cmpl   $0x1,-0xc(%rbp)
jne    11ad <BESSI+0x6d>
movsd  -0x18(%rbp),%xmm0
call   1030 <BESSI1@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    1307 <BESSI+0x1c7>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11d2 <BESSI+0x92>
jp     11d2 <BESSI+0x92>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1307 <BESSI+0x1c7>
movsd  0xe3e(%rip),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  0xe1c(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x1c(%rbp),%edi
imul   -0xc(%rbp),%edi
call   1040 <sqrt@plt>
mov    %eax,%edi
call   1060 <floor@plt>
mov    %eax,%ecx
mov    -0x64(%rbp),%eax
add    %ecx,%eax
shl    $0x1,%eax
mov    %eax,-0x60(%rbp)
mov    -0x60(%rbp),%eax
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
jle    12dd <BESSI+0x19d>
movsd  -0x50(%rbp),%xmm1
cvtsi2sdl -0x5c(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
movaps 0xda8(%rip),%xmm1
pand   %xmm1,%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    12b4 <BESSI+0x174>
movsd  -0x48(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x50(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x58(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    12ca <BESSI+0x18a>
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
jmp    12cf <BESSI+0x18f>
mov    -0x5c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x5c(%rbp)
jmp    122d <BESSI+0xed>
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1050 <BESSI0@plt>
movaps %xmm0,%xmm1
movsd  -0x70(%rbp),%xmm0
mulsd  %xmm1,%xmm0
divsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BESSI>:
push   %rbx
sub    $0x20,%rsp
movapd %xmm0,%xmm1
cmp    $0x1,%edi
je     1162 <BESSI+0x22>
mov    %edi,%ebx
test   %edi,%edi
jne    1170 <BESSI+0x30>
movapd %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbx
jmp    1050 <BESSI0@plt>
movapd %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbx
jmp    1030 <BESSI1@plt>
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    1180 <BESSI+0x40>
jnp    1289 <BESSI+0x149>
movsd  %xmm1,(%rsp)
lea    0x0(,%rbx,8),%eax
lea    (%rax,%rax,4),%edi
call   1040 <sqrt@plt>
mov    %eax,%edi
call   1060 <floor@plt>
mov    %eax,%ecx
add    %ebx,%ecx
jle    125d <BESSI+0x11d>
movsd  0xe52(%rip),%xmm9
movsd  (%rsp),%xmm0
divsd  %xmm0,%xmm9
add    %ecx,%ecx
lea    (%rbx,%rax,2),%eax
movsd  0xe43(%rip),%xmm1
xorpd  %xmm4,%xmm4
movapd 0xe4e(%rip),%xmm8
movsd  0xe35(%rip),%xmm10
movsd  0xe35(%rip),%xmm3
xorpd  %xmm6,%xmm6
jmp    1202 <BESSI+0xc2>
nopl   0x0(%rax)
lea    -0x1(%rcx),%edx
movapd %xmm2,%xmm4
movapd %xmm7,%xmm1
cmp    $0x1,%ecx
mov    %edx,%ecx
jle    126e <BESSI+0x12e>
xorps  %xmm7,%xmm7
cvtsi2sd %ecx,%xmm7
mulsd  %xmm9,%xmm7
mulsd  %xmm1,%xmm7
addsd  %xmm6,%xmm7
movapd %xmm7,%xmm2
andpd  %xmm8,%xmm2
ucomisd %xmm10,%xmm2
jbe    122a <BESSI+0xea>
mulsd  %xmm3,%xmm7
jbe    1230 <BESSI+0xf0>
mulsd  %xmm3,%xmm4
movapd %xmm1,%xmm5
mulsd  %xmm3,%xmm5
movapd %xmm10,%xmm6
cmpltsd %xmm2,%xmm6
andpd  %xmm6,%xmm5
andnpd %xmm1,%xmm6
orpd   %xmm5,%xmm6
movapd %xmm6,%xmm2
sub    $0x1,%eax
jb     11f0 <BESSI+0xb0>
movapd %xmm4,%xmm2
jmp    11f0 <BESSI+0xb0>
xorpd  %xmm2,%xmm2
movsd  0xd9f(%rip),%xmm7
movsd  (%rsp),%xmm0
movsd  %xmm2,0x18(%rsp)
movapd %xmm7,(%rsp)
call   1050 <BESSI0@plt>
mulsd  0x18(%rsp),%xmm0
divsd  (%rsp),%xmm0
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @BESSI(i32 %0, double %1) {
%3 = alloca double
%4 = alloca i32
%5 = alloca double
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca i32
%15 = alloca i32
store i32 %0, i32* %4
store double %1, double* %5
store i32 40, i32* %6
store double 1.000000e+10, double* %7
store double 1.000000e-10, double* %8
%16 = load i32, i32* %4
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = load double, double* %5
%20 = call double @BESSI0(double %19)
store double %20, double* %3
br label %87
21: ; preds = %2
%22 = load i32, i32* %4
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load double, double* %5
%26 = call double @BESSI1(double %25)
store double %26, double* %3
br label %87
27: ; preds = %21
%28 = load double, double* %5
%29 = fcmp oeq double %28, 0.000000e+00
br i1 %29, label %30, label %31
30: ; preds = %27
store double 0.000000e+00, double* %3
br label %87
31: ; preds = %27
%32 = load double, double* %5
%33 = fdiv double 2.000000e+00, %32
store double %33, double* %9
store double 0.000000e+00, double* %12
store double 1.000000e+00, double* %11
store double 0.000000e+00, double* %13
%34 = load i32, i32* %4
%35 = load i32, i32* %6
%36 = load i32, i32* %4
%37 = mul nsw i32 %35, %36
%38 = call i32 @sqrt(i32 %37)
%39 = call i32 @floor(i32 %38)
%40 = add nsw i32 %34, %39
%41 = mul nsw i32 2, %40
store i32 %41, i32* %15
%42 = load i32, i32* %15
store i32 %42, i32* %14
br label %43
43: ; preds = %77, %31
%44 = load i32, i32* %14
%45 = icmp sgt i32 %44, 0
br i1 %45, label %46, label %80
46: ; preds = %43
%47 = load double, double* %12
%48 = load i32, i32* %14
%49 = sitofp i32 %48 to double
%50 = load double, double* %9
%51 = fmul double %49, %50
%52 = load double, double* %11
%53 = call double @llvm.fmuladd.f64(double %51, double %52, double %47)
store double %53, double* %10
%54 = load double, double* %11
store double %54, double* %12
%55 = load double, double* %10
store double %55, double* %11
%56 = load double, double* %11
%57 = call double @llvm.fabs.f64(double %56)
%58 = load double, double* %7
%59 = fcmp ogt double %57, %58
br i1 %59, label %60, label %70
60: ; preds = %46
%61 = load double, double* %11
%62 = load double, double* %8
%63 = fmul double %61, %62
store double %63, double* %11
%64 = load double, double* %12
%65 = load double, double* %8
%66 = fmul double %64, %65
store double %66, double* %12
%67 = load double, double* %13
%68 = load double, double* %8
%69 = fmul double %67, %68
store double %69, double* %13
br label %70
70: ; preds = %60, %46
%71 = load i32, i32* %14
%72 = load i32, i32* %4
%73 = icmp eq i32 %71, %72
br i1 %73, label %74, label %76
74: ; preds = %70
%75 = load double, double* %12
store double %75, double* %13
br label %76
76: ; preds = %74, %70
br label %77
77: ; preds = %76
%78 = load i32, i32* %14
%79 = add nsw i32 %78, -1
store i32 %79, i32* %14
br label %43
80: ; preds = %43
%81 = load double, double* %13
%82 = load double, double* %5
%83 = call double @BESSI0(double %82)
%84 = fmul double %81, %83
%85 = load double, double* %11
%86 = fdiv double %84, %85
store double %86, double* %3
br label %87
87: ; preds = %80, %30, %24, %18
%88 = load double, double* %3
ret double %88
}

LLVM IR (-O2):
define double @BESSI(i32 %0, double %1) {
switch i32 %0, label %7 [
i32 0, label %3
i32 1, label %5
]
3: ; preds = %2
%4 = tail call double @BESSI0(double %1)
br label %44
5: ; preds = %2
%6 = tail call double @BESSI1(double %1)
br label %44
7: ; preds = %2
%8 = fcmp oeq double %1, 0.000000e+00
br i1 %8, label %44, label %9
9: ; preds = %7
%10 = fdiv double 2.000000e+00, %1
%11 = mul nsw i32 %0, 40
%12 = tail call i32 @sqrt(i32 %11)
%13 = tail call i32 @floor(i32 %12)
%14 = add nsw i32 %13, %0
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %38
16: ; preds = %9
%17 = shl nuw nsw i32 %14, 1
br label %18
18: ; preds = %16, %18
%19 = phi i32 [ %36, %18 ], [ %17, %16 ]
%20 = phi double [ %35, %18 ], [ 0.000000e+00, %16 ]
%21 = phi double [ %32, %18 ], [ 0.000000e+00, %16 ]
%22 = phi double [ %31, %18 ], [ 1.000000e+00, %16 ]
%23 = sitofp i32 %19 to double
%24 = fmul double %10, %23
%25 = tail call double @llvm.fmuladd.f64(double %24, double %22, double %21)
%26 = tail call double @llvm.fabs.f64(double %25)
%27 = fcmp ogt double %26, 1.000000e+10
%28 = fmul double %25, 1.000000e-10
%29 = fmul double %22, 1.000000e-10
%30 = fmul double %20, 1.000000e-10
%31 = select i1 %27, double %28, double %25
%32 = select i1 %27, double %29, double %22
%33 = select i1 %27, double %30, double %20
%34 = icmp eq i32 %19, %0
%35 = select i1 %34, double %32, double %33
%36 = add nsw i32 %19, -1
%37 = icmp sgt i32 %19, 1
br i1 %37, label %18, label %38
38: ; preds = %18, %9
%39 = phi double [ 1.000000e+00, %9 ], [ %31, %18 ]
%40 = phi double [ 0.000000e+00, %9 ], [ %35, %18 ]
%41 = tail call double @BESSI0(double %1)
%42 = fmul double %40, %41
%43 = fdiv double %42, %39
br label %44
44: ; preds = %7, %38, %5, %3
%45 = phi double [ %4, %3 ], [ %6, %5 ], [ %43, %38 ], [ 0.000000e+00, %7 ]
ret double %45
}