// File: 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
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x20(%rbp)
cmpq $0x0, 0x48(%rax)
jne 0xaa61
movq -0x38(%rbp), %rdi
callq 0x3e10
movq -0x38(%rbp), %rdi
movq %rax, 0x48(%rdi)
callq 0x4ad0
movq -0x38(%rbp), %rdi
movq %rax, 0x58(%rdi)
movl $0x19, %esi
callq 0x51e0
movq -0x38(%rbp), %rdi
movq %rax, 0xd8(%rdi)
movl $0x32, %esi
callq 0x51e0
movq -0x38(%rbp), %rdi
movq %rax, 0xe0(%rdi)
movl $0x64, %esi
callq 0x51e0
movq -0x38(%rbp), %rdi
movq %rax, 0xe8(%rdi)
movl 0x3c(%rdi), %esi
callq 0x5640
movq -0x38(%rbp), %rdi
movq %rax, 0xf0(%rdi)
movl 0x3c(%rdi), %esi
callq 0x58e0
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0xf8(%rax)
movl $0x0, -0x14(%rbp)
movq -0x38(%rbp), %rcx
movl -0x14(%rbp), %eax
cmpl 0xb8(%rcx), %eax
jge 0xaaad
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq -0x14(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm0
movq 0x48(%rax), %rcx
movslq -0x14(%rbp), %rdx
subsd (%rcx,%rdx,8), %xmm0
movq 0x70(%rax), %rax
movslq -0x14(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xaa68
movl $0x0, -0x24(%rbp)
movl $0x0, -0x14(%rbp)
movq -0x38(%rbp), %rcx
movl -0x14(%rbp), %eax
cmpl 0x3c(%rcx), %eax
jge 0xab54
movq -0x38(%rbp), %rdi
movl -0x14(%rbp), %esi
leaq -0x24(%rbp), %rdx
callq 0x5b80
movq -0x38(%rbp), %rdi
movq %rax, 0x78(%rdi)
movq 0xf8(%rdi), %rax
movslq -0x14(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x48(%rbp)
movq 0x78(%rdi), %rsi
movq 0xf0(%rdi), %rax
movslq -0x14(%rbp), %rcx
movl (%rax,%rcx,4), %edx
callq 0x6290
movq -0x38(%rbp), %rax
movaps %xmm0, %xmm2
movsd -0x48(%rbp), %xmm0
movsd -0x20(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x20(%rbp)
movq 0x78(%rax), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
je 0xab44
movq -0x40(%rbp), %rdi
callq 0x3230
jmp 0xab46
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xaabb
movq -0x38(%rbp), %rax
movl 0xb8(%rax), %eax
subl -0x24(%rbp), %eax
cltq
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x3030
movq %rax, -0x30(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x14(%rbp)
movq -0x38(%rbp), %rcx
movl -0x14(%rbp), %eax
cmpl 0xb8(%rcx), %eax
jge 0xabd3
movq -0x38(%rbp), %rcx
movq 0x70(%rcx), %rax
movq 0x58(%rcx), %rcx
movslq -0x14(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x30(%rbp), %rax
movl -0x14(%rbp), %ecx
subl -0x24(%rbp), %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xab8e
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
movl 0xb8(%rdi), %edx
subl -0x24(%rbp), %edx
callq 0x6290
addsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x20(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, %rax
je 0xac0a
movq -0x50(%rbp), %rdi
callq 0x3230
movsd -0x20(%rbp), %xmm0
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop