// File: 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
subq $0x190, %rsp            # imm = 0x190
movq %rdi, -0xc0(%rbp)
movq %rdi, %rax
movq %rax, -0xb8(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movsd %xmm0, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq %r8, -0x30(%rbp)
movq -0x18(%rbp), %rsi
leaq -0x48(%rbp), %rdi
movq %rdi, -0xa8(%rbp)
callq 0xfd50
movq -0x30(%rbp), %rdi
movl -0x24(%rbp), %eax
movl %eax, %esi
callq 0xfe40
movq -0xa8(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0xb0(%rbp)
movl -0x24(%rbp), %eax
movl %eax, %esi
callq 0xfe40
movsd -0xb0(%rbp), %xmm1
movq -0xa8(%rbp), %rdi
movsd (%rax), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, (%rax)
movsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movl -0x24(%rbp), %eax
movl %eax, %esi
callq 0xfe40
movq %rax, -0xa0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x72f0
movl %eax, -0x94(%rbp)
jmp 0xc54a
movq -0xa0(%rbp), %rdi
movl -0x94(%rbp), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x58(%rbp)
leaq -0x58(%rbp), %rsi
callq 0xfe60
movq %rax, -0xc8(%rbp)
jmp 0xc572
movq -0xc8(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0xe8(%rbp)
movl -0x24(%rbp), %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
movq %rdi, -0xe0(%rbp)
callq 0xfe40
movsd -0xe8(%rbp), %xmm0
movq -0xe0(%rbp), %rdi
movsd %xmm0, (%rax)
movl -0x24(%rbp), %eax
movl %eax, %esi
callq 0xfe40
movq %rax, -0xd8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x72d0
movl %eax, -0xcc(%rbp)
jmp 0xc5cf
movq -0xd8(%rbp), %rdi
movl -0xcc(%rbp), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x70(%rbp)
leaq -0x70(%rbp), %rsi
callq 0xfea0
movq %rax, -0xf0(%rbp)
jmp 0xc5f7
movq -0xf0(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x110(%rbp)
movl -0x24(%rbp), %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0xfe40
movsd -0x110(%rbp), %xmm0
movq -0x108(%rbp), %rdi
movsd %xmm0, (%rax)
movq -0x10(%rbp), %rax
movq %rax, -0x100(%rbp)
callq 0xfee0
movq -0x100(%rbp), %rdi
movq %rax, %rsi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movsd %xmm0, -0xf8(%rbp)
jmp 0xc65f
movsd -0xf8(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
movl $0x1, -0x7c(%rbp)
movsd -0x78(%rbp), %xmm1
movsd -0x20(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0xc6bb
movsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x20(%rbp)
movq -0x18(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0xff00
jmp 0xc69c
jmp 0xc8e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x10150
jmp 0xc922
movsd -0x78(%rbp), %xmm0
ucomisd -0x20(%rbp), %xmm0
jbe 0xc8de
movq -0x18(%rbp), %rdi
movl -0x24(%rbp), %eax
movl %eax, %esi
callq 0xfe40
movsd (%rax), %xmm0
movsd %xmm0, -0x138(%rbp)
movl -0x24(%rbp), %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
movq %rdi, -0x128(%rbp)
callq 0xfe40
movsd -0x138(%rbp), %xmm0
movsd %xmm0, (%rax)
movq -0x30(%rbp), %rdi
movl -0x24(%rbp), %eax
movl %eax, %esi
callq 0xfe40
movq -0x128(%rbp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, -0x130(%rbp)
movl -0x24(%rbp), %eax
movl %eax, %esi
callq 0xfe40
movsd -0x130(%rbp), %xmm0
movq -0x128(%rbp), %rdi
movsd (%rax), %xmm1
movsd 0x68dc(%rip), %xmm2     # 0x13028
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax)
movl -0x24(%rbp), %eax
movl %eax, %esi
callq 0xfe40
movq %rax, -0x120(%rbp)
movq -0x10(%rbp), %rdi
callq 0x72f0
movl %eax, -0x114(%rbp)
jmp 0xc77a
movq -0x120(%rbp), %rdi
movl -0x114(%rbp), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x88(%rbp)
leaq -0x88(%rbp), %rsi
callq 0xfe60
movq %rax, -0x140(%rbp)
jmp 0xc7a8
movq -0x140(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x160(%rbp)
movl -0x24(%rbp), %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
movq %rdi, -0x158(%rbp)
callq 0xfe40
movsd -0x160(%rbp), %xmm0
movq -0x158(%rbp), %rdi
movsd %xmm0, (%rax)
movl -0x24(%rbp), %eax
movl %eax, %esi
callq 0xfe40
movq %rax, -0x150(%rbp)
movq -0x10(%rbp), %rdi
callq 0x72d0
movl %eax, -0x144(%rbp)
jmp 0xc805
movq -0x150(%rbp), %rdi
movl -0x144(%rbp), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x90(%rbp)
leaq -0x90(%rbp), %rsi
callq 0xfea0
movq %rax, -0x168(%rbp)
jmp 0xc833
movq -0x168(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x188(%rbp)
movl -0x24(%rbp), %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
movq %rdi, -0x180(%rbp)
callq 0xfe40
movsd -0x188(%rbp), %xmm0
movq -0x180(%rbp), %rdi
movsd %xmm0, (%rax)
movq -0x10(%rbp), %rax
movq %rax, -0x178(%rbp)
callq 0xfee0
movq -0x178(%rbp), %rdi
movq %rax, %rsi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movsd %xmm0, -0x170(%rbp)
jmp 0xc89b
movsd -0x170(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
movsd -0x78(%rbp), %xmm1
movsd -0x20(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0xc8dc
movsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x20(%rbp)
movq -0x18(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0xff00
jmp 0xc8da
jmp 0xc8dc
jmp 0xc8de
jmp 0xc8e0
movq -0xc0(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xfd50
jmp 0xc8f2
movq -0xc0(%rbp), %rax
movsd -0x20(%rbp), %xmm0
movsd %xmm0, 0x18(%rax)
movl -0x7c(%rbp), %ecx
movl %ecx, 0x20(%rax)
leaq -0x48(%rbp), %rdi
callq 0x10150
movq -0xb8(%rbp), %rax
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
movq -0x60(%rbp), %rdi
callq 0x3320
nopl (%rax,%rax)