// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x68, %rsp
movsd %xmm0, 0x60(%rsp)
movsd 0x3c86(%rip), %xmm0     # 0x1c4e8
movsd %xmm0, 0x58(%rsp)
movsd 0x3c78(%rip), %xmm0     # 0x1c4e8
movsd %xmm0, 0x50(%rsp)
movsd 0x3c6a(%rip), %xmm0     # 0x1c4e8
movsd %xmm0, 0x48(%rsp)
movl $0x63, 0x44(%rsp)
movl $0x0, 0x40(%rsp)
movsd 0x38bc(%rip), %xmm0     # 0x1c158
movsd %xmm0, 0x30(%rsp)
movsd 0x30(%rsp), %xmm0
movsd 0x60(%rsp), %xmm1
callq 0x18790
movsd %xmm0, 0x20(%rsp)
movl $0x1, 0x3c(%rsp)
movl 0x3c(%rsp), %eax
cmpl 0x44(%rsp), %eax
jg 0x189ef
cmpl $0x0, 0x40(%rsp)
je 0x188db
jmp 0x189ef
movsd 0x30(%rsp), %xmm0
callq 0x18800
movsd %xmm0, 0x10(%rsp)
movsd 0x10(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x18910
jp 0x18910
movl $0x1, 0x40(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
jmp 0x18922
movsd 0x20(%rsp), %xmm0
divsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x30(%rsp), %xmm0
subsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
movsd 0x28(%rsp), %xmm0
movsd 0x60(%rsp), %xmm1
callq 0x18790
movsd %xmm0, 0x18(%rsp)
movsd 0x8(%rsp), %xmm1
movaps 0x3c28(%rip), %xmm0     # 0x1c580
pand %xmm0, %xmm1
movsd 0x3b74(%rip), %xmm0     # 0x1c4d8
mulsd %xmm1, %xmm0
movsd 0x28(%rsp), %xmm1
movaps 0x3c0b(%rip), %xmm2     # 0x1c580
pand %xmm2, %xmm1
addsd 0x48(%rsp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, (%rsp)
movsd (%rsp), %xmm1
movsd 0x58(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x189c7
movsd 0x18(%rsp), %xmm1
movaps 0x3bda(%rip), %xmm0     # 0x1c580
pand %xmm0, %xmm1
movsd 0x50(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x189c7
cmpl $0x1, 0x40(%rsp)
je 0x189c5
movl $0x2, 0x40(%rsp)
jmp 0x189c7
movsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0x188c1
cmpl $0x0, 0x40(%rsp)
jne 0x18a04
leaq 0x3ef3(%rip), %rdi      # 0x1c8f0
movb $0x0, %al
callq 0x8050
cmpl $0x1, 0x40(%rsp)
jne 0x18a19
leaq 0x3f0f(%rip), %rdi      # 0x1c921
movb $0x0, %al
callq 0x8050
movsd 0x30(%rsp), %xmm0
addq $0x68, %rsp
retq
nopw %cs:(%rax,%rax)
nop