; LLVM IR from tangjz/acm-icpc :: lydsy/2103.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"

%"struct.std::pair" = type { i32, i32 }

@st = external dso_local global [9 x [50001 x i32]], align 16
@sz = external dso_local global [50001 x i64], align 16

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

8:                                                ; preds = %18, %1
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [9 x [50001 x i32]], ptr @st, i64 0, i64 %10
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [50001 x i32], ptr %11, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %17, label %21

17:                                               ; preds = %8
  br label %18

18:                                               ; preds = %17
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %4, align 4, !tbaa !5
  br label %8, !llvm.loop !9

21:                                               ; preds = %8
  br label %22

22:                                               ; preds = %55, %21
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = add nsw i32 %23, -1
  store i32 %24, ptr %4, align 4, !tbaa !5
  %25 = icmp sge i32 %24, 0
  br i1 %25, label %26, label %56

26:                                               ; preds = %22
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [9 x [50001 x i32]], ptr @st, i64 0, i64 %28
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [50001 x i32], ptr %29, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [50001 x i64], ptr @sz, i64 0, i64 %34
  %36 = load i64, ptr %35, align 8, !tbaa !11
  %37 = shl i64 %36, 1
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [50001 x i64], ptr @sz, i64 0, i64 %39
  %41 = load i64, ptr %40, align 8, !tbaa !11
  %42 = icmp sgt i64 %37, %41
  br i1 %42, label %43, label %55

43:                                               ; preds = %26
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [9 x [50001 x i32]], ptr @st, i64 0, i64 %45
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [50001 x i32], ptr %46, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !5
  store i32 %50, ptr %5, align 4, !tbaa !5
  %51 = load i32, ptr %4, align 4, !tbaa !5
  %52 = shl i32 1, %51
  %53 = load i32, ptr %6, align 4, !tbaa !5
  %54 = add nsw i32 %53, %52
  store i32 %54, ptr %6, align 4, !tbaa !5
  br label %55

55:                                               ; preds = %43, %26
  br label %22, !llvm.loop !13

56:                                               ; preds = %22
  %57 = call i64 @_ZSt9make_pairIRiS0_ESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4) %5, ptr noundef nonnull align 4 dereferenceable(4) %6)
  store i64 %57, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %58 = load i64, ptr %2, align 4
  ret i64 %58
}

; Function Attrs: mustprogress uwtable
declare dso_local i64 @_ZSt9make_pairIRiS0_ESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !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"

@st = external dso_local local_unnamed_addr global [9 x [50001 x i32]], align 16
@sz = external dso_local local_unnamed_addr global [50001 x i64], align 16

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
define dso_local i64 @_Z5checki(i32 noundef %0) local_unnamed_addr #1 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #2
  %4 = sext i32 %0 to i64
  br label %5

5:                                                ; preds = %5, %1
  %indvars.iv = phi i64 [ %indvars.iv.next, %5 ], [ 0, %1 ]
  %6 = getelementptr inbounds [9 x [50001 x i32]], ptr @st, i64 0, i64 %indvars.iv, i64 %4
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %.not = icmp eq i32 %7, 0
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  br i1 %.not, label %.preheader, label %5, !llvm.loop !9

.preheader:                                       ; preds = %5
  %.not14 = icmp eq i64 %indvars.iv, 0
  br i1 %.not14, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %8 = getelementptr inbounds [50001 x i64], ptr @sz, i64 0, i64 %4
  %9 = load i64, ptr %8, align 8, !tbaa !11
  %xtraiter = and i64 %indvars.iv, 1
  %10 = icmp eq i64 %indvars.iv, 1
  br i1 %10, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %indvars.iv, 9223372036854775806
  br label %11

11:                                               ; preds = %11, %.lr.ph.new
  %indvars.iv17 = phi i64 [ %indvars.iv, %.lr.ph.new ], [ %indvars.iv.next18.1, %11 ]
  %12 = phi i32 [ %0, %.lr.ph.new ], [ %39, %11 ]
  %13 = phi i32 [ 0, %.lr.ph.new ], [ %38, %11 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %11 ]
  %indvars.iv.next18 = add nsw i64 %indvars.iv17, -1
  %indvars = trunc i64 %indvars.iv.next18 to i32
  %14 = and i64 %indvars.iv.next18, 4294967295
  %15 = sext i32 %12 to i64
  %16 = getelementptr inbounds [9 x [50001 x i32]], ptr @st, i64 0, i64 %14, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [50001 x i64], ptr @sz, i64 0, i64 %18
  %20 = load i64, ptr %19, align 8, !tbaa !11
  %21 = shl i64 %20, 1
  %22 = icmp sgt i64 %21, %9
  %23 = shl nuw i32 1, %indvars
  %24 = select i1 %22, i32 %23, i32 0
  %25 = add nsw i32 %13, %24
  %26 = select i1 %22, i32 %17, i32 %12
  %indvars.iv.next18.1 = add nsw i64 %indvars.iv17, -2
  %indvars.1 = trunc i64 %indvars.iv.next18.1 to i32
  %27 = and i64 %indvars.iv.next18.1, 4294967295
  %28 = sext i32 %26 to i64
  %29 = getelementptr inbounds [9 x [50001 x i32]], ptr @st, i64 0, i64 %27, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [50001 x i64], ptr @sz, i64 0, i64 %31
  %33 = load i64, ptr %32, align 8, !tbaa !11
  %34 = shl i64 %33, 1
  %35 = icmp sgt i64 %34, %9
  %36 = shl nuw i32 1, %indvars.1
  %37 = select i1 %35, i32 %36, i32 0
  %38 = add nsw i32 %25, %37
  %39 = select i1 %35, i32 %30, i32 %26
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1.not = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1.not, label %._crit_edge.loopexit.unr-lcssa, label %11, !llvm.loop !13

._crit_edge.loopexit.unr-lcssa:                   ; preds = %11, %.lr.ph
  %.lcssa22.ph = phi i32 [ poison, %.lr.ph ], [ %38, %11 ]
  %.lcssa.ph = phi i32 [ poison, %.lr.ph ], [ %39, %11 ]
  %indvars.iv17.unr = phi i64 [ %indvars.iv, %.lr.ph ], [ %indvars.iv.next18.1, %11 ]
  %.unr = phi i32 [ %0, %.lr.ph ], [ %39, %11 ]
  %.unr23 = phi i32 [ 0, %.lr.ph ], [ %38, %11 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %._crit_edge.loopexit.epilog-lcssa

._crit_edge.loopexit.epilog-lcssa:                ; preds = %._crit_edge.loopexit.unr-lcssa
  %indvars.iv.next18.epil = add nsw i64 %indvars.iv17.unr, -1
  %indvars.epil = trunc i64 %indvars.iv.next18.epil to i32
  %40 = and i64 %indvars.iv.next18.epil, 4294967295
  %41 = sext i32 %.unr to i64
  %42 = getelementptr inbounds [9 x [50001 x i32]], ptr @st, i64 0, i64 %40, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [50001 x i64], ptr @sz, i64 0, i64 %44
  %46 = load i64, ptr %45, align 8, !tbaa !11
  %47 = shl i64 %46, 1
  %48 = icmp sgt i64 %47, %9
  %49 = shl nuw i32 1, %indvars.epil
  %50 = select i1 %48, i32 %49, i32 0
  %51 = add nsw i32 %.unr23, %50
  %52 = select i1 %48, i32 %43, i32 %.unr
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.epilog-lcssa, %._crit_edge.loopexit.unr-lcssa, %.preheader
  %.lcssa12 = phi i32 [ 0, %.preheader ], [ %.lcssa22.ph, %._crit_edge.loopexit.unr-lcssa ], [ %51, %._crit_edge.loopexit.epilog-lcssa ]
  %.lcssa10 = phi i32 [ %0, %.preheader ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %52, %._crit_edge.loopexit.epilog-lcssa ]
  store i32 %.lcssa10, ptr %2, align 4, !tbaa !5
  store i32 %.lcssa12, ptr %3, align 4, !tbaa !5
  %53 = call i64 @_ZSt9make_pairIRiS0_ESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef nonnull align 4 dereferenceable(4) %3)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #2
  ret i64 %53
}

; Function Attrs: mustprogress uwtable
declare dso_local i64 @_ZSt9make_pairIRiS0_ESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !10}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass