// File: /workspace/github_cpp_makefile_star2_O3/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
movl %esi, %r13d
movq %rdi, %r14
movl %esi, %ebx
leaq (,%rbx,8), %rax
testl %esi, %esi
movq $-0x1, %r12
cmovnsq %rax, %r12
movq %r12, %rdi
callq 0x3030
movq %rax, %r15
movq %r13, -0x30(%rbp)
testl %r13d, %r13d
jle 0x49cd
xorl %r13d, %r13d
movq %r12, %rdi
callq 0x3030
movq %rax, (%r15,%r13,8)
incq %r13
cmpq %r13, %rbx
jne 0x49b9
cmpl $0x0, -0x30(%rbp)
jle 0x4b15
movq -0x30(%rbp), %rax
leal -0x1(%rax), %r12d
movslq %r12d, %rax
movq %rax, -0x40(%rbp)
leaq 0x1(%r12), %rbx
movq %r12, -0x38(%rbp)
movq %rbx, %r13
movq %r14, %rdi
callq 0x39a0
movq (%r15,%r12,8), %rax
movsd %xmm0, -0x8(%rax,%r13,8)
decq %r13
jg 0x49f2
leaq -0x1(%r12), %rax
testq %r12, %r12
movq %rax, %r12
movapd 0x66a3(%rip), %xmm2     # 0xb0c0
xorpd %xmm3, %xmm3
jg 0x49ef
movq -0x38(%rbp), %r12
cmpl $0x0, -0x30(%rbp)
jle 0x4b15
movq (%r15,%r12,8), %r13
cmpq -0x40(%rbp), %r12
jge 0x4a90
movq -0x38(%rbp), %rax
movl %eax, %ecx
movq (%r15,%rcx,8), %rcx
xorpd %xmm0, %xmm0
movq %rbx, %rdx
movsd -0x8(%r13,%rdx,8), %xmm1
mulsd -0x8(%rcx,%rdx,8), %xmm1
addsd %xmm1, %xmm0
decq %rdx
jg 0x4a4c
xorpd %xmm2, %xmm0
movq %rbx, %rdx
movsd -0x8(%rcx,%rdx,8), %xmm1
mulsd %xmm0, %xmm1
addsd -0x8(%r13,%rdx,8), %xmm1
movsd %xmm1, -0x8(%r13,%rdx,8)
decq %rdx
jg 0x4a69
decl %eax
movslq %eax, %rcx
cmpq %rcx, %r12
jl 0x4a3f
xorpd %xmm0, %xmm0
movq %rbx, %rax
movsd -0x8(%r13,%rax,8), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm1, %xmm0
decq %rax
jg 0x4a97
ucomisd %xmm0, %xmm3
jae 0x4b07
ucomisd %xmm3, %xmm0
jb 0x4abd
sqrtsd %xmm0, %xmm0
jmp 0x4ace
callq 0x31b0
xorpd %xmm3, %xmm3
movapd 0x65f2(%rip), %xmm2     # 0xb0c0
movsd 0x6542(%rip), %xmm1     # 0xb018
divsd %xmm0, %xmm1
movq %rbx, %rax
movsd -0x8(%r13,%rax,8), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x8(%r13,%rax,8)
decq %rax
jg 0x4add
leaq -0x1(%r12), %rax
testq %r12, %r12
movq %rax, %r12
jg 0x4a31
jmp 0x4b15
movq -0x38(%rbp), %r12
cmpl $0x0, -0x30(%rbp)
jg 0x49ef
movq %r15, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop