#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
double fabsf(float);
int /*<<< orphan*/ printf(char *, unsigned int, float, float, double, double);
float NewtonSolve(float lambda, float C_0, float C_1, float C_2) {
  unsigned int maxits = 500;
  float tolerance = 1.0e-6f;
  float lambda_old, lambda2;
  float a, b;
  for (int i = 0; i < maxits; i++) {
    lambda_old = lambda;
    lambda2 = lambda_old * lambda_old;
    b = (lambda2 + C_2) * lambda_old;
    a = b + C_1;
    lambda = lambda_old -
             (a * lambda_old + C_0) / (2.0f * lambda2 * lambda_old + b + a);
    if (fabsf(lambda - lambda_old) < fabsf(tolerance * lambda))
      break;
  }
  if (fabsf(lambda - lambda_old) >= fabsf(100 * tolerance * lambda)) {
    printf("RMSD Warning: No convergence after %d iterations: "
           "Lambda,Lambda0,Diff,Allowed = %f, %f, %f, %f \n",
           maxits, lambda, lambda_old, fabsf(lambda - lambda_old),
           fabsf(tolerance * lambda));
  }
  return (lambda);
}


x86 assembly (clang, -O0):
<NewtonSolve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movss  %xmm2,-0xc(%rbp)
movss  %xmm3,-0x10(%rbp)
movl   $0x1f4,-0x14(%rbp)
movss  0xeb5(%rip),%xmm0
movss  %xmm0,-0x18(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    1236 <NewtonSolve+0x116>
movss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
mulss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
addss  -0x10(%rbp),%xmm0
mulss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x28(%rbp)
movss  -0x28(%rbp),%xmm0
addss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x1c(%rbp),%xmm0
movss  -0x24(%rbp),%xmm1
movss  -0x1c(%rbp),%xmm3
movss  -0x8(%rbp),%xmm2
mulss  %xmm3,%xmm1
addss  %xmm2,%xmm1
movss  0xe41(%rip),%xmm2
mulss  -0x20(%rbp),%xmm2
movss  -0x1c(%rbp),%xmm4
movss  -0x28(%rbp),%xmm3
mulss  %xmm4,%xmm2
addss  %xmm3,%xmm2
addss  -0x24(%rbp),%xmm2
divss  %xmm2,%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
subss  -0x1c(%rbp),%xmm0
call   1030 <fabsf@plt>
movsd  %xmm0,-0x38(%rbp)
movss  -0x18(%rbp),%xmm0
mulss  -0x4(%rbp),%xmm0
call   1030 <fabsf@plt>
movsd  -0x38(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jbe    1223 <NewtonSolve+0x103>
jmp    1236 <NewtonSolve+0x116>
jmp    1228 <NewtonSolve+0x108>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1157 <NewtonSolve+0x37>
movss  -0x4(%rbp),%xmm0
subss  -0x1c(%rbp),%xmm0
call   1030 <fabsf@plt>
movsd  %xmm0,-0x40(%rbp)
movss  0xdb6(%rip),%xmm0
mulss  -0x18(%rbp),%xmm0
mulss  -0x4(%rbp),%xmm0
call   1030 <fabsf@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     12d1 <NewtonSolve+0x1b1>
mov    -0x14(%rbp),%eax
mov    %eax,-0x58(%rbp)
movss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x44(%rbp)
movss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x54(%rbp)
movss  -0x4(%rbp),%xmm0
subss  -0x1c(%rbp),%xmm0
call   1030 <fabsf@plt>
movsd  %xmm0,-0x50(%rbp)
movss  -0x18(%rbp),%xmm0
mulss  -0x4(%rbp),%xmm0
call   1030 <fabsf@plt>
mov    -0x58(%rbp),%esi
movss  -0x54(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm2
movaps %xmm0,%xmm3
movss  -0x44(%rbp),%xmm0
lea    0xd40(%rip),%rdi
call   1040 <printf@plt>
movss  -0x4(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<NewtonSolve>:
push   %rbx
sub    $0x30,%rsp
movss  %xmm3,0x2c(%rsp)
movss  %xmm2,0x28(%rsp)
movss  %xmm1,0x24(%rsp)
movss  %xmm0,0xc(%rsp)
mov    $0x1f3,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movss  0xc(%rsp),%xmm0
movaps %xmm0,%xmm2
movaps %xmm0,%xmm3
mulss  %xmm0,%xmm0
movaps %xmm0,%xmm1
addss  0x2c(%rsp),%xmm1
mulss  %xmm2,%xmm1
addss  %xmm0,%xmm0
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
addss  0x28(%rsp),%xmm1
addss  %xmm1,%xmm0
mulss  %xmm2,%xmm1
addss  0x24(%rsp),%xmm1
divss  %xmm0,%xmm1
subss  %xmm1,%xmm3
movss  %xmm3,0xc(%rsp)
movaps %xmm3,%xmm0
movss  %xmm2,0x20(%rsp)
subss  %xmm2,%xmm0
movss  %xmm0,0x18(%rsp)
call   1030 <fabsf@plt>
movsd  %xmm0,0x10(%rsp)
movss  0xc(%rsp),%xmm0
mulss  0xe39(%rip),%xmm0
movss  %xmm0,0x1c(%rsp)
call   1030 <fabsf@plt>
sub    $0x1,%ebx
setb   %al
ucomisd 0x10(%rsp),%xmm0
ja     11e8 <NewtonSolve+0xc8>
test   %al,%al
je     1150 <NewtonSolve+0x30>
movss  0x18(%rsp),%xmm0
call   1030 <fabsf@plt>
movsd  %xmm0,0x10(%rsp)
movss  0xe03(%rip),%xmm0
mulss  0xc(%rsp),%xmm0
call   1030 <fabsf@plt>
movsd  0x10(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jb     125a <NewtonSolve+0x13a>
movss  0x18(%rsp),%xmm0
call   1030 <fabsf@plt>
movsd  %xmm0,0x10(%rsp)
movss  0x1c(%rsp),%xmm0
call   1030 <fabsf@plt>
movaps %xmm0,%xmm3
lea    0xdca(%rip),%rdi
mov    $0x1f4,%esi
movss  0xc(%rsp),%xmm0
movss  0x20(%rsp),%xmm1
movsd  0x10(%rsp),%xmm2
call   1040 <printf@plt>
movss  0xc(%rsp),%xmm0
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [97 x i8] c"RMSD Warning: No convergence after %d iterations: Lambda,Lambda0,Diff,Allowed = %f, %f, %f, %f \0A\00"
define float @NewtonSolve(float %0, float %1, float %2, float %3) {
%5 = alloca float
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca i32
%10 = alloca float
%11 = alloca float
%12 = alloca float
%13 = alloca float
%14 = alloca float
%15 = alloca i32
store float %0, float* %5
store float %1, float* %6
store float %2, float* %7
store float %3, float* %8
store i32 500, i32* %9
store float 0x3EB0C6F7A0000000, float* %10
store i32 0, i32* %15
br label %16
16: ; preds = %58, %4
%17 = load i32, i32* %15
%18 = load i32, i32* %9
%19 = icmp ult i32 %17, %18
br i1 %19, label %20, label %61
20: ; preds = %16
%21 = load float, float* %5
store float %21, float* %11
%22 = load float, float* %11
%23 = load float, float* %11
%24 = fmul float %22, %23
store float %24, float* %12
%25 = load float, float* %12
%26 = load float, float* %8
%27 = fadd float %25, %26
%28 = load float, float* %11
%29 = fmul float %27, %28
store float %29, float* %14
%30 = load float, float* %14
%31 = load float, float* %7
%32 = fadd float %30, %31
store float %32, float* %13
%33 = load float, float* %11
%34 = load float, float* %13
%35 = load float, float* %11
%36 = load float, float* %6
%37 = call float @llvm.fmuladd.f32(float %34, float %35, float %36)
%38 = load float, float* %12
%39 = fmul float 2.000000e+00, %38
%40 = load float, float* %11
%41 = load float, float* %14
%42 = call float @llvm.fmuladd.f32(float %39, float %40, float %41)
%43 = load float, float* %13
%44 = fadd float %42, %43
%45 = fdiv float %37, %44
%46 = fsub float %33, %45
store float %46, float* %5
%47 = load float, float* %5
%48 = load float, float* %11
%49 = fsub float %47, %48
%50 = call double @fabsf(float %49)
%51 = load float, float* %10
%52 = load float, float* %5
%53 = fmul float %51, %52
%54 = call double @fabsf(float %53)
%55 = fcmp olt double %50, %54
br i1 %55, label %56, label %57
56: ; preds = %20
br label %61
57: ; preds = %20
br label %58
58: ; preds = %57
%59 = load i32, i32* %15
%60 = add nsw i32 %59, 1
store i32 %60, i32* %15
br label %16
61: ; preds = %56, %16
%62 = load float, float* %5
%63 = load float, float* %11
%64 = fsub float %62, %63
%65 = call double @fabsf(float %64)
%66 = load float, float* %10
%67 = fmul float 1.000000e+02, %66
%68 = load float, float* %5
%69 = fmul float %67, %68
%70 = call double @fabsf(float %69)
%71 = fcmp oge double %65, %70
br i1 %71, label %72, label %85
72: ; preds = %61
%73 = load i32, i32* %9
%74 = load float, float* %5
%75 = load float, float* %11
%76 = load float, float* %5
%77 = load float, float* %11
%78 = fsub float %76, %77
%79 = call double @fabsf(float %78)
%80 = load float, float* %10
%81 = load float, float* %5
%82 = fmul float %80, %81
%83 = call double @fabsf(float %82)
%84 = call i32 @printf(i8* getelementptr inbounds ([97 x i8], [97 x i8]* @.str, i64 0, i64 0), i32 %73, float %74, float %75, double %79, double %83)
br label %85
85: ; preds = %72, %61
%86 = load float, float* %5
ret float %86
}

LLVM IR (-O2):
@.str = [97 x i8] c"RMSD Warning: No convergence after %d iterations: Lambda,Lambda0,Diff,Allowed = %f, %f, %f, %f \0A\00"
define float @NewtonSolve(float %0, float %1, float %2, float %3) {
br label %5
5: ; preds = %5, %4
%6 = phi i32 [ 0, %4 ], [ %23, %5 ]
%7 = phi float [ %0, %4 ], [ %17, %5 ]
%8 = fmul float %7, %7
%9 = fadd float %8, %3
%10 = fmul float %7, %9
%11 = fadd float %10, %2
%12 = tail call float @llvm.fmuladd.f32(float %11, float %7, float %1)
%13 = fmul float %8, 2.000000e+00
%14 = tail call float @llvm.fmuladd.f32(float %13, float %7, float %10)
%15 = fadd float %14, %11
%16 = fdiv float %12, %15
%17 = fsub float %7, %16
%18 = fsub float %17, %7
%19 = tail call double @fabsf(float %18)
%20 = fmul float %17, 0x3EB0C6F7A0000000
%21 = tail call double @fabsf(float %20)
%22 = fcmp olt double %19, %21
%23 = add nuw nsw i32 %6, 1
%24 = icmp eq i32 %23, 500
%25 = select i1 %22, i1 true, i1 %24
br i1 %25, label %26, label %5
26: ; preds = %5
%27 = tail call double @fabsf(float %18)
%28 = fmul float %17, 0x3F1A36E2E0000000
%29 = tail call double @fabsf(float %28)
%30 = fcmp ult double %27, %29
br i1 %30, label %35, label %31
31: ; preds = %26
%32 = tail call double @fabsf(float %18)
%33 = tail call double @fabsf(float %20)
%34 = tail call i32 @printf(i8* getelementptr inbounds ([97 x i8], [97 x i8]* @.str, i64 0, i64 0), i32 500, float %17, float %7, double %32, double %33)
br label %35
35: ; preds = %31, %26
ret float %17
}