#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 spec_score(int, double *);
double spec_total(double *);
void spec_replicators(int N, double x, double y[], double result[],
                      void *data) {
  double tot = spec_total(y);
  int i;
  for (i = 0; i < N; i++) {
    result[i] = y[i] * (spec_score(i, y) - tot);
  }
}


x86 assembly (clang, -O0):
<spec_replicators>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <spec_total@plt>
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11a7 <spec_replicators+0x87>
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x34(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1030 <spec_score@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm1
mulsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1151 <spec_replicators+0x31>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spec_replicators>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebx
mov    %rsi,%rdi
call   1040 <spec_total@plt>
test   %ebx,%ebx
jle    1185 <spec_replicators+0x65>
movapd %xmm0,%xmm1
mov    %ebx,%r12d
xor    %ebx,%ebx
movsd  %xmm0,0x8(%rsp)
xchg   %ax,%ax
movsd  (%r15,%rbx,8),%xmm0
movsd  %xmm0,0x10(%rsp)
mov    %ebx,%edi
mov    %r15,%rsi
call   1030 <spec_score@plt>
movsd  0x8(%rsp),%xmm1
subsd  %xmm1,%xmm0
mulsd  0x10(%rsp),%xmm0
movsd  %xmm0,(%r14,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1150 <spec_replicators+0x30>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @spec_replicators(i32 %0, double %1, double* %2, double* %3, i8* %4) {
%6 = alloca i32
%7 = alloca double
%8 = alloca double*
%9 = alloca double*
%10 = alloca i8*
%11 = alloca double
%12 = alloca i32
store i32 %0, i32* %6
store double %1, double* %7
store double* %2, double** %8
store double* %3, double** %9
store i8* %4, i8** %10
%13 = load double*, double** %8
%14 = call double @spec_total(double* %13)
store double %14, double* %11
store i32 0, i32* %12
br label %15
15: ; preds = %35, %5
%16 = load i32, i32* %12
%17 = load i32, i32* %6
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %38
19: ; preds = %15
%20 = load double*, double** %8
%21 = load i32, i32* %12
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds double, double* %20, i64 %22
%24 = load double, double* %23
%25 = load i32, i32* %12
%26 = load double*, double** %8
%27 = call double @spec_score(i32 %25, double* %26)
%28 = load double, double* %11
%29 = fsub double %27, %28
%30 = fmul double %24, %29
%31 = load double*, double** %9
%32 = load i32, i32* %12
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %31, i64 %33
store double %30, double* %34
br label %35
35: ; preds = %19
%36 = load i32, i32* %12
%37 = add nsw i32 %36, 1
store i32 %37, i32* %12
br label %15
38: ; preds = %15
ret void
}

LLVM IR (-O2):
define void @spec_replicators(i32 %0, double %1, double* %2, double* nocapture writeonly %3, i8* nocapture readnone %4) {
%6 = tail call double @spec_total(double* %2)
%7 = icmp sgt i32 %0, 0
br i1 %7, label %8, label %21
8: ; preds = %5
%9 = zext i32 %0 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ 0, %8 ], [ %19, %10 ]
%12 = getelementptr inbounds double, double* %2, i64 %11
%13 = load double, double* %12
%14 = trunc i64 %11 to i32
%15 = tail call double @spec_score(i32 %14, double* %2)
%16 = fsub double %15, %6
%17 = fmul double %13, %16
%18 = getelementptr inbounds double, double* %3, i64 %11
store double %17, double* %18
%19 = add nuw nsw i64 %11, 1
%20 = icmp eq i64 %19, %9
br i1 %20, label %21, label %10
21: ; preds = %10, %5
ret void
}