; LLVM IR from sunkafei/xcpc-algorithm-templates :: 算法/树算法/虚树.ll (Z3insi)

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

@dep = external dso_local global [1110000 x i32], align 16
@stk = external dso_local global [1110000 x i32], align 16
@tp = external dso_local global i32, align 4
@E = external dso_local global [1110000 x %"class.std::vector"], align 16

; 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: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3lcaii(i32 noundef, i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3insi(i32 noundef %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  %5 = load i32, ptr @tp, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %7, label %79

7:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %8 = load i32, ptr @tp, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [1110000 x i32], ptr @stk, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = call noundef i32 @_Z3lcaii(i32 noundef %11, i32 noundef %12)
  store i32 %13, ptr %3, align 4, !tbaa !5
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = load i32, ptr @tp, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [1110000 x i32], ptr @stk, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = icmp ne i32 %14, %18
  br i1 %19, label %20, label %78

20:                                               ; preds = %7
  br label %21

21:                                               ; preds = %40, %20
  %22 = load i32, ptr @tp, align 4, !tbaa !5
  %23 = icmp sgt i32 %22, 1
  br i1 %23, label %24, label %38

24:                                               ; preds = %21
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [1110000 x i32], ptr @dep, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = load i32, ptr @tp, align 4, !tbaa !5
  %30 = sub nsw i32 %29, 1
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [1110000 x i32], ptr @stk, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [1110000 x i32], ptr @dep, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = icmp slt i32 %28, %36
  br label %38

38:                                               ; preds = %24, %21
  %39 = phi i1 [ false, %21 ], [ %37, %24 ]
  br i1 %39, label %40, label %53

40:                                               ; preds = %38
  %41 = load i32, ptr @tp, align 4, !tbaa !5
  %42 = sub nsw i32 %41, 1
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [1110000 x i32], ptr @stk, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [1110000 x %"class.std::vector"], ptr @E, i64 0, i64 %46
  %48 = load i32, ptr @tp, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [1110000 x i32], ptr @stk, i64 0, i64 %49
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) %47, ptr noundef nonnull align 4 dereferenceable(4) %50)
  %51 = load i32, ptr @tp, align 4, !tbaa !5
  %52 = add nsw i32 %51, -1
  store i32 %52, ptr @tp, align 4, !tbaa !5
  br label %21, !llvm.loop !9

53:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %54 = load i32, ptr @tp, align 4, !tbaa !5
  %55 = add nsw i32 %54, -1
  store i32 %55, ptr @tp, align 4, !tbaa !5
  %56 = sext i32 %54 to i64
  %57 = getelementptr inbounds [1110000 x i32], ptr @stk, i64 0, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !5
  store i32 %58, ptr %4, align 4, !tbaa !5
  %59 = load i32, ptr %3, align 4, !tbaa !5
  %60 = load i32, ptr @tp, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [1110000 x i32], ptr @stk, i64 0, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !5
  %64 = icmp ne i32 %59, %63
  br i1 %64, label %65, label %74

65:                                               ; preds = %53
  %66 = load i32, ptr %3, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [1110000 x %"class.std::vector"], ptr @E, i64 0, i64 %67
  call void @_ZNSt6vectorIiSaIiEE5clearEv(ptr noundef nonnull align 8 dereferenceable(24) %68) #3
  %69 = load i32, ptr %3, align 4, !tbaa !5
  %70 = load i32, ptr @tp, align 4, !tbaa !5
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr @tp, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [1110000 x i32], ptr @stk, i64 0, i64 %72
  store i32 %69, ptr %73, align 4, !tbaa !5
  br label %74

74:                                               ; preds = %65, %53
  %75 = load i32, ptr %3, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [1110000 x %"class.std::vector"], ptr @E, i64 0, i64 %76
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) %77, ptr noundef nonnull align 4 dereferenceable(4) %4)
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %78

78:                                               ; preds = %74, %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %79

79:                                               ; preds = %78, %1
  %80 = load i32, ptr %2, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [1110000 x %"class.std::vector"], ptr @E, i64 0, i64 %81
  call void @_ZNSt6vectorIiSaIiEE5clearEv(ptr noundef nonnull align 8 dereferenceable(24) %82) #3
  %83 = load i32, ptr %2, align 4, !tbaa !5
  %84 = load i32, ptr @tp, align 4, !tbaa !5
  %85 = add nsw i32 %84, 1
  store i32 %85, ptr @tp, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [1110000 x i32], ptr @stk, i64 0, i64 %86
  store i32 %83, ptr %87, align 4, !tbaa !5
  ret void
}

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 = distinct !{!9, !10}
!10 = !{!"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 }

@dep = external dso_local local_unnamed_addr global [1110000 x i32], align 16
@stk = external dso_local global [1110000 x i32], align 16
@tp = external dso_local local_unnamed_addr global i32, align 4
@E = external dso_local global [1110000 x %"class.std::vector"], align 16

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3lcaii(i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3insi(i32 noundef %0) local_unnamed_addr #2 {
  %2 = alloca i32, align 4
  %3 = load i32, ptr @tp, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %5, label %47

5:                                                ; preds = %1
  %6 = zext nneg i32 %3 to i64
  %7 = getelementptr inbounds [1110000 x i32], ptr @stk, i64 0, i64 %6
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = tail call noundef i32 @_Z3lcaii(i32 noundef %8, i32 noundef %0)
  %10 = load i32, ptr @tp, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [1110000 x i32], ptr @stk, i64 0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %.not = icmp eq i32 %9, %13
  br i1 %.not, label %47, label %.preheader

.preheader:                                       ; preds = %5
  %14 = sext i32 %9 to i64
  %15 = getelementptr inbounds [1110000 x i32], ptr @dep, i64 0, i64 %14
  %16 = icmp sgt i32 %10, 1
  br i1 %16, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %.preheader, %27
  %17 = phi i32 [ %32, %27 ], [ %10, %.preheader ]
  %18 = load i32, ptr %15, align 4, !tbaa !5
  %19 = add nsw i32 %17, -1
  %20 = zext nneg i32 %19 to i64
  %21 = getelementptr inbounds [1110000 x i32], ptr @stk, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [1110000 x i32], ptr @dep, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = icmp slt i32 %18, %25
  br i1 %26, label %27, label %.critedge.loopexit

27:                                               ; preds = %.lr.ph
  %28 = getelementptr inbounds [1110000 x %"class.std::vector"], ptr @E, i64 0, i64 %23
  %29 = zext nneg i32 %17 to i64
  %30 = getelementptr inbounds [1110000 x i32], ptr @stk, i64 0, i64 %29
  tail call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) %28, ptr noundef nonnull align 4 dereferenceable(4) %30)
  %31 = load i32, ptr @tp, align 4, !tbaa !5
  %32 = add nsw i32 %31, -1
  store i32 %32, ptr @tp, align 4, !tbaa !5
  %33 = icmp sgt i32 %31, 2
  br i1 %33, label %.lr.ph, label %.critedge.loopexit, !llvm.loop !9

.critedge.loopexit:                               ; preds = %27, %.lr.ph
  %.lcssa.ph = phi i32 [ %17, %.lr.ph ], [ %32, %27 ]
  %.pre = sext i32 %.lcssa.ph to i64
  %.phi.trans.insert = getelementptr inbounds [1110000 x i32], ptr @stk, i64 0, i64 %.pre
  %.pre14 = load i32, ptr %.phi.trans.insert, align 4, !tbaa !5
  br label %.critedge

.critedge:                                        ; preds = %.critedge.loopexit, %.preheader
  %34 = phi i32 [ %.pre14, %.critedge.loopexit ], [ %13, %.preheader ]
  %.lcssa = phi i32 [ %.lcssa.ph, %.critedge.loopexit ], [ %10, %.preheader ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #3
  %35 = add nsw i32 %.lcssa, -1
  store i32 %35, ptr @tp, align 4, !tbaa !5
  store i32 %34, ptr %2, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [1110000 x i32], ptr @stk, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %.not11 = icmp eq i32 %9, %38
  br i1 %.not11, label %45, label %39

39:                                               ; preds = %.critedge
  %40 = getelementptr inbounds [1110000 x %"class.std::vector"], ptr @E, i64 0, i64 %14
  tail call void @_ZNSt6vectorIiSaIiEE5clearEv(ptr noundef nonnull align 8 dereferenceable(24) %40) #3
  %41 = load i32, ptr @tp, align 4, !tbaa !5
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr @tp, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [1110000 x i32], ptr @stk, i64 0, i64 %43
  store i32 %9, ptr %44, align 4, !tbaa !5
  br label %45

45:                                               ; preds = %39, %.critedge
  %46 = getelementptr inbounds [1110000 x %"class.std::vector"], ptr @E, i64 0, i64 %14
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) %46, ptr noundef nonnull align 4 dereferenceable(4) %2)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #3
  br label %47

47:                                               ; preds = %5, %45, %1
  %48 = sext i32 %0 to i64
  %49 = getelementptr inbounds [1110000 x %"class.std::vector"], ptr @E, i64 0, i64 %48
  call void @_ZNSt6vectorIiSaIiEE5clearEv(ptr noundef nonnull align 8 dereferenceable(24) %49) #3
  %50 = load i32, ptr @tp, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr @tp, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [1110000 x i32], ptr @stk, i64 0, i64 %52
  store i32 %0, ptr %53, align 4, !tbaa !5
  ret void
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6vectorIiSaIiEE5clearEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1 align 2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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