#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 M_PI;
double S(int, double, double);
scalar_t__ ceil(double);
double fmin(double, double);
double ftrans(int);
double log(double);
double sqrt(double);
double sinc_approx(int n, double d, double alpha, double beta, double t) {
  int k, M, N;
  double mu = fmin(alpha, beta);
  double h = sqrt(M_PI * d / (mu * n));
  if (alpha <= beta) {
    M = n;
    N = (int)ceil(alpha * n / beta);
  } else {
    M = (int)ceil(beta * n / alpha);
    N = n;
  }
  double x = log(t);
  double val1 = 0;
  double val2 = 0;
  for (k = -M; k < 0; k++) {
    val1 += ftrans(k * h) * S(k, h, x);
  }
  for (k = N; k >= 0; k--) {
    val2 += ftrans(k * h) * S(k, h, x);
  }
  return val1 + val2;
}


x86 assembly (clang, -O0):
<sinc_approx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm3
movsd  -0x20(%rbp),%xmm2
movaps %xmm2,%xmm4
movaps %xmm3,%xmm0
cmpunordsd %xmm0,%xmm0
movaps %xmm0,%xmm1
pand   %xmm4,%xmm1
minsd  %xmm3,%xmm2
pandn  %xmm2,%xmm0
por    %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    0x2e45(%rip),%rax
movsd  (%rax),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
cvtsi2sdl -0x4(%rbp),%xmm2
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
call   1070 <sqrt@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x18(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1202 <sinc_approx+0xb2>
mov    -0x4(%rbp),%eax
mov    %eax,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
cvtsi2sdl -0x4(%rbp),%xmm1
mulsd  %xmm1,%xmm0
divsd  -0x20(%rbp),%xmm0
call   1030 <ceil@plt>
mov    %eax,-0x34(%rbp)
jmp    1223 <sinc_approx+0xd3>
movsd  -0x20(%rbp),%xmm0
cvtsi2sdl -0x4(%rbp),%xmm1
mulsd  %xmm1,%xmm0
divsd  -0x18(%rbp),%xmm0
call   1030 <ceil@plt>
mov    %eax,-0x30(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x34(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1060 <log@plt>
movsd  %xmm0,-0x50(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
xor    %eax,%eax
sub    -0x30(%rbp),%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    12a6 <sinc_approx+0x156>
cvtsi2sdl -0x2c(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <ftrans@plt>
movsd  %xmm0,-0x68(%rbp)
mov    -0x2c(%rbp),%edi
movsd  -0x48(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm1
call   1050 <S@plt>
movaps %xmm0,%xmm2
movsd  -0x68(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    124a <sinc_approx+0xfa>
mov    -0x34(%rbp),%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jl     1308 <sinc_approx+0x1b8>
cvtsi2sdl -0x2c(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <ftrans@plt>
movsd  %xmm0,-0x70(%rbp)
mov    -0x2c(%rbp),%edi
movsd  -0x48(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm1
call   1050 <S@plt>
movaps %xmm0,%xmm2
movsd  -0x70(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
jmp    12ac <sinc_approx+0x15c>
movsd  -0x58(%rbp),%xmm0
addsd  -0x60(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sinc_approx>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
movsd  %xmm3,0x10(%rsp)
mov    %edi,%ebp
movapd %xmm1,%xmm5
cmpunordsd %xmm1,%xmm5
movapd %xmm5,%xmm4
andpd  %xmm2,%xmm4
movapd %xmm2,%xmm3
minsd  %xmm1,%xmm3
andnpd %xmm3,%xmm5
mov    0x2e66(%rip),%rax
mulsd  (%rax),%xmm0
orpd   %xmm4,%xmm5
xorps  %xmm4,%xmm4
cvtsi2sd %edi,%xmm4
mulsd  %xmm4,%xmm5
divsd  %xmm5,%xmm0
xorpd  %xmm3,%xmm3
ucomisd %xmm3,%xmm0
jb     11a9 <sinc_approx+0x59>
sqrtsd %xmm0,%xmm0
jmp    11d2 <sinc_approx+0x82>
movapd %xmm2,0x20(%rsp)
movsd  %xmm1,0x8(%rsp)
movsd  %xmm4,0x18(%rsp)
call   1070 <sqrt@plt>
movsd  0x18(%rsp),%xmm4
movsd  0x8(%rsp),%xmm1
movapd 0x20(%rsp),%xmm2
movsd  %xmm0,0x20(%rsp)
ucomisd %xmm1,%xmm2
jae    11f5 <sinc_approx+0xa5>
mulsd  %xmm2,%xmm4
divsd  %xmm1,%xmm4
movapd %xmm4,%xmm0
call   1030 <ceil@plt>
mov    %ebp,%ebx
mov    %eax,%ebp
jmp    1209 <sinc_approx+0xb9>
mulsd  %xmm1,%xmm4
divsd  %xmm2,%xmm4
movapd %xmm4,%xmm0
call   1030 <ceil@plt>
mov    %rax,%rbx
movsd  0x10(%rsp),%xmm0
call   1060 <log@plt>
movsd  %xmm0,0x18(%rsp)
xorpd  %xmm0,%xmm0
test   %ebp,%ebp
movsd  0x20(%rsp),%xmm2
jle    1289 <sinc_approx+0x139>
neg    %ebp
xorpd  %xmm0,%xmm0
xchg   %ax,%ax
movsd  %xmm0,0x10(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  %xmm2,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <ftrans@plt>
movsd  %xmm0,0x8(%rsp)
mov    %ebp,%edi
movsd  0x20(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
call   1050 <S@plt>
movsd  0x20(%rsp),%xmm2
mulsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  0x10(%rsp),%xmm0
inc    %ebp
jne    1230 <sinc_approx+0xe0>
movsd  %xmm0,0x10(%rsp)
test   %ebx,%ebx
xorpd  %xmm1,%xmm1
js     12fa <sinc_approx+0x1aa>
xorpd  %xmm1,%xmm1
nopl   0x0(%rax,%rax,1)
movsd  %xmm1,0x8(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
mulsd  %xmm2,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <ftrans@plt>
movsd  %xmm0,0x30(%rsp)
mov    %ebx,%edi
movsd  0x20(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
call   1050 <S@plt>
movsd  0x20(%rsp),%xmm2
mulsd  0x30(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x8(%rsp),%xmm1
add    $0xffffffff,%ebx
jb     12a0 <sinc_approx+0x150>
movsd  0x10(%rsp),%xmm0
addsd  %xmm1,%xmm0
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@M_PI = global double 0.000000e+00
define double @sinc_approx(i32 %0, double %1, double %2, double %3, double %4) {
%6 = tail call double @llvm.minnum.f64(double %2, double %3)
%7 = load double, double* @M_PI
%8 = fmul double %7, %1
%9 = sitofp i32 %0 to double
%10 = fmul double %6, %9
%11 = fdiv double %8, %10
%12 = tail call double @sqrt(double %11)
%13 = fcmp ugt double %2, %3
br i1 %13, label %19, label %14
14: ; preds = %5
%15 = fmul double %9, %2
%16 = fdiv double %15, %3
%17 = tail call i64 @ceil(double %16)
%18 = trunc i64 %17 to i32
br label %24
19: ; preds = %5
%20 = fmul double %9, %3
%21 = fdiv double %20, %2
%22 = tail call i64 @ceil(double %21)
%23 = trunc i64 %22 to i32
br label %24
24: ; preds = %19, %14
%25 = phi i32 [ %18, %14 ], [ %0, %19 ]
%26 = phi i32 [ %0, %14 ], [ %23, %19 ]
%27 = tail call double @log(double %4)
%28 = icmp sgt i32 %26, 0
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = sub nsw i32 0, %26
br label %34
31: ; preds = %34, %24
%32 = phi double [ 0.000000e+00, %24 ], [ %42, %34 ]
%33 = icmp sgt i32 %25, -1
br i1 %33, label %45, label %56
34: ; preds = %29, %34
%35 = phi double [ %42, %34 ], [ 0.000000e+00, %29 ]
%36 = phi i32 [ %43, %34 ], [ %30, %29 ]
%37 = sitofp i32 %36 to double
%38 = fmul double %12, %37
%39 = fptosi double %38 to i32
%40 = tail call double @ftrans(i32 %39)
%41 = tail call double @S(i32 %36, double %12, double %27)
%42 = tail call double @llvm.fmuladd.f64(double %40, double %41, double %35)
%43 = add i32 %36, 1
%44 = icmp eq i32 %43, 0
br i1 %44, label %31, label %34
45: ; preds = %31, %45
%46 = phi double [ %53, %45 ], [ 0.000000e+00, %31 ]
%47 = phi i32 [ %54, %45 ], [ %25, %31 ]
%48 = sitofp i32 %47 to double
%49 = fmul double %12, %48
%50 = fptosi double %49 to i32
%51 = tail call double @ftrans(i32 %50)
%52 = tail call double @S(i32 %47, double %12, double %27)
%53 = tail call double @llvm.fmuladd.f64(double %51, double %52, double %46)
%54 = add nsw i32 %47, -1
%55 = icmp eq i32 %47, 0
br i1 %55, label %56, label %45
56: ; preds = %45, %31
%57 = phi double [ 0.000000e+00, %31 ], [ %53, %45 ]
%58 = fadd double %32, %57
ret double %58
}