#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);
int /*<<< orphan*/ fabsf(double);
double sin(double);
double sqrt(int /*<<< orphan*/);
double rana(double sol[], int DIM) {
  double sum, t1, t2;
  int i;
  sum = 0.0;
  for (i = 0; i < DIM - 1; i++) {
    t1 = sqrt(fabsf(sol[i + 1] + sol[i] + 1.0));
    t2 = sqrt(fabsf(sol[i + 1] - sol[i] + 1.0));
    sum += (sol[i + 1] + 1.0) * cos(t2) * sin(t1) + cos(t1) * sin(t2) * sol[i];
  }
  return sum / (double)(DIM - 1);
}


x86 assembly (clang, -O0):
<rana>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    128c <rana+0x14c>
mov    -0x8(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  0xe6a(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1030 <fabsf@plt>
mov    %eax,%edi
call   1060 <sqrt@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
subsd  (%rax,%rcx,8),%xmm0
movsd  0xe2e(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1030 <fabsf@plt>
mov    %eax,%edi
call   1060 <sqrt@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x2c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  0xe04(%rip),%xmm0
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1040 <sin@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1040 <sin@plt>
movsd  -0x48(%rbp),%xmm1
movsd  -0x40(%rbp),%xmm2
movaps %xmm0,%xmm3
movsd  -0x38(%rbp),%xmm0
mulsd  %xmm3,%xmm1
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    115e <rana+0x1e>
movsd  -0x18(%rbp),%xmm0
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rana>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
lea    -0x1(%rsi),%r14d
xorpd  %xmm1,%xmm1
cmp    $0x2,%esi
jl     124b <rana+0x10b>
mov    %rdi,%rbx
mov    %r14d,%r15d
xorpd  %xmm1,%xmm1
xor    %ebp,%ebp
nopl   0x0(%rax)
movsd  %xmm1,0x28(%rsp)
lea    0x1(%rbp),%r12
movsd  0x8(%rbx,%rbp,8),%xmm0
addsd  (%rbx,%rbp,8),%xmm0
movsd  0xe73(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1030 <fabsf@plt>
mov    %eax,%edi
call   1060 <sqrt@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x8(%rbx,%rbp,8),%xmm0
subsd  (%rbx,%rbp,8),%xmm0
addsd  0xe4a(%rip),%xmm0
call   1030 <fabsf@plt>
mov    %eax,%edi
call   1060 <sqrt@plt>
movsd  %xmm0,0x20(%rsp)
movsd  0x8(%rbx,%rbp,8),%xmm1
addsd  0xe2a(%rip),%xmm1
movsd  %xmm1,0x10(%rsp)
call   1050 <cos@plt>
mulsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1040 <sin@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0x8(%rsp),%xmm0
call   1050 <cos@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x20(%rsp),%xmm0
call   1040 <sin@plt>
movsd  0x28(%rsp),%xmm1
mulsd  0x8(%rsp),%xmm0
mulsd  (%rbx,%rbp,8),%xmm0
movsd  0x18(%rsp),%xmm2
mulsd  0x10(%rsp),%xmm2
addsd  %xmm0,%xmm2
addsd  %xmm2,%xmm1
mov    %r12,%rbp
cmp    %r12,%r15
jne    1170 <rana+0x30>
xorps  %xmm0,%xmm0
cvtsi2sd %r14d,%xmm0
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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