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

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

@logfile3 = 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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local double @secant(ptr noundef %0, ptr noundef %1, ptr noundef %2, double noundef %3, double noundef %4, double noundef %5) #3 {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  %13 = alloca double, align 8
  %14 = alloca double, align 8
  %15 = alloca double, align 8
  %16 = alloca double, align 8
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store double %3, ptr %10, align 8, !tbaa !9
  store double %4, ptr %11, align 8, !tbaa !9
  store double %5, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  %19 = load double, ptr %10, align 8, !tbaa !9
  store double %19, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  %20 = load double, ptr %14, align 8, !tbaa !9
  %21 = load double, ptr %11, align 8, !tbaa !9
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = load double, ptr %15, align 8, !tbaa !9
  %24 = call double %22(double noundef %23)
  %25 = fneg double %21
  %26 = call double @llvm.fmuladd.f64(double %25, double %24, double %20)
  store double %26, ptr %15, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #5
  store double 0x3E7AD7F29ABCAF48, ptr %16, align 8, !tbaa !9
  %27 = load ptr, ptr @logfile3, align 8, !tbaa !5
  %28 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %27, ptr noundef @.str.13) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #5
  store i32 0, ptr %17, align 4, !tbaa !11
  br label %29

29:                                               ; preds = %66, %6
  %30 = load i32, ptr %17, align 4, !tbaa !11
  %31 = sitofp i32 %30 to double
  %32 = load double, ptr %12, align 8, !tbaa !9
  %33 = fcmp olt double %31, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %29
  store i32 2, ptr %18, align 4
  br label %69

35:                                               ; preds = %29
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = load double, ptr %15, align 8, !tbaa !9
  %38 = call double %36(double noundef %37)
  %39 = call double @llvm.fabs.f64(double %38)
  %40 = load double, ptr %16, align 8, !tbaa !9
  %41 = fcmp olt double %39, %40
  br i1 %41, label %42, label %43

42:                                               ; preds = %35
  store i32 2, ptr %18, align 4
  br label %69

43:                                               ; preds = %35
  %44 = load double, ptr %15, align 8, !tbaa !9
  store double %44, ptr %13, align 8, !tbaa !9
  %45 = load double, ptr %14, align 8, !tbaa !9
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = load double, ptr %14, align 8, !tbaa !9
  %48 = call double %46(double noundef %47)
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  %50 = load double, ptr %15, align 8, !tbaa !9
  %51 = call double %49(double noundef %50)
  %52 = fdiv double %48, %51
  %53 = fsub double %45, %52
  store double %53, ptr %15, align 8, !tbaa !9
  %54 = load double, ptr %13, align 8, !tbaa !9
  store double %54, ptr %14, align 8, !tbaa !9
  %55 = load double, ptr %15, align 8, !tbaa !9
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = load double, ptr %15, align 8, !tbaa !9
  %58 = call double %56(double noundef %57)
  %59 = call i32 (ptr, ...) @printf(ptr noundef @.str.14, double noundef %55, double noundef %58)
  %60 = load ptr, ptr @logfile3, align 8, !tbaa !5
  %61 = load double, ptr %15, align 8, !tbaa !9
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  %63 = load double, ptr %15, align 8, !tbaa !9
  %64 = call double %62(double noundef %63)
  %65 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %60, ptr noundef @.str.12, double noundef %61, double noundef %64) #5
  br label %66

66:                                               ; preds = %43
  %67 = load i32, ptr %17, align 4, !tbaa !11
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %17, align 4, !tbaa !11
  br label %29, !llvm.loop !13

69:                                               ; preds = %42, %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #5
  br label %70

70:                                               ; preds = %69
  %71 = load double, ptr %15, align 8, !tbaa !9
  store i32 1, ptr %18, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  ret double %71
}

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

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

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

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 willreturn memory(argmem: readwrite) }
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 "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"

@logfile3 = 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: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

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

; Function Attrs: nounwind uwtable
define dso_local double @secant(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2, double noundef %3, double noundef %4, double noundef %5) local_unnamed_addr #2 {
  %7 = tail call double %1(double noundef undef) #3
  %8 = fneg double %4
  %9 = tail call double @llvm.fmuladd.f64(double %8, double %7, double %3)
  %10 = load ptr, ptr @logfile3, align 8, !tbaa !5
  %11 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %10, ptr noundef nonnull @.str.13) #3
  %12 = fcmp ogt double %5, 0.000000e+00
  br i1 %12, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %6, %16
  %.028 = phi i32 [ %26, %16 ], [ 0, %6 ]
  %.02427 = phi double [ %.02526, %16 ], [ %3, %6 ]
  %.02526 = phi double [ %20, %16 ], [ %9, %6 ]
  %13 = tail call double %1(double noundef %.02526) #3
  %14 = tail call double @llvm.fabs.f64(double %13)
  %15 = fcmp olt double %14, 0x3E7AD7F29ABCAF48
  br i1 %15, label %._crit_edge, label %16

16:                                               ; preds = %.lr.ph
  %17 = tail call double %1(double noundef %.02427) #3
  %18 = tail call double %2(double noundef %.02526) #3
  %19 = fdiv double %17, %18
  %20 = fsub double %.02427, %19
  %21 = tail call double %0(double noundef %20) #3
  %22 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.14, double noundef %20, double noundef %21)
  %23 = load ptr, ptr @logfile3, align 8, !tbaa !5
  %24 = tail call double %0(double noundef %20) #3
  %25 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %23, ptr noundef nonnull @.str.12, double noundef %20, double noundef %24) #3
  %26 = add nuw nsw i32 %.028, 1
  %27 = uitofp nneg i32 %26 to double
  %28 = fcmp olt double %27, %5
  br i1 %28, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %16, %.lr.ph, %6
  %.025.lcssa = phi double [ %9, %6 ], [ %.02526, %.lr.ph ], [ %20, %16 ]
  ret double %.025.lcssa
}

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

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { 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 #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: GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass