; LLVM IR from lzyrapx/Competitive-Programming :: ACdream/1101（线段树）（区间替换+区间查询LCIS）.ll (Z5queryiiiii)

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

@tree = external dso_local global [493824 x %struct.Node], align 16
@lazy = external dso_local global [493824 x i32], align 16

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z9push_downiiii(i32 noundef, i32 noundef, i32 noundef, 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 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK4NodeplERKS_(ptr dead_on_unwind noalias writable sret(%struct.Node) align 4, ptr noundef nonnull align 4 dereferenceable(28), ptr noundef nonnull align 4 dereferenceable(28)) #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5queryiiiii(ptr dead_on_unwind noalias writable sret(%struct.Node) align 4 %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) #0 {
  %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
  %13 = alloca i32, align 4
  %14 = alloca %struct.Node, align 4
  %15 = alloca %struct.Node, align 4
  store i32 %1, ptr %7, align 4, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !5
  store i32 %4, ptr %10, align 4, !tbaa !5
  store i32 %5, ptr %11, align 4, !tbaa !5
  %16 = load i32, ptr %7, align 4, !tbaa !5
  %17 = load i32, ptr %10, align 4, !tbaa !5
  %18 = icmp eq i32 %16, %17
  br i1 %18, label %19, label %27

19:                                               ; preds = %6
  %20 = load i32, ptr %8, align 4, !tbaa !5
  %21 = load i32, ptr %11, align 4, !tbaa !5
  %22 = icmp eq i32 %20, %21
  br i1 %22, label %23, label %27

23:                                               ; preds = %19
  %24 = load i32, ptr %9, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [493824 x %struct.Node], ptr @tree, i64 0, i64 %25
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %0, ptr align 4 %26, i64 28, i1 false), !tbaa.struct !9
  br label %101

27:                                               ; preds = %19, %6
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %28 = load i32, ptr %7, align 4, !tbaa !5
  %29 = load i32, ptr %8, align 4, !tbaa !5
  %30 = add nsw i32 %28, %29
  %31 = ashr i32 %30, 1
  store i32 %31, ptr %12, align 4, !tbaa !5
  %32 = load i32, ptr %9, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [493824 x i32], ptr @lazy, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %37, label %59

37:                                               ; preds = %27
  %38 = load i32, ptr %7, align 4, !tbaa !5
  %39 = load i32, ptr %12, align 4, !tbaa !5
  %40 = load i32, ptr %9, align 4, !tbaa !5
  %41 = shl i32 %40, 1
  %42 = load i32, ptr %9, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [493824 x i32], ptr @lazy, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !5
  call void @_Z9push_downiiii(i32 noundef %38, i32 noundef %39, i32 noundef %41, i32 noundef %45)
  %46 = load i32, ptr %12, align 4, !tbaa !5
  %47 = add nsw i32 %46, 1
  %48 = load i32, ptr %8, align 4, !tbaa !5
  %49 = load i32, ptr %9, align 4, !tbaa !5
  %50 = shl i32 %49, 1
  %51 = or i32 %50, 1
  %52 = load i32, ptr %9, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [493824 x i32], ptr @lazy, i64 0, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !5
  call void @_Z9push_downiiii(i32 noundef %47, i32 noundef %48, i32 noundef %51, i32 noundef %55)
  %56 = load i32, ptr %9, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [493824 x i32], ptr @lazy, i64 0, i64 %57
  store i32 0, ptr %58, align 4, !tbaa !5
  br label %59

59:                                               ; preds = %37, %27
  %60 = load i32, ptr %11, align 4, !tbaa !5
  %61 = load i32, ptr %12, align 4, !tbaa !5
  %62 = icmp sle i32 %60, %61
  br i1 %62, label %63, label %70

63:                                               ; preds = %59
  %64 = load i32, ptr %7, align 4, !tbaa !5
  %65 = load i32, ptr %12, align 4, !tbaa !5
  %66 = load i32, ptr %9, align 4, !tbaa !5
  %67 = shl i32 %66, 1
  %68 = load i32, ptr %10, align 4, !tbaa !5
  %69 = load i32, ptr %11, align 4, !tbaa !5
  call void @_Z5queryiiiii(ptr dead_on_unwind writable sret(%struct.Node) align 4 %0, i32 noundef %64, i32 noundef %65, i32 noundef %67, i32 noundef %68, i32 noundef %69)
  store i32 1, ptr %13, align 4
  br label %100

70:                                               ; preds = %59
  %71 = load i32, ptr %10, align 4, !tbaa !5
  %72 = load i32, ptr %12, align 4, !tbaa !5
  %73 = icmp sgt i32 %71, %72
  br i1 %73, label %74, label %83

74:                                               ; preds = %70
  %75 = load i32, ptr %12, align 4, !tbaa !5
  %76 = add nsw i32 %75, 1
  %77 = load i32, ptr %8, align 4, !tbaa !5
  %78 = load i32, ptr %9, align 4, !tbaa !5
  %79 = shl i32 %78, 1
  %80 = or i32 %79, 1
  %81 = load i32, ptr %10, align 4, !tbaa !5
  %82 = load i32, ptr %11, align 4, !tbaa !5
  call void @_Z5queryiiiii(ptr dead_on_unwind writable sret(%struct.Node) align 4 %0, i32 noundef %76, i32 noundef %77, i32 noundef %80, i32 noundef %81, i32 noundef %82)
  store i32 1, ptr %13, align 4
  br label %100

83:                                               ; preds = %70
  br label %84

84:                                               ; preds = %83
  call void @llvm.lifetime.start.p0(i64 28, ptr %14) #3
  %85 = load i32, ptr %7, align 4, !tbaa !5
  %86 = load i32, ptr %12, align 4, !tbaa !5
  %87 = load i32, ptr %9, align 4, !tbaa !5
  %88 = shl i32 %87, 1
  %89 = load i32, ptr %10, align 4, !tbaa !5
  %90 = load i32, ptr %12, align 4, !tbaa !5
  call void @_Z5queryiiiii(ptr dead_on_unwind writable sret(%struct.Node) align 4 %14, i32 noundef %85, i32 noundef %86, i32 noundef %88, i32 noundef %89, i32 noundef %90)
  call void @llvm.lifetime.start.p0(i64 28, ptr %15) #3
  %91 = load i32, ptr %12, align 4, !tbaa !5
  %92 = add nsw i32 %91, 1
  %93 = load i32, ptr %8, align 4, !tbaa !5
  %94 = load i32, ptr %9, align 4, !tbaa !5
  %95 = shl i32 %94, 1
  %96 = or i32 %95, 1
  %97 = load i32, ptr %12, align 4, !tbaa !5
  %98 = add nsw i32 %97, 1
  %99 = load i32, ptr %11, align 4, !tbaa !5
  call void @_Z5queryiiiii(ptr dead_on_unwind writable sret(%struct.Node) align 4 %15, i32 noundef %92, i32 noundef %93, i32 noundef %96, i32 noundef %98, i32 noundef %99)
  call void @_ZNK4NodeplERKS_(ptr dead_on_unwind writable sret(%struct.Node) align 4 %0, ptr noundef nonnull align 4 dereferenceable(28) %14, ptr noundef nonnull align 4 dereferenceable(28) %15)
  call void @llvm.lifetime.end.p0(i64 28, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 28, ptr %14) #3
  store i32 1, ptr %13, align 4
  br label %100

100:                                              ; preds = %84, %74, %63
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %101

101:                                              ; preds = %100, %23
  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 = !{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, i64 24, 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, i32 }

@tree = external dso_local local_unnamed_addr global [493824 x %struct.Node], align 16
@lazy = external dso_local local_unnamed_addr global [493824 x i32], align 16

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z9push_downiiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef) 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 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK4NodeplERKS_(ptr dead_on_unwind noalias writable sret(%struct.Node) align 4, ptr noundef nonnull align 4 dereferenceable(28), ptr noundef nonnull align 4 dereferenceable(28)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5queryiiiii(ptr dead_on_unwind noalias writable sret(%struct.Node) align 4 %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) local_unnamed_addr #0 {
  %7 = alloca %struct.Node, align 4
  %8 = alloca %struct.Node, align 4
  %9 = icmp eq i32 %1, %4
  %10 = icmp eq i32 %2, %5
  %or.cond5561 = and i1 %9, %10
  br i1 %or.cond5561, label %tailrecurse.outer._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %6, %tailrecurse.outer
  %11 = phi i1 [ %40, %tailrecurse.outer ], [ %9, %6 ]
  %.tr49.ph64 = phi i32 [ %39, %tailrecurse.outer ], [ %3, %6 ]
  %.tr48.ph63 = phi i32 [ %.us-phi59, %tailrecurse.outer ], [ %2, %6 ]
  %.tr47.ph62 = phi i32 [ %38, %tailrecurse.outer ], [ %1, %6 ]
  br i1 %11, label %.lr.ph.split, label %.lr.ph.split.us

.lr.ph.split.us:                                  ; preds = %.lr.ph, %tailrecurse.us
  %.tr4957.us = phi i32 [ %.pre, %tailrecurse.us ], [ %.tr49.ph64, %.lr.ph ]
  %.tr4856.us = phi i32 [ %13, %tailrecurse.us ], [ %.tr48.ph63, %.lr.ph ]
  %12 = add i32 %.tr4856.us, %.tr47.ph62
  %13 = ashr i32 %12, 1
  %14 = sext i32 %.tr4957.us to i64
  %15 = getelementptr inbounds [493824 x i32], ptr @lazy, i64 0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %.not.us = icmp eq i32 %16, 0
  %.pre = shl i32 %.tr4957.us, 1
  br i1 %.not.us, label %tailrecurse.us, label %17

17:                                               ; preds = %.lr.ph.split.us
  tail call void @_Z9push_downiiii(i32 noundef %.tr47.ph62, i32 noundef %13, i32 noundef %.pre, i32 noundef %16)
  %18 = add nsw i32 %13, 1
  %19 = or disjoint i32 %.pre, 1
  %20 = load i32, ptr %15, align 4, !tbaa !5
  tail call void @_Z9push_downiiii(i32 noundef %18, i32 noundef %.tr4856.us, i32 noundef %19, i32 noundef %20)
  store i32 0, ptr %15, align 4, !tbaa !5
  br label %tailrecurse.us

tailrecurse.us:                                   ; preds = %.lr.ph.split.us, %17
  %.not46.us = icmp slt i32 %13, %5
  br i1 %.not46.us, label %.split.us, label %.lr.ph.split.us

tailrecurse.outer._crit_edge:                     ; preds = %tailrecurse.outer, %tailrecurse, %6
  %.tr49.lcssa = phi i32 [ %3, %6 ], [ %34, %tailrecurse ], [ %39, %tailrecurse.outer ]
  %21 = sext i32 %.tr49.lcssa to i64
  %22 = getelementptr inbounds [493824 x %struct.Node], ptr @tree, i64 0, i64 %21
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(28) %0, ptr noundef nonnull align 4 dereferenceable(28) %22, i64 28, i1 false), !tbaa.struct !9
  br label %45

.lr.ph.split:                                     ; preds = %.lr.ph, %tailrecurse
  %.tr4957 = phi i32 [ %34, %tailrecurse ], [ %.tr49.ph64, %.lr.ph ]
  %.tr4856 = phi i32 [ %24, %tailrecurse ], [ %.tr48.ph63, %.lr.ph ]
  %23 = add i32 %.tr4856, %.tr47.ph62
  %24 = ashr i32 %23, 1
  %25 = sext i32 %.tr4957 to i64
  %26 = getelementptr inbounds [493824 x i32], ptr @lazy, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %.not = icmp eq i32 %27, 0
  br i1 %.not, label %33, label %28

28:                                               ; preds = %.lr.ph.split
  %29 = shl i32 %.tr4957, 1
  tail call void @_Z9push_downiiii(i32 noundef %.tr47.ph62, i32 noundef %24, i32 noundef %29, i32 noundef %27)
  %30 = add nsw i32 %24, 1
  %31 = or disjoint i32 %29, 1
  %32 = load i32, ptr %26, align 4, !tbaa !5
  tail call void @_Z9push_downiiii(i32 noundef %30, i32 noundef %.tr4856, i32 noundef %31, i32 noundef %32)
  store i32 0, ptr %26, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %28, %.lr.ph.split
  %.not46 = icmp slt i32 %24, %5
  br i1 %.not46, label %.split.us, label %tailrecurse

tailrecurse:                                      ; preds = %33
  %34 = shl i32 %.tr4957, 1
  %35 = icmp eq i32 %24, %5
  br i1 %35, label %tailrecurse.outer._crit_edge, label %.lr.ph.split

.split.us:                                        ; preds = %tailrecurse.us, %33
  %.us-phi = phi i32 [ %24, %33 ], [ %13, %tailrecurse.us ]
  %.us-phi59 = phi i32 [ %.tr4856, %33 ], [ %.tr4856.us, %tailrecurse.us ]
  %.us-phi60 = phi i32 [ %.tr4957, %33 ], [ %.tr4957.us, %tailrecurse.us ]
  %36 = icmp slt i32 %.us-phi, %4
  %37 = shl i32 %.us-phi60, 1
  br i1 %36, label %tailrecurse.outer, label %42

tailrecurse.outer:                                ; preds = %.split.us
  %38 = add nsw i32 %.us-phi, 1
  %39 = or disjoint i32 %37, 1
  %40 = icmp eq i32 %38, %4
  %41 = icmp eq i32 %.us-phi59, %5
  %or.cond55 = and i1 %40, %41
  br i1 %or.cond55, label %tailrecurse.outer._crit_edge, label %.lr.ph

42:                                               ; preds = %.split.us
  call void @llvm.lifetime.start.p0(i64 28, ptr nonnull %7) #3
  call void @_Z5queryiiiii(ptr dead_on_unwind nonnull writable sret(%struct.Node) align 4 %7, i32 noundef %.tr47.ph62, i32 noundef %.us-phi, i32 noundef %37, i32 noundef %4, i32 noundef %.us-phi)
  call void @llvm.lifetime.start.p0(i64 28, ptr nonnull %8) #3
  %43 = add nsw i32 %.us-phi, 1
  %44 = or disjoint i32 %37, 1
  call void @_Z5queryiiiii(ptr dead_on_unwind nonnull writable sret(%struct.Node) align 4 %8, i32 noundef %43, i32 noundef %.us-phi59, i32 noundef %44, i32 noundef %43, i32 noundef %5)
  call void @_ZNK4NodeplERKS_(ptr dead_on_unwind writable sret(%struct.Node) align 4 %0, ptr noundef nonnull align 4 dereferenceable(28) %7, ptr noundef nonnull align 4 dereferenceable(28) %8)
  call void @llvm.lifetime.end.p0(i64 28, ptr nonnull %8) #3
  call void @llvm.lifetime.end.p0(i64 28, ptr nonnull %7) #3
  br label %45

45:                                               ; preds = %42, %tailrecurse.outer._crit_edge
  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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{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, i64 24, i64 4, !5}


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