; LLVM IR from sunkafei/xcpc-algorithm-templates :: 算法/数据结构/可持久化线段树.ll (Z5queryiii)

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

@t = external dso_local global [2200000 x %struct.node], align 16
@mn = external dso_local global i32, align 4

; 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5queryiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  %8 = load i32, ptr %4, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [2200000 x %struct.node], ptr @t, i64 0, i64 %9
  %11 = getelementptr inbounds %struct.node, ptr %10, i32 0, i32 5
  %12 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) @mn, ptr noundef nonnull align 4 dereferenceable(4) %11)
  %13 = load i32, ptr %12, align 4, !tbaa !5
  store i32 %13, ptr @mn, align 4, !tbaa !5
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [2200000 x %struct.node], ptr @t, i64 0, i64 %16
  %18 = getelementptr inbounds %struct.node, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %18, align 8, !tbaa !9
  %20 = icmp sle i32 %14, %19
  br i1 %20, label %21, label %36

21:                                               ; preds = %3
  %22 = load i32, ptr %6, align 4, !tbaa !5
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [2200000 x %struct.node], ptr @t, i64 0, i64 %24
  %26 = getelementptr inbounds %struct.node, ptr %25, i32 0, i32 1
  %27 = load i32, ptr %26, align 4, !tbaa !11
  %28 = icmp sge i32 %22, %27
  br i1 %28, label %29, label %36

29:                                               ; preds = %21
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [2200000 x %struct.node], ptr @t, i64 0, i64 %31
  %33 = getelementptr inbounds %struct.node, ptr %32, i32 0, i32 4
  %34 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) @mn, ptr noundef nonnull align 4 dereferenceable(4) %33)
  %35 = load i32, ptr %34, align 4, !tbaa !5
  store i32 %35, ptr @mn, align 4, !tbaa !5
  br label %73

36:                                               ; preds = %21, %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [2200000 x %struct.node], ptr @t, i64 0, i64 %38
  %40 = getelementptr inbounds %struct.node, ptr %39, i32 0, i32 0
  %41 = load i32, ptr %40, align 8, !tbaa !9
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [2200000 x %struct.node], ptr @t, i64 0, i64 %43
  %45 = getelementptr inbounds %struct.node, ptr %44, i32 0, i32 1
  %46 = load i32, ptr %45, align 4, !tbaa !11
  %47 = add nsw i32 %41, %46
  %48 = ashr i32 %47, 1
  store i32 %48, ptr %7, align 4, !tbaa !5
  %49 = load i32, ptr %5, align 4, !tbaa !5
  %50 = load i32, ptr %7, align 4, !tbaa !5
  %51 = icmp sle i32 %49, %50
  br i1 %51, label %52, label %60

52:                                               ; preds = %36
  %53 = load i32, ptr %4, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [2200000 x %struct.node], ptr @t, i64 0, i64 %54
  %56 = getelementptr inbounds %struct.node, ptr %55, i32 0, i32 2
  %57 = load i32, ptr %56, align 8, !tbaa !12
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z5queryiii(i32 noundef %57, i32 noundef %58, i32 noundef %59)
  br label %60

60:                                               ; preds = %52, %36
  %61 = load i32, ptr %6, align 4, !tbaa !5
  %62 = load i32, ptr %7, align 4, !tbaa !5
  %63 = icmp sgt i32 %61, %62
  br i1 %63, label %64, label %72

64:                                               ; preds = %60
  %65 = load i32, ptr %4, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [2200000 x %struct.node], ptr @t, i64 0, i64 %66
  %68 = getelementptr inbounds %struct.node, ptr %67, i32 0, i32 3
  %69 = load i32, ptr %68, align 4, !tbaa !13
  %70 = load i32, ptr %5, align 4, !tbaa !5
  %71 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z5queryiii(i32 noundef %69, i32 noundef %70, i32 noundef %71)
  br label %72

72:                                               ; preds = %64, %60
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %73

73:                                               ; preds = %72, %29
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!10, !6, i64 0}
!10 = !{!"_ZTS4node", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20}
!11 = !{!10, !6, i64 4}
!12 = !{!10, !6, i64 8}
!13 = !{!10, !6, i64 12}


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

@t = external dso_local global [2200000 x %struct.node], align 16
@mn = external dso_local global i32, align 4

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z5queryiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = sext i32 %0 to i64
  %5 = getelementptr inbounds [2200000 x %struct.node], ptr @t, i64 0, i64 %4
  %6 = getelementptr inbounds i8, ptr %5, i64 20
  %7 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) @mn, ptr noundef nonnull align 4 dereferenceable(4) %6)
  %8 = load i32, ptr %7, align 4, !tbaa !5
  store i32 %8, ptr @mn, align 4, !tbaa !5
  %9 = load i32, ptr %5, align 8, !tbaa !9
  %.not27 = icmp slt i32 %9, %1
  %.phi.trans.insert28 = getelementptr inbounds i8, ptr %5, i64 4
  %.pre29 = load i32, ptr %.phi.trans.insert28, align 4, !tbaa !11
  %.not1930 = icmp sgt i32 %.pre29, %2
  %or.cond31 = select i1 %.not27, i1 true, i1 %.not1930
  br i1 %or.cond31, label %tailrecurse._crit_edge, label %tailrecurse._crit_edge33

tailrecurse._crit_edge33:                         ; preds = %tailrecurse, %3
  %10 = phi i64 [ %4, %3 ], [ %25, %tailrecurse ]
  %11 = getelementptr inbounds [2200000 x %struct.node], ptr @t, i64 0, i64 %10, i32 4
  %12 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) @mn, ptr noundef nonnull align 4 dereferenceable(4) %11)
  %13 = load i32, ptr %12, align 4, !tbaa !5
  store i32 %13, ptr @mn, align 4, !tbaa !5
  br label %.loopexit

tailrecurse._crit_edge:                           ; preds = %3, %tailrecurse
  %.pre32 = phi i32 [ %.pre, %tailrecurse ], [ %.pre29, %3 ]
  %14 = phi i32 [ %30, %tailrecurse ], [ %9, %3 ]
  %15 = phi ptr [ %26, %tailrecurse ], [ %5, %3 ]
  %16 = add nsw i32 %.pre32, %14
  %17 = ashr i32 %16, 1
  %.not20 = icmp slt i32 %17, %1
  br i1 %.not20, label %21, label %18

18:                                               ; preds = %tailrecurse._crit_edge
  %19 = getelementptr inbounds i8, ptr %15, i64 8
  %20 = load i32, ptr %19, align 8, !tbaa !12
  tail call void @_Z5queryiii(i32 noundef %20, i32 noundef %1, i32 noundef %2)
  br label %21

21:                                               ; preds = %18, %tailrecurse._crit_edge
  %22 = icmp slt i32 %17, %2
  br i1 %22, label %tailrecurse, label %.loopexit

tailrecurse:                                      ; preds = %21
  %23 = getelementptr inbounds i8, ptr %15, i64 12
  %24 = load i32, ptr %23, align 4, !tbaa !13
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [2200000 x %struct.node], ptr @t, i64 0, i64 %25
  %27 = getelementptr inbounds i8, ptr %26, i64 20
  %28 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) @mn, ptr noundef nonnull align 4 dereferenceable(4) %27)
  %29 = load i32, ptr %28, align 4, !tbaa !5
  store i32 %29, ptr @mn, align 4, !tbaa !5
  %30 = load i32, ptr %26, align 8, !tbaa !9
  %.not = icmp slt i32 %30, %1
  %.phi.trans.insert = getelementptr inbounds i8, ptr %26, i64 4
  %.pre = load i32, ptr %.phi.trans.insert, align 4, !tbaa !11
  %.not19 = icmp sgt i32 %.pre, %2
  %or.cond = select i1 %.not, i1 true, i1 %.not19
  br i1 %or.cond, label %tailrecurse._crit_edge, label %tailrecurse._crit_edge33

.loopexit:                                        ; preds = %21, %tailrecurse._crit_edge33
  ret void
}

attributes #0 = { 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 #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" }

!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, !6, i64 12, !6, i64 16, !6, i64 20}
!11 = !{!10, !6, i64 4}
!12 = !{!10, !6, i64 8}
!13 = !{!10, !6, i64 12}


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