; LLVM IR from lzyrapx/Competitive-Programming :: Retired_code/CDQ Divide and Conquer/BZOJ 1935 (强行cdq分治) (二维偏序).ll (Z5Cleari)

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

@k = external dso_local global i32, align 4
@s = external dso_local global [2525000 x i32], align 16

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z6lowbiti(i32 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5Cleari(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  br label %3

3:                                                ; preds = %15, %1
  %4 = load i32, ptr %2, align 4, !tbaa !5
  %5 = load i32, ptr @k, align 4, !tbaa !5
  %6 = icmp sle i32 %4, %5
  br i1 %6, label %7, label %13

7:                                                ; preds = %3
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [2525000 x i32], ptr @s, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = icmp ne i32 %11, 0
  br label %13

13:                                               ; preds = %7, %3
  %14 = phi i1 [ false, %3 ], [ %12, %7 ]
  br i1 %14, label %15, label %23

15:                                               ; preds = %13
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [2525000 x i32], ptr @s, i64 0, i64 %17
  store i32 0, ptr %18, align 4, !tbaa !5
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = call noundef i32 @_Z6lowbiti(i32 noundef %19)
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = add nsw i32 %21, %20
  store i32 %22, ptr %2, align 4, !tbaa !5
  br label %3, !llvm.loop !9

23:                                               ; preds = %13
  ret void
}

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 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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

@k = external dso_local local_unnamed_addr global i32, align 4
@s = external dso_local local_unnamed_addr global [2525000 x i32], align 16

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z5Cleari(i32 noundef %0) local_unnamed_addr #1 {
  %2 = load i32, ptr @k, align 4, !tbaa !5
  %.not6 = icmp slt i32 %2, %0
  br i1 %.not6, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %6
  %.07 = phi i32 [ %8, %6 ], [ %0, %1 ]
  %3 = sext i32 %.07 to i64
  %4 = getelementptr inbounds [2525000 x i32], ptr @s, i64 0, i64 %3
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %.not5 = icmp eq i32 %5, 0
  br i1 %.not5, label %.critedge, label %6

6:                                                ; preds = %.lr.ph
  store i32 0, ptr %4, align 4, !tbaa !5
  %7 = tail call noundef i32 @_Z6lowbiti(i32 noundef %.07)
  %8 = add nsw i32 %7, %.07
  %9 = load i32, ptr @k, align 4, !tbaa !5
  %.not = icmp sgt i32 %8, %9
  br i1 %.not, label %.critedge, label %.lr.ph, !llvm.loop !9

.critedge:                                        ; preds = %.lr.ph, %6, %1
  ret void
}

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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass