// File: /workspace/github_cpp_makefile_star2_O2/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 0x76d5
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r14
movq %rdx, %rsi
callq 0x80b8
pushq $0x2
popq %rsi
movq %r15, %rdi
movq %r14, 0x30(%rsp)
callq 0x891a
movsd %xmm0, 0x48(%rsp)
leaq 0x60(%rsp), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x372f
leaq 0x20(%rsp), %rdi
leaq 0x60(%rsp), %rdx
movq %r15, %rsi
callq 0x8238
leaq 0x60(%rsp), %rdi
callq 0x8104
leaq 0x60(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x80b8
leaq 0x70(%rsp), %rdi
movl %ebx, %esi
callq 0x8068
leaq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rdx
movq %r12, %rsi
callq 0x372f
leaq 0x70(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x859c
leaq 0x10(%rsp), %rdi
callq 0x8104
leaq 0x20(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x835f
movsd %xmm0, 0x38(%rsp)
leaq 0x20(%rsp), %rdi
pushq $0x2
popq %rsi
callq 0x891a
movsd %xmm0, 0x40(%rsp)
leaq 0x20(%rsp), %rdi
pushq $0x2
popq %rsi
callq 0x891a
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 0x8418
leaq 0x10(%rsp), %rdi
movq %rsp, %rdx
movq 0x30(%rsp), %r14
movq %r14, %rsi
callq 0x8111
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x859c
leaq 0x10(%rsp), %rdi
callq 0x8104
movq %rsp, %rdi
callq 0x8104
movq %rsp, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x372f
leaq 0x10(%rsp), %rdi
movq %rsp, %rdx
movq %r15, %rsi
callq 0x8238
leaq 0x20(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x859c
movq %r15, 0x40(%rsp)
leaq 0x10(%rsp), %rdi
callq 0x8104
movq %rsp, %rdi
callq 0x8104
leaq 0x10(%rsp), %rdi
movl %ebx, %esi
callq 0x8068
movsd 0x48(%rsp), %xmm0
mulsd 0x1c05(%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 0x372f
movq %rbp, %rdi
movq %r13, %rsi
movq 0x40(%rsp), %rdx
callq 0x8238
movq %rbp, %rdi
pushq $0x2
popq %rsi
callq 0x891a
movsd %xmm0, 0x90(%rsp)
movq %rbp, %rdi
callq 0x8104
movq %r13, %rdi
callq 0x8104
movsd 0x90(%rsp), %xmm0
ucomisd 0x48(%rsp), %xmm0
jbe 0x7696
movq %rbp, %rdi
movq %r12, %rsi
leaq 0x20(%rsp), %rdx
callq 0x372f
leaq 0x70(%rsp), %rdi
movq %rbp, %rsi
callq 0x859c
movq %rbp, %rdi
callq 0x8104
movq %rbp, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x372f
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x859c
movq %rbp, %rdi
callq 0x8104
leaq 0x20(%rsp), %rdi
movq %rbx, %rsi
callq 0x835f
movsd %xmm0, 0x58(%rsp)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x835f
movsd 0x58(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x58(%rsp)
movq %r13, %rdi
leaq 0x58(%rsp), %rsi
movq %r15, %rdx
callq 0x8418
movq %rbp, %rdi
leaq 0x20(%rsp), %rsi
movq %r13, %rdx
callq 0x8238
movq %r15, %rdi
movq %rbp, %rsi
callq 0x859c
movq %rbp, %rdi
callq 0x8104
movq %r13, %rdi
callq 0x8104
leaq 0x20(%rsp), %rdi
movq %r15, %rsi
callq 0x835f
movsd %xmm0, 0x38(%rsp)
movq %rbp, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x372f
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x859c
movq %rbp, %rdi
callq 0x8104
movq %r15, %rdi
movq %rbx, %rsi
callq 0x835f
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 0x8418
movq %rbp, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x8111
movq %r14, %rdi
movq %rbp, %rsi
callq 0x859c
movq %rbp, %rdi
callq 0x8104
movq %r13, %rdi
callq 0x8104
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x372f
movq %rbp, %rdi
movq 0x40(%rsp), %rsi
movq %r13, %rdx
callq 0x8238
leaq 0x20(%rsp), %rdi
movq %rbp, %rsi
callq 0x859c
movq %rbp, %rdi
callq 0x8104
movq %r13, %rdi
callq 0x8104
movq 0x50(%rsp), %rax
cmpl $0xf4241, (%rax)        # imm = 0xF4241
jl 0x74ab
movq 0x50(%rsp), %rax
orl $-0x1, (%rax)
leaq 0x10(%rsp), %rdi
callq 0x8104
leaq 0x70(%rsp), %rdi
callq 0x8104
leaq 0x60(%rsp), %rdi
callq 0x8104
leaq 0x20(%rsp), %rdi
callq 0x8104
movq 0x30(%rsp), %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1c3e(%rip), %rdi      # 0x931a
leaq 0x1a6e(%rip), %rsi      # 0x9151
leaq 0x1d43(%rip), %rcx      # 0x942d
movl $0x34d, %edx            # imm = 0x34D
callq 0x20b0
jmp 0x7734
jmp 0x76fc
jmp 0x770b
jmp 0x7734
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x8104
jmp 0x770e
movq %rax, %r14
movq %rsp, %rdi
jmp 0x7786
jmp 0x7734
jmp 0x777e
jmp 0x7734
movq %rax, %r14
jmp 0x7795
movq %rax, %r14
jmp 0x779f
movq %rax, %r14
leaq 0x60(%rsp), %rdi
jmp 0x77a4
jmp 0x772f
movq %rax, %r14
jmp 0x77a9
movq %rax, %r14
jmp 0x778b
jmp 0x7764
jmp 0x775f
jmp 0x775f
jmp 0x777e
jmp 0x7764
jmp 0x775f
jmp 0x777e
jmp 0x777e
jmp 0x777e
jmp 0x777e
jmp 0x777e
jmp 0x7764
jmp 0x7755
jmp 0x7755
movq %rax, %r14
movq %rsp, %rdi
jmp 0x7777
jmp 0x777e
movq %rax, %r14
jmp 0x776f
movq %rax, %r14
movq %rsp, %rdi
callq 0x8104
leaq 0x80(%rsp), %rdi
callq 0x8104
jmp 0x7781
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x8104
leaq 0x70(%rsp), %rdi
callq 0x8104
leaq 0x60(%rsp), %rdi
callq 0x8104
leaq 0x20(%rsp), %rdi
callq 0x8104
movq 0x30(%rsp), %rdi
callq 0x8104
movq %r14, %rdi
callq 0x21d0