#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 cos(double);
double fabs(double);
double ComputeA(double freq, int r, double ad[], double x[], double y[]) {
  int i;
  double xc, c, denom, numer;
  denom = numer = 0;
  xc = cos(6.2831853071795865 * freq);
  for (i = 0; i <= r; i++) {
    c = xc - x[i];
    if (fabs(c) < 1.0e-7) {
      numer = y[i];
      denom = 1;
      break;
    }
    c = ad[i] / c;
    denom += c;
    numer += c * y[i];
  }
  return numer / denom;
}


x86 assembly (clang, -O0):
<ComputeA>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xebc(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
call   1030 <cos@plt>
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     121b <ComputeA+0x10b>
movsd  -0x38(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm1
movaps 0xe97(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xe73(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11c3 <ComputeA+0xb3>
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  0xe57(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
jmp    121b <ComputeA+0x10b>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
divsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
addsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x50(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    115a <ComputeA+0x4a>
movsd  -0x50(%rbp),%xmm0
divsd  -0x48(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ComputeA>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rsi,%r15
mov    %edi,%ebx
mulsd  0xed5(%rip),%xmm0
call   1030 <cos@plt>
test   %ebx,%ebx
js     119b <ComputeA+0x8b>
movapd %xmm0,%xmm1
add    $0x1,%ebx
xorpd  %xmm0,%xmm0
xor    %eax,%eax
movapd 0xed7(%rip),%xmm3
movsd  0xeb7(%rip),%xmm4
xorpd  %xmm2,%xmm2
cs nopw 0x0(%rax,%rax,1)
nop
movapd %xmm1,%xmm5
subsd  (%r12,%rax,8),%xmm5
movapd %xmm5,%xmm6
andpd  %xmm3,%xmm6
ucomisd %xmm6,%xmm4
ja     11a5 <ComputeA+0x95>
movsd  (%r15,%rax,8),%xmm6
divsd  %xmm5,%xmm6
addsd  %xmm6,%xmm2
mulsd  (%r14,%rax,8),%xmm6
addsd  %xmm6,%xmm0
add    $0x1,%rax
cmp    %rax,%rbx
jne    1160 <ComputeA+0x50>
jmp    11b3 <ComputeA+0xa3>
xorpd  %xmm2,%xmm2
xorpd  %xmm0,%xmm0
jmp    11b3 <ComputeA+0xa3>
movsd  (%r14,%rax,8),%xmm0
movsd  0xe5d(%rip),%xmm2
divsd  %xmm2,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define double @ComputeA(double %0, i32 %1, double* nocapture %2, double* nocapture %3, double* nocapture %4) {
%6 = fmul double %0, 0x401921FB54442D18
%7 = tail call double @cos(double %6)
%8 = icmp slt i32 %1, 0
br i1 %8, label %35, label %9
9: ; preds = %5
%10 = add nuw i32 %1, 1
%11 = zext i32 %10 to i64
br label %12
12: ; preds = %9, %25
%13 = phi i64 [ 0, %9 ], [ %33, %25 ]
%14 = phi double [ 0.000000e+00, %9 ], [ %32, %25 ]
%15 = phi double [ 0.000000e+00, %9 ], [ %29, %25 ]
%16 = getelementptr inbounds double, double* %3, i64 %13
%17 = load double, double* %16
%18 = fsub double %7, %17
%19 = tail call double @llvm.fabs.f64(double %18)
%20 = fcmp olt double %19, 0x3E7AD7F29ABCAF48
br i1 %20, label %21, label %25
21: ; preds = %12
%22 = and i64 %13, 4294967295
%23 = getelementptr inbounds double, double* %4, i64 %22
%24 = load double, double* %23
br label %35
25: ; preds = %12
%26 = getelementptr inbounds double, double* %2, i64 %13
%27 = load double, double* %26
%28 = fdiv double %27, %18
%29 = fadd double %15, %28
%30 = getelementptr inbounds double, double* %4, i64 %13
%31 = load double, double* %30
%32 = tail call double @llvm.fmuladd.f64(double %28, double %31, double %14)
%33 = add nuw nsw i64 %13, 1
%34 = icmp eq i64 %33, %11
br i1 %34, label %35, label %12
35: ; preds = %25, %5, %21
%36 = phi double [ 1.000000e+00, %21 ], [ 0.000000e+00, %5 ], [ %29, %25 ]
%37 = phi double [ %24, %21 ], [ 0.000000e+00, %5 ], [ %32, %25 ]
%38 = fdiv double %37, %36
ret double %38
}