; LLVM IR from lzyrapx/Competitive-Programming :: Retired_code/CDQ Divide and Conquer/HDU 5618（三维偏序）.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, i32 }

@a = 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 %107

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 @a, i64 %24
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds %struct.Query, ptr @a, 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 @a, 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 @a, 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 = %87, %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 %90

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 @a, 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 @a, 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 %74

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 @a, i64 0, i64 %68
  %70 = getelementptr inbounds %struct.Query, ptr %69, i32 0, i32 2
  %71 = load i32, ptr %70, align 8, !tbaa !11
  call void @_Z6updateii(i32 noundef %71, i32 noundef 1)
  %72 = load i32, ptr %6, align 4, !tbaa !5
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %6, align 4, !tbaa !5
  br label %48, !llvm.loop !12

74:                                               ; preds = %64
  %75 = load i32, ptr %7, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [200010 x %struct.Query], ptr @a, i64 0, i64 %76
  %78 = getelementptr inbounds %struct.Query, ptr %77, i32 0, i32 2
  %79 = load i32, ptr %78, align 8, !tbaa !11
  %80 = call noundef i32 @_Z5queryi(i32 noundef %79)
  %81 = load i32, ptr %7, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [200010 x %struct.Query], ptr @a, i64 0, i64 %82
  %84 = getelementptr inbounds %struct.Query, ptr %83, i32 0, i32 3
  %85 = load i32, ptr %84, align 4, !tbaa !14
  %86 = add nsw i32 %85, %80
  store i32 %86, ptr %84, align 4, !tbaa !14
  br label %87

87:                                               ; preds = %74
  %88 = load i32, ptr %7, align 4, !tbaa !5
  %89 = add nsw i32 %88, 1
  store i32 %89, ptr %7, align 4, !tbaa !5
  br label %43, !llvm.loop !15

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

92:                                               ; preds = %103, %90
  %93 = load i32, ptr %8, align 4, !tbaa !5
  %94 = load i32, ptr %6, align 4, !tbaa !5
  %95 = icmp slt i32 %93, %94
  br i1 %95, label %97, label %96

96:                                               ; preds = %92
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %106

97:                                               ; preds = %92
  %98 = load i32, ptr %8, align 4, !tbaa !5
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds [200010 x %struct.Query], ptr @a, i64 0, i64 %99
  %101 = getelementptr inbounds %struct.Query, ptr %100, i32 0, i32 2
  %102 = load i32, ptr %101, align 8, !tbaa !11
  call void @_Z6updateii(i32 noundef %102, i32 noundef -1)
  br label %103

103:                                              ; preds = %97
  %104 = load i32, ptr %8, align 4, !tbaa !5
  %105 = add nsw i32 %104, 1
  store i32 %105, ptr %8, align 4, !tbaa !5
  br label %92, !llvm.loop !16

106:                                              ; preds = %96
  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 %107

107:                                              ; preds = %106, %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, !6, i64 20}
!11 = !{!10, !6, i64 8}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!10, !6, i64 12}
!15 = distinct !{!15, !13}
!16 = distinct !{!16, !13}


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

@a = 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 @a, i64 %7
  %9 = sext i32 %5 to i64
  %10 = getelementptr inbounds %struct.Query, ptr @a, i64 %9
  %11 = getelementptr inbounds i8, ptr %10, i64 24
  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 @a, i64 %12
  %14 = getelementptr inbounds i8, ptr %13, i64 24
  tail call void @_ZSt4sortIP5QueryPFbS0_S0_EEvT_S4_T0_(ptr noundef nonnull %11, ptr noundef nonnull %14, ptr noundef nonnull @_Z4cmpy5QueryS_)
  %.not3543.not = icmp slt i32 %5, %1
  br i1 %.not3543.not, label %.preheader38.preheader, label %.loopexit

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

.preheader38:                                     ; preds = %.preheader38.preheader, %.critedge
  %indvars.iv50 = phi i64 [ %15, %.preheader38.preheader ], [ %indvars.iv.next51, %.critedge ]
  %.03244 = phi i32 [ %0, %.preheader38.preheader ], [ %.1.lcssa, %.critedge ]
  %.not3639 = icmp sgt i32 %.03244, %5
  br i1 %.not3639, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader38
  %17 = getelementptr inbounds [200010 x %struct.Query], ptr @a, i64 0, i64 %indvars.iv50, i32 1
  %18 = sext i32 %.03244 to i64
  br label %20

.preheader:                                       ; preds = %.critedge
  %19 = icmp sgt i32 %.1.lcssa, %0
  br i1 %19, label %.lr.ph48, 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 @a, 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
  %.not37 = icmp sgt i32 %23, %24
  br i1 %.not37, label %.critedge.loopexit.split.loop.exit59, label %25

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

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

.critedge:                                        ; preds = %25, %.critedge.loopexit.split.loop.exit59, %.preheader38
  %.1.lcssa = phi i32 [ %.03244, %.preheader38 ], [ %28, %.critedge.loopexit.split.loop.exit59 ], [ %6, %25 ]
  %29 = getelementptr inbounds [200010 x %struct.Query], ptr @a, i64 0, i64 %indvars.iv50
  %30 = getelementptr inbounds i8, ptr %29, i64 8
  %31 = load i32, ptr %30, align 8, !tbaa !10
  %32 = tail call noundef i32 @_Z5queryi(i32 noundef %31)
  %33 = getelementptr inbounds i8, ptr %29, i64 12
  %34 = load i32, ptr %33, align 4, !tbaa !13
  %35 = add nsw i32 %34, %32
  store i32 %35, ptr %33, align 4, !tbaa !13
  %indvars.iv.next51 = add nsw i64 %indvars.iv50, 1
  %lftr.wideiv = trunc i64 %indvars.iv.next51 to i32
  %exitcond.not = icmp eq i32 %16, %lftr.wideiv
  br i1 %exitcond.not, label %.preheader, label %.preheader38, !llvm.loop !14

.lr.ph48:                                         ; preds = %.preheader, %.lr.ph48
  %indvars.iv53 = phi i64 [ %indvars.iv.next54, %.lr.ph48 ], [ %7, %.preheader ]
  %36 = getelementptr inbounds [200010 x %struct.Query], ptr @a, i64 0, i64 %indvars.iv53, i32 2
  %37 = load i32, ptr %36, align 8, !tbaa !10
  tail call void @_Z6updateii(i32 noundef %37, i32 noundef -1)
  %indvars.iv.next54 = add nsw i64 %indvars.iv53, 1
  %lftr.wideiv56 = trunc i64 %indvars.iv.next54 to i32
  %exitcond57.not = icmp eq i32 %.1.lcssa, %lftr.wideiv56
  br i1 %exitcond57.not, label %.loopexit, label %.lr.ph48, !llvm.loop !15

.loopexit:                                        ; preds = %.lr.ph48, %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, i64 20}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!6, !7, i64 12}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !12}


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