; LLVM IR from Tunghohin/Competitive_Coding :: Luogu/p4513.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 }

@tr = external dso_local global [2000040 x %struct.Node], align 16

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z7push_upR4NodeS0_S0_(ptr noundef nonnull align 4 dereferenceable(24), ptr noundef nonnull align 4 dereferenceable(24), ptr noundef nonnull align 4 dereferenceable(24)) #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: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5queryiii(ptr dead_on_unwind noalias writable sret(%struct.Node) align 4 %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %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 %struct.Node, align 4
  %11 = alloca %struct.Node, align 4
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  store i32 %3, ptr %7, align 4, !tbaa !5
  %12 = load i32, ptr %5, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [2000040 x %struct.Node], ptr @tr, i64 0, i64 %13
  %15 = getelementptr inbounds %struct.Node, ptr %14, i32 0, i32 0
  %16 = load i32, ptr %15, align 8, !tbaa !9
  %17 = load i32, ptr %6, align 4, !tbaa !5
  %18 = icmp sge i32 %16, %17
  br i1 %18, label %19, label %31

19:                                               ; preds = %4
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [2000040 x %struct.Node], ptr @tr, i64 0, i64 %21
  %23 = getelementptr inbounds %struct.Node, ptr %22, i32 0, i32 1
  %24 = load i32, ptr %23, align 4, !tbaa !11
  %25 = load i32, ptr %7, align 4, !tbaa !5
  %26 = icmp sle i32 %24, %25
  br i1 %26, label %27, label %31

27:                                               ; preds = %19
  %28 = load i32, ptr %5, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [2000040 x %struct.Node], ptr @tr, i64 0, i64 %29
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %0, ptr align 8 %30, i64 24, i1 false), !tbaa.struct !12
  br label %73

31:                                               ; preds = %19, %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %32 = load i32, ptr %5, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [2000040 x %struct.Node], ptr @tr, i64 0, i64 %33
  %35 = getelementptr inbounds %struct.Node, ptr %34, i32 0, i32 0
  %36 = load i32, ptr %35, align 8, !tbaa !9
  %37 = load i32, ptr %5, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [2000040 x %struct.Node], ptr @tr, i64 0, i64 %38
  %40 = getelementptr inbounds %struct.Node, ptr %39, i32 0, i32 1
  %41 = load i32, ptr %40, align 4, !tbaa !11
  %42 = add nsw i32 %36, %41
  %43 = ashr i32 %42, 1
  store i32 %43, ptr %8, align 4, !tbaa !5
  %44 = load i32, ptr %7, align 4, !tbaa !5
  %45 = load i32, ptr %8, align 4, !tbaa !5
  %46 = icmp sle i32 %44, %45
  br i1 %46, label %47, label %52

47:                                               ; preds = %31
  %48 = load i32, ptr %5, align 4, !tbaa !5
  %49 = shl i32 %48, 1
  %50 = load i32, ptr %6, align 4, !tbaa !5
  %51 = load i32, ptr %7, align 4, !tbaa !5
  call void @_Z5queryiii(ptr dead_on_unwind writable sret(%struct.Node) align 4 %0, i32 noundef %49, i32 noundef %50, i32 noundef %51)
  store i32 1, ptr %9, align 4
  br label %72

52:                                               ; preds = %31
  %53 = load i32, ptr %6, align 4, !tbaa !5
  %54 = load i32, ptr %8, align 4, !tbaa !5
  %55 = icmp sgt i32 %53, %54
  br i1 %55, label %56, label %62

56:                                               ; preds = %52
  %57 = load i32, ptr %5, align 4, !tbaa !5
  %58 = shl i32 %57, 1
  %59 = or i32 %58, 1
  %60 = load i32, ptr %6, align 4, !tbaa !5
  %61 = load i32, ptr %7, align 4, !tbaa !5
  call void @_Z5queryiii(ptr dead_on_unwind writable sret(%struct.Node) align 4 %0, i32 noundef %59, i32 noundef %60, i32 noundef %61)
  store i32 1, ptr %9, align 4
  br label %72

62:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 24, ptr %10) #3
  %63 = load i32, ptr %5, align 4, !tbaa !5
  %64 = shl i32 %63, 1
  %65 = load i32, ptr %6, align 4, !tbaa !5
  %66 = load i32, ptr %7, align 4, !tbaa !5
  call void @_Z5queryiii(ptr dead_on_unwind writable sret(%struct.Node) align 4 %10, i32 noundef %64, i32 noundef %65, i32 noundef %66)
  call void @llvm.lifetime.start.p0(i64 24, ptr %11) #3
  %67 = load i32, ptr %5, align 4, !tbaa !5
  %68 = shl i32 %67, 1
  %69 = or i32 %68, 1
  %70 = load i32, ptr %6, align 4, !tbaa !5
  %71 = load i32, ptr %7, align 4, !tbaa !5
  call void @_Z5queryiii(ptr dead_on_unwind writable sret(%struct.Node) align 4 %11, i32 noundef %69, i32 noundef %70, i32 noundef %71)
  call void @_Z7push_upR4NodeS0_S0_(ptr noundef nonnull align 4 dereferenceable(24) %0, ptr noundef nonnull align 4 dereferenceable(24) %10, ptr noundef nonnull align 4 dereferenceable(24) %11)
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 24, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %10) #3
  br label %72

72:                                               ; preds = %62, %56, %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %73

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

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{i64 0, i64 4, !5, i64 4, i64 4, !5, i64 8, i64 4, !5, i64 12, i64 4, !5, i64 16, i64 4, !5, i64 20, i64 4, !5}


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

@tr = external dso_local local_unnamed_addr global [2000040 x %struct.Node], align 16

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

; 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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5queryiii(ptr dead_on_unwind noalias writable sret(%struct.Node) align 4 %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = alloca %struct.Node, align 4
  %6 = alloca %struct.Node, align 4
  %7 = sext i32 %1 to i64
  %8 = getelementptr inbounds [2000040 x %struct.Node], ptr @tr, i64 0, i64 %7
  %9 = load i32, ptr %8, align 8, !tbaa !5
  %.not39 = icmp slt i32 %9, %2
  %.phi.trans.insert40 = getelementptr inbounds i8, ptr %8, i64 4
  %.pre41 = load i32, ptr %.phi.trans.insert40, align 4, !tbaa !10
  %.not2642 = icmp sgt i32 %.pre41, %3
  %or.cond43 = select i1 %.not39, i1 true, i1 %.not2642
  br i1 %or.cond43, label %tailrecurse._crit_edge, label %tailrecurse._crit_edge46

tailrecurse._crit_edge46:                         ; preds = %tailrecurse.backedge, %4
  %.lcssa = phi ptr [ %8, %4 ], [ %16, %tailrecurse.backedge ]
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(24) %.lcssa, i64 24, i1 false), !tbaa.struct !11
  br label %26

tailrecurse._crit_edge:                           ; preds = %4, %tailrecurse.backedge
  %.pre45 = phi i32 [ %.pre, %tailrecurse.backedge ], [ %.pre41, %4 ]
  %10 = phi i32 [ %17, %tailrecurse.backedge ], [ %9, %4 ]
  %.tr2844 = phi i32 [ %.tr28.be, %tailrecurse.backedge ], [ %1, %4 ]
  %11 = add nsw i32 %.pre45, %10
  %12 = ashr i32 %11, 1
  %.not27 = icmp slt i32 %12, %3
  br i1 %.not27, label %18, label %13

13:                                               ; preds = %tailrecurse._crit_edge
  %14 = shl i32 %.tr2844, 1
  br label %tailrecurse.backedge

tailrecurse.backedge:                             ; preds = %13, %20
  %.tr28.be = phi i32 [ %14, %13 ], [ %22, %20 ]
  %15 = sext i32 %.tr28.be to i64
  %16 = getelementptr inbounds [2000040 x %struct.Node], ptr @tr, i64 0, i64 %15
  %17 = load i32, ptr %16, align 8, !tbaa !5
  %.not = icmp slt i32 %17, %2
  %.phi.trans.insert = getelementptr inbounds i8, ptr %16, i64 4
  %.pre = load i32, ptr %.phi.trans.insert, align 4, !tbaa !10
  %.not26 = icmp sgt i32 %.pre, %3
  %or.cond = select i1 %.not, i1 true, i1 %.not26
  br i1 %or.cond, label %tailrecurse._crit_edge, label %tailrecurse._crit_edge46

18:                                               ; preds = %tailrecurse._crit_edge
  %19 = icmp slt i32 %12, %2
  br i1 %19, label %20, label %23

20:                                               ; preds = %18
  %21 = shl i32 %.tr2844, 1
  %22 = or disjoint i32 %21, 1
  br label %tailrecurse.backedge

23:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %5) #3
  %24 = shl i32 %.tr2844, 1
  call void @_Z5queryiii(ptr dead_on_unwind nonnull writable sret(%struct.Node) align 4 %5, i32 noundef %24, i32 noundef %2, i32 noundef %3)
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %6) #3
  %25 = or disjoint i32 %24, 1
  call void @_Z5queryiii(ptr dead_on_unwind nonnull writable sret(%struct.Node) align 4 %6, i32 noundef %25, i32 noundef %2, i32 noundef %3)
  call void @_Z7push_upR4NodeS0_S0_(ptr noundef nonnull align 4 dereferenceable(24) %0, ptr noundef nonnull align 4 dereferenceable(24) %5, ptr noundef nonnull align 4 dereferenceable(24) %6)
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %5) #3
  br label %26

26:                                               ; preds = %23, %tailrecurse._crit_edge46
  ret void
}

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !7, i64 0}
!6 = !{!"_ZTS4Node", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 4}
!11 = !{i64 0, i64 4, !12, i64 4, i64 4, !12, i64 8, i64 4, !12, i64 12, i64 4, !12, i64 16, i64 4, !12, i64 20, i64 4, !12}
!12 = !{!7, !7, i64 0}


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