// File: /workspace/github_cpp_makefile_star2_O2/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 %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq 0x48(%rdi), %rax
testq %rax, %rax
jne 0x70ce
movq %rbx, %rdi
callq 0x3a5e
movq %rax, 0x48(%rbx)
movq %rbx, %rdi
callq 0x42a8
movq %rax, 0x58(%rbx)
pushq $0x19
popq %rsi
movq %rbx, %rdi
callq 0x46d2
movq %rax, 0xd8(%rbx)
pushq $0x32
popq %rsi
movq %rbx, %rdi
callq 0x46d2
movq %rax, 0xe0(%rbx)
pushq $0x64
popq %rsi
movq %rbx, %rdi
callq 0x46d2
movq %rax, 0xe8(%rbx)
movl 0x3c(%rbx), %esi
movq %rbx, %rdi
callq 0x4978
movq %rax, 0xf0(%rbx)
movl 0x3c(%rbx), %esi
movq %rbx, %rdi
callq 0x4afe
movq %rax, 0xf8(%rbx)
movq 0x48(%rbx), %rax
movl 0xb8(%rbx), %ecx
movq 0x70(%rbx), %rdx
xorl %esi, %esi
testl %ecx, %ecx
cmovlel %esi, %ecx
cmpq %rsi, %rcx
je 0x70f9
movsd (%r14,%rsi,8), %xmm0
subsd (%rax,%rsi,8), %xmm0
movsd %xmm0, (%rdx,%rsi,8)
incq %rsi
jmp 0x70df
leaq -0x3c(%rbp), %r14
andl $0x0, (%r14)
xorpd %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
xorl %r15d, %r15d
movslq 0x3c(%rbx), %rax
cmpq %rax, %r15
jge 0x7184
movq %rbx, %rdi
movl %r15d, %esi
movq %r14, %rdx
callq 0x4c82
movq %rax, 0x78(%rbx)
movq 0xf0(%rbx), %rcx
movq 0xf8(%rbx), %rdx
movsd (%rdx,%r15,8), %xmm0
movsd %xmm0, -0x30(%rbp)
movl (%rcx,%r15,4), %edx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x500a
movq 0x78(%rbx), %rdi
testq %rdi, %rdi
je 0x7168
movsd %xmm0, -0x48(%rbp)
callq 0x3210
movsd -0x48(%rbp), %xmm0
movsd -0x30(%rbp), %xmm1
mulsd %xmm0, %xmm1
movsd -0x38(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x38(%rbp)
incq %r15
jmp 0x710d
movslq 0xb8(%rbx), %r12
movslq -0x3c(%rbp), %r13
movq %r12, %r14
subq %r13, %r14
movq %r14, %rax
shlq $0x3, %rax
testl %r14d, %r14d
pushq $-0x1
popq %rdi
cmovnsq %rax, %rdi
callq 0x3030
movq %rax, %r15
movq 0x70(%rbx), %rax
leaq (,%r13,4), %rcx
addq 0x58(%rbx), %rcx
xorl %edx, %edx
leaq (%rdx,%r13), %rsi
cmpq %r12, %rsi
jge 0x71dd
movslq (%rcx,%rdx,4), %rsi
movsd (%rax,%rsi,8), %xmm0
movsd %xmm0, (%r15,%rdx,8)
incq %rdx
jmp 0x71c0
movq %rbx, %rdi
movq %r15, %rsi
movl %r14d, %edx
callq 0x500a
movsd %xmm0, -0x30(%rbp)
movq %r15, %rdi
callq 0x3210
movsd -0x38(%rbp), %xmm0
addsd -0x30(%rbp), %xmm0
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)