; LLVM IR from lzyrapx/Competitive-Programming :: Xiangtan Invitation Contest 2017/1265(F)（离散化+变形LCS）.ll (Z8NextInitv)

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

@a = external dso_local global [202 x i32], align 16
@z = external dso_local global i32, align 4
@Next = external dso_local global [202 x [202 x i32]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z8NextInitv() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %4

4:                                                ; preds = %45, %0
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %6 = load i32, ptr @z, align 4, !tbaa !5
  %7 = icmp slt i32 %5, %6
  br i1 %7, label %9, label %8

8:                                                ; preds = %4
  store i32 2, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  br label %48

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

12:                                               ; preds = %41, %9
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = load i32, ptr @z, align 4, !tbaa !5
  %15 = icmp slt i32 %13, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  store i32 5, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  br label %44

17:                                               ; preds = %12
  %18 = load i32, ptr %1, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [202 x [202 x i32]], ptr @Next, i64 0, i64 %19
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [202 x i32], ptr @a, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [202 x i32], ptr %20, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = icmp eq i32 %27, -1
  br i1 %28, label %29, label %40

29:                                               ; preds = %17
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = load i32, ptr %1, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [202 x [202 x i32]], ptr @Next, i64 0, i64 %32
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [202 x i32], ptr @a, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [202 x i32], ptr %33, i64 0, i64 %38
  store i32 %30, ptr %39, align 4, !tbaa !5
  br label %40

40:                                               ; preds = %29, %17
  br label %41

41:                                               ; preds = %40
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %3, align 4, !tbaa !5
  br label %12, !llvm.loop !9

44:                                               ; preds = %16
  br label %45

45:                                               ; preds = %44
  %46 = load i32, ptr %1, align 4, !tbaa !5
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %1, align 4, !tbaa !5
  br label %4, !llvm.loop !11

48:                                               ; preds = %8
  ret void
}

; 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

attributes #0 = { 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 = { 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 = 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"

@a = external dso_local local_unnamed_addr global [202 x i32], align 16
@z = external dso_local local_unnamed_addr global i32, align 4
@Next = external dso_local local_unnamed_addr global [202 x [202 x i32]], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z8NextInitv() local_unnamed_addr #0 {
  %1 = load i32, ptr @z, align 4, !tbaa !5
  %2 = icmp sgt i32 %1, 0
  br i1 %2, label %.lr.ph13.preheader, label %._crit_edge

.lr.ph13.preheader:                               ; preds = %0
  %3 = zext nneg i32 %1 to i64
  %wide.trip.count20 = zext nneg i32 %1 to i64
  br label %.lr.ph13

.loopexit:                                        ; preds = %13, %.lr.ph13
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond21.not = icmp eq i64 %indvars.iv.next18, %wide.trip.count20
  br i1 %exitcond21.not, label %._crit_edge, label %.lr.ph13, !llvm.loop !9

._crit_edge:                                      ; preds = %.loopexit, %0
  ret void

.lr.ph13:                                         ; preds = %.lr.ph13.preheader, %.loopexit
  %indvars.iv17 = phi i64 [ 0, %.lr.ph13.preheader ], [ %indvars.iv.next18, %.loopexit ]
  %indvars.iv = phi i64 [ 1, %.lr.ph13.preheader ], [ %indvars.iv.next, %.loopexit ]
  %indvars.iv.next18 = add nuw nsw i64 %indvars.iv17, 1
  %4 = icmp ult i64 %indvars.iv.next18, %3
  br i1 %4, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.lr.ph13, %13
  %indvars.iv14 = phi i64 [ %indvars.iv.next15, %13 ], [ %indvars.iv, %.lr.ph13 ]
  %5 = getelementptr inbounds [202 x i32], ptr @a, i64 0, i64 %indvars.iv14
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [202 x [202 x i32]], ptr @Next, i64 0, i64 %indvars.iv17, i64 %7
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = icmp eq i32 %9, -1
  br i1 %10, label %11, label %13

11:                                               ; preds = %.lr.ph
  %12 = trunc nuw nsw i64 %indvars.iv14 to i32
  store i32 %12, ptr %8, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %.lr.ph, %11
  %indvars.iv.next15 = add nuw nsw i64 %indvars.iv14, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next15, %wide.trip.count20
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !11
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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"}
!11 = distinct !{!11, !10}


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