; LLVM IR from lzyrapx/Competitive-Programming :: FZU/2203（二分）.ll (Z5checki)

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

@w = external dso_local global i32, align 4
@num = external dso_local global i32, align 4
@len = external dso_local global i32, align 4
@a = external dso_local global [200010 x i32], align 16
@b = external dso_local global [200010 x i32], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z5checki(i32 noundef %0) #0 {
  %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
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %21, %1
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = icmp sle i32 %9, %10
  br i1 %11, label %13, label %12

12:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %24

13:                                               ; preds = %8
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [200010 x i32], ptr @a, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [200010 x i32], ptr @b, i64 0, i64 %19
  store i32 %17, ptr %20, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %13
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %4, align 4, !tbaa !5
  br label %8, !llvm.loop !9

24:                                               ; preds = %12
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds i32, ptr getelementptr inbounds (i32, ptr @b, i64 1), i64 %26
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef getelementptr inbounds (i32, ptr @b, i64 1), ptr noundef %27)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  store i32 0, ptr @b, align 16, !tbaa !5
  %28 = load i32, ptr @w, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [200010 x i32], ptr @b, i64 0, i64 %32
  store i32 %29, ptr %33, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %55, %24
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = load i32, ptr %3, align 4, !tbaa !5
  %37 = icmp sle i32 %35, %36
  br i1 %37, label %39, label %38

38:                                               ; preds = %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %58

39:                                               ; preds = %34
  %40 = load i32, ptr %6, align 4, !tbaa !5
  %41 = add nsw i32 %40, 1
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [200010 x i32], ptr @b, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = load i32, ptr %6, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [200010 x i32], ptr @b, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = sub nsw i32 %44, %48
  %50 = load i32, ptr @len, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  %52 = sdiv i32 %49, %51
  %53 = load i32, ptr %5, align 4, !tbaa !5
  %54 = add nsw i32 %53, %52
  store i32 %54, ptr %5, align 4, !tbaa !5
  br label %55

55:                                               ; preds = %39
  %56 = load i32, ptr %6, align 4, !tbaa !5
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %6, align 4, !tbaa !5
  br label %34, !llvm.loop !11

58:                                               ; preds = %38
  %59 = load i32, ptr %5, align 4, !tbaa !5
  %60 = load i32, ptr @num, align 4, !tbaa !5
  %61 = icmp sge i32 %59, %60
  br i1 %61, label %62, label %63

62:                                               ; preds = %58
  store i32 1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %64

63:                                               ; preds = %58
  store i32 0, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %64

64:                                               ; preds = %63, %62
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  %65 = load i32, ptr %2, align 4
  ret i32 %65
}

; 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: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPiEvT_S1_(ptr noundef, ptr noundef) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #3 = { 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}


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

@w = external dso_local local_unnamed_addr global i32, align 4
@num = external dso_local local_unnamed_addr global i32, align 4
@len = external dso_local local_unnamed_addr global i32, align 4
@a = external dso_local local_unnamed_addr global [200010 x i32], align 16
@b = external dso_local global [200010 x i32], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 2) i32 @_Z5checki(i32 noundef %0) local_unnamed_addr #0 {
  %.not21 = icmp slt i32 %0, 1
  br i1 %.not21, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %1
  %2 = zext nneg i32 %0 to i64
  %3 = shl nuw nsw i64 %2, 2
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 4 getelementptr inbounds (i8, ptr @b, i64 4), ptr nonnull align 4 getelementptr inbounds (i8, ptr @a, i64 4), i64 %3, i1 false), !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.preheader, %1
  %4 = sext i32 %0 to i64
  %5 = getelementptr inbounds i32, ptr getelementptr inbounds (i8, ptr @b, i64 4), i64 %4
  tail call void @_ZSt4sortIPiEvT_S1_(ptr noundef nonnull getelementptr inbounds (i8, ptr @b, i64 4), ptr noundef nonnull %5)
  store i32 0, ptr @b, align 16, !tbaa !5
  %6 = load i32, ptr @w, align 4, !tbaa !5
  %7 = add nsw i32 %6, 1
  %8 = add i32 %0, 1
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [200010 x i32], ptr @b, i64 0, i64 %9
  store i32 %7, ptr %10, align 4, !tbaa !5
  %.not1923 = icmp slt i32 %0, 0
  br i1 %.not1923, label %._crit_edge28, label %.lr.ph27

.lr.ph27:                                         ; preds = %._crit_edge
  %11 = load i32, ptr @len, align 4, !tbaa !5
  %12 = add nsw i32 %11, 1
  %wide.trip.count = zext i32 %8 to i64
  %.pre = load i32, ptr @b, align 16, !tbaa !5
  %xtraiter = and i64 %wide.trip.count, 1
  %13 = icmp eq i32 %0, 0
  br i1 %13, label %._crit_edge28.loopexit.unr-lcssa, label %.lr.ph27.new

.lr.ph27.new:                                     ; preds = %.lr.ph27
  %unroll_iter = and i64 %wide.trip.count, 4294967294
  br label %21

._crit_edge28.loopexit.unr-lcssa.loopexit:        ; preds = %21
  %14 = add nuw nsw i64 %indvars.iv, 3
  br label %._crit_edge28.loopexit.unr-lcssa

._crit_edge28.loopexit.unr-lcssa:                 ; preds = %._crit_edge28.loopexit.unr-lcssa.loopexit, %.lr.ph27
  %.lcssa.ph = phi i32 [ poison, %.lr.ph27 ], [ %32, %._crit_edge28.loopexit.unr-lcssa.loopexit ]
  %.unr = phi i32 [ %.pre, %.lr.ph27 ], [ %29, %._crit_edge28.loopexit.unr-lcssa.loopexit ]
  %indvars.iv.unr = phi i64 [ 1, %.lr.ph27 ], [ %14, %._crit_edge28.loopexit.unr-lcssa.loopexit ]
  %.01524.unr = phi i32 [ 0, %.lr.ph27 ], [ %32, %._crit_edge28.loopexit.unr-lcssa.loopexit ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge28, label %._crit_edge28.loopexit.epilog-lcssa

._crit_edge28.loopexit.epilog-lcssa:              ; preds = %._crit_edge28.loopexit.unr-lcssa
  %15 = getelementptr inbounds [200010 x i32], ptr @b, i64 0, i64 %indvars.iv.unr
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = sub nsw i32 %16, %.unr
  %18 = sdiv i32 %17, %12
  %19 = add nsw i32 %18, %.01524.unr
  br label %._crit_edge28

._crit_edge28:                                    ; preds = %._crit_edge28.loopexit.epilog-lcssa, %._crit_edge28.loopexit.unr-lcssa, %._crit_edge
  %.015.lcssa = phi i32 [ 0, %._crit_edge ], [ %.lcssa.ph, %._crit_edge28.loopexit.unr-lcssa ], [ %19, %._crit_edge28.loopexit.epilog-lcssa ]
  %20 = load i32, ptr @num, align 4, !tbaa !5
  %.not20 = icmp sge i32 %.015.lcssa, %20
  %. = zext i1 %.not20 to i32
  ret i32 %.

21:                                               ; preds = %21, %.lr.ph27.new
  %22 = phi i32 [ %.pre, %.lr.ph27.new ], [ %29, %21 ]
  %indvars.iv = phi i64 [ 0, %.lr.ph27.new ], [ %indvars.iv.next.1, %21 ]
  %.01524 = phi i32 [ 0, %.lr.ph27.new ], [ %32, %21 ]
  %niter = phi i64 [ 0, %.lr.ph27.new ], [ %niter.next.1, %21 ]
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %23 = getelementptr inbounds [200010 x i32], ptr @b, i64 0, i64 %indvars.iv.next
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = sub nsw i32 %24, %22
  %26 = sdiv i32 %25, %12
  %27 = add nsw i32 %26, %.01524
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %28 = getelementptr inbounds [200010 x i32], ptr @b, i64 0, i64 %indvars.iv.next.1
  %29 = load i32, ptr %28, align 8, !tbaa !5
  %30 = sub nsw i32 %29, %24
  %31 = sdiv i32 %30, %12
  %32 = add nsw i32 %31, %27
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge28.loopexit.unr-lcssa.loopexit, label %21, !llvm.loop !9
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #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 = { 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }

!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: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass