#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 */
int /*<<< orphan*/ F_ha(double, int);
double M_PI;
double cos(double);
double fabs(double);
double pow(int /*<<< orphan*/, int);
double f_chan(double x, int a, int n) {
  if (fabs(x) > (double)n / (double)(a - 1))
    return 0.;
  double pik, y = 0.5, h = M_PI * (double)(a - 1) / (double)n;
  for (pik = h; pik <= h * 50; pik += h) {
    y += pow(F_ha(pik, a), n) * cos(pik * x);
  }
  return y * (a - 1.) / (double)n;
}


x86 assembly (clang, -O0):
<f_chan>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
mov    %esi,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movaps 0xeb1(%rip),%xmm1
pand   %xmm1,%xmm0
cvtsi2sdl -0x18(%rbp),%xmm1
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm2
divsd  %xmm2,%xmm1
ucomisd %xmm1,%xmm0
jbe    117d <f_chan+0x4d>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1258 <f_chan+0x128>
movsd  0xe8b(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    0x2e57(%rip),%rax
movsd  (%rax),%xmm0
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm1
movsd  0xe50(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1230 <f_chan+0x100>
movsd  -0x20(%rbp),%xmm0
mov    -0x14(%rbp),%edi
call   1050 <F_ha@plt>
mov    %eax,%edi
mov    -0x18(%rbp),%esi
call   1040 <pow@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
call   1030 <cos@plt>
movaps %xmm0,%xmm2
movsd  -0x38(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x30(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11bb <f_chan+0x8b>
movsd  -0x28(%rbp),%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
movsd  0xdde(%rip),%xmm2
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<f_chan>:
push   %rbp
push   %rbx
sub    $0x48,%rsp
mov    %edi,%ebx
movapd %xmm0,%xmm4
movapd 0xebc(%rip),%xmm1
cvtsi2sd %esi,%xmm3
andpd  %xmm0,%xmm1
lea    -0x1(%rbx),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movapd %xmm3,%xmm2
movapd %xmm0,%xmm5
divsd  %xmm0,%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm2,%xmm1
ja     1247 <f_chan+0x117>
mov    0x2e71(%rip),%rax
mulsd  (%rax),%xmm5
movsd  %xmm3,0x10(%rsp)
divsd  %xmm3,%xmm5
movsd  0xe83(%rip),%xmm0
mulsd  %xmm5,%xmm0
movsd  %xmm5,(%rsp)
ucomisd %xmm5,%xmm0
jae    11a9 <f_chan+0x79>
movsd  0xe74(%rip),%xmm1
jmp    122e <f_chan+0xfe>
mov    %esi,%ebp
movsd  0xe65(%rip),%xmm1
movsd  (%rsp),%xmm2
movapd %xmm4,0x30(%rsp)
movsd  %xmm0,0x18(%rsp)
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  %xmm2,0x8(%rsp)
movsd  %xmm1,0x28(%rsp)
movapd %xmm2,%xmm0
mov    %ebx,%edi
call   1050 <F_ha@plt>
mov    %eax,%edi
mov    %ebp,%esi
call   1040 <pow@plt>
movsd  %xmm0,0x20(%rsp)
movsd  0x8(%rsp),%xmm0
mulsd  0x30(%rsp),%xmm0
call   1030 <cos@plt>
movsd  0x8(%rsp),%xmm2
movsd  0x28(%rsp),%xmm1
mulsd  0x20(%rsp),%xmm0
addsd  %xmm0,%xmm1
movsd  0x18(%rsp),%xmm0
addsd  (%rsp),%xmm2
ucomisd %xmm2,%xmm0
jae    11d0 <f_chan+0xa0>
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
addsd  0xde3(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  0x10(%rsp),%xmm0
add    $0x48,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@M_PI = global double 0.000000e+00
define double @f_chan(double %0, i32 %1, i32 %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = alloca double
%10 = alloca double
store double %0, double* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%11 = load double, double* %5
%12 = call double @llvm.fabs.f64(double %11)
%13 = load i32, i32* %7
%14 = sitofp i32 %13 to double
%15 = load i32, i32* %6
%16 = sub nsw i32 %15, 1
%17 = sitofp i32 %16 to double
%18 = fdiv double %14, %17
%19 = fcmp ogt double %12, %18
br i1 %19, label %20, label %21
20: ; preds = %3
store double 0.000000e+00, double* %4
br label %61
21: ; preds = %3
store double 5.000000e-01, double* %9
%22 = load double, double* @M_PI
%23 = load i32, i32* %6
%24 = sub nsw i32 %23, 1
%25 = sitofp i32 %24 to double
%26 = fmul double %22, %25
%27 = load i32, i32* %7
%28 = sitofp i32 %27 to double
%29 = fdiv double %26, %28
store double %29, double* %10
%30 = load double, double* %10
store double %30, double* %8
br label %31
31: ; preds = %48, %21
%32 = load double, double* %8
%33 = load double, double* %10
%34 = fmul double %33, 5.000000e+01
%35 = fcmp ole double %32, %34
br i1 %35, label %36, label %52
36: ; preds = %31
%37 = load double, double* %8
%38 = load i32, i32* %6
%39 = call i32 @F_ha(double %37, i32 %38)
%40 = load i32, i32* %7
%41 = call double @pow(i32 %39, i32 %40)
%42 = load double, double* %8
%43 = load double, double* %5
%44 = fmul double %42, %43
%45 = call double @cos(double %44)
%46 = load double, double* %9
%47 = call double @llvm.fmuladd.f64(double %41, double %45, double %46)
store double %47, double* %9
br label %48
48: ; preds = %36
%49 = load double, double* %10
%50 = load double, double* %8
%51 = fadd double %50, %49
store double %51, double* %8
br label %31
52: ; preds = %31
%53 = load double, double* %9
%54 = load i32, i32* %6
%55 = sitofp i32 %54 to double
%56 = fsub double %55, 1.000000e+00
%57 = fmul double %53, %56
%58 = load i32, i32* %7
%59 = sitofp i32 %58 to double
%60 = fdiv double %57, %59
store double %60, double* %4
br label %61
61: ; preds = %52, %20
%62 = load double, double* %4
ret double %62
}

LLVM IR (-O2):
@M_PI = global double 0.000000e+00
define double @f_chan(double %0, i32 %1, i32 %2) {
%4 = tail call double @llvm.fabs.f64(double %0)
%5 = sitofp i32 %2 to double
%6 = add nsw i32 %1, -1
%7 = sitofp i32 %6 to double
%8 = fdiv double %5, %7
%9 = fcmp ogt double %4, %8
br i1 %9, label %32, label %10
10: ; preds = %3
%11 = load double, double* @M_PI
%12 = fmul double %11, %7
%13 = fdiv double %12, %5
%14 = fmul double %13, 5.000000e+01
%15 = fcmp ugt double %13, %14
br i1 %15, label %26, label %16
16: ; preds = %10, %16
%17 = phi double [ %23, %16 ], [ 5.000000e-01, %10 ]
%18 = phi double [ %24, %16 ], [ %13, %10 ]
%19 = tail call i32 @F_ha(double %18, i32 %1)
%20 = tail call double @pow(i32 %19, i32 %2)
%21 = fmul double %18, %0
%22 = tail call double @cos(double %21)
%23 = tail call double @llvm.fmuladd.f64(double %20, double %22, double %17)
%24 = fadd double %13, %18
%25 = fcmp ugt double %24, %14
br i1 %25, label %26, label %16
26: ; preds = %16, %10
%27 = phi double [ 5.000000e-01, %10 ], [ %23, %16 ]
%28 = sitofp i32 %1 to double
%29 = fadd double %28, -1.000000e+00
%30 = fmul double %29, %27
%31 = fdiv double %30, %5
br label %32
32: ; preds = %3, %26
%33 = phi double [ %31, %26 ], [ 0.000000e+00, %3 ]
ret double %33
}