// File: /workspace/github_cpp_makefile_star2_O1/yukimasano[P]cpp_matrix/Matrix.cpp
// Function: Jacobi(Matrix&, Vector&, int&)
Vector Jacobi(Matrix& A, Vector& v, int& count){
	assert(nrows(A) == ncols(A));
	int m =nrows(A);
	// we want a square system

	// INITIALISATION
	Matrix T=A;
	for (int k=1; k<=m; k++){
		T.set_val(k,k, (1./A(k,k)));
	}
	Vector temp = ones(m);
	Matrix eye = diag(temp);
  Vector c = T*v;
	T =  (eye - T);
	double tol = 1.e-14*v.norm();
	Vector x=c;
	//std::cout<<" before the while loop "<<(A*x -c).norm() << std::endl<<std::flush;
  Vector r = (A*x -v);
	while (r.norm() > tol){
		count+=1;
		x = T*x + c;
    r = (A*x -v);
	//	std::cout<<(A*x -v).norm() << std::endl<<std::flush;
	}
  //	std::cout<<count<<std::endl<<std::flush;

	return x;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rcx, 0x50(%rsp)
movq %rdx, (%rsp)
movl 0x8(%rsi), %r14d
cmpl 0xc(%rsi), %r14d
jne 0x6191
movq %rsi, %r12
movq %rdi, %rbx
leaq 0x20(%rsp), %rdi
callq 0x3db2
testl %r14d, %r14d
jle 0x5fe8
leaq 0x1(%r14), %r13
movl $0x1, %r15d
movq %r12, %rdi
movl %r15d, %esi
movl %r15d, %edx
callq 0x2f92
movsd 0x404d(%rip), %xmm0     # 0xa018
divsd (%rax), %xmm0
movq 0x20(%rsp), %rax
movq -0x8(%rax,%r15,8), %rax
movsd %xmm0, -0x8(%rax,%r15,8)
incq %r15
cmpq %r15, %r13
jne 0x5fb5
leaq 0x68(%rsp), %rdi
movl %r14d, %esi
callq 0x8e81
leaq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x3d37
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movq (%rsp), %rdx
callq 0x3941
leaq 0x10(%rsp), %rdi
leaq 0x58(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x3480
leaq 0x20(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x35a0
leaq 0x10(%rsp), %rdi
callq 0x2f4c
movq (%rsp), %rdi
movl $0x2, %esi
callq 0x8dfc
movsd %xmm0, 0x8(%rsp)
leaq 0x40(%rsp), %rsi
movq %rbx, %rdi
callq 0x82b8
leaq 0x30(%rsp), %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x3941
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rsi
movq (%rsp), %rdx
callq 0x84c8
movsd 0x8(%rsp), %xmm0
mulsd 0x3ffa(%rip), %xmm0     # 0xa090
movsd %xmm0, 0x8(%rsp)
leaq 0x30(%rsp), %r13
movq %r13, %rdi
callq 0x8310
leaq 0x10(%rsp), %rbp
leaq 0x78(%rsp), %r14
leaq 0x40(%rsp), %r15
movq %rbp, %rdi
movl $0x2, %esi
callq 0x8dfc
ucomisd 0x8(%rsp), %xmm0
jbe 0x614a
movq 0x50(%rsp), %rax
incl (%rax)
movq %r14, %rdi
leaq 0x20(%rsp), %rsi
movq %rbx, %rdx
callq 0x3941
movq %r13, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x831d
movq %rbx, %rdi
movq %r13, %rsi
callq 0x89dc
movq %r13, %rdi
callq 0x8310
movq %r14, %rdi
callq 0x8310
movq %r14, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x3941
movq %r13, %rdi
movq %r14, %rsi
movq (%rsp), %rdx
callq 0x84c8
movq %rbp, %rdi
movq %r13, %rsi
callq 0x89dc
movq %r13, %rdi
callq 0x8310
movq %r14, %rdi
callq 0x8310
jmp 0x60b8
leaq 0x10(%rsp), %rdi
callq 0x8310
leaq 0x40(%rsp), %rdi
callq 0x8310
leaq 0x58(%rsp), %rdi
callq 0x2f4c
leaq 0x68(%rsp), %rdi
callq 0x8310
leaq 0x20(%rsp), %rdi
callq 0x2f4c
movq %rbx, %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4182(%rip), %rdi      # 0xa31a
leaq 0x3fb2(%rip), %rsi      # 0xa151
leaq 0x420b(%rip), %rcx      # 0xa3b1
movl $0x29a, %edx            # imm = 0x29A
callq 0x20b0
movq %rax, %r14
leaq 0x30(%rsp), %rdi
jmp 0x6214
movq %rax, %r14
jmp 0x6219
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x2f4c
jmp 0x6221
jmp 0x61dc
movq %rax, %r14
jmp 0x622b
movq %rax, %r14
jmp 0x6235
jmp 0x61e1
movq %rax, %r14
jmp 0x6221
movq %rax, %r14
jmp 0x623f
jmp 0x620c
jmp 0x61ec
jmp 0x61fd
movq %rax, %r14
leaq 0x30(%rsp), %rdi
callq 0x8310
jmp 0x6200
jmp 0x620c
movq %rax, %r14
leaq 0x78(%rsp), %rdi
callq 0x8310
jmp 0x620f
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x8310
movq %rbx, %rdi
callq 0x8310
leaq 0x40(%rsp), %rdi
callq 0x8310
leaq 0x58(%rsp), %rdi
callq 0x2f4c
leaq 0x68(%rsp), %rdi
callq 0x8310
leaq 0x20(%rsp), %rdi
callq 0x2f4c
movq %r14, %rdi
callq 0x21f0