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

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

@ans = external dso_local global [50010 x i32], align 16
@queries_y = external dso_local global [400080 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 uwtable
define dso_local void @_Z6solve3ii(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
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = load i32, ptr %4, align 4, !tbaa !5
  %9 = icmp sge i32 %7, %8
  br i1 %9, label %10, label %11

10:                                               ; preds = %2
  br label %107

11:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %12 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %12, ptr %5, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %80, %11
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = icmp sle i32 %14, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %83

18:                                               ; preds = %13
  %19 = load i32, ptr %5, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [400080 x %struct.Query], ptr @queries_y, i64 0, i64 %20
  %22 = getelementptr inbounds %struct.Query, ptr %21, i32 0, i32 3
  %23 = load i32, ptr %22, align 4, !tbaa !9
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %25, label %31

25:                                               ; preds = %18
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [400080 x %struct.Query], ptr @queries_y, i64 0, i64 %27
  %29 = getelementptr inbounds %struct.Query, ptr %28, i32 0, i32 2
  %30 = load i32, ptr %29, align 4, !tbaa !11
  call void @_Z6updateii(i32 noundef %30, i32 noundef 1)
  br label %79

31:                                               ; preds = %18
  %32 = load i32, ptr %5, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [400080 x %struct.Query], ptr @queries_y, i64 0, i64 %33
  %35 = getelementptr inbounds %struct.Query, ptr %34, i32 0, i32 3
  %36 = load i32, ptr %35, align 4, !tbaa !9
  %37 = icmp eq i32 %36, 1
  br i1 %37, label %38, label %54

38:                                               ; preds = %31
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [400080 x %struct.Query], ptr @queries_y, i64 0, i64 %40
  %42 = getelementptr inbounds %struct.Query, ptr %41, i32 0, i32 2
  %43 = load i32, ptr %42, align 4, !tbaa !11
  %44 = call noundef i32 @_Z5queryi(i32 noundef %43)
  %45 = load i32, ptr %5, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [400080 x %struct.Query], ptr @queries_y, i64 0, i64 %46
  %48 = getelementptr inbounds %struct.Query, ptr %47, i32 0, i32 4
  %49 = load i32, ptr %48, align 4, !tbaa !12
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [50010 x i32], ptr @ans, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = sub nsw i32 %52, %44
  store i32 %53, ptr %51, align 4, !tbaa !5
  br label %78

54:                                               ; preds = %31
  %55 = load i32, ptr %5, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [400080 x %struct.Query], ptr @queries_y, i64 0, i64 %56
  %58 = getelementptr inbounds %struct.Query, ptr %57, i32 0, i32 3
  %59 = load i32, ptr %58, align 4, !tbaa !9
  %60 = icmp eq i32 %59, 2
  br i1 %60, label %61, label %77

61:                                               ; preds = %54
  %62 = load i32, ptr %5, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [400080 x %struct.Query], ptr @queries_y, i64 0, i64 %63
  %65 = getelementptr inbounds %struct.Query, ptr %64, i32 0, i32 2
  %66 = load i32, ptr %65, align 4, !tbaa !11
  %67 = call noundef i32 @_Z5queryi(i32 noundef %66)
  %68 = load i32, ptr %5, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [400080 x %struct.Query], ptr @queries_y, i64 0, i64 %69
  %71 = getelementptr inbounds %struct.Query, ptr %70, i32 0, i32 4
  %72 = load i32, ptr %71, align 4, !tbaa !12
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [50010 x i32], ptr @ans, i64 0, i64 %73
  %75 = load i32, ptr %74, align 4, !tbaa !5
  %76 = add nsw i32 %75, %67
  store i32 %76, ptr %74, align 4, !tbaa !5
  br label %77

77:                                               ; preds = %61, %54
  br label %78

78:                                               ; preds = %77, %38
  br label %79

79:                                               ; preds = %78, %25
  br label %80

80:                                               ; preds = %79
  %81 = load i32, ptr %5, align 4, !tbaa !5
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %5, align 4, !tbaa !5
  br label %13, !llvm.loop !13

83:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %84 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %84, ptr %6, align 4, !tbaa !5
  br label %85

85:                                               ; preds = %104, %83
  %86 = load i32, ptr %6, align 4, !tbaa !5
  %87 = load i32, ptr %4, align 4, !tbaa !5
  %88 = icmp sle i32 %86, %87
  br i1 %88, label %90, label %89

89:                                               ; preds = %85
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %107

90:                                               ; preds = %85
  %91 = load i32, ptr %6, align 4, !tbaa !5
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds [400080 x %struct.Query], ptr @queries_y, i64 0, i64 %92
  %94 = getelementptr inbounds %struct.Query, ptr %93, i32 0, i32 3
  %95 = load i32, ptr %94, align 4, !tbaa !9
  %96 = icmp eq i32 %95, 0
  br i1 %96, label %97, label %103

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

103:                                              ; preds = %97, %90
  br label %104

104:                                              ; preds = %103
  %105 = load i32, ptr %6, align 4, !tbaa !5
  %106 = add nsw i32 %105, 1
  store i32 %106, ptr %6, align 4, !tbaa !5
  br label %85, !llvm.loop !15

107:                                              ; preds = %89, %10
  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 = { 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 12}
!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 = distinct !{!15, !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 }

@ans = external dso_local local_unnamed_addr global [50010 x i32], align 16
@queries_y = external dso_local local_unnamed_addr global [400080 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 uwtable
define dso_local void @_Z6solve3ii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %.not = icmp slt i32 %0, %1
  br i1 %.not, label %.preheader26.preheader, label %.loopexit

.preheader26.preheader:                           ; preds = %2
  %3 = sext i32 %0 to i64
  %4 = add i32 %1, 1
  br label %.preheader26

.preheader:                                       ; preds = %31
  %.not2528 = icmp sgt i32 %0, %1
  br i1 %.not2528, label %.loopexit, label %.lr.ph

.preheader26:                                     ; preds = %.preheader26.preheader, %31
  %indvars.iv = phi i64 [ %3, %.preheader26.preheader ], [ %indvars.iv.next, %31 ]
  %5 = getelementptr inbounds [400080 x %struct.Query], ptr @queries_y, i64 0, i64 %indvars.iv
  %6 = getelementptr inbounds i8, ptr %5, i64 12
  %7 = load i32, ptr %6, align 4, !tbaa !5
  switch i32 %7, label %31 [
    i32 0, label %8
    i32 1, label %11
    i32 2, label %21
  ]

8:                                                ; preds = %.preheader26
  %9 = getelementptr inbounds i8, ptr %5, i64 8
  %10 = load i32, ptr %9, align 4, !tbaa !10
  tail call void @_Z6updateii(i32 noundef %10, i32 noundef 1)
  br label %31

11:                                               ; preds = %.preheader26
  %12 = getelementptr inbounds i8, ptr %5, i64 8
  %13 = load i32, ptr %12, align 4, !tbaa !10
  %14 = tail call noundef i32 @_Z5queryi(i32 noundef %13)
  %15 = getelementptr inbounds i8, ptr %5, i64 16
  %16 = load i32, ptr %15, align 4, !tbaa !11
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [50010 x i32], ptr @ans, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !12
  %20 = sub nsw i32 %19, %14
  store i32 %20, ptr %18, align 4, !tbaa !12
  br label %31

21:                                               ; preds = %.preheader26
  %22 = getelementptr inbounds i8, ptr %5, i64 8
  %23 = load i32, ptr %22, align 4, !tbaa !10
  %24 = tail call noundef i32 @_Z5queryi(i32 noundef %23)
  %25 = getelementptr inbounds i8, ptr %5, i64 16
  %26 = load i32, ptr %25, align 4, !tbaa !11
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [50010 x i32], ptr @ans, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !12
  %30 = add nsw i32 %29, %24
  store i32 %30, ptr %28, align 4, !tbaa !12
  br label %31

31:                                               ; preds = %.preheader26, %8, %21, %11
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %lftr.wideiv = trunc i64 %indvars.iv.next to i32
  %exitcond.not = icmp eq i32 %4, %lftr.wideiv
  br i1 %exitcond.not, label %.preheader, label %.preheader26, !llvm.loop !13

.lr.ph:                                           ; preds = %.preheader, %39
  %indvars.iv31 = phi i64 [ %indvars.iv.next32, %39 ], [ %3, %.preheader ]
  %32 = getelementptr inbounds [400080 x %struct.Query], ptr @queries_y, i64 0, i64 %indvars.iv31
  %33 = getelementptr inbounds i8, ptr %32, i64 12
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = icmp eq i32 %34, 0
  br i1 %35, label %36, label %39

36:                                               ; preds = %.lr.ph
  %37 = getelementptr inbounds i8, ptr %32, i64 8
  %38 = load i32, ptr %37, align 4, !tbaa !10
  tail call void @_Z6updateii(i32 noundef %38, i32 noundef -1)
  br label %39

39:                                               ; preds = %.lr.ph, %36
  %indvars.iv.next32 = add nsw i64 %indvars.iv31, 1
  %lftr.wideiv34 = trunc i64 %indvars.iv.next32 to i32
  %exitcond35.not = icmp eq i32 %4, %lftr.wideiv34
  br i1 %exitcond35.not, label %.loopexit, label %.lr.ph, !llvm.loop !15

.loopexit:                                        ; preds = %39, %.preheader, %2
  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" }

!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 12}
!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 = !{!7, !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass