// File: /workspace/github_cpp_makefile_star2_O1/yukimasano[P]cpp_matrix/Matrix.cpp
// Function: CG_pre(Matrix&, Vector&, int&)
Vector CG_pre(Matrix& B, Vector& b, int& count){
	assert(nrows(B) == ncols(B));
	int m =nrows(B);
	// we want a square system
  // do the preconditioning by multiplying with D^{-1}
  Matrix A = B;
  for (int k=1;k<=m;k++){
    double x = A(k,k);
    //A.set_col(k, A.get_col(k)/x);
    for (int j=1;j<=m;j++){
     A.set_val(k,j, A(k,j)/x);
    }
  }
  Vector v = b;
  for (int k=1;k<=m;k++){
    v.set_val(k, v(k)/B(k,k));
  }
	// INITIALISATION
	Vector x= v;
	double tol = 1.e-12;
	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 (r.norm() > tol){
    count+=1;
		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;

		x = x + alpha*p;
		r = v - A*x;
    if (count>100){
      r = r*0;
      count = -100000;
    }
  }
  //	std::cout<<count<<std::endl<<std::flush;
	return x;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rcx, 0x60(%rsp)
movq %rdx, 0xb8(%rsp)
movq %rdi, 0x28(%rsp)
movl 0x8(%rsi), %ebx
cmpl 0xc(%rsi), %ebx
jne 0x7e13
leaq 0x50(%rsp), %rdi
movq %rsi, 0xc0(%rsp)
callq 0x3db2
movq %rbx, 0x90(%rsp)
testl %ebx, %ebx
jle 0x79a7
leaq 0x50(%rsp), %r12
movq (%r12), %r14
movq 0x90(%rsp), %rax
leaq 0x1(%rax), %r15
movl %r15d, %ebx
movl $0x1, %r13d
movq %r12, %rdi
movl %r13d, %esi
movl %r13d, %edx
callq 0x2f92
movsd (%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
movl $0x1, %ebp
movq %r12, %rdi
movl %r13d, %esi
movl %ebp, %edx
callq 0x2f92
movsd (%rax), %xmm0
divsd 0x30(%rsp), %xmm0
movq -0x8(%r14,%r13,8), %rax
movsd %xmm0, -0x8(%rax,%rbp,8)
incq %rbp
cmpq %rbp, %rbx
jne 0x7975
incq %r13
cmpq %r15, %r13
jne 0x7958
leaq 0x80(%rsp), %rdi
movq 0xb8(%rsp), %rsi
callq 0x82b8
movq 0x90(%rsp), %r15
testl %r15d, %r15d
jle 0x7a2c
movl %r15d, %ebx
negl %ebx
movl $0x1, %r12d
leaq 0x80(%rsp), %r14
movq %r14, %rdi
movl %r12d, %esi
callq 0x8b5a
movsd (%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
movq 0xc0(%rsp), %rdi
movl %r12d, %esi
movl %r12d, %edx
callq 0x2f92
movsd 0x30(%rsp), %xmm0
divsd (%rax), %xmm0
movq %r14, %rdi
movl %r12d, %esi
callq 0x8ef8
leal (%rbx,%r12), %eax
incl %eax
movl %r12d, %ecx
incl %ecx
movl %ecx, %r12d
cmpl $0x1, %eax
jne 0x79dc
leaq 0x80(%rsp), %rsi
movq 0x28(%rsp), %rbx
movq %rbx, %rdi
callq 0x82b8
leaq 0x70(%rsp), %rdi
leaq 0x50(%rsp), %rsi
movq %rbx, %rdx
callq 0x3941
leaq 0x40(%rsp), %rdi
leaq 0x80(%rsp), %rsi
leaq 0x70(%rsp), %rdx
callq 0x84c8
leaq 0x70(%rsp), %rdi
callq 0x8310
leaq 0x70(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x82b8
leaq 0x98(%rsp), %rdi
movl %r15d, %esi
callq 0x8268
leaq 0x18(%rsp), %rdi
leaq 0x50(%rsp), %rsi
leaq 0x40(%rsp), %rdx
callq 0x3941
leaq 0x98(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x89dc
leaq 0x18(%rsp), %rdi
callq 0x8310
leaq 0x40(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x8673
movsd %xmm0, 0x38(%rsp)
leaq 0x40(%rsp), %rdi
movl $0x2, %esi
callq 0x8dfc
movsd %xmm0, 0x30(%rsp)
leaq 0x40(%rsp), %rdi
movl $0x2, %esi
callq 0x8dfc
movsd 0x30(%rsp), %xmm1
mulsd %xmm0, %xmm1
leaq 0x38(%rsp), %rsi
divsd (%rsi), %xmm1
movsd %xmm1, (%rsi)
leaq 0x8(%rsp), %rdi
leaq 0x40(%rsp), %rdx
callq 0x877e
leaq 0x18(%rsp), %rdi
leaq 0x8(%rsp), %rdx
movq 0x28(%rsp), %rbx
movq %rbx, %rsi
callq 0x831d
leaq 0x18(%rsp), %rsi
movq %rbx, %rdi
callq 0x89dc
leaq 0x18(%rsp), %rdi
callq 0x8310
leaq 0x8(%rsp), %rdi
callq 0x8310
leaq 0x8(%rsp), %rdi
leaq 0x50(%rsp), %rsi
movq %rbx, %rdx
callq 0x3941
leaq 0x18(%rsp), %rdi
leaq 0x80(%rsp), %rsi
leaq 0x8(%rsp), %rdx
callq 0x84c8
leaq 0x40(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x89dc
leaq 0x18(%rsp), %rdi
callq 0x8310
leaq 0x8(%rsp), %rdi
callq 0x8310
leaq 0x18(%rsp), %rdi
movl %r15d, %esi
callq 0x8268
leaq 0x40(%rsp), %r15
leaq 0x8(%rsp), %r12
leaq 0x70(%rsp), %rbp
leaq 0x18(%rsp), %rbx
leaq 0xa8(%rsp), %r14
movq 0x28(%rsp), %r13
movq %r15, %rdi
movl $0x2, %esi
callq 0x8dfc
ucomisd 0x24ac(%rip), %xmm0     # 0xa098
jbe 0x7dba
movq 0x60(%rsp), %rax
incl (%rax)
movq %r12, %rdi
leaq 0x50(%rsp), %rsi
movq %r15, %rdx
callq 0x3941
leaq 0x98(%rsp), %rdi
movq %r12, %rsi
callq 0x89dc
movq %r12, %rdi
callq 0x8310
movq %r12, %rdi
leaq 0x50(%rsp), %rsi
movq %rbp, %rdx
callq 0x3941
movq %rbx, %rdi
movq %r12, %rsi
callq 0x89dc
movq %r12, %rdi
callq 0x8310
movq %r15, %rdi
movq %rbx, %rsi
callq 0x8673
movsd %xmm0, 0x68(%rsp)
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x8673
movsd 0x68(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x68(%rsp)
movq %r14, %rdi
leaq 0x68(%rsp), %rsi
movq %rbp, %rdx
callq 0x877e
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x84c8
movq %rbp, %rdi
movq %r12, %rsi
callq 0x89dc
movq %r12, %rdi
callq 0x8310
movq %r14, %rdi
callq 0x8310
movq %r15, %rdi
movq %rbp, %rsi
callq 0x8673
movsd %xmm0, 0x38(%rsp)
movq %r12, %rdi
leaq 0x50(%rsp), %rsi
movq %rbp, %rdx
callq 0x3941
movq %rbx, %rdi
movq %r12, %rsi
callq 0x89dc
movq %r12, %rdi
callq 0x8310
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x8673
movsd 0x38(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x38(%rsp)
movq %r14, %rdi
leaq 0x38(%rsp), %rsi
movq %rbp, %rdx
callq 0x877e
movq %r12, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x831d
movq %r13, %rdi
movq %r12, %rsi
callq 0x89dc
movq %r12, %rdi
callq 0x8310
movq %r14, %rdi
callq 0x8310
movq %r14, %rdi
leaq 0x50(%rsp), %rsi
movq %r13, %rdx
callq 0x3941
movq %r12, %rdi
leaq 0x80(%rsp), %rsi
movq %r14, %rdx
callq 0x84c8
movq %r15, %rdi
movq %r12, %rsi
callq 0x89dc
movq %r12, %rdi
callq 0x8310
movq %r14, %rdi
callq 0x8310
movq 0x60(%rsp), %rax
cmpl $0x65, (%rax)
jl 0x7bd7
movq $0x0, 0xa8(%rsp)
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x86f8
movq %r15, %rdi
movq %r12, %rsi
callq 0x89dc
movq %r12, %rdi
callq 0x8310
movq 0x60(%rsp), %rax
movl $0xfffe7960, (%rax)     # imm = 0xFFFE7960
jmp 0x7bd7
leaq 0x18(%rsp), %rdi
callq 0x8310
leaq 0x98(%rsp), %rdi
callq 0x8310
leaq 0x70(%rsp), %rdi
callq 0x8310
leaq 0x40(%rsp), %rdi
callq 0x8310
leaq 0x80(%rsp), %rdi
callq 0x8310
leaq 0x50(%rsp), %rdi
callq 0x2f4c
movq 0x28(%rsp), %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2638(%rip), %rdi      # 0xa452
leaq 0x2330(%rip), %rsi      # 0xa151
leaq 0x263f(%rip), %rcx      # 0xa467
movl $0x37a, %edx            # imm = 0x37A
callq 0x20b0
jmp 0x7e8b
jmp 0x7e3a
jmp 0x7e49
jmp 0x7e8b
movq %rax, %r14
leaq 0x18(%rsp), %rdi
callq 0x8310
jmp 0x7e4c
movq %rax, %r14
leaq 0x8(%rsp), %rdi
jmp 0x7ee9
jmp 0x7e8b
jmp 0x7ee1
jmp 0x7e8b
movq %rax, %r14
jmp 0x7efb
movq %rax, %r14
jmp 0x7f05
movq %rax, %r14
leaq 0x70(%rsp), %rdi
jmp 0x7f0a
movq %rax, %r14
jmp 0x7f0f
jmp 0x7edc
jmp 0x7f28
movq %rax, %r14
jmp 0x7eee
jmp 0x7ea3
jmp 0x7ee1
jmp 0x7f28
jmp 0x7ebc
jmp 0x7eb1
jmp 0x7ee1
jmp 0x7ea3
jmp 0x7ea3
movq %rax, %r14
leaq 0x8(%rsp), %rdi
jmp 0x7ed1
jmp 0x7eb1
jmp 0x7ee1
movq %rax, %r14
jmp 0x7ec9
jmp 0x7ee1
jmp 0x7ebc
jmp 0x7ee1
movq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0x8310
leaq 0xa8(%rsp), %rdi
callq 0x8310
jmp 0x7ee4
jmp 0x7ee1
jmp 0x7ee1
movq %rax, %r14
jmp 0x7f19
movq %rax, %r14
leaq 0x18(%rsp), %rdi
callq 0x8310
leaq 0x98(%rsp), %rdi
callq 0x8310
leaq 0x70(%rsp), %rdi
callq 0x8310
leaq 0x40(%rsp), %rdi
callq 0x8310
movq 0x28(%rsp), %rdi
callq 0x8310
leaq 0x80(%rsp), %rdi
callq 0x8310
jmp 0x7f2b
movq %rax, %r14
leaq 0x50(%rsp), %rdi
callq 0x2f4c
movq %r14, %rdi
callq 0x21f0