// File: /workspace/github_cpp_makefile_star2_O2/mateuz[P]MTS-LS1/source/main.cpp
// Function: mts_ls1_improve_dim(Benchmarks*, std::vector<double, std::allocator<double>>&, double, unsigned int, std::vector<double, std::allocator<double>>&)
LSresult mts_ls1_improve_dim(Benchmarks * bench, vector<double>& sol, double best_fitness, unsigned i, vector<double> & SR ){
  vector<double> newsol = sol;
  newsol[i] -= SR[i];

  double initial_fit = best_fitness;

  newsol[i] = min(newsol[i], (double)bench->getMaxX());
  newsol[i] = max(newsol[i], (double)bench->getMinX());

  double fitness_newsol = bench->compute(newsol.data());

  unsigned evals = 1;

  if( fitness_newsol < best_fitness ){
    best_fitness = fitness_newsol;
    sol = newsol;
  } else if( fitness_newsol > best_fitness ){
    newsol[i] = sol[i];
    newsol[i] += 0.5 * SR[i];

    newsol[i] = min(newsol[i], (double)bench->getMaxX());
    newsol[i] = max(newsol[i], (double)bench->getMinX());

    fitness_newsol = bench->compute(newsol.data());
    evals++;

    if( fitness_newsol < best_fitness ){
      best_fitness = fitness_newsol;
      sol = newsol;
    }
  }
  //printf("%1.20E -> %1.20E\n", initial_fit, best_fitness);
  return LSresult{sol, best_fitness, evals};
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, %r12
movl %ecx, %r13d
movsd %xmm0, -0x30(%rbp)
movq %rsi, %r15
movq %rdi, %rbx
leaq -0x50(%rbp), %r14
movq %r14, %rdi
movq %rdx, -0x38(%rbp)
movq %rdx, %rsi
callq 0x94c0
movl %r13d, %r13d
movq (%r12), %rax
movq (%r14), %r14
movsd (%r14,%r13,8), %xmm0
subsd (%rax,%r13,8), %xmm0
movsd %xmm0, (%r14,%r13,8)
movq %r15, %rdi
callq 0x5928
cvtsi2sd %eax, %xmm0
minsd (%r14,%r13,8), %xmm0
movq -0x50(%rbp), %r14
movsd %xmm0, (%r14,%r13,8)
movq %r15, %rdi
callq 0x591c
cvtsi2sd %eax, %xmm0
maxsd (%r14,%r13,8), %xmm0
movq -0x50(%rbp), %rsi
movsd %xmm0, (%rsi,%r13,8)
movq (%r15), %rax
movq %r15, %rdi
callq *0x10(%rax)
movsd -0x30(%rbp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x8307
movsd %xmm0, -0x30(%rbp)
leaq -0x50(%rbp), %rsi
movq -0x38(%rbp), %r15
movq %r15, %rdi
callq 0x9518
pushq $0x1
popq %r14
jmp 0x83b7
ucomisd %xmm1, %xmm0
jbe 0x83af
movq -0x38(%rbp), %rax
movq (%rax), %rax
movsd (%rax,%r13,8), %xmm0
movq -0x50(%rbp), %r14
movsd %xmm0, (%r14,%r13,8)
movq (%r12), %rax
movsd (%rax,%r13,8), %xmm1
mulsd 0x1cf6(%rip), %xmm1     # 0xa030
addsd %xmm0, %xmm1
movsd %xmm1, (%r14,%r13,8)
movq %r15, %rdi
callq 0x5928
cvtsi2sd %eax, %xmm0
minsd (%r14,%r13,8), %xmm0
movq -0x50(%rbp), %r14
movsd %xmm0, (%r14,%r13,8)
movq %r15, %rdi
callq 0x591c
cvtsi2sd %eax, %xmm0
maxsd (%r14,%r13,8), %xmm0
movq -0x50(%rbp), %rsi
movsd %xmm0, (%rsi,%r13,8)
movq (%r15), %rax
movq %r15, %rdi
callq *0x10(%rax)
movq -0x38(%rbp), %r15
movapd %xmm0, %xmm1
pushq $0x2
popq %r14
movsd -0x30(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x83b7
leaq -0x50(%rbp), %rsi
movq %r15, %rdi
movsd %xmm1, -0x30(%rbp)
callq 0x9518
jmp 0x83b7
pushq $0x1
popq %r14
movq -0x38(%rbp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x94c0
movsd -0x30(%rbp), %xmm0
movsd %xmm0, 0x18(%rbx)
movl %r14d, 0x20(%rbx)
leaq -0x50(%rbp), %rdi
callq 0x97aa
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x83f5
jmp 0x83f5
jmp 0x83f5
jmp 0x83f5
jmp 0x83f5
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x97aa
movq %rbx, %rdi
callq 0x32d0