; LLVM IR from forestLoop/Learning-ITMO-Academy-Pilot-Course :: binary-search/4-B.ll (Z14findMinAvgPathRKSt6vectorIS_ISt4pairIiiESaIS1_EESaIS3_EEi)

; 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::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%class.anon = type <{ ptr, i32, [4 x i8] }>
%"struct.std::pair" = type { i8, %"class.std::vector" }

; Function Attrs: mustprogress uwtable
define dso_local void @_Z14findMinAvgPathRKSt6vectorIS_ISt4pairIiiESaIS1_EESaIS3_EEi(ptr dead_on_unwind noalias writable sret(%"class.std::vector") align 8 %0, ptr noundef nonnull align 8 dereferenceable(24) %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca %class.anon, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca double, align 8
  %13 = alloca %"struct.std::pair", align 8
  %14 = alloca %"struct.std::pair", align 8
  store ptr %0, ptr %4, align 8
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #5
  %15 = getelementptr inbounds %class.anon, ptr %7, i32 0, i32 0
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %16, ptr %15, align 8, !tbaa !5
  %17 = getelementptr inbounds %class.anon, ptr %7, i32 0, i32 1
  %18 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %18, ptr %17, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  store double -1.000000e-01, ptr %8, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  store double 1.001000e+02, ptr %9, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  store i32 30, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %39, %3
  %20 = load i32, ptr %11, align 4, !tbaa !9
  %21 = icmp slt i32 %20, 30
  br i1 %21, label %23, label %22

22:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  br label %42

23:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %24 = load double, ptr %8, align 8, !tbaa !13
  %25 = load double, ptr %9, align 8, !tbaa !13
  %26 = load double, ptr %8, align 8, !tbaa !13
  %27 = fsub double %25, %26
  %28 = fdiv double %27, 2.000000e+00
  %29 = fadd double %24, %28
  store double %29, ptr %12, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 32, ptr %13) #5
  %30 = load double, ptr %12, align 8, !tbaa !13
  call void @"_ZZ14findMinAvgPathRKSt6vectorIS_ISt4pairIiiESaIS1_EESaIS3_EEiENK3$_0clEdb"(ptr dead_on_unwind writable sret(%"struct.std::pair") align 8 %13, ptr noundef nonnull align 8 dereferenceable(12) %7, double noundef %30, i1 noundef zeroext false)
  %31 = getelementptr inbounds %"struct.std::pair", ptr %13, i32 0, i32 0
  %32 = load i8, ptr %31, align 8, !tbaa !15, !range !22, !noundef !23
  %33 = trunc i8 %32 to i1
  call void @_ZNSt4pairIbSt6vectorIiSaIiEEED2Ev(ptr noundef nonnull align 8 dereferenceable(32) %13) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr %13) #5
  br i1 %33, label %34, label %36

34:                                               ; preds = %23
  %35 = load double, ptr %12, align 8, !tbaa !13
  store double %35, ptr %9, align 8, !tbaa !13
  br label %38

36:                                               ; preds = %23
  %37 = load double, ptr %12, align 8, !tbaa !13
  store double %37, ptr %8, align 8, !tbaa !13
  br label %38

38:                                               ; preds = %36, %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  br label %39

39:                                               ; preds = %38
  %40 = load i32, ptr %11, align 4, !tbaa !9
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %11, align 4, !tbaa !9
  br label %19, !llvm.loop !24

42:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 32, ptr %14) #5
  %43 = load double, ptr %9, align 8, !tbaa !13
  call void @"_ZZ14findMinAvgPathRKSt6vectorIS_ISt4pairIiiESaIS1_EESaIS3_EEiENK3$_0clEdb"(ptr dead_on_unwind writable sret(%"struct.std::pair") align 8 %14, ptr noundef nonnull align 8 dereferenceable(12) %7, double noundef %43, i1 noundef zeroext true)
  %44 = getelementptr inbounds %"struct.std::pair", ptr %14, i32 0, i32 1
  call void @_ZNSt6vectorIiSaIiEEC2EOS1_(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(24) %44) #5
  call void @_ZNSt4pairIbSt6vectorIiSaIiEEED2Ev(ptr noundef nonnull align 8 dereferenceable(32) %14) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #5
  ret void
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare hidden void @"_ZZ14findMinAvgPathRKSt6vectorIS_ISt4pairIiiESaIS1_EESaIS3_EEiENK3$_0clEdb"(ptr dead_on_unwind noalias writable sret(%"struct.std::pair") align 8, ptr noundef nonnull align 8 dereferenceable(12), double noundef, i1 noundef zeroext) #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZNSt4pairIbSt6vectorIiSaIiEEED2Ev(ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #3 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: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6vectorIiSaIiEEC2EOS1_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #4 align 2

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 = { 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 #3 = { inlinehint mustprogress 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 = { mustprogress 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"_ZTSZ14findMinAvgPathRKSt6vectorIS_ISt4pairIiiESaIS1_EESaIS3_EEiE3$_0", !6, i64 0, !10, i64 8}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = !{!16, !17, i64 0}
!16 = !{!"_ZTSSt4pairIbSt6vectorIiSaIiEEE", !17, i64 0, !18, i64 8}
!17 = !{!"bool", !7, i64 0}
!18 = !{!"_ZTSSt6vectorIiSaIiEE", !19, i64 0}
!19 = !{!"_ZTSSt12_Vector_baseIiSaIiEE", !20, i64 0}
!20 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE12_Vector_implE", !21, i64 0}
!21 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!22 = !{i8 0, i8 2}
!23 = !{}
!24 = distinct !{!24, !25}
!25 = !{!"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::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%class.anon = type <{ ptr, i32, [4 x i8] }>
%"struct.std::pair" = type { i8, %"class.std::vector" }

; Function Attrs: mustprogress uwtable
define dso_local void @_Z14findMinAvgPathRKSt6vectorIS_ISt4pairIiiESaIS1_EESaIS3_EEi(ptr dead_on_unwind noalias writable sret(%"class.std::vector") align 8 %0, ptr noundef nonnull align 8 dereferenceable(24) %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = alloca %class.anon, align 8
  %5 = alloca %"struct.std::pair", align 8
  %6 = alloca %"struct.std::pair", align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %4, i64 8
  store i32 %2, ptr %7, align 8, !tbaa !9
  br label %10

8:                                                ; preds = %10
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %6) #5
  call void @"_ZZ14findMinAvgPathRKSt6vectorIS_ISt4pairIiiESaIS1_EESaIS3_EEiENK3$_0clEdb"(ptr dead_on_unwind nonnull writable sret(%"struct.std::pair") align 8 %6, ptr noundef nonnull align 8 dereferenceable(12) %4, double noundef %..011, i1 noundef zeroext true)
  %9 = getelementptr inbounds i8, ptr %6, i64 8
  call void @_ZNSt6vectorIiSaIiEEC2EOS1_(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(24) %9) #5
  call void @_ZNSt4pairIbSt6vectorIiSaIiEEED2Ev(ptr noundef nonnull align 8 dereferenceable(32) %6) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #5
  ret void

10:                                               ; preds = %3, %10
  %.015 = phi double [ -1.000000e-01, %3 ], [ %.0., %10 ]
  %.01014 = phi i32 [ 0, %3 ], [ %16, %10 ]
  %.01113 = phi double [ 1.001000e+02, %3 ], [ %..011, %10 ]
  %11 = fsub double %.01113, %.015
  %12 = fmul double %11, 5.000000e-01
  %13 = fadd double %.015, %12
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %5) #5
  call void @"_ZZ14findMinAvgPathRKSt6vectorIS_ISt4pairIiiESaIS1_EESaIS3_EEiENK3$_0clEdb"(ptr dead_on_unwind nonnull writable sret(%"struct.std::pair") align 8 %5, ptr noundef nonnull align 8 dereferenceable(12) %4, double noundef %13, i1 noundef zeroext false)
  %14 = load i8, ptr %5, align 8, !tbaa !12, !range !19, !noundef !20
  %15 = trunc nuw i8 %14 to i1
  call void @_ZNSt4pairIbSt6vectorIiSaIiEEED2Ev(ptr noundef nonnull align 8 dereferenceable(32) %5) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %5) #5
  %..011 = select i1 %15, double %13, double %.01113
  %.0. = select i1 %15, double %.015, double %13
  %16 = add nuw nsw i32 %.01014, 1
  %exitcond.not = icmp eq i32 %16, 30
  br i1 %exitcond.not, label %8, label %10, !llvm.loop !21
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare hidden void @"_ZZ14findMinAvgPathRKSt6vectorIS_ISt4pairIiiESaIS1_EESaIS3_EEiENK3$_0clEdb"(ptr dead_on_unwind noalias writable sret(%"struct.std::pair") align 8, ptr noundef nonnull align 8 dereferenceable(12), double noundef, i1 noundef zeroext) local_unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZNSt4pairIbSt6vectorIiSaIiEEED2Ev(ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #3 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6vectorIiSaIiEEC2EOS1_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #4 align 2

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 willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { inlinehint mustprogress 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 = { mustprogress 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++ TBAA"}
!9 = !{!10, !11, i64 8}
!10 = !{!"_ZTSZ14findMinAvgPathRKSt6vectorIS_ISt4pairIiiESaIS1_EESaIS3_EEiE3$_0", !6, i64 0, !11, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !14, i64 0}
!13 = !{!"_ZTSSt4pairIbSt6vectorIiSaIiEEE", !14, i64 0, !15, i64 8}
!14 = !{!"bool", !7, i64 0}
!15 = !{!"_ZTSSt6vectorIiSaIiEE", !16, i64 0}
!16 = !{!"_ZTSSt12_Vector_baseIiSaIiEE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE12_Vector_implE", !18, i64 0}
!18 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopUnrollPass,SROAPass,SimplifyCFGPass