; LLVM IR from sunkafei/xcpc-algorithm-templates :: 算法/数据结构/整数集合.ll (Z3insRiiii)

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

%struct.node = type { i32, i32, i32 }

@T = external dso_local global [5250000 x %struct.node], align 16
@sz = external dso_local global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3insRiiii(ptr noundef nonnull align 4 dereferenceable(4) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = load i32, ptr %11, align 4, !tbaa !9
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %33, label %14

14:                                               ; preds = %4
  %15 = load i32, ptr @sz, align 4, !tbaa !9
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr @sz, align 4, !tbaa !9
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 %16, ptr %17, align 4, !tbaa !9
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = load i32, ptr %18, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %20
  %22 = getelementptr inbounds %struct.node, ptr %21, i32 0, i32 1
  store i32 0, ptr %22, align 4, !tbaa !11
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = load i32, ptr %23, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %25
  %27 = getelementptr inbounds %struct.node, ptr %26, i32 0, i32 0
  store i32 0, ptr %27, align 4, !tbaa !13
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = load i32, ptr %28, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %30
  %32 = getelementptr inbounds %struct.node, ptr %31, i32 0, i32 2
  store i32 0, ptr %32, align 4, !tbaa !14
  br label %33

33:                                               ; preds = %14, %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = load i32, ptr %7, align 4, !tbaa !9
  %36 = add nsw i32 %34, %35
  %37 = sdiv i32 %36, 2
  store i32 %37, ptr %9, align 4, !tbaa !9
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = load i32, ptr %38, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %40
  %42 = getelementptr inbounds %struct.node, ptr %41, i32 0, i32 2
  %43 = load i32, ptr %42, align 4, !tbaa !14
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %42, align 4, !tbaa !14
  %45 = load i32, ptr %6, align 4, !tbaa !9
  %46 = load i32, ptr %7, align 4, !tbaa !9
  %47 = icmp eq i32 %45, %46
  br i1 %47, label %48, label %49

48:                                               ; preds = %33
  store i32 1, ptr %10, align 4
  br label %73

49:                                               ; preds = %33
  %50 = load i32, ptr %8, align 4, !tbaa !9
  %51 = load i32, ptr %9, align 4, !tbaa !9
  %52 = icmp sle i32 %50, %51
  br i1 %52, label %53, label %62

53:                                               ; preds = %49
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = load i32, ptr %54, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %56
  %58 = getelementptr inbounds %struct.node, ptr %57, i32 0, i32 0
  %59 = load i32, ptr %6, align 4, !tbaa !9
  %60 = load i32, ptr %9, align 4, !tbaa !9
  %61 = load i32, ptr %8, align 4, !tbaa !9
  call void @_Z3insRiiii(ptr noundef nonnull align 4 dereferenceable(4) %58, i32 noundef %59, i32 noundef %60, i32 noundef %61)
  br label %72

62:                                               ; preds = %49
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = load i32, ptr %63, align 4, !tbaa !9
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %65
  %67 = getelementptr inbounds %struct.node, ptr %66, i32 0, i32 1
  %68 = load i32, ptr %9, align 4, !tbaa !9
  %69 = add nsw i32 %68, 1
  %70 = load i32, ptr %7, align 4, !tbaa !9
  %71 = load i32, ptr %8, align 4, !tbaa !9
  call void @_Z3insRiiii(ptr noundef nonnull align 4 dereferenceable(4) %67, i32 noundef %69, i32 noundef %70, i32 noundef %71)
  br label %72

72:                                               ; preds = %62, %53
  store i32 0, ptr %10, align 4
  br label %73

73:                                               ; preds = %72, %48
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  %74 = load i32, ptr %10, align 4
  switch i32 %74, label %76 [
    i32 0, label %75
    i32 1, label %75
  ]

75:                                               ; preds = %73, %73
  ret void

76:                                               ; preds = %73
  unreachable
}

; 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 = !{!"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 4}
!12 = !{!"_ZTS4node", !10, i64 0, !10, i64 4, !10, i64 8}
!13 = !{!12, !10, i64 0}
!14 = !{!12, !10, i64 8}


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

%struct.node = type { i32, i32, i32 }

@T = external dso_local local_unnamed_addr global [5250000 x %struct.node], align 16
@sz = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_Z3insRiiii(ptr nocapture noundef nonnull align 4 dereferenceable(4) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  br label %tailrecurse.outer

tailrecurse.outer:                                ; preds = %31, %4
  %.tr.ph = phi ptr [ %32, %31 ], [ %0, %4 ]
  %.tr24.ph = phi i32 [ %33, %31 ], [ %1, %4 ]
  %.tr25.ph = phi i32 [ %.tr25, %31 ], [ %2, %4 ]
  br label %tailrecurse

tailrecurse:                                      ; preds = %tailrecurse.outer, %29
  %.tr = phi ptr [ %30, %29 ], [ %.tr.ph, %tailrecurse.outer ]
  %.tr25 = phi i32 [ %20, %29 ], [ %.tr25.ph, %tailrecurse.outer ]
  %5 = load i32, ptr %.tr, align 4, !tbaa !5
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %6, label %17

6:                                                ; preds = %tailrecurse
  %7 = load i32, ptr @sz, align 4, !tbaa !5
  %8 = add nsw i32 %7, 1
  store i32 %8, ptr @sz, align 4, !tbaa !5
  store i32 %8, ptr %.tr, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %9, i32 1
  store i32 0, ptr %10, align 4, !tbaa !9
  %11 = load i32, ptr %.tr, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %12
  store i32 0, ptr %13, align 4, !tbaa !11
  %14 = load i32, ptr %.tr, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %15, i32 2
  store i32 0, ptr %16, align 4, !tbaa !12
  %.pre = load i32, ptr %.tr, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %6, %tailrecurse
  %18 = phi i32 [ %.pre, %6 ], [ %5, %tailrecurse ]
  %19 = add nsw i32 %.tr25, %.tr24.ph
  %20 = sdiv i32 %19, 2
  %21 = sext i32 %18 to i64
  %22 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %21, i32 2
  %23 = load i32, ptr %22, align 4, !tbaa !12
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %22, align 4, !tbaa !12
  %25 = icmp eq i32 %.tr24.ph, %.tr25
  br i1 %25, label %34, label %26

26:                                               ; preds = %17
  %.not23 = icmp slt i32 %20, %3
  %27 = load i32, ptr %.tr, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  br i1 %.not23, label %31, label %29

29:                                               ; preds = %26
  %30 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %28
  br label %tailrecurse

31:                                               ; preds = %26
  %32 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %28, i32 1
  %33 = add nsw i32 %20, 1
  br label %tailrecurse.outer

34:                                               ; preds = %17
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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" }

!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, !6, i64 4}
!10 = !{!"_ZTS4node", !6, i64 0, !6, i64 4, !6, i64 8}
!11 = !{!10, !6, i64 0}
!12 = !{!10, !6, i64 8}


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