// File: /workspace/github_cpp_makefile_star2_O1/yukimasano[P]cpp_matrix/Matrix.cpp
// Function: QRsolve2(Matrix&, Vector&)
Vector QRsolve2(Matrix& A, Vector& bb){
	assert(nrows(A) == ncols(A));
	int m = ncols(A);
  Matrix A2 = A;
  Vector b=bb;
	Matrix V(m-1,m-1);
	for (int k=0; k<m ;k++){
		Vector xx(m-k);
    //std::cout<<k<<xx<<std::flush<<std::endl;
		for (int j=1;j<=m-k; j++){
			xx.set_val(j, A(j+k,k+1));
		}
		//std::cout<<xx<<std::endl<<std::flush;
		Vector vk(m-k);

		double len =xx.norm();
		vk.set_val(1,len);
    //std::cout<<k<<vk<<std::endl<<std::flush;
    //std::cout<<k<<xx.norm()<<std::endl<<std::flush;


		vk = vk+ xx;
    if (vk.norm()!=0){
		    vk = vk / vk.norm();
    }
		Matrix A_sub(m-k,m-k);
    	for (int i = k; i<m; i++){
    		for (int h = k; h<m; h++){
    			A_sub.set_val(i-k+1,h-k+1, A(i+1,h+1));
    		}
    	}
    //std::cout<<k<<A<<std::endl<<std::flush;
    	//std::cout<<A_sub<<std::endl<<std::flush;
		Matrix vk2(m-k,1);
		for (int jj=1 ; jj<=m-k;jj++){
			vk2.set_val(jj,1, vk(jj));
		}
		Matrix vk2T= vk2.T();
		Matrix vk3 = vk2T*A_sub;
		//std::cout<<vk2<<std::endl<<std::flush;
		Matrix A_sub2 = vk2*vk3;


		A_sub2 = 2*A_sub2;
		A_sub2 = A_sub - A_sub2;
		//std::cout<<A<<std::endl<<std::flush;

		for (int j = k; j<m; j++){
			for (int h=k; h<m; h++){
				A2.set_val(j+1,h+1,A_sub2(j+1-k, h+1-k) );
			}
		}
		Vector bk2(m-k);
		for (int jj=k ; jj<m;jj++){
			bk2.set_val(jj+1-k,b(jj+1));
		}
		Vector bk3  =  vk;
		double temp = (vk*bk2);
		//std::cout<<temp<<std::endl<<std::flush;
		bk3 = temp*vk;
		bk3 = 2*bk3;
		bk3 = bk2 - bk3;
		for (int jj=k ; jj<m;jj++){
			b.set_val(jj+1, bk3(jj-k+1));
		}
		for (int j=1; j<=m-k-1; j++){
			V.set_val(j,k+1,vk(j));
		}
	}
	//std::cout<<b<<std::endl<<std::flush;
	Vector x(m);
	/// BACKSOLving////////
	for (int k=m-1; k>=0; k--){
		x.set_val(k+1, b(k+1));
		for (int j = k+1; j<m; j++){
			x.set_val(k+1, x(k+1)- A2(k+1,j+1)*x(j+1));
			}
		x.set_val(k+1, x(k+1)/A2(k+1,k+1));
		}
	return x;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %rdi, 0x10(%rsp)
movl 0xc(%rsi), %r14d
cmpl %r14d, 0x8(%rsi)
jne 0x5df2
movq %rdx, %r15
movq %rsi, %r12
leaq 0xb0(%rsp), %rdi
callq 0x3db2
leaq 0xa0(%rsp), %rdi
movq %r15, %rsi
callq 0x82b8
leal -0x1(%r14), %ebx
leaq 0x118(%rsp), %rdi
movl %ebx, %esi
movl %ebx, %edx
callq 0x2eb8
testl %r14d, %r14d
movq %rbx, 0xc0(%rsp)
jle 0x5cbc
leal 0x1(%r14), %r15d
movl %r14d, %eax
negl %eax
movq %rax, 0xd8(%rsp)
movq %r14, %rax
negq %rax
movq %rax, 0x28(%rsp)
movl $0x1, 0x34(%rsp)
xorl %ebx, %ebx
leaq 0x90(%rsp), %r13
movl %r14d, %eax
movq %rax, 0x20(%rsp)
movq %r14, 0x58(%rsp)
movq %r12, 0xc8(%rsp)
cmpl %ebx, %r14d
movl %ebx, %eax
cmovgl %r14d, %eax
movl %eax, 0x8(%rsp)
movq %r14, %rbp
subq %rbx, %rbp
movq %r13, %rdi
movl %ebp, %esi
callq 0x8268
movq %rbp, 0x18(%rsp)
testq %rbp, %rbp
jle 0x57e9
leal 0x1(%rbx), %ebp
movl $0x1, %r13d
leal (%rbx,%r13), %esi
movq %r12, %rdi
movl %ebp, %edx
callq 0x2f92
movsd (%rax), %xmm0
leaq 0x90(%rsp), %rdi
movl %r13d, %esi
callq 0x8ef8
movq 0x28(%rsp), %rax
addl %r13d, %eax
incl %eax
movl %r13d, %ecx
incl %ecx
movl %ecx, %r13d
cmpl $0x1, %eax
jne 0x57b0
leaq 0x48(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x8268
leaq 0x90(%rsp), %rdi
movl $0x2, %esi
callq 0x8dfc
leaq 0x48(%rsp), %rdi
movl $0x1, %esi
callq 0x8ef8
leaq 0x38(%rsp), %rbp
movq %rbp, %rdi
leaq 0x48(%rsp), %r13
movq %r13, %rsi
leaq 0x90(%rsp), %rdx
callq 0x831d
movq %r13, %rdi
movq %rbp, %rsi
callq 0x89dc
movq %rbp, %rdi
callq 0x8310
movq %r13, %rdi
movl $0x2, %esi
callq 0x8dfc
ucomisd 0x4822(%rip), %xmm0     # 0xa080
jne 0x5862
jnp 0x58a2
leaq 0x48(%rsp), %r13
movq %r13, %rdi
movl $0x2, %esi
callq 0x8dfc
leaq 0x38(%rsp), %rbp
movsd %xmm0, 0x60(%rsp)
movq %rbp, %rdi
movq %r13, %rsi
leaq 0x60(%rsp), %rdx
callq 0x8804
movq %r13, %rdi
movq %rbp, %rsi
callq 0x89dc
movq %rbp, %rdi
callq 0x8310
leaq 0x38(%rsp), %rdi
movq 0x18(%rsp), %rdx
movl %edx, %esi
callq 0x2eb8
movq 0x20(%rsp), %rax
movl %eax, %eax
movq %rax, 0x20(%rsp)
movl %ebx, %eax
subl 0x8(%rsp), %eax
movq %rax, 0xe0(%rsp)
movl %r15d, %r15d
movq 0x38(%rsp), %r13
movq %rbx, 0x8(%rsp)
movq %rbx, %rbp
movq %rbp, %rbx
incq %rbp
subq 0x8(%rsp), %rbx
movl $0x1, %r14d
movq 0x8(%rsp), %rax
leal (%rax,%r14), %edx
movq %r12, %rdi
movl %ebp, %esi
callq 0x2f92
movsd (%rax), %xmm0
movq (%r13,%rbx,8), %rax
movsd %xmm0, -0x8(%rax,%r14,8)
movq 0x28(%rsp), %rax
addq %r14, %rax
incq %rax
incq %r14
cmpq $0x1, %rax
jne 0x58ee
movq 0x58(%rsp), %r14
cmpq %r14, %rbp
jne 0x58dd
leaq 0x60(%rsp), %rdi
movq 0x18(%rsp), %rbx
movl %ebx, %esi
movl $0x1, %edx
callq 0x2eb8
testq %rbx, %rbx
jle 0x5977
movl $0x1, %r13d
movq 0x60(%rsp), %rbx
leaq 0x48(%rsp), %rdi
movl %r13d, %esi
callq 0x8b5a
movsd (%rax), %xmm0
movq -0x8(%rbx,%r13,8), %rax
movsd %xmm0, (%rax)
incq %r13
cmpq %r13, %r15
jne 0x5955
leaq 0x138(%rsp), %rbx
movq %rbx, %rdi
leaq 0x60(%rsp), %rsi
callq 0x3140
leaq 0x128(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
leaq 0x38(%rsp), %rdx
callq 0x37d8
leaq 0x108(%rsp), %rbx
movq %rbx, %rdi
leaq 0x60(%rsp), %rsi
movq %r14, %rdx
callq 0x37d8
movabsq $0x4000000000000000, %rax # imm = 0x4000000000000000
movq %rax, 0x70(%rsp)
leaq 0x80(%rsp), %r14
movq %r14, %rdi
leaq 0x70(%rsp), %rsi
movq %rbx, %rdx
callq 0x3afa
movq %rbx, %rdi
movq %r14, %rsi
callq 0x35a0
movq %r14, %rdi
callq 0x2f4c
movq %r14, %rdi
leaq 0x38(%rsp), %rsi
movq %rbx, %rdx
callq 0x3480
movq %r15, 0xd0(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x35a0
movq %r14, %rdi
callq 0x2f4c
movq 0xb0(%rsp), %rbx
movq 0x8(%rsp), %r15
leaq 0x1(%r15), %r14
movl %r14d, %ebp
movq 0x8(%rsp), %r12
subl %r12d, %ebp
movl $0x1, %r13d
leaq 0x108(%rsp), %rdi
movl %ebp, %esi
movl %r13d, %edx
callq 0x2f92
movsd (%rax), %xmm0
movq (%rbx,%r15,8), %rax
movsd %xmm0, (%rax,%r12,8)
incq %r12
incl %r13d
cmpq %r12, 0x58(%rsp)
jne 0x5a43
movq %r14, %r15
movq 0x58(%rsp), %rax
cmpq %rax, %r14
jne 0x5a2e
movq %rax, %r14
leaq 0x80(%rsp), %r12
movq %r12, %rdi
movq 0x18(%rsp), %rsi
callq 0x8268
movl $0x1, %ebp
movl 0x34(%rsp), %eax
movl %eax, %r13d
movq 0xd0(%rsp), %r15
movq 0x8(%rsp), %rbx
movq 0xd8(%rsp), %rax
addl %r13d, %eax
cmpl $0x1, %eax
je 0x5aeb
leaq 0xa0(%rsp), %rdi
movl %r13d, %esi
callq 0x8b5a
movsd (%rax), %xmm0
incl %r13d
leal 0x1(%rbp), %ebx
movq %r12, %rdi
movl %ebp, %esi
callq 0x8ef8
movl %ebx, %ebp
movq 0x8(%rsp), %rbx
jmp 0x5aae
leaq 0x70(%rsp), %rdi
leaq 0x48(%rsp), %r13
movq %r13, %rsi
callq 0x82b8
movq %r13, %rdi
movq %r12, %rsi
callq 0x8673
movq 0xc8(%rsp), %r12
movsd %xmm0, 0x100(%rsp)
leaq 0xf0(%rsp), %rbp
movq %rbp, %rdi
leaq 0x100(%rsp), %rsi
movq %r13, %rdx
callq 0x877e
leaq 0x70(%rsp), %r13
movq %r13, %rdi
movq %rbp, %rsi
callq 0x89dc
movq %rbp, %rdi
callq 0x8310
movabsq $0x4000000000000000, %rax # imm = 0x4000000000000000
movq %rax, 0xe8(%rsp)
movq %rbp, %rdi
leaq 0xe8(%rsp), %rsi
movq %r13, %rdx
callq 0x877e
movq %r13, %rdi
movq %rbp, %rsi
callq 0x89dc
movq %rbp, %rdi
callq 0x8310
movq %rbp, %rdi
leaq 0x80(%rsp), %rsi
movq %r13, %rdx
callq 0x84c8
movq %r13, %rdi
movq %rbp, %rsi
callq 0x89dc
movq %rbp, %rdi
callq 0x8310
movl $0x1, %r13d
movq 0xe0(%rsp), %rax
addl %r13d, %eax
cmpl $0x1, %eax
je 0x5be7
leaq 0x70(%rsp), %rdi
movl %r13d, %esi
callq 0x8b5a
leal (%rbx,%r13), %esi
movsd (%rax), %xmm0
incl %r13d
leaq 0xa0(%rsp), %rdi
callq 0x8ef8
jmp 0x5bb0
cmpq $0x2, 0x18(%rsp)
jl 0x5c27
movl $0x1, %r13d
movq 0x118(%rsp), %rbx
leaq 0x48(%rsp), %rdi
movl %r13d, %esi
callq 0x8b5a
movsd (%rax), %xmm0
movq -0x8(%rbx,%r13,8), %rax
movq 0x8(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
incq %r13
cmpq %r13, 0x20(%rsp)
jne 0x5bfd
leaq 0x70(%rsp), %rdi
callq 0x8310
leaq 0x80(%rsp), %rdi
callq 0x8310
leaq 0x108(%rsp), %rdi
callq 0x2f4c
leaq 0x128(%rsp), %rdi
callq 0x2f4c
leaq 0x138(%rsp), %rdi
callq 0x2f4c
leaq 0x60(%rsp), %rdi
callq 0x2f4c
leaq 0x38(%rsp), %rdi
callq 0x2f4c
leaq 0x48(%rsp), %rdi
callq 0x8310
leaq 0x90(%rsp), %r13
movq %r13, %rdi
callq 0x8310
movq 0x8(%rsp), %rbx
incq %rbx
decl %r15d
movq 0x20(%rsp), %rax
decl %eax
movq %rax, 0x20(%rsp)
incq 0x28(%rsp)
incl 0x34(%rsp)
cmpq %r14, %rbx
jne 0x5780
movq 0x10(%rsp), %rdi
movl %r14d, %esi
callq 0x8268
testl %r14d, %r14d
movq 0xc0(%rsp), %rax
jle 0x5db4
leaq 0xa0(%rsp), %r15
leaq 0xb0(%rsp), %r12
movq %rax, %rbx
leal 0x1(%rax), %ebp
movq %r15, %rdi
movl %ebp, %esi
callq 0x8b5a
movsd (%rax), %xmm0
movq 0x10(%rsp), %rdi
movl %ebp, %esi
callq 0x8ef8
movl %ebp, %r13d
cmpl %r14d, %r13d
jge 0x5d71
movq 0x10(%rsp), %rdi
movl %ebp, %esi
callq 0x8b5a
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
incl %r13d
movq %r12, %rdi
movl %ebp, %esi
movl %r13d, %edx
callq 0x2f92
movsd (%rax), %xmm0
movsd %xmm0, 0x28(%rsp)
movq 0x10(%rsp), %rdi
movl %r13d, %esi
callq 0x8b5a
movsd 0x28(%rsp), %xmm1
mulsd (%rax), %xmm1
movsd 0x8(%rsp), %xmm0
subsd %xmm1, %xmm0
movq 0x10(%rsp), %rdi
movl %ebp, %esi
callq 0x8ef8
jmp 0x5d0d
movq 0x10(%rsp), %rdi
movl %ebp, %esi
callq 0x8b5a
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %r12, %rdi
movl %ebp, %esi
movl %ebp, %edx
callq 0x2f92
movsd 0x8(%rsp), %xmm0
divsd (%rax), %xmm0
movq 0x10(%rsp), %rdi
movl %ebp, %esi
callq 0x8ef8
leal -0x1(%rbx), %eax
testl %ebx, %ebx
jg 0x5cea
leaq 0x118(%rsp), %rdi
callq 0x2f4c
leaq 0xa0(%rsp), %rdi
callq 0x8310
leaq 0xb0(%rsp), %rdi
callq 0x2f4c
movq 0x10(%rsp), %rax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4521(%rip), %rdi      # 0xa31a
leaq 0x4351(%rip), %rsi      # 0xa151
leaq 0x4586(%rip), %rcx      # 0xa38d
movl $0x248, %edx            # imm = 0x248
callq 0x20b0
jmp 0x5e9d
movq %rax, %r14
jmp 0x5f4c
movq %rax, %r14
jmp 0x5f59
jmp 0x5e8b
jmp 0x5e3d
jmp 0x5ec9
jmp 0x5eba
jmp 0x5eba
jmp 0x5e3d
jmp 0x5eba
movq %rax, %r14
leaq 0xf0(%rsp), %rdi
callq 0x8310
jmp 0x5ebd
jmp 0x5eba
jmp 0x5ee5
jmp 0x5e71
jmp 0x5eb0
movq %rax, %r14
jmp 0x5f02
jmp 0x5f1b
movq %rax, %r14
jmp 0x5ef5
jmp 0x5ee5
movq %rax, %r14
leaq 0x80(%rsp), %rdi
callq 0x2f4c
jmp 0x5ee8
jmp 0x5ee5
jmp 0x5ea7
jmp 0x5eb5
jmp 0x5ea7
movq %rax, %r14
leaq 0x38(%rsp), %rdi
callq 0x8310
jmp 0x5f28
movq %rax, %r14
jmp 0x5f3f
jmp 0x5ea7
movq %rax, %r14
jmp 0x5f28
jmp 0x5edb
jmp 0x5eba
movq %rax, %r14
jmp 0x5f0f
movq %rax, %r14
jmp 0x5f32
movq %rax, %r14
leaq 0x70(%rsp), %rdi
callq 0x8310
jmp 0x5ecc
movq %rax, %r14
leaq 0x80(%rsp), %rdi
callq 0x8310
jmp 0x5ee8
movq %rax, %r14
movq 0x10(%rsp), %rdi
jmp 0x5f3a
movq %rax, %r14
leaq 0x108(%rsp), %rdi
callq 0x2f4c
leaq 0x128(%rsp), %rdi
callq 0x2f4c
leaq 0x138(%rsp), %rdi
callq 0x2f4c
leaq 0x60(%rsp), %rdi
callq 0x2f4c
jmp 0x5f1e
movq %rax, %r14
leaq 0x38(%rsp), %rdi
callq 0x2f4c
leaq 0x48(%rsp), %rdi
callq 0x8310
leaq 0x90(%rsp), %rdi
callq 0x8310
leaq 0x118(%rsp), %rdi
callq 0x2f4c
leaq 0xa0(%rsp), %rdi
callq 0x8310
leaq 0xb0(%rsp), %rdi
callq 0x2f4c
movq %r14, %rdi
callq 0x21f0