// File: /workspace/github_cpp_makefile_star2_O1/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
subq $0x18, %rsp
movq %rdi, %r14
movq %rsi, -0x30(%rbp)
movslq %esi, %rbx
leaq (,%rbx,8), %rax
testl %ebx, %ebx
movq $-0x1, %r12
cmovnsq %rax, %r12
movq %r12, %rdi
callq 0x3030
movq %rax, %r15
testl %ebx, %ebx
jle 0x49d5
movl -0x30(%rbp), %ebx
xorl %r13d, %r13d
movq %r12, %rdi
callq 0x3030
movq %rax, (%r15,%r13,8)
incq %r13
cmpq %r13, %rbx
jne 0x49c1
movq -0x30(%rbp), %rax
leal -0x1(%rax), %ebx
movslq %ebx, %rax
movq %rax, -0x40(%rbp)
leaq 0x1(%rbx), %r13
movq %rbx, -0x38(%rbp)
movq %rbx, %r12
cmpl $0x0, -0x30(%rbp)
jle 0x4a1b
movq %r13, %rbx
movq %r14, %rdi
callq 0x39a0
movq (%r15,%r12,8), %rax
movsd %xmm0, -0x8(%rax,%rbx,8)
decq %rbx
jg 0x49f7
leaq -0x1(%r12), %rax
testq %r12, %r12
movq %rax, %r12
jg 0x49f4
movq -0x38(%rbp), %rbx
movq %rbx, %r12
cmpl $0x0, -0x30(%rbp)
movapd 0x6692(%rip), %xmm2     # 0xb0c0
xorpd %xmm3, %xmm3
jle 0x4b14
cmpq -0x40(%rbp), %r12
jge 0x4a96
movq (%r15,%r12,8), %rax
movl %ebx, %ecx
movl %ecx, %edx
movq (%r15,%rdx,8), %rsi
xorpd %xmm0, %xmm0
movq %r13, %rdi
movsd -0x8(%rax,%rdi,8), %xmm1
mulsd -0x8(%rsi,%rdi,8), %xmm1
addsd %xmm1, %xmm0
decq %rdi
jg 0x4a51
movq (%r15,%rdx,8), %rdx
xorpd %xmm2, %xmm0
movq %r13, %rsi
movsd -0x8(%rdx,%rsi,8), %xmm1
mulsd %xmm0, %xmm1
addsd -0x8(%rax,%rsi,8), %xmm1
movsd %xmm1, -0x8(%rax,%rsi,8)
decq %rsi
jg 0x4a71
decl %ecx
movslq %ecx, %rdx
cmpq %rdx, %r12
jl 0x4a44
movq (%r15,%r12,8), %rax
xorpd %xmm0, %xmm0
movq %r13, %rcx
movsd -0x8(%rax,%rcx,8), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm1, %xmm0
decq %rcx
jg 0x4aa1
ucomisd %xmm0, %xmm3
jae 0x49eb
ucomisd %xmm3, %xmm0
jb 0x4aca
sqrtsd %xmm0, %xmm0
jmp 0x4adb
callq 0x31b0
xorpd %xmm3, %xmm3
movapd 0x65e5(%rip), %xmm2     # 0xb0c0
movsd 0x6535(%rip), %xmm1     # 0xb018
divsd %xmm0, %xmm1
movq (%r15,%r12,8), %rax
movq %r13, %rcx
movsd -0x8(%rax,%rcx,8), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x8(%rax,%rcx,8)
decq %rcx
jg 0x4aee
leaq -0x1(%r12), %rax
testq %r12, %r12
movq %rax, %r12
jg 0x4a38
movq %r15, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq