// File: yukimasano[P]cpp_matrix/Matrix.cpp
// Function: rand_basis_angle(Matrix&)
Matrix rand_basis_angle(Matrix& A){
  //using spherical coordinates in N-d
  assert(nrows(A)==ncols(A));
  int m = nrows(A);
  A = randm(A);
  Vector d = A.diag();
  A.set_val(1,1, A(1,1)*2.0);
  A = A*M_PI;
  Matrix B = A;
  for (int k=1;k<=m;k++){
    Vector vei = A.get_col(k);
    for (int j=1;j<=m;j++){
      if (j<k){
        vei.set_val(j, -cos(B(j,j))); //orthogonal to previous
      }
      else{
  	    vei.set_val(j,cos(vei(j))); // any direction in that orthogonal space
      }
    }
    for (int j=1;j<=m;j++){
  	   A.set_val(j,k, vei(j)/vei.norm());
    }
  }
return A;
}

// Assembly:
subq $0x108, %rsp            # imm = 0x108
movq %rdi, 0x60(%rsp)
movq %rdi, %rax
movq %rax, 0x68(%rsp)
movq %rdi, 0x100(%rsp)
movq %rsi, 0xf8(%rsp)
movq 0xf8(%rsp), %rdi
callq 0x3ac0
movl %eax, 0x74(%rsp)
movq 0xf8(%rsp), %rdi
callq 0x3ad0
movl %eax, %ecx
movl 0x74(%rsp), %eax
cmpl %ecx, %eax
jne 0x57ae
jmp 0x57cd
leaq 0x9acd(%rip), %rdi      # 0xf282
leaq 0x998d(%rip), %rsi      # 0xf149
movl $0x154, %edx            # imm = 0x154
leaq 0x9aec(%rip), %rcx      # 0xf2b4
callq 0x2090
movq 0xf8(%rsp), %rdi
callq 0x3ac0
movl %eax, 0xf4(%rsp)
movq 0xf8(%rsp), %rsi
leaq 0xe0(%rsp), %rdi
movq %rdi, 0x58(%rsp)
callq 0x5140
movq 0x58(%rsp), %rsi
movq 0xf8(%rsp), %rdi
callq 0x41e0
jmp 0x580f
leaq 0xe0(%rsp), %rdi
callq 0x3660
movq 0xf8(%rsp), %rsi
leaq 0xc0(%rsp), %rdi
callq 0x4dd0
movq 0xf8(%rsp), %rdi
movq %rdi, 0x48(%rsp)
movl $0x1, %edx
movl %edx, %esi
callq 0x36e0
movq %rax, 0x50(%rsp)
jmp 0x5851
movq 0x48(%rsp), %rdi
movq 0x50(%rsp), %rax
movsd (%rax), %xmm0
addsd %xmm0, %xmm0
movl $0x1, %edx
movl %edx, %esi
callq 0x47c0
movq 0xf8(%rsp), %rsi
movabsq $0x400921fb54442d18, %rax # imm = 0x400921FB54442D18
movq %rax, 0xa8(%rsp)
leaq 0xb0(%rsp), %rdi
leaq 0xa8(%rsp), %rdx
callq 0x4960
jmp 0x58a0
movq 0xf8(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x41e0
jmp 0x58b7
leaq 0xb0(%rsp), %rdi
callq 0x3660
movq 0xf8(%rsp), %rsi
leaq 0x98(%rsp), %rdi
callq 0x5010
jmp 0x58db
movl $0x1, 0x94(%rsp)
movl 0x94(%rsp), %eax
cmpl 0xf4(%rsp), %eax
jg 0x5b4f
movq 0xf8(%rsp), %rsi
movl 0x94(%rsp), %edx
leaq 0x80(%rsp), %rdi
callq 0x3ae0
jmp 0x5918
movl $0x1, 0x7c(%rsp)
movl 0x7c(%rsp), %eax
cmpl 0xf4(%rsp), %eax
jg 0x5a86
movl 0x7c(%rsp), %eax
cmpl 0x94(%rsp), %eax
jge 0x5a35
movl 0x7c(%rsp), %edx
movl %edx, 0x3c(%rsp)
leaq 0x98(%rsp), %rdi
movl %edx, %esi
callq 0x36e0
movq %rax, 0x40(%rsp)
jmp 0x5960
movq 0x40(%rsp), %rax
movsd (%rax), %xmm0
callq 0x2200
movl 0x3c(%rsp), %esi
movaps 0x96f7(%rip), %xmm1     # 0xf070
pxor %xmm1, %xmm0
leaq 0x80(%rsp), %rdi
callq 0xe480
jmp 0x598c
jmp 0x5a74
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xd8(%rsp)
movl %eax, 0xd4(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x3660
jmp 0x5ba4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xd8(%rsp)
movl %eax, 0xd4(%rsp)
jmp 0x5b97
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xd8(%rsp)
movl %eax, 0xd4(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0x3660
jmp 0x5b97
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xd8(%rsp)
movl %eax, 0xd4(%rsp)
jmp 0x5b8a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xd8(%rsp)
movl %eax, 0xd4(%rsp)
leaq 0x80(%rsp), %rdi
callq 0xd170
jmp 0x5b8a
movl 0x7c(%rsp), %esi
movl %esi, 0x2c(%rsp)
leaq 0x80(%rsp), %rdi
callq 0xdee0
movq %rax, 0x30(%rsp)
jmp 0x5a51
movq 0x30(%rsp), %rax
movsd (%rax), %xmm0
callq 0x2200
movl 0x2c(%rsp), %esi
leaq 0x80(%rsp), %rdi
callq 0xe480
jmp 0x5a72
jmp 0x5a74
jmp 0x5a76
movl 0x7c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x7c(%rsp)
jmp 0x5920
movl $0x1, 0x78(%rsp)
movl 0x78(%rsp), %eax
cmpl 0xf4(%rsp), %eax
jg 0x5b2c
movq 0xf8(%rsp), %rax
movq %rax, 0x10(%rsp)
movl 0x78(%rsp), %esi
movl %esi, 0x18(%rsp)
movl 0x94(%rsp), %eax
movl %eax, 0x1c(%rsp)
leaq 0x80(%rsp), %rdi
callq 0xdee0
movq %rax, 0x20(%rsp)
jmp 0x5ad3
movq 0x20(%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, (%rsp)
leaq 0x80(%rsp), %rdi
movl $0x2, %esi
callq 0xe320
movsd %xmm0, 0x8(%rsp)
jmp 0x5afb
movl 0x1c(%rsp), %edx
movl 0x18(%rsp), %esi
movq 0x10(%rsp), %rdi
movsd 0x8(%rsp), %xmm1
movsd (%rsp), %xmm0
divsd %xmm1, %xmm0
callq 0x47c0
movl 0x78(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x78(%rsp)
jmp 0x5a8e
leaq 0x80(%rsp), %rdi
callq 0xd170
movl 0x94(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x94(%rsp)
jmp 0x58e6
movq 0x60(%rsp), %rdi
movq 0xf8(%rsp), %rsi
callq 0x5010
jmp 0x5b63
leaq 0x98(%rsp), %rdi
callq 0x3660
leaq 0xc0(%rsp), %rdi
callq 0xd170
movq 0x68(%rsp), %rax
addq $0x108, %rsp            # imm = 0x108
retq
leaq 0x98(%rsp), %rdi
callq 0x3660
leaq 0xc0(%rsp), %rdi
callq 0xd170
movq 0xd8(%rsp), %rdi
callq 0x21e0
nopw %cs:(%rax,%rax)