; LLVM IR from upupming/algorithm :: acwing/算法竞赛进阶指南/0x24-迭代加深/171. 送礼物.ll (Z3dfsixRSt6vectorIiSaIiEE)

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

@e = external dso_local global i32, align 4
@w = external dso_local global i32, align 4
@g = external dso_local global [60 x i32], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsixRSt6vectorIiSaIiEE(i32 noundef %0, i64 noundef %1, ptr noundef nonnull align 8 dereferenceable(24) %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !11
  %8 = load i32, ptr %4, align 4, !tbaa !5
  %9 = load i32, ptr @e, align 4, !tbaa !5
  %10 = add nsw i32 %9, 1
  %11 = icmp sge i32 %8, %10
  br i1 %11, label %12, label %16

12:                                               ; preds = %3
  %13 = load ptr, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %14 = load i64, ptr %5, align 8, !tbaa !9
  %15 = trunc i64 %14 to i32
  store i32 %15, ptr %7, align 4, !tbaa !5
  call void @_ZNSt6vectorIiSaIiEE9push_backEOi(ptr noundef nonnull align 8 dereferenceable(24) %13, ptr noundef nonnull align 4 dereferenceable(4) %7)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %43

16:                                               ; preds = %3
  %17 = load i64, ptr %5, align 8, !tbaa !9
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [60 x i32], ptr @g, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = add nsw i64 %17, %22
  %24 = load i32, ptr @w, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = icmp sle i64 %23, %25
  br i1 %26, label %27, label %38

27:                                               ; preds = %16
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  %30 = load i64, ptr %5, align 8, !tbaa !9
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [60 x i32], ptr @g, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = add nsw i64 %30, %35
  %37 = load ptr, ptr %6, align 8, !tbaa !11
  call void @_Z3dfsixRSt6vectorIiSaIiEE(i32 noundef %29, i64 noundef %36, ptr noundef nonnull align 8 dereferenceable(24) %37)
  br label %38

38:                                               ; preds = %27, %16
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  %41 = load i64, ptr %5, align 8, !tbaa !9
  %42 = load ptr, ptr %6, align 8, !tbaa !11
  call void @_Z3dfsixRSt6vectorIiSaIiEE(i32 noundef %40, i64 noundef %41, ptr noundef nonnull align 8 dereferenceable(24) %42)
  br label %43

43:                                               ; preds = %38, %12
  ret void
}

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

; 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 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 = { 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 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}


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

@e = external dso_local local_unnamed_addr global i32, align 4
@w = external dso_local local_unnamed_addr global i32, align 4
@g = external dso_local local_unnamed_addr global [60 x i32], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsixRSt6vectorIiSaIiEE(i32 noundef %0, i64 noundef %1, ptr noundef nonnull align 8 dereferenceable(24) %2) local_unnamed_addr #0 {
  %4 = alloca i32, align 4
  %5 = load i32, ptr @e, align 4, !tbaa !5
  %.not.not14 = icmp slt i32 %5, %0
  br i1 %.not.not14, label %tailrecurse._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %6 = sext i32 %0 to i64
  %.pre17 = load i32, ptr @w, align 4, !tbaa !5
  br label %.lr.ph

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #2
  %7 = trunc i64 %1 to i32
  store i32 %7, ptr %4, align 4, !tbaa !5
  call void @_ZNSt6vectorIiSaIiEE9push_backEOi(ptr noundef nonnull align 8 dereferenceable(24) %2, ptr noundef nonnull align 4 dereferenceable(4) %4)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #2
  ret void

.lr.ph:                                           ; preds = %.lr.ph.preheader, %tailrecurse
  %8 = phi i32 [ %5, %.lr.ph.preheader ], [ %17, %tailrecurse ]
  %9 = phi i32 [ %.pre17, %.lr.ph.preheader ], [ %18, %tailrecurse ]
  %indvars.iv = phi i64 [ %6, %.lr.ph.preheader ], [ %.pre19, %tailrecurse ]
  %10 = getelementptr inbounds [60 x i32], ptr @g, i64 0, i64 %indvars.iv
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = add nsw i64 %12, %1
  %14 = sext i32 %9 to i64
  %.not = icmp sgt i64 %13, %14
  %.pre19 = add nsw i64 %indvars.iv, 1
  br i1 %.not, label %tailrecurse, label %15

15:                                               ; preds = %.lr.ph
  %16 = trunc nsw i64 %.pre19 to i32
  tail call void @_Z3dfsixRSt6vectorIiSaIiEE(i32 noundef %16, i64 noundef %13, ptr noundef nonnull align 8 dereferenceable(24) %2)
  %.pre = load i32, ptr @w, align 4, !tbaa !5
  %.pre18 = load i32, ptr @e, align 4, !tbaa !5
  br label %tailrecurse

tailrecurse:                                      ; preds = %.lr.ph, %15
  %17 = phi i32 [ %.pre18, %15 ], [ %8, %.lr.ph ]
  %18 = phi i32 [ %.pre, %15 ], [ %9, %.lr.ph ]
  %19 = sext i32 %17 to i64
  %.not.not.not = icmp slt i64 %indvars.iv, %19
  br i1 %.not.not.not, label %.lr.ph, label %tailrecurse._crit_edge
}

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

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass