; LLVM IR from lzyrapx/Competitive-Programming :: Retired_code/CDQ Divide and Conquer/bzoj 3262（三维偏序）.ll (Z3cdqii)

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

@q = external dso_local global [200010 x %struct.Query], align 16

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z6updateii(i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z5queryi(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 nounwind uwtable
declare dso_local noundef zeroext i1 @_Z4cmpy5QueryS_(ptr noundef byval(%struct.Query) align 8, ptr noundef byval(%struct.Query) align 8) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3cdqii(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
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = icmp sge i32 %9, %10
  br i1 %11, label %12, label %13

12:                                               ; preds = %2
  br label %118

13:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = add nsw i32 %14, %15
  %17 = ashr i32 %16, 1
  store i32 %17, ptr %5, align 4, !tbaa !5
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = load i32, ptr %5, align 4, !tbaa !5
  call void @_Z3cdqii(i32 noundef %18, i32 noundef %19)
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  %22 = load i32, ptr %4, align 4, !tbaa !5
  call void @_Z3cdqii(i32 noundef %21, i32 noundef %22)
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds %struct.Query, ptr @q, i64 %24
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds %struct.Query, ptr @q, i64 %27
  %29 = getelementptr inbounds %struct.Query, ptr %28, i64 1
  call void @_ZSt4sortIP5QueryPFbS0_S0_EEvT_S4_T0_(ptr noundef %25, ptr noundef %29, ptr noundef @_Z4cmpy5QueryS_)
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds %struct.Query, ptr @q, i64 %31
  %33 = getelementptr inbounds %struct.Query, ptr %32, i64 1
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds %struct.Query, ptr @q, i64 %35
  %37 = getelementptr inbounds %struct.Query, ptr %36, i64 1
  call void @_ZSt4sortIP5QueryPFbS0_S0_EEvT_S4_T0_(ptr noundef %33, ptr noundef %37, ptr noundef @_Z4cmpy5QueryS_)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %38 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %38, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %7, align 4, !tbaa !5
  %41 = load i32, ptr %5, align 4, !tbaa !5
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %7, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %92, %13
  %44 = load i32, ptr %7, align 4, !tbaa !5
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = icmp sle i32 %44, %45
  br i1 %46, label %47, label %95

47:                                               ; preds = %43
  br label %48

48:                                               ; preds = %66, %47
  %49 = load i32, ptr %6, align 4, !tbaa !5
  %50 = load i32, ptr %5, align 4, !tbaa !5
  %51 = icmp sle i32 %49, %50
  br i1 %51, label %52, label %64

52:                                               ; preds = %48
  %53 = load i32, ptr %6, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [200010 x %struct.Query], ptr @q, i64 0, i64 %54
  %56 = getelementptr inbounds %struct.Query, ptr %55, i32 0, i32 1
  %57 = load i32, ptr %56, align 4, !tbaa !9
  %58 = load i32, ptr %7, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [200010 x %struct.Query], ptr @q, i64 0, i64 %59
  %61 = getelementptr inbounds %struct.Query, ptr %60, i32 0, i32 1
  %62 = load i32, ptr %61, align 4, !tbaa !9
  %63 = icmp sle i32 %57, %62
  br label %64

64:                                               ; preds = %52, %48
  %65 = phi i1 [ false, %48 ], [ %63, %52 ]
  br i1 %65, label %66, label %79

66:                                               ; preds = %64
  %67 = load i32, ptr %6, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [200010 x %struct.Query], ptr @q, i64 0, i64 %68
  %70 = getelementptr inbounds %struct.Query, ptr %69, i32 0, i32 2
  %71 = load i32, ptr %70, align 4, !tbaa !11
  %72 = load i32, ptr %6, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [200010 x %struct.Query], ptr @q, i64 0, i64 %73
  %75 = getelementptr inbounds %struct.Query, ptr %74, i32 0, i32 4
  %76 = load i32, ptr %75, align 4, !tbaa !12
  call void @_Z6updateii(i32 noundef %71, i32 noundef %76)
  %77 = load i32, ptr %6, align 4, !tbaa !5
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %6, align 4, !tbaa !5
  br label %48, !llvm.loop !13

79:                                               ; preds = %64
  %80 = load i32, ptr %7, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [200010 x %struct.Query], ptr @q, i64 0, i64 %81
  %83 = getelementptr inbounds %struct.Query, ptr %82, i32 0, i32 2
  %84 = load i32, ptr %83, align 4, !tbaa !11
  %85 = call noundef i32 @_Z5queryi(i32 noundef %84)
  %86 = load i32, ptr %7, align 4, !tbaa !5
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [200010 x %struct.Query], ptr @q, i64 0, i64 %87
  %89 = getelementptr inbounds %struct.Query, ptr %88, i32 0, i32 3
  %90 = load i32, ptr %89, align 4, !tbaa !15
  %91 = add nsw i32 %90, %85
  store i32 %91, ptr %89, align 4, !tbaa !15
  br label %92

92:                                               ; preds = %79
  %93 = load i32, ptr %7, align 4, !tbaa !5
  %94 = add nsw i32 %93, 1
  store i32 %94, ptr %7, align 4, !tbaa !5
  br label %43, !llvm.loop !16

95:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %96 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %96, ptr %8, align 4, !tbaa !5
  br label %97

97:                                               ; preds = %114, %95
  %98 = load i32, ptr %8, align 4, !tbaa !5
  %99 = load i32, ptr %6, align 4, !tbaa !5
  %100 = icmp slt i32 %98, %99
  br i1 %100, label %102, label %101

101:                                              ; preds = %97
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %117

102:                                              ; preds = %97
  %103 = load i32, ptr %8, align 4, !tbaa !5
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds [200010 x %struct.Query], ptr @q, i64 0, i64 %104
  %106 = getelementptr inbounds %struct.Query, ptr %105, i32 0, i32 2
  %107 = load i32, ptr %106, align 4, !tbaa !11
  %108 = load i32, ptr %8, align 4, !tbaa !5
  %109 = sext i32 %108 to i64
  %110 = getelementptr inbounds [200010 x %struct.Query], ptr @q, i64 0, i64 %109
  %111 = getelementptr inbounds %struct.Query, ptr %110, i32 0, i32 4
  %112 = load i32, ptr %111, align 4, !tbaa !12
  %113 = sub nsw i32 0, %112
  call void @_Z6updateii(i32 noundef %107, i32 noundef %113)
  br label %114

114:                                              ; preds = %102
  %115 = load i32, ptr %8, align 4, !tbaa !5
  %116 = add nsw i32 %115, 1
  store i32 %116, ptr %8, align 4, !tbaa !5
  br label %97, !llvm.loop !17

117:                                              ; preds = %101
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %118

118:                                              ; preds = %117, %12
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIP5QueryPFbS0_S0_EEvT_S4_T0_(ptr noundef, ptr noundef, ptr noundef) #3

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 = { 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 #3 = { inlinehint 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 #4 = { 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 4}
!10 = !{!"_ZTS5Query", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16}
!11 = !{!10, !6, i64 8}
!12 = !{!10, !6, i64 16}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!10, !6, i64 12}
!16 = distinct !{!16, !14}
!17 = distinct !{!17, !14}


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

@q = external dso_local global [200010 x %struct.Query], align 16

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z4cmpy5QueryS_(ptr noundef byval(%struct.Query) align 8, ptr noundef byval(%struct.Query) align 8) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3cdqii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %.not = icmp slt i32 %0, %1
  br i1 %.not, label %3, label %.loopexit

3:                                                ; preds = %2
  %4 = add nsw i32 %1, %0
  %5 = ashr i32 %4, 1
  tail call void @_Z3cdqii(i32 noundef %0, i32 noundef %5)
  %6 = add nsw i32 %5, 1
  tail call void @_Z3cdqii(i32 noundef %6, i32 noundef %1)
  %7 = sext i32 %0 to i64
  %8 = getelementptr inbounds %struct.Query, ptr @q, i64 %7
  %9 = sext i32 %5 to i64
  %10 = getelementptr inbounds %struct.Query, ptr @q, i64 %9
  %11 = getelementptr inbounds i8, ptr %10, i64 20
  tail call void @_ZSt4sortIP5QueryPFbS0_S0_EEvT_S4_T0_(ptr noundef nonnull %8, ptr noundef nonnull %11, ptr noundef nonnull @_Z4cmpy5QueryS_)
  %12 = sext i32 %1 to i64
  %13 = getelementptr inbounds %struct.Query, ptr @q, i64 %12
  %14 = getelementptr inbounds i8, ptr %13, i64 20
  tail call void @_ZSt4sortIP5QueryPFbS0_S0_EEvT_S4_T0_(ptr noundef nonnull %11, ptr noundef nonnull %14, ptr noundef nonnull @_Z4cmpy5QueryS_)
  %.not3745.not = icmp slt i32 %5, %1
  br i1 %.not3745.not, label %.preheader40.preheader, label %.loopexit

.preheader40.preheader:                           ; preds = %3
  %15 = add nsw i64 %9, 1
  %16 = add i32 %1, 1
  br label %.preheader40

.preheader40:                                     ; preds = %.preheader40.preheader, %.critedge
  %indvars.iv52 = phi i64 [ %15, %.preheader40.preheader ], [ %indvars.iv.next53, %.critedge ]
  %.03446 = phi i32 [ %0, %.preheader40.preheader ], [ %.1.lcssa, %.critedge ]
  %.not3841 = icmp sgt i32 %.03446, %5
  br i1 %.not3841, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader40
  %17 = getelementptr inbounds [200010 x %struct.Query], ptr @q, i64 0, i64 %indvars.iv52, i32 1
  %18 = sext i32 %.03446 to i64
  br label %20

.preheader:                                       ; preds = %.critedge
  %19 = icmp sgt i32 %.1.lcssa, %0
  br i1 %19, label %.lr.ph50, label %.loopexit

20:                                               ; preds = %.lr.ph, %25
  %indvars.iv = phi i64 [ %18, %.lr.ph ], [ %indvars.iv.next, %25 ]
  %21 = getelementptr inbounds [200010 x %struct.Query], ptr @q, i64 0, i64 %indvars.iv
  %22 = getelementptr inbounds i8, ptr %21, i64 4
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = load i32, ptr %17, align 4, !tbaa !5
  %.not39 = icmp sgt i32 %23, %24
  br i1 %.not39, label %.critedge.loopexit.split.loop.exit61, label %25

25:                                               ; preds = %20
  %26 = getelementptr inbounds i8, ptr %21, i64 8
  %27 = load i32, ptr %26, align 4, !tbaa !10
  %28 = getelementptr inbounds i8, ptr %21, i64 16
  %29 = load i32, ptr %28, align 4, !tbaa !11
  tail call void @_Z6updateii(i32 noundef %27, i32 noundef %29)
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %.not38.not = icmp slt i64 %indvars.iv, %9
  br i1 %.not38.not, label %20, label %.critedge, !llvm.loop !12

.critedge.loopexit.split.loop.exit61:             ; preds = %20
  %30 = trunc nsw i64 %indvars.iv to i32
  br label %.critedge

.critedge:                                        ; preds = %25, %.critedge.loopexit.split.loop.exit61, %.preheader40
  %.1.lcssa = phi i32 [ %.03446, %.preheader40 ], [ %30, %.critedge.loopexit.split.loop.exit61 ], [ %6, %25 ]
  %31 = getelementptr inbounds [200010 x %struct.Query], ptr @q, i64 0, i64 %indvars.iv52
  %32 = getelementptr inbounds i8, ptr %31, i64 8
  %33 = load i32, ptr %32, align 4, !tbaa !10
  %34 = tail call noundef i32 @_Z5queryi(i32 noundef %33)
  %35 = getelementptr inbounds i8, ptr %31, i64 12
  %36 = load i32, ptr %35, align 4, !tbaa !14
  %37 = add nsw i32 %36, %34
  store i32 %37, ptr %35, align 4, !tbaa !14
  %indvars.iv.next53 = add nsw i64 %indvars.iv52, 1
  %lftr.wideiv = trunc i64 %indvars.iv.next53 to i32
  %exitcond.not = icmp eq i32 %16, %lftr.wideiv
  br i1 %exitcond.not, label %.preheader, label %.preheader40, !llvm.loop !15

.lr.ph50:                                         ; preds = %.preheader, %.lr.ph50
  %indvars.iv55 = phi i64 [ %indvars.iv.next56, %.lr.ph50 ], [ %7, %.preheader ]
  %38 = getelementptr inbounds [200010 x %struct.Query], ptr @q, i64 0, i64 %indvars.iv55
  %39 = getelementptr inbounds i8, ptr %38, i64 8
  %40 = load i32, ptr %39, align 4, !tbaa !10
  %41 = getelementptr inbounds i8, ptr %38, i64 16
  %42 = load i32, ptr %41, align 4, !tbaa !11
  %43 = sub nsw i32 0, %42
  tail call void @_Z6updateii(i32 noundef %40, i32 noundef %43)
  %indvars.iv.next56 = add nsw i64 %indvars.iv55, 1
  %lftr.wideiv58 = trunc i64 %indvars.iv.next56 to i32
  %exitcond59.not = icmp eq i32 %.1.lcssa, %lftr.wideiv58
  br i1 %exitcond59.not, label %.loopexit, label %.lr.ph50, !llvm.loop !16

.loopexit:                                        ; preds = %.lr.ph50, %3, %.preheader, %2
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIP5QueryPFbS0_S0_EEvT_S4_T0_(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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 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 = { inlinehint 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, !7, i64 4}
!6 = !{!"_ZTS5Query", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = !{!6, !7, i64 16}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!6, !7, i64 12}
!15 = distinct !{!15, !13}
!16 = distinct !{!16, !13}


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