#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 INFINITY;
double NAN;
double exp(double const);
double limitK0_08(double const);
double limitK0e_upper(double const);
double sqrt(double const);
void bessel0(const double *x, double *res, const int n) {
  int i;
  for (i = 0; i < n; i++) {
    if (x[i] < 0)
      res[i] = NAN;
    else if (x[i] == 0)
      res[i] = INFINITY;
    else if (x[i] < 0.8)
      res[i] = limitK0_08(x[i]);
    else {
      res[i] = limitK0e_upper(x[i]);
      res[i] /= exp(x[i]) * sqrt(x[i]);
    }
  }
}


x86 assembly (clang, -O0):
<bessel0>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1299 <bessel0+0x159>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
xorps  %xmm0,%xmm0
ucomisd (%rax,%rcx,8),%xmm0
jbe    1199 <bessel0+0x59>
mov    0x2e75(%rip),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    1286 <bessel0+0x146>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11d6 <bessel0+0x96>
jp     11d6 <bessel0+0x96>
mov    0x2e20(%rip),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    1281 <bessel0+0x141>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  0xe1a(%rip),%xmm0
ucomisd (%rax,%rcx,8),%xmm0
jbe    1215 <bessel0+0xd5>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <limitK0_08@plt>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    127c <bessel0+0x13c>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1060 <limitK0e_upper@plt>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1040 <exp@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1050 <sqrt@plt>
movsd  -0x20(%rbp),%xmm1
mulsd  %xmm0,%xmm1
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    1281 <bessel0+0x141>
jmp    1286 <bessel0+0x146>
jmp    128b <bessel0+0x14b>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    115a <bessel0+0x1a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bessel0>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    1223 <bessel0+0xe3>
mov    %rsi,%r14
mov    %rdi,%r12
mov    %edx,%r15d
xor    %ebx,%ebx
xorpd  %xmm1,%xmm1
mov    0x2e8f(%rip),%r13
mov    0x2e70(%rip),%rbp
jmp    1199 <bessel0+0x59>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  0x0(%r13),%xmm0
movsd  %xmm0,(%r14,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r15
je     1223 <bessel0+0xe3>
movsd  (%r12,%rbx,8),%xmm0
ucomisd %xmm0,%xmm1
ja     1180 <bessel0+0x40>
ucomisd %xmm1,%xmm0
jne    11b4 <bessel0+0x74>
jp     11b4 <bessel0+0x74>
movsd  0x0(%rbp),%xmm0
jmp    1186 <bessel0+0x46>
movsd  0xe44(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    11cd <bessel0+0x8d>
call   1030 <limitK0_08@plt>
xorpd  %xmm1,%xmm1
jmp    1186 <bessel0+0x46>
call   1060 <limitK0e_upper@plt>
movsd  %xmm0,(%r14,%rbx,8)
movsd  (%r12,%rbx,8),%xmm0
call   1040 <exp@plt>
xorpd  %xmm1,%xmm1
movapd %xmm0,%xmm2
movsd  (%r12,%rbx,8),%xmm0
ucomisd %xmm1,%xmm0
jb     11fd <bessel0+0xbd>
sqrtsd %xmm0,%xmm0
jmp    1210 <bessel0+0xd0>
movsd  %xmm2,(%rsp)
call   1050 <sqrt@plt>
movsd  (%rsp),%xmm2
xorpd  %xmm1,%xmm1
mulsd  %xmm0,%xmm2
movsd  (%r14,%rbx,8),%xmm0
divsd  %xmm2,%xmm0
jmp    1186 <bessel0+0x46>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@NAN = global double 0.000000e+00
@INFINITY = global double 0.000000e+00
define void @bessel0(double* %0, double* %1, i32 %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca i32
%7 = alloca i32
store double* %0, double** %4
store double* %1, double** %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %89, %3
%9 = load i32, i32* %7
%10 = load i32, i32* %6
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %92
12: ; preds = %8
%13 = load double*, double** %4
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds double, double* %13, i64 %15
%17 = load double, double* %16
%18 = fcmp olt double %17, 0.000000e+00
br i1 %18, label %19, label %25
19: ; preds = %12
%20 = load double, double* @NAN
%21 = load double*, double** %5
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds double, double* %21, i64 %23
store double %20, double* %24
br label %88
25: ; preds = %12
%26 = load double*, double** %4
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %26, i64 %28
%30 = load double, double* %29
%31 = fcmp oeq double %30, 0.000000e+00
br i1 %31, label %32, label %38
32: ; preds = %25
%33 = load double, double* @INFINITY
%34 = load double*, double** %5
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double, double* %34, i64 %36
store double %33, double* %37
br label %87
38: ; preds = %25
%39 = load double*, double** %4
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %39, i64 %41
%43 = load double, double* %42
%44 = fcmp olt double %43, 8.000000e-01
br i1 %44, label %45, label %56
45: ; preds = %38
%46 = load double*, double** %4
%47 = load i32, i32* %7
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds double, double* %46, i64 %48
%50 = load double, double* %49
%51 = call double @limitK0_08(double %50)
%52 = load double*, double** %5
%53 = load i32, i32* %7
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds double, double* %52, i64 %54
store double %51, double* %55
br label %86
56: ; preds = %38
%57 = load double*, double** %4
%58 = load i32, i32* %7
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds double, double* %57, i64 %59
%61 = load double, double* %60
%62 = call double @limitK0e_upper(double %61)
%63 = load double*, double** %5
%64 = load i32, i32* %7
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds double, double* %63, i64 %65
store double %62, double* %66
%67 = load double*, double** %4
%68 = load i32, i32* %7
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds double, double* %67, i64 %69
%71 = load double, double* %70
%72 = call double @exp(double %71)
%73 = load double*, double** %4
%74 = load i32, i32* %7
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds double, double* %73, i64 %75
%77 = load double, double* %76
%78 = call double @sqrt(double %77)
%79 = fmul double %72, %78
%80 = load double*, double** %5
%81 = load i32, i32* %7
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds double, double* %80, i64 %82
%84 = load double, double* %83
%85 = fdiv double %84, %79
store double %85, double* %83
br label %86
86: ; preds = %56, %45
br label %87
87: ; preds = %86, %32
br label %88
88: ; preds = %87, %19
br label %89
89: ; preds = %88
%90 = load i32, i32* %7
%91 = add nsw i32 %90, 1
store i32 %91, i32* %7
br label %8
92: ; preds = %8
ret void
}

LLVM IR (-O2):
@NAN = global double 0.000000e+00
@INFINITY = global double 0.000000e+00
define void @bessel0(double* nocapture %0, double* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %38
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %5, %35
%8 = phi i64 [ 0, %5 ], [ %36, %35 ]
%9 = getelementptr inbounds double, double* %0, i64 %8
%10 = load double, double* %9
%11 = fcmp olt double %10, 0.000000e+00
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = load double, double* @NAN
%14 = getelementptr inbounds double, double* %1, i64 %8
store double %13, double* %14
br label %35
15: ; preds = %7
%16 = fcmp oeq double %10, 0.000000e+00
br i1 %16, label %17, label %20
17: ; preds = %15
%18 = load double, double* @INFINITY
%19 = getelementptr inbounds double, double* %1, i64 %8
store double %18, double* %19
br label %35
20: ; preds = %15
%21 = fcmp olt double %10, 8.000000e-01
br i1 %21, label %22, label %25
22: ; preds = %20
%23 = tail call double @limitK0_08(double %10)
%24 = getelementptr inbounds double, double* %1, i64 %8
store double %23, double* %24
br label %35
25: ; preds = %20
%26 = tail call double @limitK0e_upper(double %10)
%27 = getelementptr inbounds double, double* %1, i64 %8
store double %26, double* %27
%28 = load double, double* %9
%29 = tail call double @exp(double %28)
%30 = load double, double* %9
%31 = tail call double @sqrt(double %30)
%32 = fmul double %29, %31
%33 = load double, double* %27
%34 = fdiv double %33, %32
store double %34, double* %27
br label %35
35: ; preds = %12, %22, %25, %17
%36 = add nuw nsw i64 %8, 1
%37 = icmp eq i64 %36, %6
br i1 %37, label %38, label %7
38: ; preds = %35, %3
ret void
}