#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 cos(double);
double fabs(double);
double pow(double, int);
double sin(double);
double f_chan(double x, double a, int n) {
  int k, m, mmax, kmax;
  double y, psin, t, pi, en;
  pi = M_PI;
  y = n;
  y = y / (a - 1);
  if (fabs(x) >= y)
    return 0;
  en = 1. / n;
  mmax = 10;
  kmax = 40;
  y = 0.5;
  for (k = 1; k < kmax; k++) {
    psin = 1;
    t = (pi * k) * (a - 1) * en;
    for (m = 1; m < mmax; m++) {
      t = t / a;
      psin = psin * (sin(t) / t);
    }
    psin = pow(psin, n) * cos((pi * k * (a - 1) * en) * x);
    y = y + psin;
  }
  y = y * (a - 1) * en;
  return y;
}


x86 assembly (clang, -O0):
<f_chan>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %edi,-0x1c(%rbp)
mov    0x2e9c(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x50(%rbp)
cvtsi2sdl -0x1c(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  0xe9f(%rip),%xmm2
subsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%rbp),%xmm0
movaps 0xe76(%rip),%xmm1
pand   %xmm1,%xmm0
ucomisd -0x38(%rbp),%xmm0
jb     11a6 <f_chan+0x76>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    131e <f_chan+0x1ee>
cvtsi2sdl -0x1c(%rbp),%xmm1
movsd  0xe5d(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movl   $0xa,-0x28(%rbp)
movl   $0x28,-0x2c(%rbp)
movsd  0xe46(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    12f0 <f_chan+0x1c0>
movsd  0xe1e(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x50(%rbp),%xmm0
cvtsi2sdl -0x20(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  0xdfe(%rip),%xmm2
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
mulsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    127e <f_chan+0x14e>
movsd  -0x48(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x48(%rbp),%xmm0
call   1030 <sin@plt>
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
divsd  -0x48(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    122b <f_chan+0xfb>
movsd  -0x40(%rbp),%xmm0
mov    -0x1c(%rbp),%edi
call   1050 <pow@plt>
movsd  %xmm0,-0x68(%rbp)
movsd  -0x50(%rbp),%xmm0
cvtsi2sdl -0x20(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  0xd65(%rip),%xmm2
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
mulsd  -0x58(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
call   1040 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x68(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11de <f_chan+0xae>
movsd  -0x38(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  0xd0e(%rip),%xmm2
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
mulsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<f_chan>:
push   %rbp
push   %rbx
sub    $0xa8,%rsp
cvtsi2sd %edi,%xmm5
movsd  0xebb(%rip),%xmm3
addsd  %xmm1,%xmm3
movapd %xmm5,%xmm4
divsd  %xmm3,%xmm4
movapd 0xec7(%rip),%xmm2
andpd  %xmm0,%xmm2
xorps  %xmm6,%xmm6
movsd  %xmm6,0x28(%rsp)
ucomisd %xmm4,%xmm2
jae    1413 <f_chan+0x2e3>
mov    %edi,%ebx
mov    0x2e6f(%rip),%rax
movsd  (%rax),%xmm2
movsd  %xmm2,0x68(%rsp)
movsd  0xe7d(%rip),%xmm4
movapd %xmm4,%xmm2
divsd  %xmm5,%xmm2
movsd  %xmm2,0x28(%rsp)
movsd  0xe6f(%rip),%xmm2
mov    $0x27,%ebp
movapd %xmm0,0x90(%rsp)
movsd  %xmm3,0x70(%rsp)
movsd  %xmm1,0x8(%rsp)
nopl   0x0(%rax,%rax,1)
movsd  %xmm4,0x80(%rsp)
movsd  %xmm2,0x88(%rsp)
movsd  0x68(%rsp),%xmm0
mulsd  %xmm4,%xmm0
mulsd  %xmm3,%xmm0
mulsd  0x28(%rsp),%xmm0
movsd  %xmm0,0x78(%rsp)
divsd  %xmm1,%xmm0
movapd %xmm0,0x30(%rsp)
call   1030 <sin@plt>
movapd %xmm0,0x50(%rsp)
movapd 0x30(%rsp),%xmm0
divsd  0x8(%rsp),%xmm0
movapd %xmm0,0x10(%rsp)
call   1030 <sin@plt>
movapd %xmm0,%xmm1
movapd 0x10(%rsp),%xmm0
divsd  %xmm0,%xmm1
movsd  %xmm1,0x40(%rsp)
divsd  0x8(%rsp),%xmm0
movapd %xmm0,0x10(%rsp)
call   1030 <sin@plt>
movapd 0x50(%rsp),%xmm1
unpcklpd %xmm0,%xmm1
movapd 0x30(%rsp),%xmm0
movapd 0x10(%rsp),%xmm2
unpcklpd %xmm2,%xmm0
divpd  %xmm0,%xmm1
movsd  0x40(%rsp),%xmm0
mulsd  %xmm1,%xmm0
unpckhpd %xmm1,%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,0x50(%rsp)
movapd %xmm2,%xmm0
divsd  0x8(%rsp),%xmm0
movapd %xmm0,0x10(%rsp)
call   1030 <sin@plt>
movapd %xmm0,0x40(%rsp)
movapd 0x10(%rsp),%xmm0
divsd  0x8(%rsp),%xmm0
movapd %xmm0,0x30(%rsp)
call   1030 <sin@plt>
movapd 0x40(%rsp),%xmm1
unpcklpd %xmm0,%xmm1
movapd 0x30(%rsp),%xmm2
movapd 0x10(%rsp),%xmm0
unpcklpd %xmm2,%xmm0
divpd  %xmm0,%xmm1
movapd 0x50(%rsp),%xmm0
mulsd  %xmm1,%xmm0
unpckhpd %xmm1,%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,0x40(%rsp)
movapd %xmm2,%xmm0
divsd  0x8(%rsp),%xmm0
movapd %xmm0,0x30(%rsp)
call   1030 <sin@plt>
movapd %xmm0,0x50(%rsp)
movapd 0x30(%rsp),%xmm0
divsd  0x8(%rsp),%xmm0
movapd %xmm0,0x10(%rsp)
call   1030 <sin@plt>
movapd 0x50(%rsp),%xmm1
unpcklpd %xmm0,%xmm1
movapd 0x10(%rsp),%xmm2
movapd 0x30(%rsp),%xmm0
unpcklpd %xmm2,%xmm0
divpd  %xmm0,%xmm1
movapd 0x40(%rsp),%xmm0
mulsd  %xmm1,%xmm0
unpckhpd %xmm1,%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,0x50(%rsp)
movapd %xmm2,%xmm0
divsd  0x8(%rsp),%xmm0
movapd %xmm0,0x10(%rsp)
call   1030 <sin@plt>
movapd %xmm0,0x30(%rsp)
movapd 0x10(%rsp),%xmm0
divsd  0x8(%rsp),%xmm0
movapd %xmm0,0x40(%rsp)
call   1030 <sin@plt>
movapd 0x30(%rsp),%xmm1
unpcklpd %xmm0,%xmm1
movapd 0x10(%rsp),%xmm0
unpcklpd 0x40(%rsp),%xmm0
divpd  %xmm0,%xmm1
movapd 0x50(%rsp),%xmm0
mulsd  %xmm1,%xmm0
unpckhpd %xmm1,%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
mov    %ebx,%edi
call   1050 <pow@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x78(%rsp),%xmm0
mulsd  0x90(%rsp),%xmm0
call   1040 <cos@plt>
movsd  0x80(%rsp),%xmm4
movsd  0x88(%rsp),%xmm2
movsd  0x8(%rsp),%xmm1
movsd  0x70(%rsp),%xmm3
mulsd  0x10(%rsp),%xmm0
addsd  %xmm0,%xmm2
addsd  0xc12(%rip),%xmm4
add    $0xffffffff,%ebp
jne    11c0 <f_chan+0x90>
mulsd  %xmm2,%xmm3
movsd  0x28(%rsp),%xmm0
mulsd  %xmm3,%xmm0
movsd  %xmm0,0x28(%rsp)
movsd  0x28(%rsp),%xmm0
add    $0xa8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@M_PI = global double 0.000000e+00
define double @f_chan(double %0, double %1, i32 %2) {
%4 = load double, double* @M_PI
%5 = sitofp i32 %2 to double
%6 = fadd double %1, -1.000000e+00
%7 = fdiv double %5, %6
%8 = tail call double @llvm.fabs.f64(double %0)
%9 = fcmp ult double %8, %7
br i1 %9, label %10, label %84
10: ; preds = %3
%11 = fdiv double 1.000000e+00, %5
br label %12
12: ; preds = %10, %12
%13 = phi i32 [ 1, %10 ], [ %79, %12 ]
%14 = phi double [ 5.000000e-01, %10 ], [ %78, %12 ]
%15 = sitofp i32 %13 to double
%16 = fmul double %4, %15
%17 = fmul double %6, %16
%18 = fmul double %11, %17
%19 = fdiv double %18, %1
%20 = tail call double @sin(double %19)
%21 = fdiv double %19, %1
%22 = tail call double @sin(double %21)
%23 = fdiv double %22, %21
%24 = fdiv double %21, %1
%25 = tail call double @sin(double %24)
%26 = insertelement <2 x double> poison, double %20, i64 0
%27 = insertelement <2 x double> %26, double %25, i64 1
%28 = insertelement <2 x double> poison, double %19, i64 0
%29 = insertelement <2 x double> %28, double %24, i64 1
%30 = fdiv <2 x double> %27, %29
%31 = extractelement <2 x double> %30, i64 0
%32 = fmul double %31, %23
%33 = extractelement <2 x double> %30, i64 1
%34 = fmul double %32, %33
%35 = fdiv double %24, %1
%36 = tail call double @sin(double %35)
%37 = fdiv double %35, %1
%38 = tail call double @sin(double %37)
%39 = insertelement <2 x double> poison, double %36, i64 0
%40 = insertelement <2 x double> %39, double %38, i64 1
%41 = insertelement <2 x double> poison, double %35, i64 0
%42 = insertelement <2 x double> %41, double %37, i64 1
%43 = fdiv <2 x double> %40, %42
%44 = extractelement <2 x double> %43, i64 0
%45 = fmul double %34, %44
%46 = extractelement <2 x double> %43, i64 1
%47 = fmul double %45, %46
%48 = fdiv double %37, %1
%49 = tail call double @sin(double %48)
%50 = fdiv double %48, %1
%51 = tail call double @sin(double %50)
%52 = insertelement <2 x double> poison, double %49, i64 0
%53 = insertelement <2 x double> %52, double %51, i64 1
%54 = insertelement <2 x double> poison, double %48, i64 0
%55 = insertelement <2 x double> %54, double %50, i64 1
%56 = fdiv <2 x double> %53, %55
%57 = extractelement <2 x double> %56, i64 0
%58 = fmul double %47, %57
%59 = extractelement <2 x double> %56, i64 1
%60 = fmul double %58, %59
%61 = fdiv double %50, %1
%62 = tail call double @sin(double %61)
%63 = fdiv double %61, %1
%64 = tail call double @sin(double %63)
%65 = insertelement <2 x double> poison, double %62, i64 0
%66 = insertelement <2 x double> %65, double %64, i64 1
%67 = insertelement <2 x double> poison, double %61, i64 0
%68 = insertelement <2 x double> %67, double %63, i64 1
%69 = fdiv <2 x double> %66, %68
%70 = extractelement <2 x double> %69, i64 0
%71 = fmul double %60, %70
%72 = extractelement <2 x double> %69, i64 1
%73 = fmul double %71, %72
%74 = tail call double @pow(double %73, i32 %2)
%75 = fmul double %18, %0
%76 = tail call double @cos(double %75)
%77 = fmul double %74, %76
%78 = fadd double %14, %77
%79 = add nuw nsw i32 %13, 1
%80 = icmp eq i32 %79, 40
br i1 %80, label %81, label %12
81: ; preds = %12
%82 = fmul double %6, %78
%83 = fmul double %11, %82
br label %84
84: ; preds = %3, %81
%85 = phi double [ %83, %81 ], [ 0.000000e+00, %3 ]
ret double %85
}