// File: /workspace/github_c_makefile_star2_O1/guszejnovdavid[P]MISFIT/FindParameter_Newton.c
// Function: FindMach(double)
double FindMach(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_Mach(P0,m);

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

        if(Cond) break;

        Df = dffunction_Mach(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_Mach(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:
movsd 0x2cea(%rip), %xmm1     # 0xb838
movapd %xmm1, %xmm10
subsd %xmm0, %xmm10
movsd 0x24f0(%rip), %xmm2     # 0xb050
movl $0x1, %eax
movsd 0x27eb(%rip), %xmm3     # 0xb358
movsd 0x2ccb(%rip), %xmm4     # 0xb840
movsd 0x2813(%rip), %xmm5     # 0xb390
movsd 0x24f3(%rip), %xmm6     # 0xb078
movapd 0x29a3(%rip), %xmm7     # 0xb530
movsd 0x288a(%rip), %xmm8     # 0xb420
movapd %xmm2, %xmm13
movapd %xmm13, %xmm11
mulsd %xmm1, %xmm11
mulsd %xmm13, %xmm11
movapd %xmm13, %xmm9
mulsd %xmm3, %xmm9
addsd %xmm4, %xmm9
mulsd %xmm13, %xmm9
addsd %xmm5, %xmm9
mulsd %xmm13, %xmm9
addsd %xmm6, %xmm9
mulsd %xmm11, %xmm9
movapd %xmm13, %xmm11
addsd %xmm2, %xmm11
mulsd %xmm11, %xmm11
divsd %xmm11, %xmm9
xorpd %xmm11, %xmm11
ucomisd %xmm11, %xmm9
leal 0x1(%rax), %ecx
movapd %xmm10, %xmm11
divsd %xmm9, %xmm11
movapd %xmm11, %xmm10
jne 0x8c10
movapd %xmm11, %xmm10
jp 0x8c10
xorpd %xmm10, %xmm10
andpd %xmm7, %xmm11
addsd %xmm11, %xmm11
jne 0x8c23
jp 0x8c23
xorpd %xmm11, %xmm11
subsd %xmm10, %xmm13
movapd %xmm13, %xmm12
mulsd %xmm1, %xmm12
mulsd %xmm13, %xmm12
movapd %xmm13, %xmm10
mulsd %xmm13, %xmm10
addsd %xmm2, %xmm10
mulsd %xmm12, %xmm10
movapd %xmm2, %xmm12
divsd %xmm13, %xmm12
addsd %xmm2, %xmm12
divsd %xmm12, %xmm10
subsd %xmm0, %xmm10
movapd %xmm13, %xmm12
andpd %xmm7, %xmm12
addsd %xmm8, %xmm12
divsd %xmm12, %xmm11
movapd %xmm10, %xmm12
andpd %xmm7, %xmm12
cmpltpd %xmm8, %xmm11
cmpltpd %xmm8, %xmm12
andpd %xmm11, %xmm12
movd %xmm12, %edx
jne 0x8c9c
jnp 0x8cac
cmpl $0x62, %eax
ja 0x8cac
movl %ecx, %eax
testb $0x1, %dl
je 0x8b9b
subq $0x18, %rsp
xorpd %xmm0, %xmm0
cmpeqsd %xmm0, %xmm9
movq %xmm9, %rax
movl %eax, %ecx
andl $0x1, %ecx
addl $0x2, %eax
testb $0x1, %dl
cmovel %ecx, %eax
testl %eax, %eax
je 0x8ce5
cmpl $0x1, %eax
jne 0x8cfd
movapd %xmm13, (%rsp)
leaq 0x2bad(%rip), %rdi      # 0xb890
jmp 0x8cf2
movapd %xmm13, (%rsp)
leaq 0x2b6e(%rip), %rdi      # 0xb860
callq 0x2300
movapd (%rsp), %xmm13
movapd %xmm13, %xmm0
addq $0x18, %rsp
retq