// File: /workspace/github_cpp_makefile_star2_O2/mateuz[P]MTS-LS1/source/Benchmarks.cpp
// Function: Benchmarks::createRotMatrix(int)
double** Benchmarks::createRotMatrix(int dim){
  double** m;
  int      i, j, k;
  double   dp, t;
  //m = (double**)malloc(sizeof(double*) * dim);
  m = new double*[dim];

  for(i = 0; i < dim; i++) {
    //m[i] = (double*)malloc(sizeof(double) * dim);
    m[i] = new double[dim];
  }

 loop:
  for (;;) {
    for (i = (dim - 1); i >= 0; i--) {
      for (j = (dim - 1); j >= 0; j--) {
        m[i][j] = nextGaussian();
      }
    }

    // main loop of gram/schmidt
    for (i = (dim - 1); i >= 0; i--) {
      for (j = (dim - 1); j > i; j--) {
        // dot product
        dp = 0;

        for (k = (dim - 1); k >= 0; k--) {
          dp += (m[i][k] * m[j][k]);
        }

        // subtract
        for (k = (dim - 1); k >= 0; k--) {
          m[i][k] -= (dp * m[j][k]);
        }
      }

      // normalize
      dp = 0;

      for (k = (dim - 1); k >= 0; k--) {
        t   = m[i][k];
        dp += (t * t);
      }

      // linear dependency -> restart
      if (dp <= 0) {
        goto loop;
      }

      dp = (1 / sqrt(dp));

      for (k = (dim - 1); k >= 0; k--) {
        m[i][k] *= dp;
      }
    }

    return(m) ;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, -0x30(%rbp)
movl %esi, %eax
shlq $0x3, %rax
xorl %r13d, %r13d
testl %esi, %esi
pushq $-0x1
popq %r12
cmovnsq %rax, %r12
movl $0x0, %r14d
cmovgl %esi, %r14d
movq %r12, %rdi
callq 0x3030
movq %rax, %r15
cmpq %r13, %r14
je 0x448c
movq %r12, %rdi
callq 0x3030
movq %rax, (%r15,%r13,8)
incq %r13
jmp 0x4476
decl %ebx
movapd 0x5c2a(%rip), %xmm2     # 0xa0c0
xorpd %xmm3, %xmm3
movl %ebx, %r13d
movl %ebx, %r12d
testl %r13d, %r13d
js 0x4529
movl %r13d, %r14d
movl %ebx, %r12d
testl %r12d, %r12d
js 0x44d2
movq -0x30(%rbp), %rdi
callq 0x38e8
xorpd %xmm3, %xmm3
movq (%r15,%r14,8), %rax
movl %r12d, %ecx
movsd %xmm0, (%rax,%rcx,8)
decl %r12d
jmp 0x44af
decl %r13d
movapd 0x5be3(%rip), %xmm2     # 0xa0c0
jmp 0x449d
ucomisd %xmm3, %xmm0
jb 0x44eb
sqrtsd %xmm0, %xmm0
jmp 0x44fc
callq 0x3180
xorpd %xmm3, %xmm3
movapd 0x5bc4(%rip), %xmm2     # 0xa0c0
movsd 0x5b14(%rip), %xmm1     # 0xa018
divsd %xmm0, %xmm1
movl %ebx, %eax
testl %eax, %eax
js 0x4526
movq (%r15,%r13,8), %rcx
movl %eax, %edx
movsd (%rcx,%rdx,8), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, (%rcx,%rdx,8)
decl %eax
jmp 0x450a
decl %r12d
testl %r12d, %r12d
js 0x45c5
movl %r12d, %r13d
movl %ebx, %eax
cmpl %r12d, %eax
jle 0x4595
movl %eax, %ecx
xorpd %xmm0, %xmm0
movl %ebx, %edx
testl %edx, %edx
js 0x4564
movq (%r15,%r13,8), %rsi
movl %edx, %edi
movsd (%rsi,%rdi,8), %xmm1
movq (%r15,%rcx,8), %rsi
mulsd (%rsi,%rdi,8), %xmm1
addsd %xmm1, %xmm0
decl %edx
jmp 0x4544
xorpd %xmm2, %xmm0
movl %ebx, %edx
testl %edx, %edx
js 0x4591
movq (%r15,%rcx,8), %rsi
movl %edx, %edi
movq (%r15,%r13,8), %r8
movsd (%rsi,%rdi,8), %xmm1
mulsd %xmm0, %xmm1
addsd (%r8,%rdi,8), %xmm1
movsd %xmm1, (%r8,%rdi,8)
decl %edx
jmp 0x456a
decl %eax
jmp 0x4537
xorpd %xmm0, %xmm0
movl %ebx, %eax
testl %eax, %eax
js 0x45b6
movq (%r15,%r13,8), %rcx
movl %eax, %edx
movsd (%rcx,%rdx,8), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm1, %xmm0
decl %eax
jmp 0x459b
ucomisd %xmm0, %xmm3
jb 0x44df
jmp 0x449a
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop