// File: /workspace/github_cpp_makefile_star2_O1/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, -0x34(%rbp)
movq %rdi, %r12
movq (%rdx), %rsi
movq (%rdi), %rax
callq *0x10(%rax)
movsd %xmm0, -0x30(%rbp)
movq 0x8(%rbx), %rsi
movq %rbx, -0x88(%rbp)
subq (%rbx), %rsi
sarq $0x3, %rsi
leaq -0xb8(%rbp), %rbx
leaq -0x80(%rbp), %rdx
movq %rbx, %rdi
callq 0xa784
movq 0x8(%rbx), %rax
cmpq (%rbx), %rax
je 0x9324
movl $0x1, %r14d
xorl %r15d, %r15d
movq %r12, %rdi
callq 0x6758
movl %eax, %ebx
movq %r12, %rdi
callq 0x674c
subl %eax, %ebx
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
mulsd 0x1eca(%rip), %xmm0     # 0xb1c8
movq -0xb8(%rbp), %rax
movsd %xmm0, (%rax,%r15,8)
movl %r14d, %r15d
movq -0xb0(%rbp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
incl %r14d
cmpq %r15, %rcx
ja 0x92db
xorpd %xmm0, %xmm0
movapd %xmm0, -0x80(%rbp)
movq $0x0, -0x70(%rbp)
leaq -0x108(%rbp), %rdi
movq -0x88(%rbp), %rsi
callq 0xa62c
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0xf0(%rbp)
movl $0x0, -0xe8(%rbp)
movl 0x5e63(%rip), %esi      # 0xf1c8
leaq -0xe0(%rbp), %rdx
movq $0x0, (%rdx)
leaq -0xa0(%rbp), %rdi
leaq -0x58(%rbp), %rcx
callq 0xa818
movl 0x5e3f(%rip), %esi      # 0xf1c8
leaq -0x58(%rbp), %rdi
leaq -0xe0(%rbp), %rdx
callq 0xa784
movq %r12, -0x40(%rbp)
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rsi
cmpq %rsi, %rdi
je 0x93ca
xorpd %xmm0, %xmm0
movsd 0x1c62(%rip), %xmm1     # 0xb018
movq %rdi, %rax
movsd %xmm0, (%rax)
addsd %xmm1, %xmm0
addq $0x8, %rax
cmpq %rsi, %rax
jne 0x93b9
xorl %r13d, %r13d
cmpl $0x0, -0x34(%rbp)
je 0x9559
callq 0xa8c2
movq -0x58(%rbp), %r15
cmpq -0x50(%rbp), %r15
je 0x9559
leaq -0x68(%rbp), %r14
xorl %r13d, %r13d
leaq -0xc8(%rbp), %rbx
leaq -0xb8(%rbp), %r12
cvttsd2si (%r15), %rcx
leaq -0xe0(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x88(%rbp), %rdx
movsd -0x30(%rbp), %xmm0
movq %r12, %r8
callq 0x90a0
movq -0x80(%rbp), %rdi
movq -0xe0(%rbp), %rax
movq %rax, -0x80(%rbp)
movups -0xd8(%rbp), %xmm0
movups %xmm0, -0x78(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0xe0(%rbp)
movq $0x0, -0xd0(%rbp)
testq %rdi, %rdi
je 0x945c
callq 0x31f0
movl 0x8(%rbx), %eax
movl %eax, 0x8(%r14)
movq (%rbx), %rax
movq %rax, (%r14)
movq -0xe0(%rbp), %rdi
testq %rdi, %rdi
je 0x947a
callq 0x31f0
movsd -0xf0(%rbp), %xmm0
subsd -0x68(%rbp), %xmm0
xorpd %xmm2, %xmm2
maxsd %xmm0, %xmm2
movsd (%r15), %xmm0
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
movsd 0x1d28(%rip), %xmm1     # 0xb1d0
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rdx
andq %rcx, %rdx
orq %rax, %rdx
addl -0x60(%rbp), %r13d
movq -0xa0(%rbp), %rax
movsd %xmm2, (%rax,%rdx,8)
ucomisd 0x1bb1(%rip), %xmm2     # 0xb080
jbe 0x9512
movsd -0xf0(%rbp), %xmm0
movsd -0x68(%rbp), %xmm1
leaq 0x1d7f(%rip), %rdi      # 0xb264
movb $0x3, %al
callq 0x3060
leaq -0x108(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0xa6ac
movl 0x8(%r14), %eax
leaq -0xf0(%rbp), %rcx
movl %eax, 0x8(%rcx)
movq (%r14), %rax
movq %rax, (%rcx)
jmp 0x954b
movsd (%r15), %xmm0
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rdx
andq %rcx, %rdx
orq %rax, %rdx
movq -0xb8(%rbp), %rax
movsd (%rax,%rdx,8), %xmm0
mulsd 0x1ae2(%rip), %xmm0     # 0xb028
movsd %xmm0, (%rax,%rdx,8)
addq $0x8, %r15
cmpq -0x50(%rbp), %r15
jne 0x93ff
movq -0x58(%rbp), %r12
movq -0x50(%rbp), %rbx
cmpq %rbx, %r12
je 0x965e
xorpd %xmm0, %xmm0
movsd 0x1aa2(%rip), %xmm1     # 0xb018
movq %r12, %rax
movsd %xmm0, (%rax)
addsd %xmm1, %xmm0
addq $0x8, %rax
cmpq %rbx, %rax
jne 0x9579
cmpq %rbx, %r12
je 0x965e
movq %rbx, %r14
subq %r12, %r14
movq %r14, %rax
sarq $0x3, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
leaq -0xa0(%rbp), %rcx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x9e41
cmpq $0x81, %r14
jl 0x964c
leaq 0x80(%r12), %r14
leaq -0xa0(%rbp), %rdx
movq %r12, %rdi
movq %r14, %rsi
callq 0xa160
cmpq %rbx, %r14
je 0x965e
movq -0xa0(%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 0x963d
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 0x961d
movsd %xmm0, (%rdx)
addq $0x8, %r14
cmpq %rbx, %r14
jne 0x95f2
jmp 0x965e
leaq -0xa0(%rbp), %rdx
movq %r12, %rdi
movq %rbx, %rsi
callq 0xa160
cmpl -0x34(%rbp), %r13d
jae 0x992b
movl %r13d, %r15d
xorl %r14d, %r14d
leaq -0xa0(%rbp), %r13
movslq %r14d, %rax
movq -0x58(%rbp), %rcx
cvttsd2si (%rcx,%rax,8), %ebx
movsd -0xf0(%rbp), %xmm0
leaq -0xe0(%rbp), %rdi
movq -0x40(%rbp), %rsi
leaq -0x108(%rbp), %rdx
movl %ebx, %ecx
leaq -0xb8(%rbp), %r8
callq 0x90a0
movq -0x80(%rbp), %rdi
movq -0xe0(%rbp), %rax
movq %rax, -0x80(%rbp)
movups -0xd8(%rbp), %xmm0
movups %xmm0, -0x78(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0xe0(%rbp)
movq $0x0, -0xd0(%rbp)
testq %rdi, %rdi
je 0x96e2
callq 0x31f0
leaq -0xc8(%rbp), %rdx
movl 0x8(%rdx), %eax
leaq -0x68(%rbp), %rcx
movl %eax, 0x8(%rcx)
movq (%rdx), %rax
movq %rax, (%rcx)
movq -0xe0(%rbp), %rdi
testq %rdi, %rdi
je 0x970a
callq 0x31f0
movsd -0xf0(%rbp), %xmm0
subsd -0x68(%rbp), %xmm0
xorpd %xmm2, %xmm2
maxsd %xmm0, %xmm2
movslq %ebx, %r12
movq -0xa0(%rbp), %rax
addl -0x60(%rbp), %r15d
movsd %xmm2, (%rax,%r12,8)
leal 0x1(%r14), %eax
xorl %edx, %edx
divl 0x5a89(%rip)            # 0xf1c8
movl %edx, %ebx
ucomisd 0x1937(%rip), %xmm2     # 0xb080
jbe 0x98ac
movslq %ebx, %rax
movq -0x58(%rbp), %rcx
cvttsd2si (%rcx,%rax,8), %ebx
movsd -0xf0(%rbp), %xmm0
movsd -0x68(%rbp), %xmm1
leaq 0x1b1c(%rip), %rdi      # 0xb28b
movb $0x3, %al
callq 0x3060
leaq -0x108(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0xa6ac
leaq -0x68(%rbp), %rdx
movl 0x8(%rdx), %eax
leaq -0xf0(%rbp), %rcx
movl %eax, 0x8(%rcx)
movq (%rdx), %rax
movq %rax, (%rcx)
movq -0xa0(%rbp), %rax
movslq %ebx, %rcx
movsd (%rax,%rcx,8), %xmm0
ucomisd (%rax,%r12,8), %xmm0
jbe 0x9921
movq %r14, -0x30(%rbp)
movq -0x58(%rbp), %rbx
movq -0x50(%rbp), %r14
cmpq %r14, %rbx
je 0x991d
xorpd %xmm0, %xmm0
movq %rbx, %rax
movsd 0x183c(%rip), %xmm1     # 0xb018
movsd %xmm0, (%rax)
addsd %xmm1, %xmm0
addq $0x8, %rax
cmpq %r14, %rax
jne 0x97dc
cmpq %r14, %rbx
je 0x991d
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
movq %r13, %rcx
callq 0xa236
cmpq $0x81, %r12
jl 0x990f
leaq 0x80(%rbx), %r12
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0xa555
cmpq %r14, %r12
je 0x991d
movq -0xa0(%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 0x989d
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 0x987d
movsd %xmm0, (%rdx)
addq $0x8, %r12
cmpq %r14, %r12
jne 0x9850
jmp 0x991d
movq -0xb8(%rbp), %rax
movsd (%rax,%r12,8), %xmm0
mulsd 0x1767(%rip), %xmm0     # 0xb028
movsd %xmm0, (%rax,%r12,8)
movsd 0x1909(%rip), %xmm1     # 0xb1d8
ucomisd %xmm0, %xmm1
jbe 0x990a
movq -0x40(%rbp), %rdi
callq 0x6758
movl %eax, %r14d
movq -0x40(%rbp), %rdi
callq 0x674c
subl %eax, %r14d
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
mulsd 0x18cb(%rip), %xmm0     # 0xb1c8
movq -0xb8(%rbp), %rax
movsd %xmm0, (%rax,%r12,8)
movl %ebx, %r14d
jmp 0x9921
movq %rbx, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0xa555
movq -0x30(%rbp), %r14
cmpl -0x34(%rbp), %r15d
jb 0x9675
leaq -0x108(%rbp), %rsi
movq -0x88(%rbp), %rdi
callq 0xa6ac
movq -0x58(%rbp), %rdi
testq %rdi, %rdi
je 0x994c
callq 0x31f0
movq -0xa0(%rbp), %rdi
testq %rdi, %rdi
je 0x995d
callq 0x31f0
movq -0x108(%rbp), %rdi
testq %rdi, %rdi
je 0x996e
callq 0x31f0
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x997c
callq 0x31f0
movq -0xb8(%rbp), %rdi
testq %rdi, %rdi
je 0x998d
callq 0x31f0
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x99b8
jmp 0x99b8
movq %rax, %rbx
jmp 0x99c9
movq %rax, %rbx
jmp 0x99da
movq %rax, %rbx
jmp 0x99eb
jmp 0x99b8
jmp 0x99b8
jmp 0x99b8
movq %rax, %rbx
movq -0x58(%rbp), %rdi
testq %rdi, %rdi
je 0x99c9
callq 0x31f0
movq -0xa0(%rbp), %rdi
testq %rdi, %rdi
je 0x99da
callq 0x31f0
movq -0x108(%rbp), %rdi
testq %rdi, %rdi
je 0x99eb
callq 0x31f0
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x99fe
callq 0x31f0
jmp 0x99fe
movq %rax, %rbx
movq -0xb8(%rbp), %rdi
testq %rdi, %rdi
je 0x9a0f
callq 0x31f0
movq %rbx, %rdi
callq 0x3320