; LLVM IR from atlantis13579/Riemann :: Src/Solver/NewtonRaphsonIteration.ll (ZN13NewtonRaphson8FindRootERKSt8functionIFffEEfi)

; 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"

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_Z10DerivativeRKSt8functionIFffEEf(ptr noundef nonnull align 8 dereferenceable(32), float noundef) #0

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_ZNKSt8functionIFffEEclEf(ptr noundef nonnull align 8 dereferenceable(32), float noundef) #0 align 2

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fabs.f32(float) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZN13NewtonRaphson8FindRootERKSt8functionIFffEEfi(ptr noundef nonnull align 8 dereferenceable(32) %0, float noundef %1, i32 noundef %2) #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca float, align 4
  %6 = alloca i32, align 4
  %7 = alloca float, align 4
  %8 = alloca i32, align 4
  %9 = alloca float, align 4
  %10 = alloca float, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store float %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %11 = load float, ptr %5, align 4, !tbaa !9
  store float %11, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !11
  br label %12

12:                                               ; preds = %25, %3
  %13 = load i32, ptr %8, align 4, !tbaa !11
  %14 = add nsw i32 %13, 1
  store i32 %14, ptr %8, align 4, !tbaa !11
  %15 = load i32, ptr %6, align 4, !tbaa !11
  %16 = icmp slt i32 %13, %15
  br i1 %16, label %17, label %23

17:                                               ; preds = %12
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = load float, ptr %7, align 4, !tbaa !9
  %20 = call noundef float @_ZNKSt8functionIFffEEclEf(ptr noundef nonnull align 8 dereferenceable(32) %18, float noundef %19)
  %21 = call float @llvm.fabs.f32(float %20)
  %22 = fcmp ogt float %21, 0x3F50624DE0000000
  br label %23

23:                                               ; preds = %17, %12
  %24 = phi i1 [ false, %12 ], [ %22, %17 ]
  br i1 %24, label %25, label %37

25:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = load float, ptr %7, align 4, !tbaa !9
  %28 = call noundef float @_ZNKSt8functionIFffEEclEf(ptr noundef nonnull align 8 dereferenceable(32) %26, float noundef %27)
  store float %28, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = load float, ptr %7, align 4, !tbaa !9
  %31 = call noundef float @_Z10DerivativeRKSt8functionIFffEEf(ptr noundef nonnull align 8 dereferenceable(32) %29, float noundef %30)
  store float %31, ptr %10, align 4, !tbaa !9
  %32 = load float, ptr %7, align 4, !tbaa !9
  %33 = load float, ptr %9, align 4, !tbaa !9
  %34 = load float, ptr %10, align 4, !tbaa !9
  %35 = fdiv float %33, %34
  %36 = fsub float %32, %35
  store float %36, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %12, !llvm.loop !13

37:                                               ; preds = %23
  %38 = load float, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret float %38
}

attributes #0 = { mustprogress 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; 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"

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_Z10DerivativeRKSt8functionIFffEEf(ptr noundef nonnull align 8 dereferenceable(32), float noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_ZNKSt8functionIFffEEclEf(ptr noundef nonnull align 8 dereferenceable(32), float noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fabs.f32(float) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_ZN13NewtonRaphson8FindRootERKSt8functionIFffEEfi(ptr noundef nonnull align 8 dereferenceable(32) %0, float noundef %1, i32 noundef %2) local_unnamed_addr #0 align 2 {
  %4 = icmp sgt i32 %2, 0
  br i1 %4, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %3, %9
  %5 = phi i32 [ %14, %9 ], [ 1, %3 ]
  %.013 = phi float [ %13, %9 ], [ %1, %3 ]
  %6 = tail call noundef float @_ZNKSt8functionIFffEEclEf(ptr noundef nonnull align 8 dereferenceable(32) %0, float noundef %.013)
  %7 = tail call float @llvm.fabs.f32(float %6)
  %8 = fcmp ogt float %7, 0x3F50624DE0000000
  br i1 %8, label %9, label %.critedge

9:                                                ; preds = %.lr.ph
  %10 = tail call noundef float @_ZNKSt8functionIFffEEclEf(ptr noundef nonnull align 8 dereferenceable(32) %0, float noundef %.013)
  %11 = tail call noundef float @_Z10DerivativeRKSt8functionIFffEEf(ptr noundef nonnull align 8 dereferenceable(32) %0, float noundef %.013)
  %12 = fdiv float %10, %11
  %13 = fsub float %.013, %12
  %14 = add nuw i32 %5, 1
  %exitcond.not = icmp eq i32 %5, %2
  br i1 %exitcond.not, label %.critedge, label %.lr.ph, !llvm.loop !5

.critedge:                                        ; preds = %.lr.ph, %9, %3
  %.0.lcssa = phi float [ %1, %3 ], [ %13, %9 ], [ %.013, %.lr.ph ]
  ret float %.0.lcssa
}

attributes #0 = { mustprogress 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 #1 = { mustprogress 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)"}
!5 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass