// File: yukimasano[P]cpp_matrix/Matrix.cpp
// Function: SD(Matrix&, Vector&, int&)
Vector SD(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();
	double top;
	Vector r = A*x;
	r= r-v;
	double bottom;
	Vector temp(m);
	double alpha;
	//std::cout<<" before the while loop "<<(A*x -c).norm() << std::endl<<std::flush;
	while (r.norm() > tol){
		top = r*r;
		temp = A*r;
		bottom = r*temp;
		alpha= top/bottom;
		count+=1;
		x = x + top*r/bottom;
		r = v - A*x;
	}
   //	std::cout<<count<<std::endl<<std::flush;

	return x;
}

// Assembly:
subq $0x128, %rsp            # imm = 0x128
movq %rdi, 0x28(%rsp)
movq %rdi, %rax
movq %rax, 0x30(%rsp)
movq %rdi, 0x120(%rsp)
movq %rsi, 0x118(%rsp)
movq %rdx, 0x110(%rsp)
movq %rcx, 0x108(%rsp)
movq 0x118(%rsp), %rdi
callq 0x3ac0
movl %eax, 0x3c(%rsp)
movq 0x118(%rsp), %rdi
callq 0x3ad0
movl %eax, %ecx
movl 0x3c(%rsp), %eax
cmpl %ecx, %eax
jne 0xaf7e
jmp 0xaf9d
leaq 0x438d(%rip), %rdi      # 0xf312
leaq 0x41bd(%rip), %rsi      # 0xf149
movl $0x330, %edx            # imm = 0x330
leaq 0x4468(%rip), %rcx      # 0xf400
callq 0x2090
movq 0x118(%rsp), %rdi
callq 0x3ac0
movq 0x28(%rsp), %rdi
movl %eax, 0x104(%rsp)
movb $0x0, 0x103(%rsp)
movq 0x110(%rsp), %rsi
callq 0xd0d0
movq 0x110(%rsp), %rdi
movl $0x2, %esi
callq 0xe320
movsd %xmm0, 0x20(%rsp)
jmp 0xafe5
movq 0x28(%rsp), %rdx
movsd 0x20(%rsp), %xmm0
movsd 0x4098(%rip), %xmm1     # 0xf090
mulsd %xmm1, %xmm0
movsd %xmm0, 0xf8(%rsp)
movq 0x118(%rsp), %rsi
leaq 0xd0(%rsp), %rdi
callq 0x4800
jmp 0xb01c
movq 0x110(%rsp), %rdx
leaq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0xd470
jmp 0xb03b
leaq 0xd0(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0xdc70
jmp 0xb052
leaq 0xc0(%rsp), %rdi
callq 0xd170
movl 0x104(%rsp), %esi
leaq 0xa8(%rsp), %rdi
callq 0xd040
jmp 0xb075
jmp 0xb077
leaq 0xd0(%rsp), %rdi
movl $0x2, %esi
callq 0xe320
movsd %xmm0, 0x18(%rsp)
jmp 0xb091
movsd 0x18(%rsp), %xmm0
ucomisd 0xf8(%rsp), %xmm0
jbe 0xb38d
leaq 0xd0(%rsp), %rsi
movq %rsi, %rdi
callq 0xd740
movsd %xmm0, 0x10(%rsp)
jmp 0xb0be
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0xe0(%rsp)
movq 0x118(%rsp), %rsi
leaq 0x90(%rsp), %rdi
leaq 0xd0(%rsp), %rdx
callq 0x4800
jmp 0xb0ec
leaq 0xa8(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0xdc70
jmp 0xb103
leaq 0x90(%rsp), %rdi
callq 0xd170
leaq 0xd0(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0xd740
movsd %xmm0, 0x8(%rsp)
jmp 0xb12d
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0xb8(%rsp)
movsd 0xe0(%rsp), %xmm0
movsd 0xb8(%rsp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0xa0(%rsp)
movq 0x108(%rsp), %rax
movl (%rax), %ecx
incl %ecx
movl %ecx, (%rax)
leaq 0x60(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
leaq 0xd0(%rsp), %rdx
callq 0xd910
jmp 0xb185
leaq 0x70(%rsp), %rdi
leaq 0x60(%rsp), %rsi
leaq 0xb8(%rsp), %rdx
callq 0xd9c0
jmp 0xb19e
movq 0x28(%rsp), %rsi
leaq 0x80(%rsp), %rdi
leaq 0x70(%rsp), %rdx
callq 0xd1a0
jmp 0xb1b7
movq 0x28(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0xdc70
jmp 0xb1cb
leaq 0x80(%rsp), %rdi
callq 0xd170
leaq 0x70(%rsp), %rdi
callq 0xd170
leaq 0x60(%rsp), %rdi
callq 0xd170
movq 0x28(%rsp), %rdx
movq 0x110(%rsp), %rax
movq %rax, (%rsp)
movq 0x118(%rsp), %rsi
leaq 0x40(%rsp), %rdi
callq 0x4800
jmp 0xb211
movq (%rsp), %rsi
leaq 0x50(%rsp), %rdi
leaq 0x40(%rsp), %rdx
callq 0xd470
jmp 0xb226
leaq 0xd0(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0xdc70
jmp 0xb23a
leaq 0x50(%rsp), %rdi
callq 0xd170
leaq 0x40(%rsp), %rdi
callq 0xd170
jmp 0xb077
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf0(%rsp)
movl %eax, 0xec(%rsp)
jmp 0xb3ee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf0(%rsp)
movl %eax, 0xec(%rsp)
jmp 0xb3c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf0(%rsp)
movl %eax, 0xec(%rsp)
leaq 0xc0(%rsp), %rdi
callq 0xd170
jmp 0xb3c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf0(%rsp)
movl %eax, 0xec(%rsp)
jmp 0xb3bb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf0(%rsp)
movl %eax, 0xec(%rsp)
leaq 0x90(%rsp), %rdi
callq 0xd170
jmp 0xb3bb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf0(%rsp)
movl %eax, 0xec(%rsp)
jmp 0xb341
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf0(%rsp)
movl %eax, 0xec(%rsp)
jmp 0xb337
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf0(%rsp)
movl %eax, 0xec(%rsp)
leaq 0x80(%rsp), %rdi
callq 0xd170
leaq 0x70(%rsp), %rdi
callq 0xd170
leaq 0x60(%rsp), %rdi
callq 0xd170
jmp 0xb3bb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf0(%rsp)
movl %eax, 0xec(%rsp)
jmp 0xb381
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf0(%rsp)
movl %eax, 0xec(%rsp)
leaq 0x50(%rsp), %rdi
callq 0xd170
leaq 0x40(%rsp), %rdi
callq 0xd170
jmp 0xb3bb
movb $0x1, 0x103(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0xd170
leaq 0xd0(%rsp), %rdi
callq 0xd170
testb $0x1, 0x103(%rsp)
jne 0xb3e1
jmp 0xb3d7
leaq 0xa8(%rsp), %rdi
callq 0xd170
leaq 0xd0(%rsp), %rdi
callq 0xd170
jmp 0xb3ee
movq 0x28(%rsp), %rdi
callq 0xd170
movq 0x30(%rsp), %rax
addq $0x128, %rsp            # imm = 0x128
retq
movq 0x28(%rsp), %rdi
callq 0xd170
movq 0xf0(%rsp), %rdi
callq 0x21e0
nopw %cs:(%rax,%rax)