// File: /workspace/github_cpp_makefile_star2_O1/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 0x7807
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r14
movq %rdx, %rsi
callq 0x82b8
movq %r15, %rdi
movl $0x2, %esi
movq %r14, 0x30(%rsp)
callq 0x8dfc
movsd %xmm0, 0x48(%rsp)
leaq 0x60(%rsp), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x3941
leaq 0x20(%rsp), %rdi
leaq 0x60(%rsp), %rdx
movq %r15, %rsi
callq 0x84c8
leaq 0x60(%rsp), %rdi
callq 0x8310
leaq 0x60(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x82b8
leaq 0x70(%rsp), %rdi
movl %ebx, %esi
callq 0x8268
leaq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rdx
movq %r12, %rsi
callq 0x3941
leaq 0x70(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x89dc
leaq 0x10(%rsp), %rdi
callq 0x8310
leaq 0x20(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x8673
movsd %xmm0, 0x38(%rsp)
leaq 0x20(%rsp), %rdi
movl $0x2, %esi
callq 0x8dfc
movsd %xmm0, 0x40(%rsp)
leaq 0x20(%rsp), %rdi
movl $0x2, %esi
callq 0x8dfc
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 0x877e
leaq 0x10(%rsp), %rdi
movq %rsp, %rdx
movq 0x30(%rsp), %r14
movq %r14, %rsi
callq 0x831d
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x89dc
leaq 0x10(%rsp), %rdi
callq 0x8310
movq %rsp, %rdi
callq 0x8310
movq %rsp, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x3941
leaq 0x10(%rsp), %rdi
movq %rsp, %rdx
movq %r15, %rsi
callq 0x84c8
leaq 0x20(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x89dc
movq %r15, 0x40(%rsp)
leaq 0x10(%rsp), %rdi
callq 0x8310
movq %rsp, %rdi
callq 0x8310
leaq 0x10(%rsp), %rdi
movl %ebx, %esi
callq 0x8268
movsd 0x48(%rsp), %xmm0
mulsd 0x2ad8(%rip), %xmm0     # 0xa090
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 0x3941
movq %rbp, %rdi
movq %r13, %rsi
movq 0x40(%rsp), %rdx
callq 0x84c8
movq %rbp, %rdi
movl $0x2, %esi
callq 0x8dfc
movsd %xmm0, 0x90(%rsp)
movq %rbp, %rdi
callq 0x8310
movq %r13, %rdi
callq 0x8310
movsd 0x90(%rsp), %xmm0
ucomisd 0x48(%rsp), %xmm0
jbe 0x77c8
movq %rbp, %rdi
movq %r12, %rsi
leaq 0x20(%rsp), %rdx
callq 0x3941
leaq 0x70(%rsp), %rdi
movq %rbp, %rsi
callq 0x89dc
movq %rbp, %rdi
callq 0x8310
movq %rbp, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x3941
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x89dc
movq %rbp, %rdi
callq 0x8310
leaq 0x20(%rsp), %rdi
movq %rbx, %rsi
callq 0x8673
movsd %xmm0, 0x58(%rsp)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x8673
movsd 0x58(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x58(%rsp)
movq %r13, %rdi
leaq 0x58(%rsp), %rsi
movq %r15, %rdx
callq 0x877e
movq %rbp, %rdi
leaq 0x20(%rsp), %rsi
movq %r13, %rdx
callq 0x84c8
movq %r15, %rdi
movq %rbp, %rsi
callq 0x89dc
movq %rbp, %rdi
callq 0x8310
movq %r13, %rdi
callq 0x8310
leaq 0x20(%rsp), %rdi
movq %r15, %rsi
callq 0x8673
movsd %xmm0, 0x38(%rsp)
movq %rbp, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x3941
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x89dc
movq %rbp, %rdi
callq 0x8310
movq %r15, %rdi
movq %rbx, %rsi
callq 0x8673
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 0x877e
movq %rbp, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x831d
movq %r14, %rdi
movq %rbp, %rsi
callq 0x89dc
movq %rbp, %rdi
callq 0x8310
movq %r13, %rdi
callq 0x8310
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x3941
movq %rbp, %rdi
movq 0x40(%rsp), %rsi
movq %r13, %rdx
callq 0x84c8
leaq 0x20(%rsp), %rdi
movq %rbp, %rsi
callq 0x89dc
movq %rbp, %rdi
callq 0x8310
movq %r13, %rdi
callq 0x8310
movq 0x50(%rsp), %rax
cmpl $0xf4241, (%rax)        # imm = 0xF4241
jl 0x75d8
movq 0x50(%rsp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
leaq 0x10(%rsp), %rdi
callq 0x8310
leaq 0x70(%rsp), %rdi
callq 0x8310
leaq 0x60(%rsp), %rdi
callq 0x8310
leaq 0x20(%rsp), %rdi
callq 0x8310
movq 0x30(%rsp), %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2b0c(%rip), %rdi      # 0xa31a
leaq 0x293c(%rip), %rsi      # 0xa151
leaq 0x2c11(%rip), %rcx      # 0xa42d
movl $0x34d, %edx            # imm = 0x34D
callq 0x20b0
jmp 0x7866
jmp 0x782e
jmp 0x783d
jmp 0x7866
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x8310
jmp 0x7840
movq %rax, %r14
movq %rsp, %rdi
jmp 0x78b8
jmp 0x7866
jmp 0x78b0
jmp 0x7866
movq %rax, %r14
jmp 0x78c7
movq %rax, %r14
jmp 0x78d1
movq %rax, %r14
leaq 0x60(%rsp), %rdi
jmp 0x78d6
jmp 0x7861
movq %rax, %r14
jmp 0x78db
movq %rax, %r14
jmp 0x78bd
jmp 0x7896
jmp 0x7891
jmp 0x7891
jmp 0x78b0
jmp 0x7896
jmp 0x7891
jmp 0x78b0
jmp 0x78b0
jmp 0x78b0
jmp 0x78b0
jmp 0x78b0
jmp 0x7896
jmp 0x7887
jmp 0x7887
movq %rax, %r14
movq %rsp, %rdi
jmp 0x78a9
jmp 0x78b0
movq %rax, %r14
jmp 0x78a1
movq %rax, %r14
movq %rsp, %rdi
callq 0x8310
leaq 0x80(%rsp), %rdi
callq 0x8310
jmp 0x78b3
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x8310
leaq 0x70(%rsp), %rdi
callq 0x8310
leaq 0x60(%rsp), %rdi
callq 0x8310
leaq 0x20(%rsp), %rdi
callq 0x8310
movq 0x30(%rsp), %rdi
callq 0x8310
movq %r14, %rdi
callq 0x21f0