; LLVM IR from Tunghohin/Competitive_Coding :: Luogu (p1102)

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

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@sum = external dso_local global i64, align 8
@a = external dso_local global [200005 x i32], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z10quick_sortPiii(ptr 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 norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %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
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %22, %0
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = load i32, ptr @n, align 4, !tbaa !5
  %15 = icmp slt i32 %13, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %25

17:                                               ; preds = %12
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [200005 x i32], ptr @a, i64 0, i64 %19
  %21 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %20)
  br label %22

22:                                               ; preds = %17
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %2, align 4, !tbaa !5
  br label %12, !llvm.loop !9

25:                                               ; preds = %16
  %26 = load i32, ptr @n, align 4, !tbaa !5
  %27 = sub nsw i32 %26, 1
  call void @_Z10quick_sortPiii(ptr noundef @a, i32 noundef 0, i32 noundef %27)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %122, %25
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = load i32, ptr @n, align 4, !tbaa !5
  %31 = sub nsw i32 %30, 1
  %32 = icmp slt i32 %29, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %28
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %125

34:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %35 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %35, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %36 = load i32, ptr @n, align 4, !tbaa !5
  %37 = sub nsw i32 %36, 1
  store i32 %37, ptr %6, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %63, %34
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = load i32, ptr %6, align 4, !tbaa !5
  %41 = icmp slt i32 %39, %40
  br i1 %41, label %42, label %64

42:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = load i32, ptr %6, align 4, !tbaa !5
  %45 = add nsw i32 %43, %44
  %46 = ashr i32 %45, 1
  store i32 %46, ptr %7, align 4, !tbaa !5
  %47 = load i32, ptr %7, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [200005 x i32], ptr @a, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = load i32, ptr %3, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [200005 x i32], ptr @a, i64 0, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = sub nsw i32 %50, %54
  %56 = load i32, ptr @m, align 4, !tbaa !5
  %57 = icmp slt i32 %55, %56
  br i1 %57, label %58, label %61

58:                                               ; preds = %42
  %59 = load i32, ptr %7, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %5, align 4, !tbaa !5
  br label %63

61:                                               ; preds = %42
  %62 = load i32, ptr %7, align 4, !tbaa !5
  store i32 %62, ptr %6, align 4, !tbaa !5
  br label %63

63:                                               ; preds = %61, %58
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %38, !llvm.loop !11

64:                                               ; preds = %38
  %65 = load i32, ptr %5, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [200005 x i32], ptr @a, i64 0, i64 %66
  %68 = load i32, ptr %67, align 4, !tbaa !5
  %69 = load i32, ptr %3, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [200005 x i32], ptr @a, i64 0, i64 %70
  %72 = load i32, ptr %71, align 4, !tbaa !5
  %73 = sub nsw i32 %68, %72
  %74 = load i32, ptr @m, align 4, !tbaa !5
  %75 = icmp ne i32 %73, %74
  br i1 %75, label %76, label %77

76:                                               ; preds = %64
  store i32 7, ptr %4, align 4
  br label %119

77:                                               ; preds = %64
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %78 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %78, ptr %8, align 4, !tbaa !5
  %79 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %79, ptr %5, align 4, !tbaa !5
  %80 = load i32, ptr @n, align 4, !tbaa !5
  %81 = sub nsw i32 %80, 1
  store i32 %81, ptr %6, align 4, !tbaa !5
  br label %82

82:                                               ; preds = %108, %77
  %83 = load i32, ptr %5, align 4, !tbaa !5
  %84 = load i32, ptr %6, align 4, !tbaa !5
  %85 = icmp slt i32 %83, %84
  br i1 %85, label %86, label %109

86:                                               ; preds = %82
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %87 = load i32, ptr %5, align 4, !tbaa !5
  %88 = load i32, ptr %6, align 4, !tbaa !5
  %89 = add nsw i32 %87, %88
  %90 = add nsw i32 %89, 1
  %91 = ashr i32 %90, 1
  store i32 %91, ptr %9, align 4, !tbaa !5
  %92 = load i32, ptr %9, align 4, !tbaa !5
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds [200005 x i32], ptr @a, i64 0, i64 %93
  %95 = load i32, ptr %94, align 4, !tbaa !5
  %96 = load i32, ptr %3, align 4, !tbaa !5
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds [200005 x i32], ptr @a, i64 0, i64 %97
  %99 = load i32, ptr %98, align 4, !tbaa !5
  %100 = sub nsw i32 %95, %99
  %101 = load i32, ptr @m, align 4, !tbaa !5
  %102 = icmp sle i32 %100, %101
  br i1 %102, label %103, label %105

103:                                              ; preds = %86
  %104 = load i32, ptr %9, align 4, !tbaa !5
  store i32 %104, ptr %5, align 4, !tbaa !5
  br label %108

105:                                              ; preds = %86
  %106 = load i32, ptr %9, align 4, !tbaa !5
  %107 = sub nsw i32 %106, 1
  store i32 %107, ptr %6, align 4, !tbaa !5
  br label %108

108:                                              ; preds = %105, %103
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %82, !llvm.loop !12

109:                                              ; preds = %82
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %110 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %110, ptr %10, align 4, !tbaa !5
  %111 = load i32, ptr %10, align 4, !tbaa !5
  %112 = load i32, ptr %8, align 4, !tbaa !5
  %113 = sub nsw i32 %111, %112
  %114 = add nsw i32 %113, 1
  %115 = sext i32 %114 to i64
  %116 = load i64, ptr @sum, align 8, !tbaa !13
  %117 = add nsw i64 %116, %115
  store i64 %117, ptr @sum, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %118

118:                                              ; preds = %109
  store i32 0, ptr %4, align 4
  br label %119

119:                                              ; preds = %118, %76
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  %120 = load i32, ptr %4, align 4
  switch i32 %120, label %128 [
    i32 0, label %121
    i32 7, label %122
  ]

121:                                              ; preds = %119
  br label %122

122:                                              ; preds = %121, %119
  %123 = load i32, ptr %3, align 4, !tbaa !5
  %124 = add nsw i32 %123, 1
  store i32 %124, ptr %3, align 4, !tbaa !5
  br label %28, !llvm.loop !15

125:                                              ; preds = %33
  %126 = load i64, ptr @sum, align 8, !tbaa !13
  %127 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %126)
  ret i32 0

128:                                              ; preds = %119
  unreachable
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #3

declare i32 @printf(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 norecurse 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 = { "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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = !{!14, !14, i64 0}
!14 = !{!"long long", !7, i64 0}
!15 = distinct !{!15, !10}


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

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@sum = external dso_local local_unnamed_addr global i64, align 8
@a = external dso_local global [200005 x i32], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %0
  %.lcssa = phi i32 [ %2, %0 ], [ %11, %.lr.ph ]
  %4 = add nsw i32 %.lcssa, -1
  tail call void @_Z10quick_sortPiii(ptr noundef nonnull @a, i32 noundef 0, i32 noundef %4)
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %6 = add i32 %5, -1
  %7 = icmp sgt i32 %5, 1
  %sum.promoted = load i64, ptr @sum, align 8, !tbaa !9
  br i1 %7, label %.preheader38.lr.ph, label %._crit_edge49

.preheader38.lr.ph:                               ; preds = %._crit_edge
  %8 = load i32, ptr @m, align 4, !tbaa !5
  %wide.trip.count = zext nneg i32 %6 to i64
  br label %.preheader38

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %9 = getelementptr inbounds [200005 x i32], ptr @a, i64 0, i64 %indvars.iv
  %10 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %9)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %11 = load i32, ptr @n, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = icmp slt i64 %indvars.iv.next, %12
  br i1 %13, label %.lr.ph, label %._crit_edge, !llvm.loop !11

.preheader38:                                     ; preds = %.preheader38.lr.ph, %47
  %indvars.iv52 = phi i64 [ 0, %.preheader38.lr.ph ], [ %indvars.iv.next53, %47 ]
  %14 = phi i64 [ %sum.promoted, %.preheader38.lr.ph ], [ %48, %47 ]
  %15 = getelementptr inbounds [200005 x i32], ptr @a, i64 0, i64 %indvars.iv52
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = trunc nuw nsw i64 %indvars.iv52 to i32
  br label %20

._crit_edge49:                                    ; preds = %47, %._crit_edge
  %18 = phi i64 [ %sum.promoted, %._crit_edge ], [ %48, %47 ]
  %19 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %18)
  ret i32 0

20:                                               ; preds = %.preheader38, %20
  %.03041 = phi i32 [ %17, %.preheader38 ], [ %.1, %20 ]
  %.03140 = phi i32 [ %6, %.preheader38 ], [ %.132, %20 ]
  %21 = add nsw i32 %.03041, %.03140
  %22 = ashr i32 %21, 1
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [200005 x i32], ptr @a, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = sub nsw i32 %25, %16
  %27 = icmp slt i32 %26, %8
  %28 = add nsw i32 %22, 1
  %.132 = select i1 %27, i32 %.03140, i32 %22
  %.1 = select i1 %27, i32 %28, i32 %.03041
  %29 = icmp slt i32 %.1, %.132
  br i1 %29, label %20, label %30, !llvm.loop !13

30:                                               ; preds = %20
  %31 = sext i32 %.1 to i64
  %32 = getelementptr inbounds [200005 x i32], ptr @a, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = sub nsw i32 %33, %16
  %.not = icmp eq i32 %34, %8
  br i1 %.not, label %.lr.ph44, label %47

.lr.ph44:                                         ; preds = %30, %.lr.ph44
  %.243 = phi i32 [ %.3, %.lr.ph44 ], [ %17, %30 ]
  %.23342 = phi i32 [ %.334, %.lr.ph44 ], [ %6, %30 ]
  %35 = add i32 %.23342, 1
  %36 = add i32 %35, %.243
  %37 = ashr i32 %36, 1
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [200005 x i32], ptr @a, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = sub nsw i32 %40, %16
  %.not37 = icmp sgt i32 %41, %8
  %42 = add nsw i32 %37, -1
  %.334 = select i1 %.not37, i32 %42, i32 %.23342
  %.3 = select i1 %.not37, i32 %.243, i32 %37
  %43 = icmp slt i32 %.3, %.334
  br i1 %43, label %.lr.ph44, label %._crit_edge45, !llvm.loop !14

._crit_edge45:                                    ; preds = %.lr.ph44
  %reass.sub = sub i32 %.3, %.1
  %44 = add i32 %reass.sub, 1
  %45 = sext i32 %44 to i64
  %46 = add nsw i64 %14, %45
  store i64 %46, ptr @sum, align 8, !tbaa !9
  br label %47

47:                                               ; preds = %30, %._crit_edge45
  %48 = phi i64 [ %14, %30 ], [ %46, %._crit_edge45 ]
  %indvars.iv.next53 = add nuw nsw i64 %indvars.iv52, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next53, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge49, label %.preheader38, !llvm.loop !15
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) 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 norecurse 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 = { nofree nounwind "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, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !12}


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