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

; 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.anon = type { ptr, i32, i64 }

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z10findMinSumRKSt6vectorIiSaIiEEi(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca %class.anon, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %10) #4
  store i64 %11, ptr %5, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 24, ptr %6) #4
  %12 = getelementptr inbounds %class.anon, ptr %6, i32 0, i32 0
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %13, ptr %12, align 8, !tbaa !5
  %14 = getelementptr inbounds %class.anon, ptr %6, i32 0, i32 1
  %15 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %15, ptr %14, align 8, !tbaa !13
  %16 = getelementptr inbounds %class.anon, ptr %6, i32 0, i32 2
  %17 = load i64, ptr %5, align 8, !tbaa !11
  store i64 %17, ptr %16, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store i64 0, ptr %7, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %18 = load i64, ptr %5, align 8, !tbaa !11
  %19 = uitofp i64 %18 to double
  %20 = fmul double %19, 1.000000e+09
  %21 = fptosi double %20 to i64
  store i64 %21, ptr %8, align 8, !tbaa !16
  br label %22

22:                                               ; preds = %40, %2
  %23 = load i64, ptr %7, align 8, !tbaa !16
  %24 = add nsw i64 %23, 1
  %25 = load i64, ptr %8, align 8, !tbaa !16
  %26 = icmp slt i64 %24, %25
  br i1 %26, label %27, label %41

27:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %28 = load i64, ptr %7, align 8, !tbaa !16
  %29 = load i64, ptr %8, align 8, !tbaa !16
  %30 = load i64, ptr %7, align 8, !tbaa !16
  %31 = sub nsw i64 %29, %30
  %32 = sdiv i64 %31, 2
  %33 = add nsw i64 %28, %32
  store i64 %33, ptr %9, align 8, !tbaa !16
  %34 = load i64, ptr %9, align 8, !tbaa !16
  %35 = call noundef zeroext i1 @"_ZZ10findMinSumRKSt6vectorIiSaIiEEiENK3$_0clEx"(ptr noundef nonnull align 8 dereferenceable(24) %6, i64 noundef %34)
  br i1 %35, label %36, label %38

36:                                               ; preds = %27
  %37 = load i64, ptr %9, align 8, !tbaa !16
  store i64 %37, ptr %8, align 8, !tbaa !16
  br label %40

38:                                               ; preds = %27
  %39 = load i64, ptr %9, align 8, !tbaa !16
  store i64 %39, ptr %7, align 8, !tbaa !16
  br label %40

40:                                               ; preds = %38, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %22, !llvm.loop !18

41:                                               ; preds = %22
  %42 = load i64, ptr %8, align 8, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret i64 %42
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef zeroext i1 @"_ZZ10findMinSumRKSt6vectorIiSaIiEEiENK3$_0clEx"(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #3 align 2

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

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 = { 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 #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 = { 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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !10, i64 8}
!14 = !{!"_ZTSZ10findMinSumRKSt6vectorIiSaIiEEiE3$_0", !6, i64 0, !10, i64 8, !12, i64 16}
!15 = !{!14, !12, i64 16}
!16 = !{!17, !17, i64 0}
!17 = !{!"long long", !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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.anon = type { ptr, i32, i64 }

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z10findMinSumRKSt6vectorIiSaIiEEi(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca %class.anon, align 8
  %4 = tail call noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #3
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #3
  store ptr %0, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %3, i64 8
  store i32 %1, ptr %5, align 8, !tbaa !9
  %6 = getelementptr inbounds i8, ptr %3, i64 16
  store i64 %4, ptr %6, align 8, !tbaa !13
  %7 = uitofp i64 %4 to double
  %8 = fmul double %7, 1.000000e+09
  %9 = fptosi double %8 to i64
  %10 = icmp sgt i64 %9, 1
  br i1 %10, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.016 = phi i64 [ %.0., %.lr.ph ], [ 0, %2 ]
  %.01315 = phi i64 [ %..013, %.lr.ph ], [ %9, %2 ]
  %11 = sub nsw i64 %.01315, %.016
  %12 = sdiv i64 %11, 2
  %13 = add nsw i64 %12, %.016
  %14 = call noundef zeroext i1 @"_ZZ10findMinSumRKSt6vectorIiSaIiEEiENK3$_0clEx"(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef %13)
  %..013 = select i1 %14, i64 %13, i64 %.01315
  %.0. = select i1 %14, i64 %.016, i64 %13
  %15 = add nsw i64 %.0., 1
  %16 = icmp slt i64 %15, %..013
  br i1 %16, label %.lr.ph, label %._crit_edge, !llvm.loop !14

._crit_edge:                                      ; preds = %.lr.ph, %2
  %.013.lcssa = phi i64 [ %9, %2 ], [ %..013, %.lr.ph ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #3
  ret i64 %.013.lcssa
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIiSaIiEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef zeroext i1 @"_ZZ10findMinSumRKSt6vectorIiSaIiEEiENK3$_0clEx"(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #2 align 2

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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, !11, i64 8}
!10 = !{!"_ZTSZ10findMinSumRKSt6vectorIiSaIiEEiE3$_0", !6, i64 0, !11, i64 8, !12, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!10, !12, i64 16}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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