; LLVM IR from bjack205/altro :: src/linesearch (linesearch)

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

%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
%"class.linesearch::CubicLineSearch" = type <{ i32, [4 x i8], double, double, double, double, i8, i8, [2 x i8], i32, double, double, i32, [4 x i8], double, double, double, double, double, double, double, double, i8, i8, i8, [5 x i8] }>

@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str.8 = external hidden unnamed_addr constant [23 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

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

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNKSt8functionIFvdPdS0_EEclEdS0_S0_(ptr noundef nonnull align 8 dereferenceable(32), double noundef, ptr noundef, ptr noundef) #2 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZN10linesearch15CubicLineSearch18SimpleBacktrackingESt8functionIFvdPdS2_EEd(ptr noundef nonnull align 8 dereferenceable(139) %0, ptr noundef %1, double noundef %2) #2 align 2 {
  %4 = alloca double, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca ptr, align 8
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i8, align 1
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store double %2, ptr %7, align 8, !tbaa !9
  %16 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %17 = load double, ptr %7, align 8, !tbaa !9
  store double %17, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %18 = getelementptr inbounds %"class.linesearch::CubicLineSearch", ptr %16, i32 0, i32 10
  %19 = load double, ptr %18, align 8, !tbaa !11
  store double %19, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %20 = getelementptr inbounds %"class.linesearch::CubicLineSearch", ptr %16, i32 0, i32 15
  store ptr %20, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %21 = getelementptr inbounds %"class.linesearch::CubicLineSearch", ptr %16, i32 0, i32 14
  %22 = load double, ptr %21, align 8, !tbaa !16
  store double %22, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %23 = getelementptr inbounds %"class.linesearch::CubicLineSearch", ptr %16, i32 0, i32 18
  %24 = load double, ptr %23, align 8, !tbaa !17
  store double %24, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  store i32 1, ptr %13, align 4, !tbaa !18
  br label %25

25:                                               ; preds = %69, %3
  %26 = load i32, ptr %13, align 4, !tbaa !18
  %27 = getelementptr inbounds %"class.linesearch::CubicLineSearch", ptr %16, i32 0, i32 0
  %28 = load i32, ptr %27, align 8, !tbaa !19
  %29 = icmp slt i32 %26, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %25
  store i32 2, ptr %14, align 4
  br label %72

31:                                               ; preds = %25
  %32 = getelementptr inbounds %"class.linesearch::CubicLineSearch", ptr %16, i32 0, i32 12
  %33 = load i32, ptr %32, align 8, !tbaa !20
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %32, align 8, !tbaa !20
  %35 = load double, ptr %8, align 8, !tbaa !9
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  call void @_ZNKSt8functionIFvdPdS0_EEclEdS0_S0_(ptr noundef nonnull align 8 dereferenceable(32) %1, double noundef %35, ptr noundef %36, ptr noundef null)
  call void @llvm.lifetime.start.p0(i64 1, ptr %15) #4
  %37 = load ptr, ptr %10, align 8, !tbaa !5
  %38 = load double, ptr %37, align 8, !tbaa !9
  %39 = load double, ptr %11, align 8, !tbaa !9
  %40 = load double, ptr %9, align 8, !tbaa !9
  %41 = load double, ptr %8, align 8, !tbaa !9
  %42 = fmul double %40, %41
  %43 = load double, ptr %12, align 8, !tbaa !9
  %44 = call double @llvm.fmuladd.f64(double %42, double %43, double %39)
  %45 = fcmp ole double %38, %44
  %46 = zext i1 %45 to i8
  store i8 %46, ptr %15, align 1, !tbaa !21
  %47 = load i8, ptr %15, align 1, !tbaa !21, !range !22, !noundef !23
  %48 = trunc i8 %47 to i1
  br i1 %48, label %49, label %60

49:                                               ; preds = %31
  %50 = getelementptr inbounds %"class.linesearch::CubicLineSearch", ptr %16, i32 0, i32 24
  %51 = load i8, ptr %50, align 2, !tbaa !24, !range !22, !noundef !23
  %52 = trunc i8 %51 to i1
  br i1 %52, label %53, label %55

53:                                               ; preds = %49
  %54 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef @.str.8)
  br label %55

55:                                               ; preds = %53, %49
  %56 = getelementptr inbounds %"class.linesearch::CubicLineSearch", ptr %16, i32 0, i32 22
  store i8 1, ptr %56, align 8, !tbaa !25
  %57 = getelementptr inbounds %"class.linesearch::CubicLineSearch", ptr %16, i32 0, i32 23
  store i8 1, ptr %57, align 1, !tbaa !26
  %58 = getelementptr inbounds %"class.linesearch::CubicLineSearch", ptr %16, i32 0, i32 9
  store i32 1, ptr %58, align 4, !tbaa !27
  %59 = load double, ptr %8, align 8, !tbaa !9
  store double %59, ptr %4, align 8
  store i32 1, ptr %14, align 4
  br label %66

60:                                               ; preds = %31
  %61 = getelementptr inbounds %"class.linesearch::CubicLineSearch", ptr %16, i32 0, i32 4
  %62 = load double, ptr %61, align 8, !tbaa !28
  %63 = load double, ptr %8, align 8, !tbaa !9
  %64 = fmul double %63, %62
  store double %64, ptr %8, align 8, !tbaa !9
  br label %65

65:                                               ; preds = %60
  store i32 0, ptr %14, align 4
  br label %66

66:                                               ; preds = %65, %55
  call void @llvm.lifetime.end.p0(i64 1, ptr %15) #4
  %67 = load i32, ptr %14, align 4
  switch i32 %67, label %72 [
    i32 0, label %68
  ]

68:                                               ; preds = %66
  br label %69

69:                                               ; preds = %68
  %70 = load i32, ptr %13, align 4, !tbaa !18
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %13, align 4, !tbaa !18
  br label %25, !llvm.loop !29

72:                                               ; preds = %66, %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  %73 = load i32, ptr %14, align 4
  switch i32 %73, label %76 [
    i32 2, label %74
  ]

74:                                               ; preds = %72
  %75 = load double, ptr %8, align 8, !tbaa !9
  store double %75, ptr %4, align 8
  store i32 1, ptr %14, align 4
  br label %76

76:                                               ; preds = %74, %72
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %77 = load double, ptr %4, align 8
  ret double %77
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 #2 = { 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 #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !10, i64 48}
!12 = !{!"_ZTSN10linesearch15CubicLineSearchE", !13, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !14, i64 40, !14, i64 41, !15, i64 44, !10, i64 48, !10, i64 56, !13, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96, !10, i64 104, !10, i64 112, !10, i64 120, !10, i64 128, !14, i64 136, !14, i64 137, !14, i64 138}
!13 = !{!"int", !7, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{!"_ZTSN10linesearch15CubicLineSearch11ReturnCodesE", !7, i64 0}
!16 = !{!12, !10, i64 72}
!17 = !{!12, !10, i64 104}
!18 = !{!13, !13, i64 0}
!19 = !{!12, !13, i64 0}
!20 = !{!12, !13, i64 64}
!21 = !{!14, !14, i64 0}
!22 = !{i8 0, i8 2}
!23 = !{}
!24 = !{!12, !14, i64 138}
!25 = !{!12, !14, i64 136}
!26 = !{!12, !14, i64 137}
!27 = !{!12, !15, i64 44}
!28 = !{!12, !10, i64 24}
!29 = distinct !{!29, !30}
!30 = !{!"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"

%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }

@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str.8 = external hidden unnamed_addr constant [23 x i8], align 1

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNKSt8functionIFvdPdS0_EEclEdS0_S0_(ptr noundef nonnull align 8 dereferenceable(32), double noundef, ptr noundef, ptr noundef) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZN10linesearch15CubicLineSearch18SimpleBacktrackingESt8functionIFvdPdS2_EEd(ptr noundef nonnull align 8 dereferenceable(139) %0, ptr noundef %1, double noundef %2) local_unnamed_addr #1 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 48
  %5 = load double, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 80
  %7 = getelementptr inbounds i8, ptr %0, i64 72
  %8 = load double, ptr %7, align 8, !tbaa !13
  %9 = getelementptr inbounds i8, ptr %0, i64 104
  %10 = load double, ptr %9, align 8, !tbaa !14
  %11 = load i32, ptr %0, align 8, !tbaa !15
  %.not30 = icmp sgt i32 %11, 1
  br i1 %.not30, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %3
  %12 = getelementptr inbounds i8, ptr %0, i64 64
  %13 = getelementptr inbounds i8, ptr %0, i64 24
  br label %14

14:                                               ; preds = %.lr.ph, %31
  %.02032 = phi i32 [ 1, %.lr.ph ], [ %34, %31 ]
  %.02131 = phi double [ %2, %.lr.ph ], [ %33, %31 ]
  %15 = load i32, ptr %12, align 8, !tbaa !16
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr %12, align 8, !tbaa !16
  tail call void @_ZNKSt8functionIFvdPdS0_EEclEdS0_S0_(ptr noundef nonnull align 8 dereferenceable(32) %1, double noundef %.02131, ptr noundef nonnull %6, ptr noundef null)
  %17 = load double, ptr %6, align 8, !tbaa !17
  %18 = fmul double %5, %.02131
  %19 = tail call double @llvm.fmuladd.f64(double %18, double %10, double %8)
  %20 = fcmp ugt double %17, %19
  br i1 %20, label %31, label %21

21:                                               ; preds = %14
  %22 = getelementptr inbounds i8, ptr %0, i64 138
  %23 = load i8, ptr %22, align 2, !tbaa !18, !range !19, !noundef !20
  %24 = trunc nuw i8 %23 to i1
  br i1 %24, label %25, label %27

25:                                               ; preds = %21
  %26 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef nonnull @.str.8)
  br label %27

27:                                               ; preds = %21, %25
  %28 = getelementptr inbounds i8, ptr %0, i64 136
  store i8 1, ptr %28, align 8, !tbaa !21
  %29 = getelementptr inbounds i8, ptr %0, i64 137
  store i8 1, ptr %29, align 1, !tbaa !22
  %30 = getelementptr inbounds i8, ptr %0, i64 44
  store i32 1, ptr %30, align 4, !tbaa !23
  br label %.loopexit

31:                                               ; preds = %14
  %32 = load double, ptr %13, align 8, !tbaa !24
  %33 = fmul double %.02131, %32
  %34 = add nuw nsw i32 %.02032, 1
  %35 = load i32, ptr %0, align 8, !tbaa !15
  %.not = icmp slt i32 %34, %35
  br i1 %.not, label %14, label %.loopexit, !llvm.loop !25

.loopexit:                                        ; preds = %31, %3, %27
  %.02129 = phi double [ %.02131, %27 ], [ %2, %3 ], [ %33, %31 ]
  ret double %.02129
}

attributes #0 = { inlinehint 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 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 #2 = { 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 = !{!6, !10, i64 48}
!6 = !{!"_ZTSN10linesearch15CubicLineSearchE", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !11, i64 40, !11, i64 41, !12, i64 44, !10, i64 48, !10, i64 56, !7, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96, !10, i64 104, !10, i64 112, !10, i64 120, !10, i64 128, !11, i64 136, !11, i64 137, !11, i64 138}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"double", !8, i64 0}
!11 = !{!"bool", !8, i64 0}
!12 = !{!"_ZTSN10linesearch15CubicLineSearch11ReturnCodesE", !8, i64 0}
!13 = !{!6, !10, i64 72}
!14 = !{!6, !10, i64 104}
!15 = !{!6, !7, i64 0}
!16 = !{!6, !7, i64 64}
!17 = !{!10, !10, i64 0}
!18 = !{!6, !11, i64 138}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!6, !11, i64 136}
!22 = !{!6, !11, i64 137}
!23 = !{!6, !12, i64 44}
!24 = !{!6, !10, i64 24}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass