#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(int);
double fun1(double **vars, int n) {
  int i;
  double sum = 0;
  for (i = 0; i < n; ++i)
    sum += vars[i][0] * vars[i][0] - 10 * cos(2 * 3.1415926 * vars[i][0]) + 10;
  return sum;
}


x86 assembly (clang, -O0):
<fun1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d9 <fun1+0xc9>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsd  0xe90(%rip),%xmm0
mulsd  (%rax),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <cos@plt>
movsd  -0x28(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
imul   $0xa,%eax,%eax
cvtsi2sd %eax,%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe43(%rip),%xmm1
addsd  %xmm1,%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112e <fun1+0x1e>
movsd  -0x18(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fun1>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %esi,%esi
jle    1135 <fun1+0x25>
mov    %rdi,%r15
mov    %esi,%r14d
cmp    $0x1,%esi
jne    113e <fun1+0x2e>
xorpd  %xmm0,%xmm0
xor    %ebx,%ebx
jmp    1204 <fun1+0xf4>
xorpd  %xmm0,%xmm0
jmp    125f <fun1+0x14f>
mov    %r14d,%r12d
and    $0xfffffffe,%r12d
xorpd  %xmm0,%xmm0
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movsd  %xmm0,0x10(%rsp)
mov    (%r15,%rbx,8),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0xe94(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <cos@plt>
add    %eax,%eax
lea    (%rax,%rax,4),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  %xmm1,%xmm1
subsd  %xmm0,%xmm1
movsd  0xe6d(%rip),%xmm0
addsd  %xmm0,%xmm1
addsd  0x10(%rsp),%xmm1
movsd  %xmm1,0x8(%rsp)
mov    0x8(%r15,%rbx,8),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,0x10(%rsp)
mulsd  0xe3e(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1030 <cos@plt>
add    %eax,%eax
lea    (%rax,%rax,4),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x10(%rsp),%xmm1
mulsd  %xmm1,%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
addsd  0xe17(%rip),%xmm0
addsd  0x8(%rsp),%xmm0
add    $0x2,%rbx
cmp    %rbx,%r12
jne    1150 <fun1+0x40>
test   $0x1,%r14b
je     125f <fun1+0x14f>
mov    (%r15,%rbx,8),%rax
movsd  (%rax),%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,0x10(%rsp)
movsd  0xdda(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <cos@plt>
add    %eax,%eax
lea    (%rax,%rax,4),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  %xmm1,%xmm1
subsd  %xmm0,%xmm1
movsd  0x10(%rsp),%xmm0
addsd  0xdad(%rip),%xmm1
addsd  %xmm1,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @fun1(double** %0, i32 %1) {
%3 = alloca double**
%4 = alloca i32
%5 = alloca i32
%6 = alloca double
store double** %0, double*** %3
store i32 %1, i32* %4
store double 0.000000e+00, double* %6
store i32 0, i32* %5
br label %7
7: ; preds = %43, %2
%8 = load i32, i32* %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %46
11: ; preds = %7
%12 = load double**, double*** %3
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds double*, double** %12, i64 %14
%16 = load double*, double** %15
%17 = getelementptr inbounds double, double* %16, i64 0
%18 = load double, double* %17
%19 = load double**, double*** %3
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds double*, double** %19, i64 %21
%23 = load double*, double** %22
%24 = getelementptr inbounds double, double* %23, i64 0
%25 = load double, double* %24
%26 = load double**, double*** %3
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double*, double** %26, i64 %28
%30 = load double*, double** %29
%31 = getelementptr inbounds double, double* %30, i64 0
%32 = load double, double* %31
%33 = fmul double 0x401921FB4D12D84A, %32
%34 = fptosi double %33 to i32
%35 = call i32 @cos(i32 %34)
%36 = mul nsw i32 10, %35
%37 = sitofp i32 %36 to double
%38 = fneg double %37
%39 = call double @llvm.fmuladd.f64(double %18, double %25, double %38)
%40 = fadd double %39, 1.000000e+01
%41 = load double, double* %6
%42 = fadd double %41, %40
store double %42, double* %6
br label %43
43: ; preds = %11
%44 = load i32, i32* %5
%45 = add nsw i32 %44, 1
store i32 %45, i32* %5
br label %7
46: ; preds = %7
%47 = load double, double* %6
ret double %47
}

LLVM IR (-O2):
define double @fun1(double** nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %60
4: ; preds = %2
%5 = zext i32 %1 to i64
%6 = and i64 %5, 1
%7 = icmp eq i32 %1, 1
br i1 %7, label %42, label %8
8: ; preds = %4
%9 = and i64 %5, 4294967294
br label %10
10: ; preds = %10, %8
%11 = phi i64 [ 0, %8 ], [ %39, %10 ]
%12 = phi double [ 0.000000e+00, %8 ], [ %38, %10 ]
%13 = phi i64 [ 0, %8 ], [ %40, %10 ]
%14 = getelementptr inbounds double*, double** %0, i64 %11
%15 = load double*, double** %14
%16 = load double, double* %15
%17 = fmul double %16, 0x401921FB4D12D84A
%18 = fptosi double %17 to i32
%19 = tail call i32 @cos(i32 %18)
%20 = mul nsw i32 %19, 10
%21 = sitofp i32 %20 to double
%22 = fneg double %21
%23 = tail call double @llvm.fmuladd.f64(double %16, double %16, double %22)
%24 = fadd double %23, 1.000000e+01
%25 = fadd double %12, %24
%26 = or i64 %11, 1
%27 = getelementptr inbounds double*, double** %0, i64 %26
%28 = load double*, double** %27
%29 = load double, double* %28
%30 = fmul double %29, 0x401921FB4D12D84A
%31 = fptosi double %30 to i32
%32 = tail call i32 @cos(i32 %31)
%33 = mul nsw i32 %32, 10
%34 = sitofp i32 %33 to double
%35 = fneg double %34
%36 = tail call double @llvm.fmuladd.f64(double %29, double %29, double %35)
%37 = fadd double %36, 1.000000e+01
%38 = fadd double %25, %37
%39 = add nuw nsw i64 %11, 2
%40 = add i64 %13, 2
%41 = icmp eq i64 %40, %9
br i1 %41, label %42, label %10
42: ; preds = %10, %4
%43 = phi double [ undef, %4 ], [ %38, %10 ]
%44 = phi i64 [ 0, %4 ], [ %39, %10 ]
%45 = phi double [ 0.000000e+00, %4 ], [ %38, %10 ]
%46 = icmp eq i64 %6, 0
br i1 %46, label %60, label %47
47: ; preds = %42
%48 = getelementptr inbounds double*, double** %0, i64 %44
%49 = load double*, double** %48
%50 = load double, double* %49
%51 = fmul double %50, 0x401921FB4D12D84A
%52 = fptosi double %51 to i32
%53 = tail call i32 @cos(i32 %52)
%54 = mul nsw i32 %53, 10
%55 = sitofp i32 %54 to double
%56 = fneg double %55
%57 = tail call double @llvm.fmuladd.f64(double %50, double %50, double %56)
%58 = fadd double %57, 1.000000e+01
%59 = fadd double %45, %58
br label %60
60: ; preds = %47, %42, %2
%61 = phi double [ 0.000000e+00, %2 ], [ %43, %42 ], [ %59, %47 ]
ret double %61
}