#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 RAND_MAX;
int /*<<< orphan*/ free(double *);
scalar_t__ malloc(int);
scalar_t__ rand();
void MY_OPTIMIZER(double (*fitnessfunction)(double *), unsigned int dim,
                  double ftarget, double maxfunevals) {
  double *x = (double *)malloc(sizeof(double) * dim);
  double f;
  double iter;
  unsigned int j;
  if (maxfunevals > 1000000000. * dim)
    maxfunevals = 1000000000. * dim;
  for (iter = 0.; iter < maxfunevals; iter++) {
    for (j = 0; j < dim; j++)
      x[j] = 10. * ((double)rand() / RAND_MAX) - 5.;
    f = fitnessfunction(x);
    if (f < ftarget)
      break;
  }
  free(x);
}


x86 assembly (clang, -O0):
<MY_OPTIMIZER>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
mov    -0xc(%rbp),%edi
shl    $0x3,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
mov    -0xc(%rbp),%eax
cvtsi2sd %rax,%xmm2
movsd  0xe93(%rip),%xmm1
mulsd  %xmm2,%xmm1
ucomisd %xmm1,%xmm0
jbe    1194 <MY_OPTIMIZER+0x64>
mov    -0xc(%rbp),%eax
cvtsi2sd %rax,%xmm1
movsd  0xe75(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1250 <MY_OPTIMIZER+0x120>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    120c <MY_OPTIMIZER+0xdc>
mov    $0x0,%al
call   1050 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e12(%rip),%rax
divsd  (%rax),%xmm0
movsd  0xe2e(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe2a(%rip),%xmm1
addsd  %xmm1,%xmm0
mov    -0x28(%rbp),%rax
mov    -0x3c(%rbp),%ecx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11b7 <MY_OPTIMIZER+0x87>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rdi
call   *%rax
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1234 <MY_OPTIMIZER+0x104>
jmp    1250 <MY_OPTIMIZER+0x120>
jmp    1239 <MY_OPTIMIZER+0x109>
movsd  0xdc7(%rip),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    119c <MY_OPTIMIZER+0x6c>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MY_OPTIMIZER>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movsd  %xmm1,(%rsp)
movsd  %xmm0,0x10(%rsp)
mov    %esi,%r15d
mov    %rdi,%r14
lea    0x0(,%r15,8),%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    %r15d,%r12d
xorps  %xmm0,%xmm0
cvtsi2sd %r12,%xmm0
mulsd  0xe8e(%rip),%xmm0
minsd  (%rsp),%xmm0
xorpd  %xmm1,%xmm1
movsd  %xmm0,0x8(%rsp)
ucomisd %xmm1,%xmm0
jbe    1206 <MY_OPTIMIZER+0xd6>
mov    0x2e5a(%rip),%r13
xchg   %ax,%ax
movsd  %xmm1,(%rsp)
test   %r15d,%r15d
je     11db <MY_OPTIMIZER+0xab>
xor    %ebp,%ebp
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <rand@plt>
movsd  0xe59(%rip),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  0x0(%r13),%xmm0
mulsd  %xmm1,%xmm0
movsd  0xe47(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rbx,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%r12
jne    11a0 <MY_OPTIMIZER+0x70>
mov    %rbx,%rdi
call   *%r14
movsd  0x10(%rsp),%xmm1
ucomisd %xmm0,%xmm1
movsd  (%rsp),%xmm1
addsd  0xe20(%rip),%xmm1
ja     1206 <MY_OPTIMIZER+0xd6>
movsd  0x8(%rsp),%xmm0
ucomisd %xmm1,%xmm0
ja     1190 <MY_OPTIMIZER+0x60>
mov    %rbx,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@RAND_MAX = global double 0.000000e+00
define void @MY_OPTIMIZER(double (double*)* %0, i32 %1, double %2, double %3) {
%5 = alloca double (double*)*
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca double*
%10 = alloca double
%11 = alloca double
%12 = alloca i32
store double (double*)* %0, double (double*)** %5
store i32 %1, i32* %6
store double %2, double* %7
store double %3, double* %8
%13 = load i32, i32* %6
%14 = zext i32 %13 to i64
%15 = mul i64 8, %14
%16 = trunc i64 %15 to i32
%17 = call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to double*
store double* %18, double** %9
%19 = load double, double* %8
%20 = load i32, i32* %6
%21 = uitofp i32 %20 to double
%22 = fmul double 1.000000e+09, %21
%23 = fcmp ogt double %19, %22
br i1 %23, label %24, label %28
24: ; preds = %4
%25 = load i32, i32* %6
%26 = uitofp i32 %25 to double
%27 = fmul double 1.000000e+09, %26
store double %27, double* %8
br label %28
28: ; preds = %24, %4
store double 0.000000e+00, double* %11
br label %29
29: ; preds = %60, %28
%30 = load double, double* %11
%31 = load double, double* %8
%32 = fcmp olt double %30, %31
br i1 %32, label %33, label %63
33: ; preds = %29
store i32 0, i32* %12
br label %34
34: ; preds = %48, %33
%35 = load i32, i32* %12
%36 = load i32, i32* %6
%37 = icmp ult i32 %35, %36
br i1 %37, label %38, label %51
38: ; preds = %34
%39 = call i64 (...) @rand()
%40 = sitofp i64 %39 to double
%41 = load double, double* @RAND_MAX
%42 = fdiv double %40, %41
%43 = call double @llvm.fmuladd.f64(double 1.000000e+01, double %42, double -5.000000e+00)
%44 = load double*, double** %9
%45 = load i32, i32* %12
%46 = zext i32 %45 to i64
%47 = getelementptr inbounds double, double* %44, i64 %46
store double %43, double* %47
br label %48
48: ; preds = %38
%49 = load i32, i32* %12
%50 = add i32 %49, 1
store i32 %50, i32* %12
br label %34
51: ; preds = %34
%52 = load double (double*)*, double (double*)** %5
%53 = load double*, double** %9
%54 = call double %52(double* %53)
store double %54, double* %10
%55 = load double, double* %10
%56 = load double, double* %7
%57 = fcmp olt double %55, %56
br i1 %57, label %58, label %59
58: ; preds = %51
br label %63
59: ; preds = %51
br label %60
60: ; preds = %59
%61 = load double, double* %11
%62 = fadd double %61, 1.000000e+00
store double %62, double* %11
br label %29
63: ; preds = %58, %29
%64 = load double*, double** %9
%65 = call i32 @free(double* %64)
ret void
}

LLVM IR (-O2):
@RAND_MAX = global double 0.000000e+00
define void @MY_OPTIMIZER(double (double*)* nocapture %0, i32 %1, double %2, double %3) {
%5 = shl i32 %1, 3
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to double*
%8 = uitofp i32 %1 to double
%9 = fmul double %8, 1.000000e+09
%10 = fcmp olt double %9, %3
%11 = select i1 %10, double %9, double %3
%12 = fcmp ogt double %11, 0.000000e+00
br i1 %12, label %13, label %34
13: ; preds = %4
%14 = icmp eq i32 %1, 0
%15 = zext i32 %1 to i64
br label %16
16: ; preds = %28, %13
%17 = phi double [ 0.000000e+00, %13 ], [ %31, %28 ]
br i1 %14, label %28, label %18
18: ; preds = %16, %18
%19 = phi i64 [ %26, %18 ], [ 0, %16 ]
%20 = tail call i64 (...) @rand()
%21 = sitofp i64 %20 to double
%22 = load double, double* @RAND_MAX
%23 = fdiv double %21, %22
%24 = tail call double @llvm.fmuladd.f64(double %23, double 1.000000e+01, double -5.000000e+00)
%25 = getelementptr inbounds double, double* %7, i64 %19
store double %24, double* %25
%26 = add nuw nsw i64 %19, 1
%27 = icmp eq i64 %26, %15
br i1 %27, label %28, label %18
28: ; preds = %18, %16
%29 = tail call double %0(double* %7)
%30 = fcmp uge double %29, %2
%31 = fadd double %17, 1.000000e+00
%32 = fcmp olt double %31, %11
%33 = select i1 %30, i1 %32, i1 false
br i1 %33, label %16, label %34
34: ; preds = %28, %4
%35 = tail call i32 @free(double* %7)
ret void
}