// File: /workspace/github_cpp_makefile_star2_O2/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 $0x158, %rsp            # imm = 0x158
movq %rdi, %rbx
movl 0xc(%rsi), %r14d
leaq 0x88(%rsp), %rdi
callq 0x3b80
leaq 0x128(%rsp), %rdi
movl %r14d, %esi
callq 0x8995
leaq 0x128(%rsp), %rsi
movq %rbx, 0x30(%rsp)
movq %rbx, %rdi
callq 0x3b09
xorl %r13d, %r13d
testl %r14d, %r14d
movl $0x0, %eax
cmovgl %r14d, %eax
movq %rax, 0x70(%rsp)
movq %r14, %rax
negq %rax
leaq 0xc8(%rsp), %rbx
pushq $0x1
popq %r15
movl %r14d, %ecx
movq %r14, 0x38(%rsp)
cmpl %r13d, %r14d
movl %r13d, %edx
cmovgl %r14d, %edx
movq %rdx, 0x78(%rsp)
testl %ecx, %ecx
movl $0x0, %edx
cmovgl %ecx, %edx
movq %rdx, 0x68(%rsp)
cmpq 0x70(%rsp), %r13
je 0x6e86
movl %ecx, 0x84(%rsp)
movq %rax, 0x28(%rsp)
movl %r14d, %eax
subl %r13d, %eax
movq %rbx, %rdi
movl %eax, %ebx
movl %eax, %esi
movl %r15d, %edx
callq 0x2d58
movq %r13, %r12
subq 0x78(%rsp), %r12
movq 0x68(%rsp), %rax
negl %eax
movq %rax, 0x68(%rsp)
movq %r13, 0x10(%rsp)
leaq 0x1(%r13), %r14
movq 0xc8(%rsp), %rax
movq %rax, 0x60(%rsp)
xorpd %xmm0, %xmm0
pushq $0x1
popq %r13
movl %ebx, 0x1c(%rsp)
movq 0x28(%rsp), %rax
addq %r13, %rax
cmpq $0x1, %rax
je 0x692a
movsd %xmm0, 0x8(%rsp)
movq 0x10(%rsp), %rax
leaq (%rax,%r13), %rbp
leaq 0x88(%rsp), %rbx
movq %rbx, %rdi
movl %ebp, %esi
movl %r14d, %edx
callq 0x2e20
movsd (%rax), %xmm0
movq 0x60(%rsp), %rax
movq -0x8(%rax,%r13,8), %rax
movsd %xmm0, (%rax)
movq %rbx, %rdi
movl %ebp, %esi
movl %r14d, %edx
callq 0x2e20
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
movq %rbx, %rdi
movl %ebp, %esi
movl %r14d, %edx
callq 0x2e20
movsd 0x20(%rsp), %xmm1
mulsd (%rax), %xmm1
movsd 0x8(%rsp), %xmm0
addsd %xmm1, %xmm0
incq %r13
jmp 0x68a6
ucomisd 0x274e(%rip), %xmm0     # 0x9080
movq %r14, 0xe8(%rsp)
jb 0x6942
sqrtsd %xmm0, %xmm0
jmp 0x6947
callq 0x20f0
movsd %xmm0, 0x8(%rsp)
movq 0x38(%rsp), %rbx
movq 0x28(%rsp), %r13
leaq 0xc8(%rsp), %r14
movq %r14, %rdi
movl %r15d, %esi
movl %r15d, %edx
callq 0x2e20
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
movq %r14, %rdi
movl %r15d, %esi
movl %r15d, %edx
callq 0x2e20
movsd (%rax), %xmm0
movsd %xmm0, 0x60(%rsp)
leaq 0x118(%rsp), %r14
movq %r14, %rdi
movl 0x1c(%rsp), %esi
movl %r15d, %edx
callq 0x2d58
xorl %eax, %eax
xorpd %xmm0, %xmm0
ucomisd 0x60(%rsp), %xmm0
seta %al
movsd 0x20(%rsp), %xmm1
ucomisd %xmm0, %xmm1
adcl $-0x1, %eax
negl %eax
movq 0x118(%rsp), %rcx
movq (%rcx), %rcx
movabsq $0x3ff0000000000000, %rdx # imm = 0x3FF0000000000000
movq %rdx, (%rcx)
cvtsi2sd %eax, %xmm0
movsd 0x8(%rsp), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, 0x40(%rsp)
leaq 0x50(%rsp), %rbp
movq %rbp, %rdi
leaq 0x40(%rsp), %rsi
movq %r14, %rdx
callq 0x38f1
leaq 0xb8(%rsp), %rdi
movq %rbp, %rsi
leaq 0xc8(%rsp), %rdx
callq 0x30c0
movq %rbp, %rdi
callq 0x2dea
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movl %r15d, %ebp
movq 0x68(%rsp), %rax
addl %ebp, %eax
cmpl $0x1, %eax
je 0x6a88
leaq 0xb8(%rsp), %r14
movq %r14, %rdi
movl %ebp, %esi
movl %r15d, %edx
callq 0x2e20
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
movq %r14, %rdi
movl %ebp, %esi
movl %r15d, %edx
callq 0x2e20
movsd 0x20(%rsp), %xmm1
mulsd (%rax), %xmm1
movsd 0x8(%rsp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
incl %ebp
jmp 0x6a32
movsd 0x8(%rsp), %xmm1
ucomisd 0x25ea(%rip), %xmm1     # 0x9080
leaq 0x50(%rsp), %r14
jne 0x6a9f
jnp 0x6adc
movsd 0x2571(%rip), %xmm0     # 0x9018
divsd %xmm1, %xmm0
movsd %xmm0, 0x40(%rsp)
movq %r14, %rdi
leaq 0x40(%rsp), %rsi
leaq 0xb8(%rsp), %r15
movq %r15, %rdx
callq 0x38f1
movq %r15, %rdi
movq %r14, %rsi
callq 0x33ce
movq %r14, %rdi
callq 0x2dea
movq %r14, %rdi
movl 0x1c(%rsp), %ebp
movl %ebp, %esi
movl %ebp, %edx
callq 0x2d58
leaq 0x40(%rsp), %rdi
movl %ebx, %esi
movl %ebp, %edx
callq 0x2d58
movl 0x78(%rsp), %eax
movq %rax, 0x8(%rsp)
movq 0x10(%rsp), %rbp
cmpq 0x8(%rsp), %rbp
je 0x6b5a
incq %rbp
movq %rbp, %r14
subq 0x10(%rsp), %r14
pushq $0x1
popq %r15
leaq (%r15,%r13), %rax
cmpq $0x1, %rax
je 0x6b08
movq 0x10(%rsp), %rax
leal (%rax,%r15), %edx
leaq 0x88(%rsp), %rdi
movl %ebp, %esi
callq 0x2e20
movsd (%rax), %xmm0
movq 0x50(%rsp), %rax
movq -0x8(%rax,%r14,8), %rax
movsd %xmm0, -0x8(%rax,%r15,8)
incq %r15
jmp 0x6b1e
xorl %ebp, %ebp
leaq 0x50(%rsp), %rbx
leaq 0x40(%rsp), %r15
leaq 0xb8(%rsp), %r13
cmpq 0x70(%rsp), %rbp
je 0x6bb5
incq %rbp
pushq $0x1
popq %r14
leaq (%r12,%r14), %rax
cmpq $0x1, %rax
je 0x6b6e
movq 0x10(%rsp), %rax
leal (%rax,%r14), %edx
movq 0x30(%rsp), %rdi
movl %ebp, %esi
callq 0x2e20
movsd (%rax), %xmm0
movq 0x40(%rsp), %rax
movq -0x8(%rax,%rbp,8), %rax
movsd %xmm0, -0x8(%rax,%r14,8)
incq %r14
jmp 0x6b7c
leaq 0x108(%rsp), %r14
movq %r14, %rdi
movq %r13, %rsi
callq 0x2f86
leaq 0x138(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x35d4
movabsq $0x4000000000000000, %rax # imm = 0x4000000000000000
movq %rax, 0xd8(%rsp)
leaq 0x98(%rsp), %r14
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x35d4
leaq 0xa8(%rsp), %r12
movq %r12, %rdi
leaq 0xd8(%rsp), %rsi
movq %r14, %rdx
callq 0x38f1
leaq 0xf8(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x32b3
movq %rbx, %rdi
movq %r14, %rsi
callq 0x33ce
movq %r14, %rdi
callq 0x2dea
leaq 0xa8(%rsp), %rbx
movq %rbx, %rdi
callq 0x2dea
leaq 0x98(%rsp), %rdi
callq 0x2dea
movq %r14, %rdi
movl 0x1c(%rsp), %esi
callq 0x8995
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3b09
movabsq $0x4000000000000000, %rax # imm = 0x4000000000000000
movq %rax, 0xf0(%rsp)
leaq 0x148(%rsp), %r12
movq %r12, %rdi
movq %r13, %rsi
leaq 0x108(%rsp), %rdx
callq 0x35d4
leaq 0xd8(%rsp), %r14
movq %r14, %rdi
leaq 0xf0(%rsp), %rsi
movq %r12, %rdx
callq 0x38f1
leaq 0x98(%rsp), %rbx
leaq 0xa8(%rsp), %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x32b3
movq %r14, %rdi
callq 0x2dea
movq %r12, %rdi
callq 0x2dea
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x35d4
movq %r15, %rdi
movq %r14, %rsi
callq 0x33ce
movq %r14, %rdi
callq 0x2dea
movq 0x88(%rsp), %r13
movq 0x10(%rsp), %r15
cmpq 0x8(%rsp), %r15
je 0x6d69
leaq 0x1(%r15), %r14
movl %r14d, %ebp
movq 0x10(%rsp), %rbx
subl %ebx, %ebp
pushq $0x1
popq %r12
cmpq %rbx, 0x38(%rsp)
je 0x6d64
leaq 0x50(%rsp), %rdi
movl %ebp, %esi
movl %r12d, %edx
callq 0x2e20
movsd (%rax), %xmm0
movq (%r13,%r15,8), %rax
movsd %xmm0, (%rax,%rbx,8)
incl %r12d
incq %rbx
jmp 0x6d38
movq %r14, %r15
jmp 0x6d1f
movq 0x6260(%rip), %rbx      # 0xcfd0
movq %rbx, %rdi
leaq 0x88(%rsp), %rsi
callq 0x395b
movq %rbx, %rdi
callq 0x20d0
movq %rax, %rdi
callq 0x2080
movq 0x30(%rsp), %rax
movq (%rax), %r13
xorl %r15d, %r15d
cmpq 0x70(%rsp), %r15
je 0x6de0
leaq 0x1(%r15), %rbp
pushq $0x1
popq %r12
movq 0x10(%rsp), %rbx
cmpq %rbx, 0x78(%rsp)
je 0x6ddb
leaq 0x40(%rsp), %rdi
movl %ebp, %esi
movl %r12d, %edx
callq 0x2e20
movsd (%rax), %xmm0
movq (%r13,%r15,8), %rax
movsd %xmm0, (%rax,%rbx,8)
incl %r12d
incq %rbx
jmp 0x6daf
movq %rbp, %r15
jmp 0x6d9b
leaq 0x98(%rsp), %rdi
callq 0x2dea
leaq 0xa8(%rsp), %rdi
callq 0x2dea
leaq 0xf8(%rsp), %rdi
callq 0x8104
leaq 0x138(%rsp), %rdi
callq 0x2dea
leaq 0x108(%rsp), %rdi
callq 0x2dea
leaq 0x40(%rsp), %rdi
callq 0x2dea
leaq 0x50(%rsp), %rdi
callq 0x2dea
leaq 0xb8(%rsp), %rdi
callq 0x2dea
leaq 0x118(%rsp), %rdi
callq 0x2dea
leaq 0xc8(%rsp), %rbx
movq %rbx, %rdi
callq 0x2dea
movl 0x84(%rsp), %ecx
decl %ecx
movq 0x28(%rsp), %rax
incq %rax
movq 0xe8(%rsp), %r13
movq 0x38(%rsp), %r14
pushq $0x1
popq %r15
jmp 0x6826
leaq 0x128(%rsp), %rdi
callq 0x8104
leaq 0x88(%rsp), %rdi
callq 0x2dea
movq 0x30(%rsp), %rax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
jmp 0x702d
movq %rax, %r14
jmp 0x703a
jmp 0x6f91
jmp 0x6f64
movq %rax, %r14
jmp 0x6ef2
jmp 0x6f4d
movq %rax, %r14
jmp 0x6f3e
jmp 0x6fe5
movq %rax, %r14
leaq 0xd8(%rsp), %rdi
callq 0x2dea
leaq 0x148(%rsp), %rdi
jmp 0x6fa8
movq %rax, %r14
jmp 0x6fba
movq %rax, %r14
jmp 0x6f31
movq %rax, %r14
jmp 0x6fd4
jmp 0x6f9d
movq %rax, %r14
jmp 0x6fad
movq %rax, %r14
leaq 0xf8(%rsp), %rdi
callq 0x2dea
leaq 0xa8(%rsp), %rdi
callq 0x2dea
leaq 0x98(%rsp), %rdi
callq 0x2dea
jmp 0x6fc7
movq %rax, %r14
jmp 0x6fc7
movq %rax, %r14
leaq 0xd8(%rsp), %rdi
callq 0x2dea
jmp 0x6fa0
movq %rax, %r14
jmp 0x6ff2
jmp 0x6f91
movq %rax, %r14
leaq 0x50(%rsp), %rdi
jmp 0x7004
jmp 0x6f96
movq %rax, %r14
jmp 0x7009
movq %rax, %r14
jmp 0x7023
jmp 0x6f96
jmp 0x6f9d
movq %rax, %r14
jmp 0x6ffc
movq %rax, %r14
jmp 0x7016
jmp 0x6f9d
movq %rax, %r14
leaq 0x98(%rsp), %rdi
callq 0x2dea
leaq 0xa8(%rsp), %rdi
callq 0x2dea
leaq 0xf8(%rsp), %rdi
callq 0x8104
leaq 0x138(%rsp), %rdi
callq 0x2dea
leaq 0x108(%rsp), %rdi
callq 0x2dea
jmp 0x6fe8
jmp 0x6fe5
movq %rax, %r14
leaq 0x40(%rsp), %rdi
callq 0x2dea
leaq 0x50(%rsp), %rdi
callq 0x2dea
leaq 0xb8(%rsp), %rdi
callq 0x2dea
leaq 0x118(%rsp), %rdi
callq 0x2dea
leaq 0xc8(%rsp), %rdi
callq 0x2dea
movq 0x30(%rsp), %rdi
callq 0x2dea
leaq 0x128(%rsp), %rdi
callq 0x8104
leaq 0x88(%rsp), %rdi
callq 0x2dea
movq %r14, %rdi
callq 0x21d0