// File: /workspace/github_cpp_makefile_star2_O1/yukimasano[P]cpp_matrix/Matrix.cpp
// Function: qr_q(Matrix&)
Matrix qr_q(Matrix& A){
	int m = ncols(A);
	Matrix R= A;
	Vector temp=ones(m);
	Matrix Q = diag(temp);
    for (int j = 0; j<m; j++){
    	Matrix x(m-j,1);
    	double len=0.0;
    	for (int l=j; l<m; l++){
    		x.set_val(l+1-j,1 ,R(l+1,j+1));
    		len+=R(l+1,j+1) * R(l+1,j+1);
    	}

    	len=sqrt(len);

    	int sign = (x(1,1) >= 0) - (x(1,1) < 0);
    	Matrix e(m-j,1);
    	e.set_val(1,1,1.0);

    	Matrix u = (sign*len*e + x);

    	// normalise u
    	len=0.0;
    	for (int i = 1; i<=m-j; i++){
    		len+=u(i,1)*u(i,1);
    	}
      if (len!=0){u= (1./len)*u;}
      //   	std::cout<<"here comes  u " << std::endl<< j<<"  "<< u << std::endl<<std::flush;

    	// SUBMULTIPLICATION    START /////////////////////////////
    	Matrix sub(m-j, m-j);
    	Matrix subQ(m,m-j);
    	for (int i = j; i<m; i++){
    		for (int h = j; h<m; h++){
    			sub.set_val(i+1 - j,h+1 - j, R(i+1,h+1));
    		}
    	}

    	for (int i = 0; i<m; i++){
			for (int h = j; h<m; h++){
				subQ.set_val(i+1,h+1-j,Q(i+1,h+1));
			}
		}

    	Matrix w=(u.T());
    	Matrix z= w*sub;
    	sub = sub -2.0*(u*z);

    	Vector temp2= ones(m-j);
    	Matrix subeye= diag(temp2);
    	Matrix temp3= subeye -2.0*(u*w);
    	subQ= subQ*(temp3);
    	for (int i = j; i<m; i++){
    		for (int h = j; h<m; h++){
    			R.set_val(i+1,h+1, sub(i+1- j,h+1- j));
    		}
    	}
      std::cout<<R<<std::flush<<std::endl;
    	for (int i = 0; i<m; i++){
  			for (int h = j; h<m; h++){
  				Q.set_val(i+1, h+1, subQ(i+1,h+1-j));
  			}
		  }
    }
    return Q;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rdi, %rbx
movl 0xc(%rsi), %r12d
leaq 0x60(%rsp), %rdi
callq 0x3db2
leaq 0xe8(%rsp), %rdi
movl %r12d, %esi
callq 0x8e81
leaq 0xe8(%rsp), %rsi
movq %rbx, 0x28(%rsp)
movq %rbx, %rdi
callq 0x3d37
testl %r12d, %r12d
jle 0x6fc1
movq %r12, %r14
negq %r14
xorl %ebp, %ebp
leaq 0x90(%rsp), %rbx
movq %r12, %rsi
subq %rbp, %rsi
movq %rbx, %rdi
movq %rsi, 0x20(%rsp)
movl $0x1, %edx
callq 0x2eb8
leal 0x1(%rbp), %r15d
movq 0x90(%rsp), %rax
movq %rax, 0x18(%rsp)
xorpd %xmm0, %xmm0
movl $0x1, %r13d
movsd %xmm0, 0x8(%rsp)
leal (%rbp,%r13), %esi
leaq 0x60(%rsp), %rbx
movq %rbx, %rdi
movl %r15d, %edx
callq 0x2f92
movsd (%rax), %xmm0
movq 0x18(%rsp), %rax
movq -0x8(%rax,%r13,8), %rax
movsd %xmm0, (%rax)
leal (%rbp,%r13), %esi
movq %rbx, %rdi
movl %r15d, %edx
callq 0x2f92
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
leal (%rbp,%r13), %esi
movq %rbx, %rdi
movl %r15d, %edx
callq 0x2f92
movsd 0x10(%rsp), %xmm1
mulsd (%rax), %xmm1
movsd 0x8(%rsp), %xmm0
addsd %xmm1, %xmm0
leaq (%r14,%r13), %rax
incq %rax
incq %r13
cmpq $0x1, %rax
jne 0x69dc
ucomisd 0x3621(%rip), %xmm0     # 0xa080
jb 0x6a67
sqrtsd %xmm0, %xmm0
jmp 0x6a6c
callq 0x2100
movsd %xmm0, 0x8(%rsp)
leaq 0xb0(%rsp), %rbx
leaq 0x40(%rsp), %r13
leaq 0x90(%rsp), %r15
movq %r15, %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0x2f92
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %r15, %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0x2f92
movsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movq %rbx, %rdi
movq 0x20(%rsp), %rsi
movl $0x1, %edx
callq 0x2eb8
xorl %eax, %eax
xorpd %xmm0, %xmm0
ucomisd 0x18(%rsp), %xmm0
seta %al
movsd 0x10(%rsp), %xmm1
ucomisd %xmm0, %xmm1
adcl $-0x1, %eax
negl %eax
movq 0xb0(%rsp), %rcx
movq (%rcx), %rcx
movabsq $0x3ff0000000000000, %rdx # imm = 0x3FF0000000000000
movq %rdx, (%rcx)
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd 0x8(%rsp), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x30(%rsp)
movq %r13, %rdi
leaq 0x30(%rsp), %rsi
movq %rbx, %rdx
callq 0x3afa
leaq 0x50(%rsp), %rdi
movq %r13, %rsi
leaq 0x90(%rsp), %rdx
callq 0x327f
movq %r13, %rdi
callq 0x2f4c
cmpq $0x0, 0x20(%rsp)
jle 0x6bc1
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movl $0x1, %r15d
leaq 0x50(%rsp), %rbx
movq %rbx, %rdi
movl %r15d, %esi
movl $0x1, %edx
callq 0x2f92
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %rbx, %rdi
movl %r15d, %esi
movl $0x1, %edx
callq 0x2f92
movsd 0x10(%rsp), %xmm1
mulsd (%rax), %xmm1
movsd 0x8(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
leal (%r14,%r15), %eax
incl %eax
movl %r15d, %ecx
incl %ecx
movl %ecx, %r15d
cmpl $0x1, %eax
jne 0x6b63
jmp 0x6bcb
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x8(%rsp), %xmm1
ucomisd 0x34a7(%rip), %xmm1     # 0xa080
movq 0x20(%rsp), %r15
jne 0x6be2
jnp 0x6c1c
movsd 0x342e(%rip), %xmm0     # 0xa018
divsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rsp)
movq %r13, %rdi
leaq 0x30(%rsp), %rsi
leaq 0x50(%rsp), %rbx
movq %rbx, %rdx
callq 0x3afa
movq %rbx, %rdi
movq %r13, %rsi
callq 0x35a0
movq %r13, %rdi
callq 0x2f4c
movq %r13, %rdi
movl %r15d, %esi
movl %r15d, %edx
callq 0x2eb8
leaq 0x30(%rsp), %rdi
movl %r12d, %esi
movl %r15d, %edx
callq 0x2eb8
movq %rbp, %r15
incq %r15
movq %r15, %rbx
subq %rbp, %rbx
movl $0x1, %r13d
leal (%rbp,%r13), %edx
leaq 0x60(%rsp), %rdi
movl %r15d, %esi
callq 0x2f92
movsd (%rax), %xmm0
movq 0x40(%rsp), %rax
movq -0x8(%rax,%rbx,8), %rax
movsd %xmm0, -0x8(%rax,%r13,8)
leaq (%r14,%r13), %rax
incq %rax
incq %r13
cmpq $0x1, %rax
jne 0x6c4c
cmpq %r12, %r15
jne 0x6c3d
xorl %ebx, %ebx
leal 0x1(%rbx), %r15d
movl $0x1, %r13d
leal (%rbp,%r13), %edx
movq 0x28(%rsp), %rdi
movl %r15d, %esi
callq 0x2f92
movsd (%rax), %xmm0
movq 0x30(%rsp), %rax
movq (%rax,%rbx,8), %rax
movsd %xmm0, -0x8(%rax,%r13,8)
leaq (%r14,%r13), %rax
incq %rax
incq %r13
cmpq $0x1, %rax
jne 0x6c94
incq %rbx
cmpq %r12, %rbx
jne 0x6c8a
leaq 0xd8(%rsp), %rbx
movq %rbx, %rdi
leaq 0x50(%rsp), %rsi
callq 0x3140
leaq 0xf8(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
leaq 0x40(%rsp), %rbx
movq %rbx, %rdx
callq 0x37d8
movabsq $0x4000000000000000, %rax # imm = 0x4000000000000000
movq %rax, 0xa0(%rsp)
leaq 0x70(%rsp), %r13
movq %r13, %rdi
leaq 0x50(%rsp), %rsi
movq %r15, %rdx
callq 0x37d8
leaq 0x80(%rsp), %r15
movq %r15, %rdi
leaq 0xa0(%rsp), %rsi
movq %r13, %rdx
callq 0x3afa
leaq 0xc8(%rsp), %r13
movq %r13, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x3480
movq %rbx, %rdi
movq %r13, %rsi
callq 0x35a0
movq %r13, %rdi
callq 0x2f4c
leaq 0x80(%rsp), %rbx
movq %rbx, %rdi
callq 0x2f4c
leaq 0x70(%rsp), %rdi
callq 0x2f4c
movq %r13, %rdi
movq 0x20(%rsp), %rsi
callq 0x8e81
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3d37
leaq 0x108(%rsp), %rbx
movabsq $0x4000000000000000, %rax # imm = 0x4000000000000000
movq %rax, 0xc0(%rsp)
movq %rbx, %rdi
leaq 0x50(%rsp), %rsi
leaq 0xd8(%rsp), %rdx
callq 0x37d8
leaq 0xa0(%rsp), %r15
movq %r15, %rdi
leaq 0xc0(%rsp), %rsi
movq %rbx, %rdx
callq 0x3afa
leaq 0x70(%rsp), %r13
movq %r13, %rdi
leaq 0x80(%rsp), %rsi
movq %r15, %rdx
callq 0x3480
movq %r15, %rdi
callq 0x2f4c
movq %rbx, %rdi
callq 0x2f4c
movq %r15, %rdi
leaq 0x30(%rsp), %rbx
movq %rbx, %rsi
movq %r13, %rdx
callq 0x37d8
movq %r14, 0x18(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x35a0
movq %r15, %rdi
callq 0x2f4c
movq 0x60(%rsp), %rbx
movq %rbp, 0x8(%rsp)
movq %r12, %r14
leaq 0x1(%rbp), %rax
movq %rax, 0x10(%rsp)
movl %eax, %r15d
movq 0x8(%rsp), %r12
subl %r12d, %r15d
movl $0x1, %r13d
leaq 0x40(%rsp), %rdi
movl %r15d, %esi
movl %r13d, %edx
callq 0x2f92
movsd (%rax), %xmm0
movq (%rbx,%rbp,8), %rax
movsd %xmm0, (%rax,%r12,8)
incq %r12
incl %r13d
cmpq %r12, %r14
jne 0x6e63
movq 0x10(%rsp), %rax
movq %rax, %rbp
movq %r14, %r12
cmpq %r14, %rax
jne 0x6e46
movq 0x712d(%rip), %rbx      # 0xdfd0
movq %rbx, %rdi
leaq 0x60(%rsp), %rsi
callq 0x3b61
movq %rbx, %rdi
callq 0x20d0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2150
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20d0
movq 0x28(%rsp), %rax
movq (%rax), %rbx
xorl %ebp, %ebp
leal 0x1(%rbp), %r15d
movl $0x1, %r13d
movq 0x8(%rsp), %r12
leaq 0x30(%rsp), %rdi
movl %r15d, %esi
movl %r13d, %edx
callq 0x2f92
movsd (%rax), %xmm0
movq (%rbx,%rbp,8), %rax
movsd %xmm0, (%rax,%r12,8)
incq %r12
incl %r13d
cmpq %r12, %r14
jne 0x6efb
incq %rbp
cmpq %r14, %rbp
jne 0x6eec
movq %r14, %r12
leaq 0x70(%rsp), %rdi
callq 0x2f4c
leaq 0x80(%rsp), %rdi
callq 0x2f4c
leaq 0xc8(%rsp), %rdi
callq 0x8310
leaq 0xf8(%rsp), %rdi
callq 0x2f4c
leaq 0xd8(%rsp), %rdi
callq 0x2f4c
leaq 0x30(%rsp), %rdi
callq 0x2f4c
leaq 0x40(%rsp), %rdi
callq 0x2f4c
leaq 0x50(%rsp), %rdi
callq 0x2f4c
leaq 0xb0(%rsp), %rdi
callq 0x2f4c
leaq 0x90(%rsp), %rbx
movq %rbx, %rdi
callq 0x2f4c
movq 0x8(%rsp), %rbp
incq %rbp
movq 0x18(%rsp), %r14
incq %r14
cmpq %r12, %rbp
jne 0x69a9
leaq 0xe8(%rsp), %rdi
callq 0x8310
leaq 0x60(%rsp), %rdi
callq 0x2f4c
movq 0x28(%rsp), %rax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
jmp 0x7153
movq %rax, %r14
jmp 0x7160
jmp 0x7093
jmp 0x70bd
movq %rax, %r14
leaq 0xa0(%rsp), %rdi
callq 0x2f4c
jmp 0x7054
jmp 0x708c
jmp 0x70c9
movq %rax, %r14
jmp 0x70e3
movq %rax, %r14
jmp 0x707b
movq %rax, %r14
leaq 0xa0(%rsp), %rdi
callq 0x2f4c
jmp 0x70cc
movq %rax, %r14
jmp 0x70d6
movq %rax, %r14
jmp 0x706e
movq %rax, %r14
leaq 0x108(%rsp), %rdi
jmp 0x70d1
movq %rax, %r14
leaq 0xc8(%rsp), %rdi
callq 0x2f4c
leaq 0x80(%rsp), %rdi
callq 0x2f4c
leaq 0x70(%rsp), %rdi
callq 0x2f4c
jmp 0x70f0
movq %rax, %r14
jmp 0x70fd
movq %rax, %r14
jmp 0x70f0
jmp 0x710e
movq %rax, %r14
jmp 0x711b
jmp 0x70bd
movq %rax, %r14
leaq 0x40(%rsp), %rdi
jmp 0x712a
jmp 0x70c2
movq %rax, %r14
jmp 0x712f
movq %rax, %r14
jmp 0x7149
jmp 0x70c2
jmp 0x70c9
movq %rax, %r14
jmp 0x7125
movq %rax, %r14
jmp 0x713c
jmp 0x70c9
movq %rax, %r14
leaq 0x70(%rsp), %rdi
callq 0x2f4c
leaq 0x80(%rsp), %rdi
callq 0x2f4c
leaq 0xc8(%rsp), %rdi
callq 0x8310
leaq 0xf8(%rsp), %rdi
callq 0x2f4c
leaq 0xd8(%rsp), %rdi
callq 0x2f4c
jmp 0x7111
jmp 0x710e
movq %rax, %r14
leaq 0x30(%rsp), %rdi
callq 0x2f4c
leaq 0x40(%rsp), %rdi
callq 0x2f4c
leaq 0x50(%rsp), %rdi
callq 0x2f4c
leaq 0xb0(%rsp), %rdi
callq 0x2f4c
leaq 0x90(%rsp), %rdi
callq 0x2f4c
movq 0x28(%rsp), %rdi
callq 0x2f4c
leaq 0xe8(%rsp), %rdi
callq 0x8310
leaq 0x60(%rsp), %rdi
callq 0x2f4c
movq %r14, %rdi
callq 0x21f0