#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 cos(double);
double cheb(double i, int n, double lower_bound, double upper_bound) {
  return (lower_bound +
          ((upper_bound - lower_bound) / 2) *
              (1 + cos(1.5707963267948966 * (2 * i + 1) / (2 * (n + 1)))));
}


x86 assembly (clang, -O0):
<cheb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  0xeca(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x8(%rbp),%xmm1
addsd  %xmm1,%xmm1
movsd  0xea8(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  0xe94(%rip),%xmm0
mulsd  %xmm1,%xmm0
mov    -0xc(%rbp),%eax
add    $0x1,%eax
shl    $0x1,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
call   1030 <cos@plt>
movsd  -0x30(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
add    $0x1,%eax
cvtsi2sd %eax,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cheb>:
sub    $0x18,%rsp
movsd  %xmm1,0x10(%rsp)
subsd  %xmm1,%xmm2
mulsd  0xeda(%rip),%xmm2
movsd  %xmm2,0x8(%rsp)
addsd  %xmm0,%xmm0
addsd  0xed0(%rip),%xmm0
mulsd  0xed0(%rip),%xmm0
lea    0x2(%rdi,%rdi,1),%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
call   1030 <cos@plt>
add    $0x1,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0x8(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @cheb(double %0, i32 %1, double %2, double %3) {
%5 = alloca double
%6 = alloca i32
%7 = alloca double
%8 = alloca double
store double %0, double* %5
store i32 %1, i32* %6
store double %2, double* %7
store double %3, double* %8
%9 = load double, double* %7
%10 = load double, double* %8
%11 = load double, double* %7
%12 = fsub double %10, %11
%13 = fdiv double %12, 2.000000e+00
%14 = load double, double* %5
%15 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %14, double 1.000000e+00)
%16 = fmul double 0x3FF921FB54442D18, %15
%17 = load i32, i32* %6
%18 = add nsw i32 %17, 1
%19 = mul nsw i32 2, %18
%20 = sitofp i32 %19 to double
%21 = fdiv double %16, %20
%22 = call i32 @cos(double %21)
%23 = add nsw i32 1, %22
%24 = sitofp i32 %23 to double
%25 = call double @llvm.fmuladd.f64(double %13, double %24, double %9)
ret double %25
}

LLVM IR (-O2):
define double @cheb(double %0, i32 %1, double %2, double %3) {
%5 = fsub double %3, %2
%6 = fmul double %5, 5.000000e-01
%7 = tail call double @llvm.fmuladd.f64(double %0, double 2.000000e+00, double 1.000000e+00)
%8 = fmul double %7, 0x3FF921FB54442D18
%9 = shl i32 %1, 1
%10 = add i32 %9, 2
%11 = sitofp i32 %10 to double
%12 = fdiv double %8, %11
%13 = tail call i32 @cos(double %12)
%14 = add nsw i32 %13, 1
%15 = sitofp i32 %14 to double
%16 = tail call double @llvm.fmuladd.f64(double %6, double %15, double %2)
ret double %16
}