// File: /workspace/github_cpp_makefile_star2_O3/yukimasano[P]cpp_matrix/Matrix.cpp
// Function: CG(Matrix&, Vector&, int&)
Vector CG(Matrix& A, Vector& v, int& count){
	assert(nrows(A) == ncols(A));
	int m =nrows(A);
	// we want a square system

	// INITIALISATION
  Vector x= v;
	double tol = 1.e-14*v.norm();
	Vector r = v - A*x;
	Vector p = r;
	Vector temp(m);
	temp = A*r;
	double alpha;
	alpha = r*temp;
	alpha = ((r.norm())*(r.norm()))/alpha;
	x = x +alpha *r;
	r = v - A*x;
	double beta;
	double anorm;
	Vector temp2(m);
	//std::cout<<" before the while loop "<<(A*x -c).norm() << std::endl<<std::flush;
	while ((A*x -v).norm() > tol){
		temp = A*r;
		temp2 = A*p;
		beta = r*temp2;
		anorm = p*temp2;
		beta = beta /anorm;
		p = r-beta*p;
		alpha = r*p;
    temp2 = A*p;
    anorm = p*temp2;
		alpha = alpha/anorm;
		count+=1;
		x = x + alpha*p;
		r = v - A*x;
    if (count>1000000){
      count = -1;
      return x;
    }
	}
  //	std::cout<<count<<std::endl<<std::flush;
	return x;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rcx, 0x50(%rsp)
movl 0x8(%rsi), %ebx
cmpl 0xc(%rsi), %ebx
jne 0x77b7
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r14
movq %rdx, %rsi
callq 0x822a
movq %r15, %rdi
movl $0x2, %esi
movq %r14, 0x30(%rsp)
callq 0x8d68
movsd %xmm0, 0x48(%rsp)
leaq 0x60(%rsp), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x3915
leaq 0x20(%rsp), %rdi
leaq 0x60(%rsp), %rdx
movq %r15, %rsi
callq 0x8428
leaq 0x60(%rsp), %rdi
callq 0x827e
leaq 0x60(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x822a
leaq 0x70(%rsp), %rdi
movl %ebx, %esi
callq 0x81e8
leaq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rdx
movq %r12, %rsi
callq 0x3915
leaq 0x70(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x893a
leaq 0x10(%rsp), %rdi
callq 0x827e
leaq 0x20(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x85c5
movsd %xmm0, 0x38(%rsp)
leaq 0x20(%rsp), %rdi
movl $0x2, %esi
callq 0x8d68
movsd %xmm0, 0x40(%rsp)
leaq 0x20(%rsp), %rdi
movl $0x2, %esi
callq 0x8d68
movsd 0x40(%rsp), %xmm1
mulsd %xmm0, %xmm1
leaq 0x38(%rsp), %rsi
divsd (%rsi), %xmm1
movsd %xmm1, (%rsi)
movq %rsp, %rdi
leaq 0x20(%rsp), %rdx
callq 0x86d1
leaq 0x10(%rsp), %rdi
movq %rsp, %rdx
movq 0x30(%rsp), %r14
movq %r14, %rsi
callq 0x828b
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x893a
leaq 0x10(%rsp), %rdi
callq 0x827e
movq %rsp, %rdi
callq 0x827e
movq %rsp, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x3915
leaq 0x10(%rsp), %rdi
movq %rsp, %rdx
movq %r15, %rsi
callq 0x8428
leaq 0x20(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x893a
movq %r15, 0x40(%rsp)
leaq 0x10(%rsp), %rdi
callq 0x827e
movq %rsp, %rdi
callq 0x827e
leaq 0x10(%rsp), %rdi
movl %ebx, %esi
callq 0x81e8
movsd 0x48(%rsp), %xmm0
mulsd 0x1b28(%rip), %xmm0     # 0x9090
movsd %xmm0, 0x48(%rsp)
leaq 0x80(%rsp), %r13
movq %rsp, %rbp
leaq 0x60(%rsp), %r15
leaq 0x10(%rsp), %rbx
movq 0x30(%rsp), %r14
movq %r13, %rdi
movq %r12, %rsi
movq 0x30(%rsp), %rdx
callq 0x3915
movq %rbp, %rdi
movq %r13, %rsi
movq 0x40(%rsp), %rdx
callq 0x8428
movq %rbp, %rdi
movl $0x2, %esi
callq 0x8d68
movsd %xmm0, 0x90(%rsp)
movq %rbp, %rdi
callq 0x827e
movq %r13, %rdi
callq 0x827e
movsd 0x90(%rsp), %xmm0
ucomisd 0x48(%rsp), %xmm0
jbe 0x7778
movq %rbp, %rdi
movq %r12, %rsi
leaq 0x20(%rsp), %rdx
callq 0x3915
leaq 0x70(%rsp), %rdi
movq %rbp, %rsi
callq 0x893a
movq %rbp, %rdi
callq 0x827e
movq %rbp, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x3915
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x893a
movq %rbp, %rdi
callq 0x827e
leaq 0x20(%rsp), %rdi
movq %rbx, %rsi
callq 0x85c5
movsd %xmm0, 0x58(%rsp)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x85c5
movsd 0x58(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x58(%rsp)
movq %r13, %rdi
leaq 0x58(%rsp), %rsi
movq %r15, %rdx
callq 0x86d1
movq %rbp, %rdi
leaq 0x20(%rsp), %rsi
movq %r13, %rdx
callq 0x8428
movq %r15, %rdi
movq %rbp, %rsi
callq 0x893a
movq %rbp, %rdi
callq 0x827e
movq %r13, %rdi
callq 0x827e
leaq 0x20(%rsp), %rdi
movq %r15, %rsi
callq 0x85c5
movsd %xmm0, 0x38(%rsp)
movq %rbp, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x3915
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x893a
movq %rbp, %rdi
callq 0x827e
movq %r15, %rdi
movq %rbx, %rsi
callq 0x85c5
movsd 0x38(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x38(%rsp)
movq 0x50(%rsp), %rax
incl (%rax)
movq %r13, %rdi
leaq 0x38(%rsp), %rsi
movq %r15, %rdx
callq 0x86d1
movq %rbp, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x828b
movq %r14, %rdi
movq %rbp, %rsi
callq 0x893a
movq %rbp, %rdi
callq 0x827e
movq %r13, %rdi
callq 0x827e
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x3915
movq %rbp, %rdi
movq 0x40(%rsp), %rsi
movq %r13, %rdx
callq 0x8428
leaq 0x20(%rsp), %rdi
movq %rbp, %rsi
callq 0x893a
movq %rbp, %rdi
callq 0x827e
movq %r13, %rdi
callq 0x827e
movq 0x50(%rsp), %rax
cmpl $0xf4241, (%rax)        # imm = 0xF4241
jl 0x7588
movq 0x50(%rsp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
leaq 0x10(%rsp), %rdi
callq 0x827e
leaq 0x70(%rsp), %rdi
callq 0x827e
leaq 0x60(%rsp), %rdi
callq 0x827e
leaq 0x20(%rsp), %rdi
callq 0x827e
movq 0x30(%rsp), %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1b5c(%rip), %rdi      # 0x931a
leaq 0x198c(%rip), %rsi      # 0x9151
leaq 0x1c61(%rip), %rcx      # 0x942d
movl $0x34d, %edx            # imm = 0x34D
callq 0x20b0
jmp 0x7816
jmp 0x77de
jmp 0x77ed
jmp 0x7816
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x827e
jmp 0x77f0
movq %rax, %r14
movq %rsp, %rdi
jmp 0x7868
jmp 0x7816
jmp 0x7860
jmp 0x7816
movq %rax, %r14
jmp 0x7877
movq %rax, %r14
jmp 0x7881
movq %rax, %r14
leaq 0x60(%rsp), %rdi
jmp 0x7886
jmp 0x7811
movq %rax, %r14
jmp 0x788b
movq %rax, %r14
jmp 0x786d
jmp 0x7846
jmp 0x7841
jmp 0x7841
jmp 0x7860
jmp 0x7846
jmp 0x7841
jmp 0x7860
jmp 0x7860
jmp 0x7860
jmp 0x7860
jmp 0x7860
jmp 0x7846
jmp 0x7837
jmp 0x7837
movq %rax, %r14
movq %rsp, %rdi
jmp 0x7859
jmp 0x7860
movq %rax, %r14
jmp 0x7851
movq %rax, %r14
movq %rsp, %rdi
callq 0x827e
leaq 0x80(%rsp), %rdi
callq 0x827e
jmp 0x7863
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x827e
leaq 0x70(%rsp), %rdi
callq 0x827e
leaq 0x60(%rsp), %rdi
callq 0x827e
leaq 0x20(%rsp), %rdi
callq 0x827e
movq 0x30(%rsp), %rdi
callq 0x827e
movq %r14, %rdi
callq 0x21f0