// File: /workspace/github_cpp_makefile_star2_O3/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 $0x128, %rsp            # imm = 0x128
movq %rdi, %rbx
movl 0xc(%rsi), %ebp
leaq 0x58(%rsp), %rdi
callq 0x3d86
leaq 0xf8(%rsp), %rdi
movl %ebp, %esi
callq 0x8ded
leaq 0xf8(%rsp), %rsi
movq %rbx, 0x28(%rsp)
movq %rbx, %rdi
callq 0x3d0b
testl %ebp, %ebp
jle 0x6f6b
movq %rbp, %r14
negq %r14
xorl %r13d, %r13d
leaq 0xe8(%rsp), %r12
movq %rbp, %rsi
subq %r13, %rsi
movq %r12, %rdi
movq %rsi, 0x18(%rsp)
movl $0x1, %edx
callq 0x2e94
movq 0xe8(%rsp), %rax
movq %rax, 0x40(%rsp)
leal 0x1(%r13), %r15d
xorpd %xmm0, %xmm0
movl $0x1, %ebx
movq %r14, 0x68(%rsp)
movq %r13, 0x20(%rsp)
movsd %xmm0, 0x8(%rsp)
addq %rbx, %r13
leaq 0x58(%rsp), %r14
movq %r14, %rdi
movl %r13d, %esi
movl %r15d, %edx
callq 0x2f5c
movsd (%rax), %xmm0
movq 0x40(%rsp), %rax
movq -0x8(%rax,%rbx,8), %rax
movsd %xmm0, (%rax)
movq %r14, %rdi
movl %r13d, %esi
movl %r15d, %edx
callq 0x2f5c
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %r14, %rdi
movl %r13d, %esi
movl %r15d, %edx
callq 0x2f5c
movsd 0x10(%rsp), %xmm1
mulsd (%rax), %xmm1
movsd 0x8(%rsp), %xmm0
addsd %xmm1, %xmm0
movq 0x68(%rsp), %r14
leaq (%r14,%rbx), %rax
incq %rax
incq %rbx
cmpq $0x1, %rax
movq 0x20(%rsp), %r13
jne 0x6994
ucomisd 0x265e(%rip), %xmm0     # 0x9080
jb 0x6a2a
sqrtsd %xmm0, %xmm0
jmp 0x6a2f
callq 0x2100
movsd %xmm0, 0x8(%rsp)
leaq 0xb0(%rsp), %rbx
movq %r12, %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0x2f5c
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %r12, %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0x2f5c
movsd (%rax), %xmm0
movsd %xmm0, 0x40(%rsp)
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
movl $0x1, %edx
callq 0x2e94
xorl %eax, %eax
xorpd %xmm0, %xmm0
ucomisd 0x40(%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)
leaq 0x48(%rsp), %r15
movq %r15, %rdi
leaq 0x30(%rsp), %rsi
movq %rbx, %rdx
callq 0x3ace
leaq 0xa0(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x3253
movq %r15, %rbx
movq %r15, %rdi
callq 0x2f1c
cmpq $0x0, 0x18(%rsp)
leaq 0xa0(%rsp), %r12
jle 0x6bc9
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movl $0x1, %r15d
movq %r12, %rdi
movl %r15d, %esi
movl $0x1, %edx
callq 0x2f5c
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %r12, %rdi
movl %r15d, %esi
movl $0x1, %edx
callq 0x2f5c
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 0x6b2b
movsd 0x8(%rsp), %xmm1
ucomisd 0x24f0(%rip), %xmm1     # 0x9080
jne 0x6b94
jnp 0x6bc9
movsd 0x247c(%rip), %xmm0     # 0x9018
divsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rsp)
movq %rbx, %rdi
leaq 0x30(%rsp), %rsi
movq %r12, %rdx
callq 0x3ace
movq %r12, %rdi
movq %rbx, %rsi
callq 0x3574
movq %rbx, %rdi
callq 0x2f1c
movq %rbx, %rdi
movq 0x18(%rsp), %rbx
movl %ebx, %esi
movl %ebx, %edx
callq 0x2e94
leaq 0x30(%rsp), %rdi
movl %ebp, %esi
movl %ebx, %edx
callq 0x2e94
movq %r13, %r15
incq %r15
movq %r15, %rbx
subq %r13, %rbx
movl $0x1, %r12d
leal (%r12,%r13), %edx
leaq 0x58(%rsp), %rdi
movl %r15d, %esi
callq 0x2f5c
movsd (%rax), %xmm0
movq 0x48(%rsp), %rax
movq -0x8(%rax,%rbx,8), %rax
movsd %xmm0, -0x8(%rax,%r12,8)
leaq (%r14,%r12), %rax
incq %rax
incq %r12
cmpq $0x1, %rax
jne 0x6bfa
cmpq %rbp, %r15
jne 0x6beb
xorl %r15d, %r15d
leaq 0xa0(%rsp), %r12
incq %r15
movl $0x1, %ebx
leal (%rbx,%r13), %edx
movq 0x28(%rsp), %rdi
movl %r15d, %esi
callq 0x2f5c
movsd (%rax), %xmm0
movq 0x30(%rsp), %rax
movq -0x8(%rax,%r15,8), %rax
movsd %xmm0, -0x8(%rax,%rbx,8)
leaq (%r14,%rbx), %rax
incq %rax
incq %rbx
cmpq $0x1, %rax
jne 0x6c48
cmpq %rbp, %r15
jne 0x6c40
leaq 0xd8(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3114
leaq 0x108(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
leaq 0x48(%rsp), %rbx
movq %rbx, %rdx
callq 0x37a8
movabsq $0x4000000000000000, %rax # imm = 0x4000000000000000
movq %rax, 0x90(%rsp)
leaq 0x70(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x37a8
leaq 0x80(%rsp), %r14
movq %r14, %rdi
leaq 0x90(%rsp), %rsi
movq %r15, %rdx
callq 0x3ace
leaq 0xc8(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x3454
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3574
movq %r15, %rdi
callq 0x2f1c
leaq 0x80(%rsp), %rbx
movq %rbx, %rdi
callq 0x2f1c
leaq 0x70(%rsp), %rdi
callq 0x2f1c
movq %r15, %rdi
movq 0x18(%rsp), %rsi
callq 0x8ded
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3d0b
movabsq $0x4000000000000000, %rax # imm = 0x4000000000000000
movq %rax, 0xc0(%rsp)
leaq 0x118(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
leaq 0xd8(%rsp), %rdx
callq 0x37a8
leaq 0x90(%rsp), %r15
movq %r15, %rdi
leaq 0xc0(%rsp), %rsi
movq %rbx, %rdx
callq 0x3ace
leaq 0x70(%rsp), %r14
leaq 0x80(%rsp), %rsi
movq %r14, %rdi
movq %r15, %rdx
callq 0x3454
movq %r15, %rdi
callq 0x2f1c
movq %rbx, %rdi
callq 0x2f1c
movq %r15, %rdi
leaq 0x30(%rsp), %rbx
movq %rbx, %rsi
movq %r14, %rdx
callq 0x37a8
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3574
movq %r15, %rdi
callq 0x2f1c
movq 0x58(%rsp), %rbx
movq %r13, %r12
movq %rbp, %r14
leaq 0x1(%r12), %rax
movq %rax, 0x8(%rsp)
movl %eax, %r15d
subl %r13d, %r15d
movq %r13, %rbp
movl $0x1, %r13d
leaq 0x48(%rsp), %rdi
movl %r15d, %esi
movl %r13d, %edx
callq 0x2f5c
movsd (%rax), %xmm0
movq (%rbx,%r12,8), %rax
movsd %xmm0, (%rax,%rbp,8)
incq %rbp
incl %r13d
cmpq %rbp, %r14
jne 0x6e05
movq 0x8(%rsp), %rax
movq %rax, %r12
movq %r14, %rbp
cmpq %r14, %rax
movq 0x20(%rsp), %r13
jne 0x6de9
movq 0x6187(%rip), %rbx      # 0xcfd0
movq %rbx, %rdi
leaq 0x58(%rsp), %rsi
callq 0x3b35
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 %r12d, %r12d
leaq 0x1(%r12), %r15
movl $0x1, %r13d
movq 0x20(%rsp), %rbp
leaq 0x30(%rsp), %rdi
movl %r15d, %esi
movl %r13d, %edx
callq 0x2f5c
movsd (%rax), %xmm0
movq (%rbx,%r12,8), %rax
movsd %xmm0, (%rax,%rbp,8)
incq %rbp
incl %r13d
cmpq %rbp, %r14
jne 0x6ea3
movq %r15, %r12
cmpq %r14, %r15
jne 0x6e93
movq %r14, %rbp
leaq 0x70(%rsp), %rdi
callq 0x2f1c
leaq 0x80(%rsp), %rdi
callq 0x2f1c
leaq 0xc8(%rsp), %rdi
callq 0x827e
leaq 0x108(%rsp), %rdi
callq 0x2f1c
leaq 0xd8(%rsp), %rdi
callq 0x2f1c
leaq 0x30(%rsp), %rdi
callq 0x2f1c
leaq 0x48(%rsp), %rdi
callq 0x2f1c
leaq 0xa0(%rsp), %rdi
callq 0x2f1c
leaq 0xb0(%rsp), %rdi
callq 0x2f1c
leaq 0xe8(%rsp), %r12
movq %r12, %rdi
callq 0x2f1c
movq 0x20(%rsp), %r13
incq %r13
movq 0x68(%rsp), %r14
incq %r14
cmpq %rbp, %r13
jne 0x6958
leaq 0xf8(%rsp), %rdi
callq 0x827e
leaq 0x58(%rsp), %rdi
callq 0x2f1c
movq 0x28(%rsp), %rax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
jmp 0x7103
movq %rax, %r14
jmp 0x7110
jmp 0x703d
jmp 0x706a
movq %rax, %r14
leaq 0x90(%rsp), %rdi
callq 0x2f1c
jmp 0x6ffe
jmp 0x7036
jmp 0x7076
movq %rax, %r14
jmp 0x7090
movq %rax, %r14
jmp 0x7025
movq %rax, %r14
leaq 0x90(%rsp), %rdi
callq 0x2f1c
jmp 0x7079
movq %rax, %r14
jmp 0x7083
movq %rax, %r14
jmp 0x7018
movq %rax, %r14
leaq 0x118(%rsp), %rdi
jmp 0x707e
movq %rax, %r14
leaq 0xc8(%rsp), %rdi
callq 0x2f1c
leaq 0x80(%rsp), %rdi
callq 0x2f1c
leaq 0x70(%rsp), %rdi
callq 0x2f1c
jmp 0x709d
movq %rax, %r14
jmp 0x70aa
movq %rax, %r14
jmp 0x709d
jmp 0x70bb
movq %rax, %r14
jmp 0x70c8
jmp 0x706a
movq %rax, %r14
leaq 0x48(%rsp), %rdi
jmp 0x70da
jmp 0x706f
movq %rax, %r14
jmp 0x70df
movq %rax, %r14
jmp 0x70f9
jmp 0x706f
jmp 0x7076
movq %rax, %r14
jmp 0x70d2
movq %rax, %r14
jmp 0x70ec
jmp 0x7076
movq %rax, %r14
leaq 0x70(%rsp), %rdi
callq 0x2f1c
leaq 0x80(%rsp), %rdi
callq 0x2f1c
leaq 0xc8(%rsp), %rdi
callq 0x827e
leaq 0x108(%rsp), %rdi
callq 0x2f1c
leaq 0xd8(%rsp), %rdi
callq 0x2f1c
jmp 0x70be
jmp 0x70bb
movq %rax, %r14
leaq 0x30(%rsp), %rdi
callq 0x2f1c
leaq 0x48(%rsp), %rdi
callq 0x2f1c
leaq 0xa0(%rsp), %rdi
callq 0x2f1c
leaq 0xb0(%rsp), %rdi
callq 0x2f1c
leaq 0xe8(%rsp), %rdi
callq 0x2f1c
movq 0x28(%rsp), %rdi
callq 0x2f1c
leaq 0xf8(%rsp), %rdi
callq 0x827e
leaq 0x58(%rsp), %rdi
callq 0x2f1c
movq %r14, %rdi
callq 0x21f0