#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);
int fabs(double);
double fourier_fup(double, int);
double f_fup(double x, int n) {
  double y, pk, pi;
  int i, m = 20;
  pi = M_PI;
  if ((2. * fabs(x)) > n + 2)
    return (0);
  y = 0.5;
  for (i = 1; i < m; i++) {
    pk = i;
    pk = pk * pi * 2;
    pk = pk / (n + 2);
    y = y + fourier_fup(pk, n) * cos(pk * x);
  }
  y = y / (n + 2);
  y = y * 2;
  return y;
}


x86 assembly (clang, -O0):
<f_fup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %edi,-0x14(%rbp)
movl   $0x14,-0x38(%rbp)
mov    0x2e9a(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <fabs@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe93(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x14(%rbp),%eax
add    $0x2,%eax
cvtsi2sd %eax,%xmm1
ucomisd %xmm1,%xmm0
jbe    1192 <f_fup+0x62>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1276 <f_fup+0x146>
movsd  0xe6e(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    1242 <f_fup+0x112>
cvtsi2sdl -0x34(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  0xe32(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    -0x14(%rbp),%eax
add    $0x2,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    -0x14(%rbp),%edi
call   1050 <fourier_fup@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
call   1040 <cos@plt>
movsd  -0x48(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11a6 <f_fup+0x76>
movsd  -0x20(%rbp),%xmm0
mov    -0x14(%rbp),%eax
add    $0x2,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xd9e(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<f_fup>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
mov    %edi,%ebx
mov    0x2ea9(%rip),%rax
movsd  (%rax),%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,0x10(%rsp)
call   1030 <fabs@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
lea    0x2(%rbx),%eax
cvtsi2sd %eax,%xmm2
addsd  %xmm0,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm2,%xmm0
ja     1202 <f_fup+0xd2>
movsd  0xe84(%rip),%xmm1
movsd  0xe84(%rip),%xmm3
mov    $0x13,%ebp
movsd  %xmm2,(%rsp)
xchg   %ax,%ax
movsd  %xmm3,0x28(%rsp)
movsd  %xmm1,0x30(%rsp)
movsd  0x8(%rsp),%xmm0
mulsd  %xmm3,%xmm0
addsd  %xmm0,%xmm0
divsd  %xmm2,%xmm0
movsd  %xmm0,0x18(%rsp)
mov    %ebx,%edi
call   1050 <fourier_fup@plt>
movsd  %xmm0,0x20(%rsp)
movsd  0x18(%rsp),%xmm0
mulsd  0x10(%rsp),%xmm0
call   1040 <cos@plt>
movsd  (%rsp),%xmm2
movsd  0x30(%rsp),%xmm1
mulsd  0x20(%rsp),%xmm0
addsd  %xmm0,%xmm1
movsd  0x28(%rsp),%xmm3
addsd  0xe13(%rip),%xmm3
add    $0xffffffff,%ebp
jne    1190 <f_fup+0x60>
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm1
movapd %xmm1,%xmm0
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret

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

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