// File: /workspace/github_c_makefile_star2_O1/guszejnovdavid[P]MISFIT/FindParameter_Newton.c
// Function: FindR(double)
double FindR(double m)

{
    double Delta = 1E-6;       /* Tolerance  */
    double Epsilon = 1E-6;     /* Tolerance  */
    double Small = 1E-6;       /* Tolerance  */

    int Max = 99;  /* Maximum number of iterations  */
    int Cond = 0;  /* Condition fo loop termination */
    int K;         /* Counter for loop              */

    double P0=1.0;    /* INPUT : Must be close to the root */
    double P1;    /* New iterate    */
    double Y0;    /* Function value */
    double Y1;    /* Function value */
    double Df;    /* Derivative     */
    double Dp;
    double RelErr;


    Y0 = ffunction_R(P0,m);

    for ( K = 1; K <= Max ; K++) {

        if(Cond) break;

        Df = dffunction_R(P0);      /* Compute the derivative  */

         if( Df == 0) {       /* Check division by zero */
             Cond = 1;
             Dp   = 0;
         }

         else Dp = Y0/Df;

        P1 = P0 - Dp;       /* New iterate */
        Y1 = ffunction_R(P1,m);   /* New function value */

        RelErr = 2 * fabs(Dp) / ( fabs(P1) + Small );  /* Relative error */

        if( (RelErr < Delta)  && (fabs(Y1) < Epsilon) ) { /* Check for   */

            if( Cond != 1) Cond = 2;                      /* convergence */

        }

        P0 = P1;
        Y0 = Y1;
    }

if(Cond == 0) printf("The maximum number of iterations was exceeded !\n");

if(Cond == 1) printf("Division by zero was encountered !\n");

return P0;

//if(Cond == 2) printf("The root was found with the desired tolerance !\n");

}

// Assembly:
movapd 0x278b(%rip), %xmm1     # 0xb4e0
xorpd %xmm0, %xmm1
movsd 0x2af6(%rip), %xmm8     # 0xb858
subsd %xmm0, %xmm8
movsd 0x22e0(%rip), %xmm11    # 0xb050
movl $0x1, %eax
movsd 0x22f3(%rip), %xmm2     # 0xb070
movsd 0x2acb(%rip), %xmm3     # 0xb850
movsd 0x2abb(%rip), %xmm4     # 0xb848
movapd 0x279b(%rip), %xmm5     # 0xb530
movsd 0x2683(%rip), %xmm6     # 0xb420
movapd %xmm11, %xmm0
movapd %xmm0, %xmm9
divsd %xmm2, %xmm9
movapd %xmm9, %xmm7
addsd %xmm11, %xmm7
addsd %xmm9, %xmm7
mulsd %xmm3, %xmm7
xorpd %xmm9, %xmm9
ucomisd %xmm9, %xmm7
leal 0x1(%rax), %ecx
movapd %xmm8, %xmm9
divsd %xmm7, %xmm9
movapd %xmm9, %xmm8
jne 0x8de9
movapd %xmm9, %xmm8
jp 0x8de9
xorpd %xmm8, %xmm8
subsd %xmm8, %xmm0
movapd %xmm0, %xmm10
divsd %xmm2, %xmm10
movapd %xmm10, %xmm8
mulsd %xmm4, %xmm8
andpd %xmm5, %xmm9
addsd %xmm9, %xmm9
jne 0x8e15
jp 0x8e15
xorpd %xmm9, %xmm9
addsd %xmm11, %xmm10
mulsd %xmm10, %xmm8
addsd %xmm1, %xmm8
movapd %xmm0, %xmm10
andpd %xmm5, %xmm10
addsd %xmm6, %xmm10
divsd %xmm10, %xmm9
movapd %xmm8, %xmm10
andpd %xmm5, %xmm10
cmpltpd %xmm6, %xmm10
cmpltpd %xmm6, %xmm9
andpd %xmm10, %xmm9
movd %xmm9, %edx
jne 0x8e5c
jnp 0x8e6c
cmpl $0x62, %eax
ja 0x8e6c
movl %ecx, %eax
testb $0x1, %dl
je 0x8da2
subq $0x18, %rsp
xorpd %xmm1, %xmm1
cmpeqsd %xmm1, %xmm7
movq %xmm7, %rax
movl %eax, %ecx
andl $0x1, %ecx
addl $0x2, %eax
testb $0x1, %dl
cmovel %ecx, %eax
testl %eax, %eax
je 0x8ea3
cmpl $0x1, %eax
jne 0x8eb9
movapd %xmm0, (%rsp)
leaq 0x29ef(%rip), %rdi      # 0xb890
jmp 0x8eaf
movapd %xmm0, (%rsp)
leaq 0x29b1(%rip), %rdi      # 0xb860
callq 0x2300
movapd (%rsp), %xmm0
addq $0x18, %rsp
retq
nop