#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 cos(double);
double sin(double);
double Bessel(double x, int n) {
  double v, theta, dtheta, sum = 0;
  dtheta = 3.141592653589793238462643 / 10000;
  for (theta = 0; theta < 3.141592653589793238462643; theta += dtheta) {
    v = cos(x * sin(theta) - n * theta);
    sum += v * dtheta;
  }
  return (sum / 3.141592653589793238462643);
}


x86 assembly (clang, -O0):
<Bessel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xec0(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xeb3(%rip),%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    11df <Bessel+0xbf>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1030 <sin@plt>
movaps %xmm0,%xmm2
movsd  -0x38(%rbp),%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
mulsd  -0x20(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1040 <cos@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    114d <Bessel+0x2d>
movsd  -0x30(%rbp),%xmm0
movsd  0xe1c(%rip),%xmm1
divsd  %xmm1,%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Bessel>:
sub    $0x28,%rsp
movsd  %xmm0,0x20(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %edi,%xmm0
movsd  %xmm0,0x18(%rsp)
xorpd  %xmm0,%xmm0
xorpd  %xmm1,%xmm1
nop
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,0x10(%rsp)
movapd %xmm1,%xmm0
call   1030 <sin@plt>
movsd  0x18(%rsp),%xmm1
mulsd  0x8(%rsp),%xmm1
mulsd  0x20(%rsp),%xmm0
subsd  %xmm1,%xmm0
call   1040 <cos@plt>
movsd  0xe88(%rip),%xmm2
mulsd  %xmm2,%xmm0
movsd  0x10(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm2,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0xe5e(%rip),%xmm1
ucomisd 0x8(%rsp),%xmm1
movsd  0x8(%rsp),%xmm1
ja     1140 <Bessel+0x20>
divsd  0xe48(%rip),%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
define double @Bessel(double %0, i32 %1) {
%3 = alloca double
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
store double %0, double* %3
store i32 %1, i32* %4
store double 0.000000e+00, double* %8
store double 0x3F3496B7C53C5B02, double* %7
store double 0.000000e+00, double* %6
br label %9
9: ; preds = %27, %2
%10 = load double, double* %6
%11 = fcmp olt double %10, 0x400921FB54442D18
br i1 %11, label %12, label %31
12: ; preds = %9
%13 = load double, double* %3
%14 = load double, double* %6
%15 = call double @sin(double %14)
%16 = load i32, i32* %4
%17 = sitofp i32 %16 to double
%18 = load double, double* %6
%19 = fmul double %17, %18
%20 = fneg double %19
%21 = call double @llvm.fmuladd.f64(double %13, double %15, double %20)
%22 = call double @cos(double %21)
store double %22, double* %5
%23 = load double, double* %5
%24 = load double, double* %7
%25 = load double, double* %8
%26 = call double @llvm.fmuladd.f64(double %23, double %24, double %25)
store double %26, double* %8
br label %27
27: ; preds = %12
%28 = load double, double* %7
%29 = load double, double* %6
%30 = fadd double %29, %28
store double %30, double* %6
br label %9
31: ; preds = %9
%32 = load double, double* %8
%33 = fdiv double %32, 0x400921FB54442D18
ret double %33
}

LLVM IR (-O2):
define double @Bessel(double %0, i32 %1) {
%3 = sitofp i32 %1 to double
br label %4
4: ; preds = %2, %4
%5 = phi double [ 0.000000e+00, %2 ], [ %12, %4 ]
%6 = phi double [ 0.000000e+00, %2 ], [ %13, %4 ]
%7 = tail call double @sin(double %6)
%8 = fneg double %6
%9 = fmul double %3, %8
%10 = tail call double @llvm.fmuladd.f64(double %0, double %7, double %9)
%11 = tail call double @cos(double %10)
%12 = tail call double @llvm.fmuladd.f64(double %11, double 0x3F3496B7C53C5B02, double %5)
%13 = fadd double %6, 0x3F3496B7C53C5B02
%14 = fcmp olt double %13, 0x400921FB54442D18
br i1 %14, label %4, label %15
15: ; preds = %4
%16 = fdiv double %12, 0x400921FB54442D18
ret double %16
}