// File: /workspace/github_cpp_makefile_star2_O1/mateuz[P]MTS-LS1/source/F4.cpp
// Function: F4::compute(double*)
double F4::compute(double*x){
  int    i;
  double result = 0.0;

  if(Ovector == NULL) {
    Ovector = readOvector();
    Pvector = readPermVector();
    r25 = readR(25);
    r50 = readR(50);
    r100 = readR(100);
    s = readS(s_size);
    w = readW(s_size);
  }
  
  for(i = 0; i < dimension; i++) {
    anotherz[i] = x[i] - Ovector[i];
  }

  // for (int i = 0; i < dimension; ++i)
  //   {
  //     cout<<anotherz[i]<<endl;
  //   }
  // cout<<endl;

  // // T_{osz}
  // transform_osz(anotherz);
  
  // s_size non-separable part with rotation
  int c = 0;
  for (i = 0; i < s_size; i++)
    {
      // cout<<"c="<<c<<", i="<<i<<endl;
      anotherz1 = rotateVector(i, c);
      // cout<<"done rot"<<endl;
      result += w[i] * elliptic(anotherz1, s[i]);
      delete []anotherz1;
      // cout<<result<<endl;
    }
  
  // one separable part without rotation
  double* z = new double[dimension-c];
  for (i = c; i < dimension; i++)
    {
      // cout<<i-c<<" "<<Pvector[i]<<" "<<anotherz[Pvector[i]]<<endl;
      z[i-c] = anotherz[Pvector[i]];
    }
  
  // cout<<"sep\n"<<elliptic(z, dimension-c)<<endl;
  
  result += elliptic(z, dimension-c);
  delete[] z;

//  printf("Rotated Part = %1.16E\n", rot_elliptic(anotherz1,nonSeparableGroupSize) * 1e6);
//  printf("Separable Part = %1.16E\n", elliptic(anotherz2,dimension - nonSeparableGroupSize));

  return(result);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x20, %rsp
movq %rsi, %r14
movq %rdi, %rbx
cmpq $0x0, 0x48(%rdi)
jne 0x7e84
movq %rbx, %rdi
callq 0x3bc0
movq %rax, 0x48(%rbx)
movq %rbx, %rdi
callq 0x4732
movq %rax, 0x58(%rbx)
movq %rbx, %rdi
movl $0x19, %esi
callq 0x4c36
movq %rax, 0xd8(%rbx)
movq %rbx, %rdi
movl $0x32, %esi
callq 0x4c36
movq %rax, 0xe0(%rbx)
movq %rbx, %rdi
movl $0x64, %esi
callq 0x4c36
movq %rax, 0xe8(%rbx)
movl 0x3c(%rbx), %esi
movq %rbx, %rdi
callq 0x5036
movq %rax, 0xf0(%rbx)
movl 0x3c(%rbx), %esi
movq %rbx, %rdi
callq 0x52b0
movq %rax, 0xf8(%rbx)
movslq 0xb8(%rbx), %rax
testq %rax, %rax
jle 0x7eb2
movq 0x48(%rbx), %rcx
movq 0x70(%rbx), %rdx
xorl %esi, %esi
movsd (%r14,%rsi,8), %xmm0
subsd (%rcx,%rsi,8), %xmm0
movsd %xmm0, (%rdx,%rsi,8)
incq %rsi
cmpq %rsi, %rax
jne 0x7e9a
movl $0x0, -0x24(%rbp)
cmpl $0x0, 0x3c(%rbx)
jle 0x7f4a
xorpd %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
xorl %r14d, %r14d
leaq -0x24(%rbp), %r15
movq %rbx, %rdi
movl %r14d, %esi
movq %r15, %rdx
callq 0x5528
movq %rax, 0x78(%rbx)
movq 0xf0(%rbx), %rcx
movq 0xf8(%rbx), %rdx
movsd (%rdx,%r14,8), %xmm0
movsd %xmm0, -0x38(%rbp)
movl (%rcx,%r14,4), %edx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x5ba2
movq 0x78(%rbx), %rdi
testq %rdi, %rdi
je 0x7f25
movsd %xmm0, -0x40(%rbp)
callq 0x3260
movsd -0x40(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
mulsd %xmm0, %xmm1
movsd -0x30(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
incq %r14
movslq 0x3c(%rbx), %rax
cmpq %rax, %r14
jl 0x7ed3
jmp 0x7f53
xorpd %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
movslq 0xb8(%rbx), %r15
movslq -0x24(%rbp), %r12
movl %r15d, %eax
subl %r12d, %eax
cltq
leaq (,%rax,8), %rcx
testl %eax, %eax
movq $-0x1, %rdi
cmovnsq %rcx, %rdi
callq 0x3030
movq %rax, %r14
movl %r15d, %edx
subl %r12d, %edx
jle 0x7fb7
movq 0x70(%rbx), %rax
leaq (,%r12,4), %rcx
addq 0x58(%rbx), %rcx
subq %r12, %r15
xorl %esi, %esi
movslq (%rcx,%rsi,4), %rdi
movsd (%rax,%rdi,8), %xmm0
movsd %xmm0, (%r14,%rsi,8)
incq %rsi
cmpq %rsi, %r15
jne 0x7fa0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5ba2
movsd %xmm0, -0x38(%rbp)
movq %r14, %rdi
callq 0x3260
movsd -0x30(%rbp), %xmm0
addsd -0x38(%rbp), %xmm0
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop