; LLVM IR from radualexandrub/Optimization-Algorithms-Find-local-minimum :: 1D_Derivative_Algorithms (newton)

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

@logfile2 = external dso_local global ptr, align 8
@.str.12 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [16 x i8], align 1

declare i32 @printf(ptr 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: 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 double @llvm.fabs.f64(double) #2

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #3

; Function Attrs: nounwind uwtable
define dso_local double @newton(ptr noundef %0, ptr noundef %1, ptr noundef %2, double noundef %3, i32 noundef %4) #4 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca double, align 8
  %10 = alloca i32, align 4
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store double %3, ptr %9, align 8, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %16 = load double, ptr %9, align 8, !tbaa !9
  store double %16, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  store double 0x3E7AD7F29ABCAF48, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  %18 = load double, ptr %11, align 8, !tbaa !9
  %19 = call double %17(double noundef %18)
  %20 = call double @llvm.fabs.f64(double %19)
  %21 = fdiv double 1.000000e+00, %20
  store double %21, ptr %13, align 8, !tbaa !9
  %22 = load ptr, ptr @logfile2, align 8, !tbaa !5
  %23 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %22, ptr noundef @.str.13) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  store i32 0, ptr %14, align 4, !tbaa !11
  br label %24

24:                                               ; preds = %56, %5
  %25 = load i32, ptr %14, align 4, !tbaa !11
  %26 = load i32, ptr %10, align 4, !tbaa !11
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %24
  store i32 2, ptr %15, align 4
  br label %59

29:                                               ; preds = %24
  %30 = load double, ptr %11, align 8, !tbaa !9
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = load double, ptr %11, align 8, !tbaa !9
  %33 = call double %31(double noundef %32)
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = load double, ptr %11, align 8, !tbaa !9
  %36 = call double %34(double noundef %35)
  %37 = call double @llvm.fabs.f64(double %36)
  %38 = fdiv double %33, %37
  %39 = fsub double %30, %38
  store double %39, ptr %11, align 8, !tbaa !9
  %40 = load double, ptr %13, align 8, !tbaa !9
  %41 = load double, ptr %12, align 8, !tbaa !9
  %42 = fcmp olt double %40, %41
  br i1 %42, label %43, label %44

43:                                               ; preds = %29
  store i32 2, ptr %15, align 4
  br label %59

44:                                               ; preds = %29
  %45 = load double, ptr %11, align 8, !tbaa !9
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = load double, ptr %11, align 8, !tbaa !9
  %48 = call double %46(double noundef %47)
  %49 = call i32 (ptr, ...) @printf(ptr noundef @.str.14, double noundef %45, double noundef %48)
  %50 = load ptr, ptr @logfile2, align 8, !tbaa !5
  %51 = load double, ptr %11, align 8, !tbaa !9
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = load double, ptr %11, align 8, !tbaa !9
  %54 = call double %52(double noundef %53)
  %55 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %50, ptr noundef @.str.12, double noundef %51, double noundef %54) #5
  br label %56

56:                                               ; preds = %44
  %57 = load i32, ptr %14, align 4, !tbaa !11
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %14, align 4, !tbaa !11
  br label %24, !llvm.loop !13

59:                                               ; preds = %43, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  br label %60

60:                                               ; preds = %59
  %61 = load double, ptr %11, align 8, !tbaa !9
  store i32 1, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  ret double %61
}

attributes #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 "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 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 #5 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !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"

@logfile2 = external dso_local local_unnamed_addr global ptr, align 8
@.str.12 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [16 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.fabs.f64(double) #1

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

; Function Attrs: nounwind uwtable
define dso_local double @newton(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2, double noundef %3, i32 noundef %4) local_unnamed_addr #2 {
  %6 = tail call double %2(double noundef %3) #3
  %7 = load ptr, ptr @logfile2, align 8, !tbaa !5
  %8 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %7, ptr noundef nonnull @.str.13) #3
  %9 = icmp sgt i32 %4, 0
  br i1 %9, label %.lr.ph, label %._crit_edge22

.lr.ph:                                           ; preds = %5
  %.fr25 = freeze double %6
  %10 = tail call double @llvm.fabs.f64(double %.fr25)
  %11 = fdiv double 1.000000e+00, %10
  %12 = fcmp olt double %11, 0x3E7AD7F29ABCAF48
  br i1 %12, label %.lr.ph.split.us, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph
  %13 = tail call double %1(double noundef %3) #3
  %14 = tail call double %2(double noundef %3) #3
  %15 = tail call double @llvm.fabs.f64(double %14)
  %16 = fdiv double %13, %15
  %17 = fsub double %3, %16
  br label %._crit_edge22

.lr.ph.split:                                     ; preds = %.lr.ph, %.lr.ph.split
  %.021 = phi i32 [ %28, %.lr.ph.split ], [ 0, %.lr.ph ]
  %.01920 = phi double [ %22, %.lr.ph.split ], [ %3, %.lr.ph ]
  %18 = tail call double %1(double noundef %.01920) #3
  %19 = tail call double %2(double noundef %.01920) #3
  %20 = tail call double @llvm.fabs.f64(double %19)
  %21 = fdiv double %18, %20
  %22 = fsub double %.01920, %21
  %23 = tail call double %0(double noundef %22) #3
  %24 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.14, double noundef %22, double noundef %23)
  %25 = load ptr, ptr @logfile2, align 8, !tbaa !5
  %26 = tail call double %0(double noundef %22) #3
  %27 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %25, ptr noundef nonnull @.str.12, double noundef %22, double noundef %26) #3
  %28 = add nuw nsw i32 %.021, 1
  %exitcond.not = icmp eq i32 %28, %4
  br i1 %exitcond.not, label %._crit_edge22, label %.lr.ph.split, !llvm.loop !9

._crit_edge22:                                    ; preds = %.lr.ph.split, %.lr.ph.split.us, %5
  %.1 = phi double [ %17, %.lr.ph.split.us ], [ %3, %5 ], [ %22, %.lr.ph.split ]
  ret double %.1
}

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 = { 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 = { 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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass