; 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 @Secant() #3 {
  %1 = alloca double, align 8
  %2 = alloca double, align 8
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  %5 = 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 2.000000e+00, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store double 0.000000e+00, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %6

6:                                                ; preds = %31, %0
  br label %7

7:                                                ; preds = %6
  %8 = load i32, ptr %5, align 4, !tbaa !9
  %9 = add nsw i32 %8, 1
  store i32 %9, ptr %5, align 4, !tbaa !9
  %10 = load double, ptr %3, align 8, !tbaa !5
  %11 = load double, ptr %3, align 8, !tbaa !5
  %12 = fmul double %10, %11
  %13 = load double, ptr %3, align 8, !tbaa !5
  %14 = load double, ptr %3, 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 = fcmp olt double %17, 1.000000e-05
  br i1 %18, label %19, label %31

19:                                               ; preds = %7
  %20 = load double, ptr %3, align 8, !tbaa !5
  %21 = load double, ptr %3, align 8, !tbaa !5
  %22 = fmul double %20, %21
  %23 = load double, ptr %3, align 8, !tbaa !5
  %24 = load double, ptr %3, align 8, !tbaa !5
  %25 = fneg double %24
  %26 = call double @llvm.fmuladd.f64(double %22, double %23, double %25)
  %27 = fsub double %26, 2.000000e+00
  %28 = fcmp ogt double %27, -1.000000e-05
  br i1 %28, label %29, label %31

29:                                               ; preds = %19
  %30 = load double, ptr %3, align 8, !tbaa !5
  store double %30, ptr %1, align 8, !tbaa !5
  br label %73

31:                                               ; preds = %19, %7
  %32 = load double, ptr %2, align 8, !tbaa !5
  %33 = load double, ptr %3, align 8, !tbaa !5
  %34 = load double, ptr %3, align 8, !tbaa !5
  %35 = fmul double %33, %34
  %36 = load double, ptr %3, align 8, !tbaa !5
  %37 = load double, ptr %3, align 8, !tbaa !5
  %38 = fneg double %37
  %39 = call double @llvm.fmuladd.f64(double %35, double %36, double %38)
  %40 = fsub double %39, 2.000000e+00
  %41 = load double, ptr %3, align 8, !tbaa !5
  %42 = load double, ptr %2, align 8, !tbaa !5
  %43 = load double, ptr %2, align 8, !tbaa !5
  %44 = fmul double %42, %43
  %45 = load double, ptr %2, align 8, !tbaa !5
  %46 = load double, ptr %2, align 8, !tbaa !5
  %47 = fneg double %46
  %48 = call double @llvm.fmuladd.f64(double %44, double %45, double %47)
  %49 = fsub double %48, 2.000000e+00
  %50 = fmul double %41, %49
  %51 = fneg double %50
  %52 = call double @llvm.fmuladd.f64(double %32, double %40, double %51)
  %53 = load double, ptr %3, align 8, !tbaa !5
  %54 = load double, ptr %3, align 8, !tbaa !5
  %55 = fmul double %53, %54
  %56 = load double, ptr %3, align 8, !tbaa !5
  %57 = load double, ptr %3, align 8, !tbaa !5
  %58 = fneg double %57
  %59 = call double @llvm.fmuladd.f64(double %55, double %56, double %58)
  %60 = fsub double %59, 2.000000e+00
  %61 = load double, ptr %2, align 8, !tbaa !5
  %62 = load double, ptr %2, align 8, !tbaa !5
  %63 = fmul double %61, %62
  %64 = load double, ptr %2, align 8, !tbaa !5
  %65 = load double, ptr %2, align 8, !tbaa !5
  %66 = fneg double %65
  %67 = call double @llvm.fmuladd.f64(double %63, double %64, double %66)
  %68 = fsub double %67, 2.000000e+00
  %69 = fsub double %60, %68
  %70 = fdiv double %52, %69
  store double %70, ptr %4, align 8, !tbaa !5
  %71 = load double, ptr %3, align 8, !tbaa !5
  store double %71, ptr %2, align 8, !tbaa !5
  %72 = load double, ptr %4, align 8, !tbaa !5
  store double %72, ptr %3, align 8, !tbaa !5
  br label %6

73:                                               ; preds = %29
  %74 = load i32, ptr %5, align 4, !tbaa !9
  %75 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, i32 noundef %74)
  %76 = load double, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, 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 %76
}

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 @Secant() local_unnamed_addr #2 {
  br label %3

1:                                                ; preds = %3
  %2 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, i32 noundef %15)
  ret double %14

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

; 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,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass