; LLVM IR from HarshCasper/NeoAlgo :: C-Plus-Plus/cp/Plucking_Flowers.ll (Z9maxBeautyiiRSt6vectorIiSaIiEE)

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z9maxBeautyiiRSt6vectorIiSaIiEE(i32 noundef %0, i32 noundef %1, ptr noundef nonnull align 8 dereferenceable(24) %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  %12 = load i32, ptr %5, align 4, !tbaa !5
  %13 = add nsw i32 %12, 1
  %14 = zext i32 %13 to i64
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = add nsw i32 %15, 1
  %17 = zext i32 %16 to i64
  %18 = call ptr @llvm.stacksave.p0()
  store ptr %18, ptr %9, align 8
  %19 = mul nuw i64 %14, %17
  %20 = alloca i64, i64 %19, align 16
  store i64 %14, ptr %10, align 8
  store i64 %17, ptr %11, align 8
  %21 = mul nuw i64 %14, %17
  %22 = mul nuw i64 8, %21
  call void @llvm.memset.p0.i64(ptr align 16 %20, i8 0, i64 %22, i1 false)
  store i64 1, ptr %7, align 8, !tbaa !11
  br label %23

23:                                               ; preds = %91, %3
  %24 = load i64, ptr %7, align 8, !tbaa !11
  %25 = load i32, ptr %5, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = icmp sle i64 %24, %26
  br i1 %27, label %28, label %94

28:                                               ; preds = %23
  %29 = load i64, ptr %7, align 8, !tbaa !11
  %30 = mul nsw i64 2, %29
  %31 = sub nsw i64 %30, 1
  store i64 %31, ptr %8, align 8, !tbaa !11
  br label %32

32:                                               ; preds = %87, %28
  %33 = load i64, ptr %8, align 8, !tbaa !11
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = icmp sle i64 %33, %35
  br i1 %36, label %37, label %90

37:                                               ; preds = %32
  %38 = load ptr, ptr %6, align 8, !tbaa !9
  %39 = load i64, ptr %8, align 8, !tbaa !11
  %40 = sub nsw i64 %39, 1
  %41 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %38, i64 noundef %40) #6
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = load i64, ptr %7, align 8, !tbaa !11
  %45 = mul nsw i64 %44, %17
  %46 = getelementptr inbounds i64, ptr %20, i64 %45
  %47 = load i64, ptr %8, align 8, !tbaa !11
  %48 = getelementptr inbounds i64, ptr %46, i64 %47
  store i64 %43, ptr %48, align 8, !tbaa !11
  %49 = load i64, ptr %8, align 8, !tbaa !11
  %50 = sub nsw i64 %49, 2
  %51 = icmp sge i64 %50, 0
  br i1 %51, label %52, label %68

52:                                               ; preds = %37
  %53 = load i64, ptr %7, align 8, !tbaa !11
  %54 = sub nsw i64 %53, 1
  %55 = mul nsw i64 %54, %17
  %56 = getelementptr inbounds i64, ptr %20, i64 %55
  %57 = load i64, ptr %8, align 8, !tbaa !11
  %58 = sub nsw i64 %57, 2
  %59 = getelementptr inbounds i64, ptr %56, i64 %58
  %60 = load i64, ptr %59, align 8, !tbaa !11
  %61 = load i64, ptr %7, align 8, !tbaa !11
  %62 = mul nsw i64 %61, %17
  %63 = getelementptr inbounds i64, ptr %20, i64 %62
  %64 = load i64, ptr %8, align 8, !tbaa !11
  %65 = getelementptr inbounds i64, ptr %63, i64 %64
  %66 = load i64, ptr %65, align 8, !tbaa !11
  %67 = add nsw i64 %66, %60
  store i64 %67, ptr %65, align 8, !tbaa !11
  br label %68

68:                                               ; preds = %52, %37
  %69 = load i64, ptr %7, align 8, !tbaa !11
  %70 = mul nsw i64 %69, %17
  %71 = getelementptr inbounds i64, ptr %20, i64 %70
  %72 = load i64, ptr %8, align 8, !tbaa !11
  %73 = getelementptr inbounds i64, ptr %71, i64 %72
  %74 = load i64, ptr %7, align 8, !tbaa !11
  %75 = mul nsw i64 %74, %17
  %76 = getelementptr inbounds i64, ptr %20, i64 %75
  %77 = load i64, ptr %8, align 8, !tbaa !11
  %78 = sub nsw i64 %77, 1
  %79 = getelementptr inbounds i64, ptr %76, i64 %78
  %80 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %73, ptr noundef nonnull align 8 dereferenceable(8) %79)
  %81 = load i64, ptr %80, align 8, !tbaa !11
  %82 = load i64, ptr %7, align 8, !tbaa !11
  %83 = mul nsw i64 %82, %17
  %84 = getelementptr inbounds i64, ptr %20, i64 %83
  %85 = load i64, ptr %8, align 8, !tbaa !11
  %86 = getelementptr inbounds i64, ptr %84, i64 %85
  store i64 %81, ptr %86, align 8, !tbaa !11
  br label %87

87:                                               ; preds = %68
  %88 = load i64, ptr %8, align 8, !tbaa !11
  %89 = add nsw i64 %88, 1
  store i64 %89, ptr %8, align 8, !tbaa !11
  br label %32, !llvm.loop !13

90:                                               ; preds = %32
  br label %91

91:                                               ; preds = %90
  %92 = load i64, ptr %7, align 8, !tbaa !11
  %93 = add nsw i64 %92, 1
  store i64 %93, ptr %7, align 8, !tbaa !11
  br label %23, !llvm.loop !15

94:                                               ; preds = %23
  %95 = load i32, ptr %5, align 4, !tbaa !5
  %96 = sext i32 %95 to i64
  %97 = mul nsw i64 %96, %17
  %98 = getelementptr inbounds i64, ptr %20, i64 %97
  %99 = load i32, ptr %4, align 4, !tbaa !5
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds i64, ptr %98, i64 %100
  %102 = load i64, ptr %101, align 8, !tbaa !11
  %103 = load ptr, ptr %9, align 8
  call void @llvm.stackrestore.p0(ptr %103)
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  ret i64 %102
}

; 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
declare ptr @llvm.stacksave.p0() #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #5

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #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 = { nocallback nofree nosync nounwind willreturn }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { 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 #6 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z9maxBeautyiiRSt6vectorIiSaIiEE(i32 noundef %0, i32 noundef %1, ptr noundef nonnull align 8 dereferenceable(24) %2) local_unnamed_addr #0 {
  %4 = add nsw i32 %1, 1
  %5 = zext i32 %4 to i64
  %6 = add nsw i32 %0, 1
  %7 = zext i32 %6 to i64
  %8 = mul nuw i64 %5, %7
  %9 = alloca i64, i64 %8, align 16
  %10 = shl nuw i64 %8, 3
  call void @llvm.memset.p0.i64(ptr nonnull align 16 %9, i8 0, i64 %10, i1 false)
  %11 = sext i32 %1 to i64
  %invariant.gep32 = getelementptr i8, ptr %9, i64 -16
  %.not34 = icmp slt i32 %1, 1
  %.pre = sext i32 %0 to i64
  br i1 %.not34, label %._crit_edge38, label %.lr.ph37

.lr.ph37:                                         ; preds = %3, %._crit_edge
  %.035 = phi i64 [ %33, %._crit_edge ], [ 1, %3 ]
  %12 = shl nuw nsw i64 %.035, 1
  %13 = add nsw i64 %12, -1
  %.not2930 = icmp sgt i64 %13, %.pre
  br i1 %.not2930, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph37
  %14 = mul nuw nsw i64 %.035, %7
  %15 = getelementptr inbounds i64, ptr %9, i64 %14
  %16 = add nsw i64 %.035, -1
  %17 = mul nuw nsw i64 %16, %7
  %gep33 = getelementptr i64, ptr %invariant.gep32, i64 %17
  br label %18

18:                                               ; preds = %.lr.ph, %28
  %.02631 = phi i64 [ %13, %.lr.ph ], [ %32, %28 ]
  %19 = add nsw i64 %.02631, -1
  %20 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %2, i64 noundef %19) #3
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds i64, ptr %15, i64 %.02631
  store i64 %22, ptr %23, align 8, !tbaa !9
  %24 = icmp ugt i64 %.02631, 1
  br i1 %24, label %25, label %28

25:                                               ; preds = %18
  %gep = getelementptr i64, ptr %gep33, i64 %.02631
  %26 = load i64, ptr %gep, align 8, !tbaa !9
  %27 = add nsw i64 %26, %22
  store i64 %27, ptr %23, align 8, !tbaa !9
  br label %28

28:                                               ; preds = %25, %18
  %29 = getelementptr inbounds i64, ptr %15, i64 %19
  %30 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %23, ptr noundef nonnull align 8 dereferenceable(8) %29)
  %31 = load i64, ptr %30, align 8, !tbaa !9
  store i64 %31, ptr %23, align 8, !tbaa !9
  %32 = add nuw nsw i64 %.02631, 1
  %.not29.not = icmp slt i64 %.02631, %.pre
  br i1 %.not29.not, label %18, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %28, %.lr.ph37
  %33 = add nuw nsw i64 %.035, 1
  %exitcond.not = icmp eq i64 %.035, %11
  br i1 %exitcond.not, label %._crit_edge38, label %.lr.ph37, !llvm.loop !13

._crit_edge38:                                    ; preds = %._crit_edge, %3
  %34 = mul nsw i64 %11, %7
  %35 = getelementptr inbounds i64, ptr %9, i64 %34
  %36 = getelementptr inbounds i64, ptr %35, i64 %.pre
  %37 = load i64, ptr %36, align 8, !tbaa !9
  ret i64 %37
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2

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 nounwind willreturn memory(argmem: write) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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