// File: /workspace/github_cpp_makefile_star2_O3/mateuz[P]MTS-LS1/source/main.cpp
// Function: mts_ls1(Benchmarks*, unsigned int, std::vector<double, std::allocator<double>>&)
void mts_ls1(Benchmarks * bench, unsigned maxevals, vector<double>& sol){
  //unsigned int n_dim = ndim;
  unsigned totalevals = 0;
  double best_fitness = bench->compute(sol.data());

  vector<double> SR(sol.size());
  for( unsigned i = 0; i < SR.size(); i++ ){
    SR[i] = (bench->getMaxX() - bench->getMinX()) * 0.4;
  }

  LSresult result;
  LSresult current_best = {sol, best_fitness, 0};

  vector<double> improvement(dim, 0.0);

  vector<double> dim_sorted(dim);
  iota(dim_sorted.begin(), dim_sorted.end(), 0);

  double improve;
  //warm-up
  if( totalevals < maxevals ){
    next_permutation(dim_sorted.begin(), dim_sorted.end());
    for( auto it = dim_sorted.begin(); it != dim_sorted.end(); it++ ){
      result = mts_ls1_improve_dim(bench, sol, best_fitness, *it, SR);
      totalevals += result.evals;
      improve = max(current_best.fitness - result.fitness, 0.0);
      improvement[*it] = improve;

      if( improve > 0.0 ){
        printf("[1] %.10lf > %.10lf ~ improve: %.20lf\n", current_best.fitness, result.fitness, improve);
        current_best = result;
      } else {
        SR[*it] /= 2.0f;
      }
    }
  }

  iota(dim_sorted.begin(), dim_sorted.end(), 0);
  sort(dim_sorted.begin(), dim_sorted.end(), [&](unsigned i1, unsigned i2) { return improvement[i1] > improvement[i2]; });

  int i, d = 0, next_d, next_i;
  while( totalevals < maxevals ){
    i = dim_sorted[d];
    result = mts_ls1_improve_dim(bench, current_best.solution, current_best.fitness, i, SR);
    totalevals += result.evals;
    improve = max(current_best.fitness - result.fitness, 0.0);
    improvement[i] = improve;
    next_d = (d+1)%dim;
    next_i = dim_sorted[next_d];

    if( improve > 0.0 ){
      printf("[2] %.10lf > %.10lf ~ improve: %.20lf\n", current_best.fitness, result.fitness, improve);
      current_best = result;

      if( improvement[i] < improvement[next_i] ){
        iota(dim_sorted.begin(), dim_sorted.end(), 0);
        sort(dim_sorted.begin(), dim_sorted.end(), [&](unsigned i1, unsigned i2) { return improvement[i1] > improvement[i2]; });
      }
    } else {
      SR[i] /= 2.0;
      d = next_d;
      if( SR[i] < 1e-15 ){
        SR[i] = (bench->getMaxX() - bench->getMinX()) * 0.4;
      }
    }
  }
  sol = current_best.solution;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rdx, %rbx
movl %esi, -0x2c(%rbp)
movq %rdi, %r12
movq (%rdx), %rsi
movq (%rdi), %rax
callq *0x10(%rax)
movsd %xmm0, -0x108(%rbp)
movq 0x8(%rbx), %rsi
movq %rbx, -0x98(%rbp)
subq (%rbx), %rsi
sarq $0x3, %rsi
leaq -0xd8(%rbp), %rbx
leaq -0x90(%rbp), %rdx
movq %rbx, %rdi
callq 0xa746
movq 0x8(%rbx), %rax
cmpq (%rbx), %rax
je 0x931a
movl $0x1, %r14d
xorl %r15d, %r15d
movq %r12, %rdi
callq 0x674e
movl %eax, %ebx
movq %r12, %rdi
callq 0x6742
subl %eax, %ebx
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
mulsd 0x1ed4(%rip), %xmm0     # 0xb1c8
movq -0xd8(%rbp), %rax
movsd %xmm0, (%rax,%r15,8)
movl %r14d, %r15d
movq -0xd0(%rbp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
incl %r14d
cmpq %r15, %rcx
ja 0x92d1
xorpd %xmm0, %xmm0
movapd %xmm0, -0x90(%rbp)
movq $0x0, -0x80(%rbp)
leaq -0x100(%rbp), %rdi
movq -0x98(%rbp), %rsi
callq 0xa5e0
movsd -0x108(%rbp), %xmm0
movsd %xmm0, -0xe8(%rbp)
movl $0x0, -0xe0(%rbp)
movl 0x5e67(%rip), %esi      # 0xf1c8
leaq -0xc0(%rbp), %rdx
movq $0x0, (%rdx)
leaq -0x68(%rbp), %rdi
leaq -0x50(%rbp), %rcx
callq 0xa7de
movl 0x5e46(%rip), %esi      # 0xf1c8
leaq -0x50(%rbp), %rdi
leaq -0xc0(%rbp), %rdx
callq 0xa746
movq %r12, -0x38(%rbp)
movq -0x50(%rbp), %rbx
movq -0x48(%rbp), %r12
cmpq %r12, %rbx
je 0x93c3
xorpd %xmm0, %xmm0
movsd 0x1c69(%rip), %xmm1     # 0xb018
movq %rbx, %rax
movsd %xmm0, (%rax)
addsd %xmm1, %xmm0
addq $0x8, %rax
cmpq %r12, %rax
jne 0x93b2
xorl %r13d, %r13d
cmpl $0x0, -0x2c(%rbp)
je 0x957a
movq %rbx, %rdi
movq %r12, %rsi
callq 0xa888
movq -0x50(%rbp), %rbx
movq -0x48(%rbp), %r12
cmpq %r12, %rbx
je 0x957a
leaq -0x78(%rbp), %r15
xorl %r13d, %r13d
leaq -0xa8(%rbp), %r14
cvttsd2si (%rbx), %rcx
leaq -0xc0(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x98(%rbp), %rdx
movsd -0x108(%rbp), %xmm0
leaq -0xd8(%rbp), %r8
callq 0x9090
movq -0x90(%rbp), %rdi
movq -0xc0(%rbp), %rax
movq %rax, -0x90(%rbp)
movups -0xb8(%rbp), %xmm0
movups %xmm0, -0x88(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0xc0(%rbp)
movq $0x0, -0xb0(%rbp)
testq %rdi, %rdi
je 0x9488
callq 0x31f0
movq -0xc0(%rbp), %rdi
movl 0x8(%r14), %eax
movl %eax, 0x8(%r15)
movq (%r14), %rax
movq %rax, (%r15)
testq %rdi, %rdi
je 0x9496
callq 0x31f0
jmp 0x9496
movl 0x8(%r14), %eax
movl %eax, 0x8(%r15)
movq (%r14), %rax
movq %rax, (%r15)
movsd -0xe8(%rbp), %xmm0
subsd -0x78(%rbp), %xmm0
xorpd %xmm2, %xmm2
maxsd %xmm0, %xmm2
movsd (%rbx), %xmm0
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
movsd 0x1d0d(%rip), %xmm1     # 0xb1d0
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rdx
andq %rcx, %rdx
orq %rax, %rdx
addl -0x70(%rbp), %r13d
movq -0x68(%rbp), %rax
movsd %xmm2, (%rax,%rdx,8)
ucomisd 0x1b99(%rip), %xmm2     # 0xb080
jbe 0x952d
movsd -0xe8(%rbp), %xmm0
movsd -0x78(%rbp), %xmm1
leaq 0x1d67(%rip), %rdi      # 0xb264
movb $0x3, %al
callq 0x3060
leaq -0x100(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0xa660
movl 0x8(%r15), %eax
leaq -0xe8(%rbp), %rcx
movl %eax, 0x8(%rcx)
movq (%r15), %rax
movq %rax, (%rcx)
jmp 0x9565
movsd (%rbx), %xmm0
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rdx
andq %rcx, %rdx
orq %rax, %rdx
movq -0xd8(%rbp), %rax
movsd (%rax,%rdx,8), %xmm0
mulsd 0x1ac8(%rip), %xmm0     # 0xb028
movsd %xmm0, (%rax,%rdx,8)
addq $0x8, %rbx
movq -0x48(%rbp), %r12
cmpq %r12, %rbx
jne 0x93fa
movq -0x50(%rbp), %rbx
cmpq %r12, %rbx
je 0x965d
xorpd %xmm0, %xmm0
movsd 0x1a89(%rip), %xmm1     # 0xb018
movq %rbx, %rax
movsd %xmm0, (%rax)
addsd %xmm1, %xmm0
addq $0x8, %rax
cmpq %r12, %rax
jne 0x9592
movq %r12, %r14
subq %rbx, %r14
movq %r14, %rax
sarq $0x3, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
leaq -0x68(%rbp), %rcx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x9e32
cmpq $0x81, %r14
jl 0x964e
leaq 0x80(%rbx), %r14
leaq -0x68(%rbp), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0xa135
cmpq %r12, %r14
je 0x965d
movq -0x68(%rbp), %rax
movsd -0x8(%r14), %xmm1
movsd (%r14), %xmm0
cvttsd2si %xmm0, %rcx
movl %ecx, %ecx
cvttsd2si %xmm1, %rdx
movsd (%rax,%rcx,8), %xmm2
movl %edx, %edx
ucomisd (%rax,%rdx,8), %xmm2
movq %r14, %rdx
jbe 0x963f
movq %r14, %rdx
movsd %xmm1, (%rdx)
movsd -0x10(%rdx), %xmm1
cvttsd2si %xmm1, %rsi
movsd (%rax,%rcx,8), %xmm2
movl %esi, %esi
addq $-0x8, %rdx
ucomisd (%rax,%rsi,8), %xmm2
ja 0x961f
movsd %xmm0, (%rdx)
addq $0x8, %r14
cmpq %r12, %r14
jne 0x95f4
jmp 0x965d
leaq -0x68(%rbp), %rdx
movq %rbx, %rdi
movq %r12, %rsi
callq 0xa135
cmpl -0x2c(%rbp), %r13d
jae 0x9932
xorl %r15d, %r15d
movslq %r15d, %rax
movq -0x50(%rbp), %rcx
cvttsd2si (%rcx,%rax,8), %r14d
movsd -0xe8(%rbp), %xmm0
leaq -0xc0(%rbp), %rdi
movq -0x38(%rbp), %rsi
leaq -0x100(%rbp), %rdx
movl %r14d, %ecx
leaq -0xd8(%rbp), %r8
callq 0x9090
movq -0x90(%rbp), %rdi
movq -0xc0(%rbp), %rax
movq %rax, -0x90(%rbp)
movups -0xb8(%rbp), %xmm0
movups %xmm0, -0x88(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0xc0(%rbp)
movq $0x0, -0xb0(%rbp)
testq %rdi, %rdi
je 0x970c
callq 0x31f0
movq -0xc0(%rbp), %rdi
leaq -0xa8(%rbp), %rdx
movl 0x8(%rdx), %eax
leaq -0x78(%rbp), %rcx
movl %eax, 0x8(%rcx)
movq (%rdx), %rax
movq %rax, (%rcx)
testq %rdi, %rdi
je 0x9723
callq 0x31f0
jmp 0x9723
leaq -0xa8(%rbp), %rdx
movl 0x8(%rdx), %eax
leaq -0x78(%rbp), %rcx
movl %eax, 0x8(%rcx)
movq (%rdx), %rax
movq %rax, (%rcx)
movsd -0xe8(%rbp), %xmm0
subsd -0x78(%rbp), %xmm0
xorpd %xmm2, %xmm2
maxsd %xmm0, %xmm2
movslq %r14d, %r12
movq -0x68(%rbp), %rax
addl -0x70(%rbp), %r13d
movsd %xmm2, (%rax,%r12,8)
leal 0x1(%r15), %eax
xorl %edx, %edx
divl 0x5a73(%rip)            # 0xf1c8
movl %edx, %ebx
ucomisd 0x1921(%rip), %xmm2     # 0xb080
jbe 0x98b4
movslq %ebx, %rax
movq -0x50(%rbp), %rcx
cvttsd2si (%rcx,%rax,8), %ebx
movsd -0xe8(%rbp), %xmm0
movsd -0x78(%rbp), %xmm1
leaq 0x1b06(%rip), %rdi      # 0xb28b
movb $0x3, %al
callq 0x3060
leaq -0x100(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0xa660
leaq -0x78(%rbp), %rdx
movl 0x8(%rdx), %eax
leaq -0xe8(%rbp), %rcx
movl %eax, 0x8(%rcx)
movq (%rdx), %rax
movq %rax, (%rcx)
movq -0x68(%rbp), %rax
movslq %ebx, %rcx
movsd (%rax,%rcx,8), %xmm0
ucomisd (%rax,%r12,8), %xmm0
jbe 0x9915
movq -0x50(%rbp), %rbx
movq -0x48(%rbp), %r14
cmpq %r14, %rbx
je 0x9915
xorpd %xmm0, %xmm0
movq %rbx, %rax
movsd 0x182a(%rip), %xmm1     # 0xb018
movsd %xmm0, (%rax)
addsd %xmm1, %xmm0
addq $0x8, %rax
cmpq %r14, %rax
jne 0x97ee
movq %r14, %r12
subq %rbx, %r12
movq %r12, %rax
sarq $0x3, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %rbx, %rdi
movq %r14, %rsi
leaq -0x68(%rbp), %rcx
callq 0xa209
cmpq $0x81, %r12
jl 0x9921
leaq 0x80(%rbx), %r12
movq %rbx, %rdi
movq %r12, %rsi
leaq -0x68(%rbp), %rdx
callq 0xa50c
cmpq %r14, %r12
je 0x9915
movq -0x68(%rbp), %rax
movsd -0x8(%r12), %xmm1
movsd (%r12), %xmm0
cvttsd2si %xmm0, %rcx
movl %ecx, %ecx
cvttsd2si %xmm1, %rdx
movsd (%rax,%rcx,8), %xmm2
movl %edx, %edx
ucomisd (%rax,%rdx,8), %xmm2
movq %r12, %rdx
jbe 0x98a5
movq %r12, %rdx
movsd %xmm1, (%rdx)
movsd -0x10(%rdx), %xmm1
cvttsd2si %xmm1, %rsi
movsd (%rax,%rcx,8), %xmm2
movl %esi, %esi
addq $-0x8, %rdx
ucomisd (%rax,%rsi,8), %xmm2
ja 0x9885
movsd %xmm0, (%rdx)
addq $0x8, %r12
cmpq %r14, %r12
jne 0x9858
jmp 0x9915
movq -0xd8(%rbp), %rax
movsd (%rax,%r12,8), %xmm0
mulsd 0x175f(%rip), %xmm0     # 0xb028
movsd %xmm0, (%rax,%r12,8)
movsd 0x1901(%rip), %xmm1     # 0xb1d8
ucomisd %xmm0, %xmm1
jbe 0x9912
movq -0x38(%rbp), %rdi
callq 0x674e
movl %eax, %r14d
movq -0x38(%rbp), %rdi
callq 0x6742
subl %eax, %r14d
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
mulsd 0x18c3(%rip), %xmm0     # 0xb1c8
movq -0xd8(%rbp), %rax
movsd %xmm0, (%rax,%r12,8)
movl %ebx, %r15d
cmpl -0x2c(%rbp), %r13d
jb 0x966a
jmp 0x9932
movq %rbx, %rdi
movq %r14, %rsi
leaq -0x68(%rbp), %rdx
callq 0xa50c
jmp 0x9915
leaq -0x100(%rbp), %rsi
movq -0x98(%rbp), %rdi
callq 0xa660
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x9953
callq 0x31f0
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x9961
callq 0x31f0
movq -0x100(%rbp), %rdi
testq %rdi, %rdi
je 0x9972
callq 0x31f0
movq -0x90(%rbp), %rdi
testq %rdi, %rdi
je 0x9983
callq 0x31f0
movq -0xd8(%rbp), %rdi
testq %rdi, %rdi
je 0x9994
callq 0x31f0
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x99bf
jmp 0x99bf
movq %rax, %rbx
jmp 0x99d0
movq %rax, %rbx
jmp 0x99de
movq %rax, %rbx
jmp 0x99ef
jmp 0x99bf
jmp 0x99bf
jmp 0x99bf
movq %rax, %rbx
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x99d0
callq 0x31f0
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x99de
callq 0x31f0
movq -0x100(%rbp), %rdi
testq %rdi, %rdi
je 0x99ef
callq 0x31f0
movq -0x90(%rbp), %rdi
testq %rdi, %rdi
je 0x9a05
callq 0x31f0
jmp 0x9a05
movq %rax, %rbx
movq -0xd8(%rbp), %rdi
testq %rdi, %rdi
je 0x9a16
callq 0x31f0
movq %rbx, %rdi
callq 0x3320