; LLVM IR from MinhasKamal/AlgorithmImplementations :: numericalMethods/equationSolving (NonLinearEquationSolvingProcess)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@.str.5 = external hidden unnamed_addr constant [19 x i8], align 1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

declare i32 @printf(ptr noundef, ...) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

; Function Attrs: nounwind uwtable
define dso_local double @NewtonRaphson() #3 {
  %1 = alloca double, align 8
  %2 = alloca double, align 8
  %3 = alloca double, align 8
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #4
  store double 0.000000e+00, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  store double 1.000000e+00, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store double 0.000000e+00, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %5

5:                                                ; preds = %45, %0
  br label %6

6:                                                ; preds = %5
  %7 = load i32, ptr %4, align 4, !tbaa !9
  %8 = add nsw i32 %7, 1
  store i32 %8, ptr %4, align 4, !tbaa !9
  %9 = load double, ptr %2, align 8, !tbaa !5
  %10 = load double, ptr %2, align 8, !tbaa !5
  %11 = load double, ptr %2, align 8, !tbaa !5
  %12 = fmul double %10, %11
  %13 = load double, ptr %2, align 8, !tbaa !5
  %14 = load double, ptr %2, align 8, !tbaa !5
  %15 = fneg double %14
  %16 = call double @llvm.fmuladd.f64(double %12, double %13, double %15)
  %17 = fsub double %16, 2.000000e+00
  %18 = load double, ptr %2, align 8, !tbaa !5
  %19 = fmul double 3.000000e+00, %18
  %20 = load double, ptr %2, align 8, !tbaa !5
  %21 = call double @llvm.fmuladd.f64(double %19, double %20, double -1.000000e+00)
  %22 = fdiv double %17, %21
  %23 = fsub double %9, %22
  store double %23, ptr %3, align 8, !tbaa !5
  %24 = load double, ptr %3, align 8, !tbaa !5
  %25 = load double, ptr %3, align 8, !tbaa !5
  %26 = fmul double %24, %25
  %27 = load double, ptr %3, align 8, !tbaa !5
  %28 = load double, ptr %3, align 8, !tbaa !5
  %29 = fneg double %28
  %30 = call double @llvm.fmuladd.f64(double %26, double %27, double %29)
  %31 = fsub double %30, 2.000000e+00
  %32 = fcmp olt double %31, 1.000000e-05
  br i1 %32, label %33, label %45

33:                                               ; preds = %6
  %34 = load double, ptr %3, align 8, !tbaa !5
  %35 = load double, ptr %3, align 8, !tbaa !5
  %36 = fmul double %34, %35
  %37 = load double, ptr %3, align 8, !tbaa !5
  %38 = load double, ptr %3, align 8, !tbaa !5
  %39 = fneg double %38
  %40 = call double @llvm.fmuladd.f64(double %36, double %37, double %39)
  %41 = fsub double %40, 2.000000e+00
  %42 = fcmp ogt double %41, -1.000000e-05
  br i1 %42, label %43, label %45

43:                                               ; preds = %33
  %44 = load double, ptr %3, align 8, !tbaa !5
  store double %44, ptr %1, align 8, !tbaa !5
  br label %47

45:                                               ; preds = %33, %6
  %46 = load double, ptr %3, align 8, !tbaa !5
  store double %46, ptr %2, align 8, !tbaa !5
  br label %5

47:                                               ; preds = %43
  %48 = load i32, ptr %4, align 4, !tbaa !9
  %49 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, i32 noundef %48)
  %50 = load double, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #4
  ret double %50
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@.str.5 = external hidden unnamed_addr constant [19 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: nofree nounwind uwtable
define dso_local double @NewtonRaphson() local_unnamed_addr #2 {
  br label %1

1:                                                ; preds = %1, %0
  %.019 = phi double [ 1.000000e+00, %0 ], [ %10, %1 ]
  %.0 = phi i32 [ 0, %0 ], [ %2, %1 ]
  %2 = add nuw nsw i32 %.0, 1
  %3 = fmul double %.019, %.019
  %4 = fneg double %.019
  %5 = tail call double @llvm.fmuladd.f64(double %3, double %.019, double %4)
  %6 = fadd double %5, -2.000000e+00
  %7 = fmul double %.019, 3.000000e+00
  %8 = tail call double @llvm.fmuladd.f64(double %7, double %.019, double -1.000000e+00)
  %9 = fdiv double %6, %8
  %10 = fsub double %.019, %9
  %11 = fmul double %10, %10
  %12 = fneg double %10
  %13 = tail call double @llvm.fmuladd.f64(double %11, double %10, double %12)
  %14 = fadd double %13, -2.000000e+00
  %15 = tail call double @llvm.fabs.f64(double %14)
  %or.cond = fcmp olt double %15, 1.000000e-05
  br i1 %or.cond, label %16, label %1

16:                                               ; preds = %1
  %17 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, i32 noundef %2)
  ret double %10
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #3

attributes #0 = { nofree nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nofree nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass