// File: /workspace/github_c_makefile_star2_O2/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 0x2eeb(%rip), %xmm1     # 0xb490
xorpd %xmm0, %xmm1
movsd 0x3247(%rip), %xmm3     # 0xb7f8
subsd %xmm0, %xmm3
xorl %ecx, %ecx
pushq $0x1
popq %rax
movsd 0x2a8d(%rip), %xmm11    # 0xb050
movsd 0x2aa5(%rip), %xmm2     # 0xb070
movsd 0x321d(%rip), %xmm4     # 0xb7f0
movsd 0x320d(%rip), %xmm5     # 0xb7e8
movapd 0x2eed(%rip), %xmm6     # 0xb4d0
movsd 0x2e25(%rip), %xmm7     # 0xb410
movapd %xmm11, %xmm0
cmpl $0x63, %eax
ja 0x86ca
testl %ecx, %ecx
jne 0x86ca
movapd %xmm0, %xmm8
divsd %xmm2, %xmm8
movapd %xmm8, %xmm9
addsd %xmm11, %xmm9
addsd %xmm8, %xmm9
mulsd %xmm4, %xmm9
xorpd %xmm8, %xmm8
movapd %xmm9, %xmm10
cmpeqsd %xmm8, %xmm10
movq %xmm10, %rcx
movl %ecx, %edx
andl $0x1, %edx
addl $0x2, %ecx
ucomisd %xmm8, %xmm9
divsd %xmm9, %xmm3
movapd %xmm3, %xmm8
jne 0x8659
movapd %xmm3, %xmm8
jp 0x8659
xorpd %xmm8, %xmm8
subsd %xmm8, %xmm0
movapd %xmm0, %xmm9
divsd %xmm2, %xmm9
movapd %xmm9, %xmm8
mulsd %xmm5, %xmm8
andpd %xmm6, %xmm3
addsd %xmm3, %xmm3
jne 0x8682
jp 0x8682
xorpd %xmm3, %xmm3
addsd %xmm11, %xmm9
mulsd %xmm9, %xmm8
addsd %xmm1, %xmm8
movapd %xmm8, %xmm9
andpd %xmm6, %xmm9
ucomisd %xmm9, %xmm7
movapd %xmm0, %xmm9
andpd %xmm6, %xmm9
cmovbel %edx, %ecx
addsd %xmm7, %xmm9
divsd %xmm9, %xmm3
ucomisd %xmm3, %xmm7
cmovbel %edx, %ecx
incl %eax
movapd %xmm8, %xmm3
jmp 0x85f0
subq $0x18, %rsp
testl %ecx, %ecx
je 0x86e5
cmpl $0x1, %ecx
jne 0x86fb
movapd %xmm0, (%rsp)
leaq 0x314d(%rip), %rdi      # 0xb830
jmp 0x86f1
movapd %xmm0, (%rsp)
leaq 0x310f(%rip), %rdi      # 0xb800
callq 0x22c0
movapd (%rsp), %xmm0
addq $0x18, %rsp
retq