// File: /workspace/github_cpp_makefile_star2_O3/Chrom3D[P]Chrom3D/src/Util.cpp
// Function: util::rotatePointsAroundArbitraryAxis(double, boost::numeric::ublas::vector<double, boost::numeric::ublas::unbounded_array<double, std::allocator<double>>>, boost::numeric::ublas::vector<double, boost::numeric::ublas::unbounded_array<double, std::allocator<double>>>, boost::numeric::ublas::matrix<double, boost::numeric::ublas::basic_row_major<unsigned long, long>, boost::numeric::ublas::unbounded_array<double, std::allocator<double>>>)
CoordinateMatrix rotatePointsAroundArbitraryAxis(double theta, CoordinateVector startPoint, CoordinateVector endPoint, CoordinateMatrix mat) {
  CoordinateVector rU = normalizeVector(startPoint-endPoint); // Normalized rotation vector

  double C = cos(theta);
  double S = sin(theta);
  double t = 1 - C;
  double ux = rU(0);
  double uy = rU(1);
  double uz = rU(2); 

  CoordinateMatrix rotMat(3,3);
  
  rotMat(0,0) = t*ux*ux + C;
  rotMat(1,0) = t*ux*uy + S*uz;
  rotMat(2,0) = t*ux*uz - S*uy;
  rotMat(0,1) = t*ux*uy - S*uz;
  rotMat(1,1) = t*uy*uy + C;
  rotMat(2,1) =  t*uy*uz + S*ux;
  rotMat(0,2) = t*ux*uz + S*uy;
  rotMat(1,2) = t*uy*uz - S*ux;
  rotMat(2,2) =  t*uz*uz + C;


  CoordinateMatrix res(mat.size1(),3);
  
  res = ublas::trans(ublas::prod(rotMat, ublas::trans(mat-repeatVector(startPoint,mat.size1())))); // rotated matrix at origo

  return res + repeatVector(startPoint,mat.size1()); // rotated matrix transformed back to original coordinate system
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x140, %rsp            # imm = 0x140
movq %rcx, %r14
movq %rsi, %r15
movsd %xmm0, (%rsp)
movq %rdi, %rbx
leaq 0x100(%rsp), %rsi
movq %r15, (%rsi)
movq %rdx, 0x8(%rsi)
leaq 0xe8(%rsp), %r12
movq %r12, %rdi
callq 0x837e
leaq 0x10(%rsp), %rdi
movq %r12, (%rdi)
callq 0x94ce
leaq 0x80(%rsp), %rax
movsd %xmm0, (%rax)
leaq 0x10(%rsp), %rsi
movq %r12, (%rsi)
movq %rax, 0x8(%rsi)
leaq 0x68(%rsp), %rdi
callq 0x831e
movq 0xf0(%rsp), %rsi
testq %rsi, %rsi
je 0x6d50
movq 0xf8(%rsp), %rdi
shlq $0x3, %rsi
callq 0x6310
movsd (%rsp), %xmm0
callq 0x6610
movsd %xmm0, 0x48(%rsp)
movsd (%rsp), %xmm0
callq 0x60a0
movsd %xmm0, (%rsp)
leaq 0x68(%rsp), %rdi
xorl %esi, %esi
callq 0x8fe2
movsd (%rax), %xmm0
movsd %xmm0, 0x60(%rsp)
leaq 0x68(%rsp), %rdi
movl $0x1, %esi
callq 0x8fe2
movsd (%rax), %xmm0
movsd %xmm0, 0x50(%rsp)
leaq 0x68(%rsp), %rdi
movl $0x2, %esi
callq 0x8fe2
movsd (%rax), %xmm0
movsd %xmm0, 0x38(%rsp)
leaq 0x10(%rsp), %r12
movl $0x3, %esi
movl $0x3, %edx
movq %r12, %rdi
callq 0x82e6
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rcx
xorl %edi, %edi
xorl %edx, %edx
callq 0x9124
leaq 0x20(%rsp), %r13
movq %r13, %rdi
movq %rax, %rsi
callq 0x8fe2
movsd 0x2220f(%rip), %xmm0    # 0x29008
movsd 0x48(%rsp), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, 0x58(%rsp)
movsd 0x60(%rsp), %xmm2
mulsd %xmm2, %xmm0
movsd %xmm0, 0x40(%rsp)
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rcx
movl $0x1, %edi
xorl %edx, %edx
callq 0x9124
movq %r13, %rdi
movq %rax, %rsi
callq 0x8fe2
movsd (%rsp), %xmm1
mulsd 0x38(%rsp), %xmm1
movsd 0x40(%rsp), %xmm0
mulsd 0x50(%rsp), %xmm0
movsd %xmm0, 0xb0(%rsp)
movsd %xmm1, 0x8(%rsp)
addsd %xmm1, %xmm0
movsd %xmm0, (%rax)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rcx
movl $0x2, %edi
xorl %edx, %edx
callq 0x9124
movq %r13, %rdi
movq %rax, %rsi
callq 0x8fe2
movsd (%rsp), %xmm1
mulsd 0x50(%rsp), %xmm1
movsd 0x40(%rsp), %xmm0
mulsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movsd %xmm1, 0xa8(%rsp)
subsd %xmm1, %xmm0
movsd %xmm0, (%rax)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rcx
movl $0x1, %edx
xorl %edi, %edi
callq 0x9124
movq %r13, %rdi
movq %rax, %rsi
callq 0x8fe2
movsd 0xb0(%rsp), %xmm0
subsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rcx
movl $0x1, %edi
movl $0x1, %edx
callq 0x9124
movq %r13, %rdi
movq %rax, %rsi
callq 0x8fe2
movsd 0x58(%rsp), %xmm1
movsd 0x50(%rsp), %xmm0
mulsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
mulsd %xmm1, %xmm0
addsd 0x48(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rcx
movl $0x2, %edi
movl $0x1, %edx
callq 0x9124
movq %r13, %rdi
movq %rax, %rsi
callq 0x8fe2
movsd (%rsp), %xmm1
mulsd 0x60(%rsp), %xmm1
movsd 0x8(%rsp), %xmm0
mulsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd %xmm1, (%rsp)
addsd %xmm1, %xmm0
movsd %xmm0, (%rax)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rcx
movl $0x2, %edx
xorl %edi, %edi
callq 0x9124
movq %r13, %rdi
movq %rax, %rsi
callq 0x8fe2
movsd 0x40(%rsp), %xmm0
addsd 0xa8(%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rcx
movl $0x1, %edi
movl $0x2, %edx
callq 0x9124
movq %r13, %rdi
movq %rax, %rsi
callq 0x8fe2
movsd 0x8(%rsp), %xmm0
subsd (%rsp), %xmm0
movsd %xmm0, (%rax)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rcx
movl $0x2, %edi
movl $0x2, %edx
callq 0x9124
movq %r13, %rdi
movq %rax, %rsi
callq 0x8fe2
movsd 0x38(%rsp), %xmm0
movsd 0x58(%rsp), %xmm1
mulsd %xmm0, %xmm1
mulsd %xmm0, %xmm1
addsd 0x48(%rsp), %xmm1
movsd %xmm1, (%rax)
movq (%r14), %rsi
leaq 0x100(%rsp), %rdi
movl $0x3, %edx
callq 0x82e6
leaq 0xd0(%rsp), %rdi
movq %r15, %rsi
callq 0x9478
movl (%r14), %edx
leaq 0x80(%rsp), %r13
leaq 0xd0(%rsp), %rsi
movq %r13, %rdi
callq 0x6b59
leaq 0x128(%rsp), %rsi
movq %r12, (%rsi)
movq %r14, 0x8(%rsi)
movq %r13, 0x10(%rsi)
leaq 0x100(%rsp), %r12
movq %r12, %rdi
callq 0x840e
movq 0x98(%rsp), %rsi
testq %rsi, %rsi
je 0x70b7
movq 0xa0(%rsp), %rdi
shlq $0x3, %rsi
callq 0x6310
movq 0xd8(%rsp), %rsi
testq %rsi, %rsi
je 0x70d5
movq 0xe0(%rsp), %rdi
shlq $0x3, %rsi
callq 0x6310
leaq 0xb8(%rsp), %rdi
movq %r15, %rsi
callq 0x9478
movl (%r14), %edx
leaq 0x80(%rsp), %r14
leaq 0xb8(%rsp), %rsi
movq %r14, %rdi
callq 0x6b59
leaq 0x128(%rsp), %rsi
movq %r12, (%rsi)
movq %r14, 0x8(%rsi)
movq %rbx, %rdi
callq 0x8480
movq 0x98(%rsp), %rsi
testq %rsi, %rsi
je 0x7135
movq 0xa0(%rsp), %rdi
shlq $0x3, %rsi
callq 0x6310
movq 0xc0(%rsp), %rsi
testq %rsi, %rsi
je 0x7153
movq 0xc8(%rsp), %rdi
shlq $0x3, %rsi
callq 0x6310
movq 0x118(%rsp), %rsi
testq %rsi, %rsi
je 0x7171
movq 0x120(%rsp), %rdi
shlq $0x3, %rsi
callq 0x6310
movq 0x28(%rsp), %rsi
testq %rsi, %rsi
je 0x7189
movq 0x30(%rsp), %rdi
shlq $0x3, %rsi
callq 0x6310
movq 0x70(%rsp), %rsi
testq %rsi, %rsi
je 0x71a1
movq 0x78(%rsp), %rdi
shlq $0x3, %rsi
callq 0x6310
movq %rbx, %rax
addq $0x140, %rsp            # imm = 0x140
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq %rax, %rbx
movq 0x98(%rsp), %rsi
testq %rsi, %rsi
je 0x71db
movq 0xa0(%rsp), %rdi
shlq $0x3, %rsi
callq 0x6310
jmp 0x71db
movq %rax, %rbx
movq 0xc0(%rsp), %rsi
testq %rsi, %rsi
je 0x723d
movq 0xc8(%rsp), %rdi
jmp 0x722f
jmp 0x723a
movq %rax, %rbx
movq 0x98(%rsp), %rsi
testq %rsi, %rsi
je 0x721a
movq 0xa0(%rsp), %rdi
shlq $0x3, %rsi
callq 0x6310
jmp 0x721a
movq %rax, %rbx
movq 0xd8(%rsp), %rsi
testq %rsi, %rsi
je 0x723d
movq 0xe0(%rsp), %rdi
shlq $0x3, %rsi
callq 0x6310
jmp 0x723d
movq %rax, %rbx
movq 0x118(%rsp), %rsi
testq %rsi, %rsi
je 0x728c
movq 0x120(%rsp), %rdi
shlq $0x3, %rsi
callq 0x6310
jmp 0x728c
jmp 0x7289
jmp 0x7265
jmp 0x7265
jmp 0x7265
movq %rax, %rbx
jmp 0x72a4
movq %rax, %rbx
jmp 0x72bc
movq %rax, %rbx
movq 0xf0(%rsp), %rsi
testq %rsi, %rsi
je 0x72bc
movq 0xf8(%rsp), %rdi
jmp 0x72b3
movq %rax, %rbx
movq 0x28(%rsp), %rsi
testq %rsi, %rsi
je 0x72a4
movq 0x30(%rsp), %rdi
shlq $0x3, %rsi
callq 0x6310
movq 0x70(%rsp), %rsi
testq %rsi, %rsi
je 0x72bc
movq 0x78(%rsp), %rdi
shlq $0x3, %rsi
callq 0x6310
movq %rbx, %rdi
callq 0x65b0