#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 */
struct correlate {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ correlateFree(struct correlate **);
struct correlate *correlateNew();
int /*<<< orphan*/ correlateNext(struct correlate *, double, double);
double correlateResult(struct correlate *);
double correlateArrays(double *x, double *y, int size) {
  struct correlate *c = correlateNew();
  double r;
  int i;
  for (i = 0; i < size; ++i)
    correlateNext(c, x[i], y[i]);
  r = correlateResult(c);
  correlateFree(&c);
  return r;
}


x86 assembly (clang, -O0):
<correlateArrays>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    $0x0,%al
call   1050 <correlateNew@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11a2 <correlateArrays+0x62>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
call   1030 <correlateNext@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1165 <correlateArrays+0x25>
mov    -0x20(%rbp),%rdi
call   1040 <correlateResult@plt>
movsd  %xmm0,-0x28(%rbp)
lea    -0x20(%rbp),%rdi
call   1060 <correlateFree@plt>
movsd  -0x28(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<correlateArrays>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%r15
xor    %eax,%eax
call   1050 <correlateNew@plt>
mov    %rax,%r12
mov    %rax,0x8(%rsp)
test   %ebp,%ebp
jle    118d <correlateArrays+0x4d>
mov    %ebp,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movsd  (%r15,%rbx,8),%xmm0
movsd  (%r14,%rbx,8),%xmm1
mov    %r12,%rdi
call   1030 <correlateNext@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1170 <correlateArrays+0x30>
mov    %r12,%rdi
call   1040 <correlateResult@plt>
movsd  %xmm0,(%rsp)
lea    0x8(%rsp),%rdi
call   1060 <correlateFree@plt>
movsd  (%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.correlate = type { i32 }
define double @correlateArrays(double* %0, double* %1, i32 %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca i32
%7 = alloca %struct.correlate*
%8 = alloca double
%9 = alloca i32
store double* %0, double** %4
store double* %1, double** %5
store i32 %2, i32* %6
%10 = call %struct.correlate* (...) @correlateNew()
store %struct.correlate* %10, %struct.correlate** %7
store i32 0, i32* %9
br label %11
11: ; preds = %28, %3
%12 = load i32, i32* %9
%13 = load i32, i32* %6
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %31
15: ; preds = %11
%16 = load %struct.correlate*, %struct.correlate** %7
%17 = load double*, double** %4
%18 = load i32, i32* %9
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds double, double* %17, i64 %19
%21 = load double, double* %20
%22 = load double*, double** %5
%23 = load i32, i32* %9
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double, double* %22, i64 %24
%26 = load double, double* %25
%27 = call i32 @correlateNext(%struct.correlate* %16, double %21, double %26)
br label %28
28: ; preds = %15
%29 = load i32, i32* %9
%30 = add nsw i32 %29, 1
store i32 %30, i32* %9
br label %11
31: ; preds = %11
%32 = load %struct.correlate*, %struct.correlate** %7
%33 = call double @correlateResult(%struct.correlate* %32)
store double %33, double* %8
%34 = call i32 @correlateFree(%struct.correlate** %7)
%35 = load double, double* %8
ret double %35
}

LLVM IR (-O2):
%struct.correlate = type { i32 }
define double @correlateArrays(double* nocapture %0, double* nocapture %1, i32 %2) {
%4 = alloca %struct.correlate*
%5 = bitcast %struct.correlate** %4 to i8*
%6 = tail call %struct.correlate* (...) @correlateNew()
store %struct.correlate* %6, %struct.correlate** %4
%7 = icmp sgt i32 %2, 0
br i1 %7, label %8, label %19
8: ; preds = %3
%9 = zext i32 %2 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ 0, %8 ], [ %17, %10 ]
%12 = getelementptr inbounds double, double* %0, i64 %11
%13 = load double, double* %12
%14 = getelementptr inbounds double, double* %1, i64 %11
%15 = load double, double* %14
%16 = tail call i32 @correlateNext(%struct.correlate* %6, double %13, double %15)
%17 = add nuw nsw i64 %11, 1
%18 = icmp eq i64 %17, %9
br i1 %18, label %19, label %10
19: ; preds = %10, %3
%20 = tail call double @correlateResult(%struct.correlate* %6)
%21 = call i32 @correlateFree(%struct.correlate** %4)
ret double %20
}