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

; 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
@len = external dso_local global i32, align 4

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z7rankingi(i32 noundef) #0

; 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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z3askii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %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
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 1, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %13 = load i32, ptr @len, align 4, !tbaa !5
  store i32 %13, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = call noundef i32 @_Z7rankingi(i32 noundef %14)
  %16 = sub nsw i32 %15, 1
  store i32 %16, ptr %9, align 4, !tbaa !5
  %17 = load i32, ptr %9, align 4, !tbaa !5
  %18 = icmp sle i32 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %2
  store i32 0, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %70

20:                                               ; preds = %2
  br label %21

21:                                               ; preds = %60, %20
  %22 = load i32, ptr %6, align 4, !tbaa !5
  %23 = load i32, ptr %7, align 4, !tbaa !5
  %24 = icmp slt i32 %22, %23
  br i1 %24, label %25, label %61

25:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %26 = load i32, ptr %6, align 4, !tbaa !5
  %27 = load i32, ptr %7, align 4, !tbaa !5
  %28 = add nsw i32 %26, %27
  %29 = sdiv i32 %28, 2
  store i32 %29, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %31
  %33 = getelementptr inbounds %struct.node, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %33, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %35
  %37 = getelementptr inbounds %struct.node, ptr %36, i32 0, i32 2
  %38 = load i32, ptr %37, align 4, !tbaa !11
  store i32 %38, ptr %12, align 4, !tbaa !5
  %39 = load i32, ptr %9, align 4, !tbaa !5
  %40 = load i32, ptr %11, align 4, !tbaa !5
  %41 = icmp sle i32 %39, %40
  br i1 %41, label %42, label %49

42:                                               ; preds = %25
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %44
  %46 = getelementptr inbounds %struct.node, ptr %45, i32 0, i32 0
  %47 = load i32, ptr %46, align 4, !tbaa !9
  store i32 %47, ptr %4, align 4, !tbaa !5
  %48 = load i32, ptr %11, align 4, !tbaa !5
  store i32 %48, ptr %7, align 4, !tbaa !5
  br label %60

49:                                               ; preds = %25
  %50 = load i32, ptr %4, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %51
  %53 = getelementptr inbounds %struct.node, ptr %52, i32 0, i32 1
  %54 = load i32, ptr %53, align 4, !tbaa !12
  store i32 %54, ptr %4, align 4, !tbaa !5
  %55 = load i32, ptr %11, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %6, align 4, !tbaa !5
  %57 = load i32, ptr %12, align 4, !tbaa !5
  %58 = load i32, ptr %8, align 4, !tbaa !5
  %59 = add nsw i32 %58, %57
  store i32 %59, ptr %8, align 4, !tbaa !5
  br label %60

60:                                               ; preds = %49, %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  br label %21, !llvm.loop !13

61:                                               ; preds = %21
  %62 = load i32, ptr %4, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %63
  %65 = getelementptr inbounds %struct.node, ptr %64, i32 0, i32 2
  %66 = load i32, ptr %65, align 4, !tbaa !11
  %67 = load i32, ptr %8, align 4, !tbaa !5
  %68 = add nsw i32 %67, %66
  store i32 %68, ptr %8, align 4, !tbaa !5
  %69 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %69, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %70

70:                                               ; preds = %61, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %71 = load i32, ptr %3, align 4
  ret i32 %71
}

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

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z7rankingi(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z3askii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr @len, align 4, !tbaa !5
  %4 = tail call noundef i32 @_Z7rankingi(i32 noundef %1)
  %5 = add nsw i32 %4, -1
  %6 = icmp slt i32 %4, 2
  br i1 %6, label %27, label %.preheader

.preheader:                                       ; preds = %2
  %7 = icmp sgt i32 %3, 1
  br i1 %7, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader, %21
  %.01931 = phi i32 [ %.1, %21 ], [ %0, %.preheader ]
  %.02030 = phi i32 [ %.121, %21 ], [ 1, %.preheader ]
  %.02229 = phi i32 [ %.123, %21 ], [ 0, %.preheader ]
  %.02428 = phi i32 [ %.125, %21 ], [ %3, %.preheader ]
  %8 = add nuw nsw i32 %.02030, %.02428
  %9 = lshr i32 %8, 1
  %10 = sext i32 %.01931 to i64
  %11 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !9
  %.not = icmp sgt i32 %5, %9
  br i1 %.not, label %13, label %21

13:                                               ; preds = %.lr.ph
  %14 = sext i32 %12 to i64
  %15 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %14, i32 2
  %16 = load i32, ptr %15, align 4, !tbaa !11
  %17 = getelementptr inbounds i8, ptr %11, i64 4
  %18 = load i32, ptr %17, align 4, !tbaa !12
  %19 = add nuw nsw i32 %9, 1
  %20 = add nsw i32 %16, %.02229
  br label %21

21:                                               ; preds = %.lr.ph, %13
  %.125 = phi i32 [ %.02428, %13 ], [ %9, %.lr.ph ]
  %.123 = phi i32 [ %20, %13 ], [ %.02229, %.lr.ph ]
  %.121 = phi i32 [ %19, %13 ], [ %.02030, %.lr.ph ]
  %.1 = phi i32 [ %18, %13 ], [ %12, %.lr.ph ]
  %22 = icmp slt i32 %.121, %.125
  br i1 %22, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %21, %.preheader
  %.022.lcssa = phi i32 [ 0, %.preheader ], [ %.123, %21 ]
  %.019.lcssa = phi i32 [ %0, %.preheader ], [ %.1, %21 ]
  %23 = sext i32 %.019.lcssa to i64
  %24 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %23, i32 2
  %25 = load i32, ptr %24, align 4, !tbaa !11
  %26 = add nsw i32 %25, %.022.lcssa
  br label %27

27:                                               ; preds = %2, %._crit_edge
  %.0 = phi i32 [ %26, %._crit_edge ], [ 0, %2 ]
  ret i32 %.0
}

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

!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 0}
!10 = !{!"_ZTS4node", !6, i64 0, !6, i64 4, !6, i64 8}
!11 = !{!10, !6, i64 8}
!12 = !{!10, !6, i64 4}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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