; LLVM IR from sunkafei/xcpc-algorithm-templates :: 算法/数据结构/动态开点线段树.ll (Z5queryRiiiii)

; 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.segment = type { i32, i32, i32, i32, i32, i32, i32 }

@tot = external dso_local global i32, align 4
@mn = external dso_local global i32, align 4
@mx = external dso_local global i32, align 4
@t = external dso_local global [840000 x %struct.segment], align 16

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5queryRiiiii(ptr noundef nonnull align 4 dereferenceable(4) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #2 {
  %6 = alloca ptr, align 8
  %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
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !9
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_Z7newnodeRi(ptr noundef nonnull align 4 dereferenceable(4) %12)
  %13 = load i32, ptr %7, align 4, !tbaa !9
  %14 = load i32, ptr %9, align 4, !tbaa !9
  %15 = icmp sle i32 %13, %14
  br i1 %15, label %16, label %43

16:                                               ; preds = %5
  %17 = load i32, ptr %8, align 4, !tbaa !9
  %18 = load i32, ptr %10, align 4, !tbaa !9
  %19 = icmp sge i32 %17, %18
  br i1 %19, label %20, label %43

20:                                               ; preds = %16
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = load i32, ptr %21, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [840000 x %struct.segment], ptr @t, i64 0, i64 %23
  %25 = getelementptr inbounds %struct.segment, ptr %24, i32 0, i32 2
  %26 = load i32, ptr %25, align 4, !tbaa !11
  %27 = load i32, ptr @tot, align 4, !tbaa !9
  %28 = add nsw i32 %27, %26
  store i32 %28, ptr @tot, align 4, !tbaa !9
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = load i32, ptr %29, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [840000 x %struct.segment], ptr @t, i64 0, i64 %31
  %33 = getelementptr inbounds %struct.segment, ptr %32, i32 0, i32 3
  %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 !9
  store i32 %35, ptr @mn, align 4, !tbaa !9
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = load i32, ptr %36, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [840000 x %struct.segment], ptr @t, i64 0, i64 %38
  %40 = getelementptr inbounds %struct.segment, ptr %39, i32 0, i32 4
  %41 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) @mx, ptr noundef nonnull align 4 dereferenceable(4) %40)
  %42 = load i32, ptr %41, align 4, !tbaa !9
  store i32 %42, ptr @mx, align 4, !tbaa !9
  br label %81

43:                                               ; preds = %16, %5
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = load i32, ptr %44, align 4, !tbaa !9
  %46 = load i32, ptr %9, align 4, !tbaa !9
  %47 = load i32, ptr %10, align 4, !tbaa !9
  call void @_Z8pushdowniii(i32 noundef %45, i32 noundef %46, i32 noundef %47)
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %48 = load i32, ptr %9, align 4, !tbaa !9
  %49 = load i32, ptr %10, align 4, !tbaa !9
  %50 = add nsw i32 %48, %49
  %51 = ashr i32 %50, 1
  store i32 %51, ptr %11, align 4, !tbaa !9
  %52 = load i32, ptr %7, align 4, !tbaa !9
  %53 = load i32, ptr %11, align 4, !tbaa !9
  %54 = icmp sle i32 %52, %53
  br i1 %54, label %55, label %65

55:                                               ; preds = %43
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = load i32, ptr %56, align 4, !tbaa !9
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [840000 x %struct.segment], ptr @t, i64 0, i64 %58
  %60 = getelementptr inbounds %struct.segment, ptr %59, i32 0, i32 0
  %61 = load i32, ptr %7, align 4, !tbaa !9
  %62 = load i32, ptr %8, align 4, !tbaa !9
  %63 = load i32, ptr %9, align 4, !tbaa !9
  %64 = load i32, ptr %11, align 4, !tbaa !9
  call void @_Z5queryRiiiii(ptr noundef nonnull align 4 dereferenceable(4) %60, i32 noundef %61, i32 noundef %62, i32 noundef %63, i32 noundef %64)
  br label %65

65:                                               ; preds = %55, %43
  %66 = load i32, ptr %8, align 4, !tbaa !9
  %67 = load i32, ptr %11, align 4, !tbaa !9
  %68 = icmp sgt i32 %66, %67
  br i1 %68, label %69, label %80

69:                                               ; preds = %65
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = load i32, ptr %70, align 4, !tbaa !9
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [840000 x %struct.segment], ptr @t, i64 0, i64 %72
  %74 = getelementptr inbounds %struct.segment, ptr %73, i32 0, i32 1
  %75 = load i32, ptr %7, align 4, !tbaa !9
  %76 = load i32, ptr %8, align 4, !tbaa !9
  %77 = load i32, ptr %11, align 4, !tbaa !9
  %78 = add nsw i32 %77, 1
  %79 = load i32, ptr %10, align 4, !tbaa !9
  call void @_Z5queryRiiiii(ptr noundef nonnull align 4 dereferenceable(4) %74, i32 noundef %75, i32 noundef %76, i32 noundef %78, i32 noundef %79)
  br label %80

80:                                               ; preds = %69, %65
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %81

81:                                               ; preds = %80, %20
  ret void
}

; 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)) #0

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

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


; 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.segment = type { i32, i32, i32, i32, i32, i32, i32 }

@tot = external dso_local local_unnamed_addr global i32, align 4
@mn = external dso_local global i32, align 4
@mx = external dso_local global i32, align 4
@t = external dso_local global [840000 x %struct.segment], align 16

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z8pushdowniii(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z5queryRiiiii(ptr noundef nonnull align 4 dereferenceable(4) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #1 {
  tail call void @_Z7newnodeRi(ptr noundef nonnull align 4 dereferenceable(4) %0)
  %.not35 = icmp sgt i32 %1, %3
  %.not28 = icmp slt i32 %2, %4
  %or.cond36 = or i1 %.not28, %.not35
  br i1 %or.cond36, label %.lr.ph, label %tailrecurse._crit_edge

.lr.ph:                                           ; preds = %5
  br i1 %.not28, label %.lr.ph.split.us, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph, %tailrecurse.us
  %.tr3238.us = phi i32 [ %18, %tailrecurse.us ], [ %3, %.lr.ph ]
  %.tr37.us = phi ptr [ %17, %tailrecurse.us ], [ %0, %.lr.ph ]
  %6 = load i32, ptr %.tr37.us, align 4, !tbaa !5
  tail call void @_Z8pushdowniii(i32 noundef %6, i32 noundef %.tr3238.us, i32 noundef %4)
  %7 = add nsw i32 %.tr3238.us, %4
  %8 = ashr i32 %7, 1
  %.not29.us = icmp slt i32 %8, %1
  br i1 %.not29.us, label %13, label %9

9:                                                ; preds = %.lr.ph.split.us
  %10 = load i32, ptr %.tr37.us, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [840000 x %struct.segment], ptr @t, i64 0, i64 %11
  tail call void @_Z5queryRiiiii(ptr noundef nonnull align 4 dereferenceable(4) %12, i32 noundef %1, i32 noundef %2, i32 noundef %.tr3238.us, i32 noundef %8)
  br label %13

13:                                               ; preds = %9, %.lr.ph.split.us
  %14 = icmp slt i32 %8, %2
  br i1 %14, label %tailrecurse.us, label %.loopexit

tailrecurse.us:                                   ; preds = %13
  %15 = load i32, ptr %.tr37.us, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [840000 x %struct.segment], ptr @t, i64 0, i64 %16, i32 1
  %18 = add nsw i32 %8, 1
  tail call void @_Z7newnodeRi(ptr noundef nonnull align 4 dereferenceable(4) %17)
  br label %.lr.ph.split.us

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %5
  %.tr.lcssa = phi ptr [ %0, %5 ], [ %46, %tailrecurse ]
  %19 = load i32, ptr %.tr.lcssa, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [840000 x %struct.segment], ptr @t, i64 0, i64 %20, i32 2
  %22 = load i32, ptr %21, align 4, !tbaa !9
  %23 = load i32, ptr @tot, align 4, !tbaa !5
  %24 = add nsw i32 %23, %22
  store i32 %24, ptr @tot, align 4, !tbaa !5
  %25 = load i32, ptr %.tr.lcssa, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [840000 x %struct.segment], ptr @t, i64 0, i64 %26, i32 3
  %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 %.tr.lcssa, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [840000 x %struct.segment], ptr @t, i64 0, i64 %31, i32 4
  %33 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) @mx, ptr noundef nonnull align 4 dereferenceable(4) %32)
  %34 = load i32, ptr %33, align 4, !tbaa !5
  store i32 %34, ptr @mx, align 4, !tbaa !5
  br label %.loopexit

.lr.ph.split:                                     ; preds = %.lr.ph, %tailrecurse
  %.tr3238 = phi i32 [ %47, %tailrecurse ], [ %3, %.lr.ph ]
  %.tr37 = phi ptr [ %46, %tailrecurse ], [ %0, %.lr.ph ]
  %35 = load i32, ptr %.tr37, align 4, !tbaa !5
  tail call void @_Z8pushdowniii(i32 noundef %35, i32 noundef %.tr3238, i32 noundef %4)
  %36 = add nsw i32 %.tr3238, %4
  %37 = ashr i32 %36, 1
  %.not29 = icmp slt i32 %37, %1
  br i1 %.not29, label %42, label %38

38:                                               ; preds = %.lr.ph.split
  %39 = load i32, ptr %.tr37, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [840000 x %struct.segment], ptr @t, i64 0, i64 %40
  tail call void @_Z5queryRiiiii(ptr noundef nonnull align 4 dereferenceable(4) %41, i32 noundef %1, i32 noundef %2, i32 noundef %.tr3238, i32 noundef %37)
  br label %42

42:                                               ; preds = %38, %.lr.ph.split
  %43 = icmp slt i32 %37, %2
  br i1 %43, label %tailrecurse, label %.loopexit

tailrecurse:                                      ; preds = %42
  %44 = load i32, ptr %.tr37, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [840000 x %struct.segment], ptr @t, i64 0, i64 %45, i32 1
  %47 = add nsw i32 %37, 1
  tail call void @_Z7newnodeRi(ptr noundef nonnull align 4 dereferenceable(4) %46)
  %.not = icmp slt i32 %47, %1
  br i1 %.not, label %.lr.ph.split, label %tailrecurse._crit_edge

.loopexit:                                        ; preds = %42, %13, %tailrecurse._crit_edge
  ret void
}

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

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 8}
!10 = !{!"_ZTS7segment", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24}


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