#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 sqrt(int);
double func(double d[4]) {
  double a = 0, b = 1, c = 0;
  for (int i = 0; i < 4; i++) {
    a = a + d[i] * d[i];
    b = b * cos(d[i] / sqrt(i + 1.0));
  }
  c = (1.0 / 4000.0) * a - b + 1.0;
  return c;
}


x86 assembly (clang, -O0):
<func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xec4(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jge    11ec <func+0xcc>
movsd  -0x10(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
cvtsi2sdl -0x24(%rbp),%xmm0
movsd  0xe51(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
divsd  %xmm1,%xmm0
call   1030 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1150 <func+0x30>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
movsd  0xdf3(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xddb(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<func>:
push   %rbx
sub    $0x30,%rsp
mov    %rdi,%rbx
movsd  (%rdi),%xmm0
movsd  %xmm0,0x28(%rsp)
mulsd  %xmm0,%xmm0
xorpd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x20(%rsp)
mov    $0x1,%edi
call   1040 <sqrt@plt>
movsd  0x28(%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1030 <cos@plt>
movsd  %xmm0,0x28(%rsp)
movsd  0x8(%rbx),%xmm0
movsd  %xmm0,0x8(%rsp)
mulsd  %xmm0,%xmm0
addsd  0x20(%rsp),%xmm0
movsd  %xmm0,0x18(%rsp)
mov    $0x2,%edi
call   1040 <sqrt@plt>
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1030 <cos@plt>
movsd  %xmm0,0x20(%rsp)
movsd  0x10(%rbx),%xmm0
movsd  %xmm0,0x10(%rsp)
mulsd  %xmm0,%xmm0
addsd  0x18(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    $0x3,%edi
call   1040 <sqrt@plt>
movsd  0x10(%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1030 <cos@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0x18(%rbx),%xmm0
movsd  %xmm0,0x10(%rsp)
mulsd  %xmm0,%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    $0x4,%edi
call   1040 <sqrt@plt>
movsd  0x10(%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1030 <cos@plt>
movsd  0x20(%rsp),%xmm1
mulsd  0x28(%rsp),%xmm1
mulsd  0x18(%rsp),%xmm1
movsd  0x8(%rsp),%xmm2
mulsd  0xdc5(%rip),%xmm2
mulsd  %xmm0,%xmm1
subsd  %xmm1,%xmm2
addsd  0xdbd(%rip),%xmm2
movapd %xmm2,%xmm0
add    $0x30,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
define double @func(double* nocapture %0) {
%2 = load double, double* %0
%3 = tail call double @llvm.fmuladd.f64(double %2, double %2, double 0.000000e+00)
%4 = tail call double @sqrt(i32 1)
%5 = fdiv double %2, %4
%6 = tail call double @cos(double %5)
%7 = getelementptr inbounds double, double* %0, i64 1
%8 = load double, double* %7
%9 = tail call double @llvm.fmuladd.f64(double %8, double %8, double %3)
%10 = tail call double @sqrt(i32 2)
%11 = fdiv double %8, %10
%12 = tail call double @cos(double %11)
%13 = getelementptr inbounds double, double* %0, i64 2
%14 = load double, double* %13
%15 = tail call double @llvm.fmuladd.f64(double %14, double %14, double %9)
%16 = tail call double @sqrt(i32 3)
%17 = fdiv double %14, %16
%18 = tail call double @cos(double %17)
%19 = getelementptr inbounds double, double* %0, i64 3
%20 = load double, double* %19
%21 = tail call double @llvm.fmuladd.f64(double %20, double %20, double %15)
%22 = tail call double @sqrt(i32 4)
%23 = fdiv double %20, %22
%24 = tail call double @cos(double %23)
%25 = fneg double %6
%26 = fmul double %12, %25
%27 = fmul double %26, %18
%28 = fmul double %27, %24
%29 = tail call double @llvm.fmuladd.f64(double %21, double 2.500000e-04, double %28)
%30 = fadd double %29, 1.000000e+00
ret double %30
}