#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 parameters {
  int dummy;
};
struct dataSet {
  int dummy;
};
struct chromosome {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ executeChromosome(struct chromosome *, double *);
scalar_t__ fabs(scalar_t__);
scalar_t__ getChromosomeOutput(struct chromosome *, int /*<<< orphan*/);
scalar_t__ sin(double);
double sinWave(struct parameters *params, struct chromosome *chromo,
               struct dataSet *data) {
  double i;
  double error = 0;
  double range = 6;
  double stepSize = 0.5;
  double inputs[1];
  for (i = 0; i < range; i += stepSize) {
    inputs[0] = i;
    executeChromosome(chromo, inputs);
    error += fabs(getChromosomeOutput(chromo, 0) - sin(i));
  }
  return error;
}


x86 assembly (clang, -O0):
<sinWave>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xea4(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xe8f(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11f1 <sinWave+0xb1>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1050 <executeChromosome@plt>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1060 <getChromosomeOutput@plt>
mov    %rax,-0x48(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1040 <sin@plt>
mov    -0x48(%rbp),%rdi
sub    %rax,%rdi
call   1030 <fabs@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x38(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    117e <sinWave+0x3e>
movsd  -0x28(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sinWave>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r15
xorpd  %xmm2,%xmm2
lea    0x18(%rsp),%r14
xorpd  %xmm0,%xmm0
nopl   0x0(%rax)
movsd  %xmm0,0x10(%rsp)
movsd  %xmm2,0x8(%rsp)
movsd  %xmm2,0x18(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <executeChromosome@plt>
mov    %r15,%rdi
xor    %esi,%esi
call   1060 <getChromosomeOutput@plt>
mov    %rax,%rbx
movsd  0x8(%rsp),%xmm0
call   1040 <sin@plt>
sub    %rax,%rbx
mov    %rbx,%rdi
call   1030 <fabs@plt>
movsd  0x10(%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
addsd  %xmm1,%xmm0
movsd  0x8(%rsp),%xmm2
addsd  0xe40(%rip),%xmm2
movsd  0xe40(%rip),%xmm1
ucomisd %xmm2,%xmm1
ja     1160 <sinWave+0x20>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.parameters = type { i32 }
%struct.chromosome = type { i32 }
%struct.dataSet = type { i32 }
define double @sinWave(%struct.parameters* %0, %struct.chromosome* %1, %struct.dataSet* %2) {
%4 = alloca %struct.parameters*
%5 = alloca %struct.chromosome*
%6 = alloca %struct.dataSet*
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca [1 x double]
store %struct.parameters* %0, %struct.parameters** %4
store %struct.chromosome* %1, %struct.chromosome** %5
store %struct.dataSet* %2, %struct.dataSet** %6
store double 0.000000e+00, double* %8
store double 6.000000e+00, double* %9
store double 5.000000e-01, double* %10
store double 0.000000e+00, double* %7
br label %12
12: ; preds = %31, %3
%13 = load double, double* %7
%14 = load double, double* %9
%15 = fcmp olt double %13, %14
br i1 %15, label %16, label %35
16: ; preds = %12
%17 = load double, double* %7
%18 = getelementptr inbounds [1 x double], [1 x double]* %11, i64 0, i64 0
store double %17, double* %18
%19 = load %struct.chromosome*, %struct.chromosome** %5
%20 = getelementptr inbounds [1 x double], [1 x double]* %11, i64 0, i64 0
%21 = call i32 @executeChromosome(%struct.chromosome* %19, double* %20)
%22 = load %struct.chromosome*, %struct.chromosome** %5
%23 = call i64 @getChromosomeOutput(%struct.chromosome* %22, i32 0)
%24 = load double, double* %7
%25 = call i64 @sin(double %24)
%26 = sub nsw i64 %23, %25
%27 = call i64 @fabs(i64 %26)
%28 = sitofp i64 %27 to double
%29 = load double, double* %8
%30 = fadd double %29, %28
store double %30, double* %8
br label %31
31: ; preds = %16
%32 = load double, double* %10
%33 = load double, double* %7
%34 = fadd double %33, %32
store double %34, double* %7
br label %12
35: ; preds = %12
%36 = load double, double* %8
ret double %36
}

LLVM IR (-O2):
%struct.parameters = type { i32 }
%struct.chromosome = type { i32 }
%struct.dataSet = type { i32 }
define double @sinWave(%struct.parameters* nocapture readnone %0, %struct.chromosome* %1, %struct.dataSet* nocapture readnone %2) {
%4 = alloca [1 x double]
%5 = bitcast [1 x double]* %4 to i8*
%6 = getelementptr inbounds [1 x double], [1 x double]* %4, i64 0, i64 0
br label %7
7: ; preds = %3, %7
%8 = phi double [ 0.000000e+00, %3 ], [ %17, %7 ]
%9 = phi double [ 0.000000e+00, %3 ], [ %16, %7 ]
store double %8, double* %6
%10 = call i32 @executeChromosome(%struct.chromosome* %1, double* %6)
%11 = call i64 @getChromosomeOutput(%struct.chromosome* %1, i32 0)
%12 = call i64 @sin(double %8)
%13 = sub nsw i64 %11, %12
%14 = call i64 @fabs(i64 %13)
%15 = sitofp i64 %14 to double
%16 = fadd double %9, %15
%17 = fadd double %8, 5.000000e-01
%18 = fcmp olt double %17, 6.000000e+00
br i1 %18, label %7, label %19
19: ; preds = %7
ret double %16
}