// File: /workspace/github_c_makefile_star2_O3/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 0x2813(%rip), %xmm1     # 0xb4e0
xorpd %xmm0, %xmm1
movsd 0x2b7e(%rip), %xmm8     # 0xb858
subsd %xmm0, %xmm8
movsd 0x2368(%rip), %xmm11    # 0xb050
movl $0x1, %eax
movsd 0x237b(%rip), %xmm2     # 0xb070
movsd 0x2b53(%rip), %xmm3     # 0xb850
movsd 0x2b43(%rip), %xmm4     # 0xb848
movapd 0x2823(%rip), %xmm5     # 0xb530
movsd 0x270b(%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 0x8d61
movapd %xmm9, %xmm8
jp 0x8d61
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 0x8d8d
jp 0x8d8d
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 0x8dd4
jnp 0x8de4
cmpl $0x62, %eax
ja 0x8de4
movl %ecx, %eax
testb $0x1, %dl
je 0x8d1a
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 0x8e1b
cmpl $0x1, %eax
jne 0x8e31
movapd %xmm0, (%rsp)
leaq 0x2a77(%rip), %rdi      # 0xb890
jmp 0x8e27
movapd %xmm0, (%rsp)
leaq 0x2a39(%rip), %rdi      # 0xb860
callq 0x2300
movapd (%rsp), %xmm0
addq $0x18, %rsp
retq
nop