; LLVM IR from lzyrapx/Competitive-Programming :: HDUOJ/5750.ll (Z4initv)

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

@isprime = external dso_local global [100005 x i32], align 16
@prime = external dso_local global [100005 x i32], align 16
@k = external dso_local global i32, align 4

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

3:                                                ; preds = %35, %0
  %4 = load i32, ptr %1, align 4, !tbaa !5
  %5 = icmp slt i32 %4, 100000
  br i1 %5, label %6, label %38

6:                                                ; preds = %3
  %7 = load i32, ptr %1, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [100005 x i32], ptr @isprime, i64 0, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %34

12:                                               ; preds = %6
  store i32 2, ptr %2, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %24, %12
  %14 = load i32, ptr %1, align 4, !tbaa !5
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = mul nsw i32 %14, %15
  %17 = icmp slt i32 %16, 100000
  br i1 %17, label %18, label %27

18:                                               ; preds = %13
  %19 = load i32, ptr %1, align 4, !tbaa !5
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = mul nsw i32 %19, %20
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [100005 x i32], ptr @isprime, i64 0, i64 %22
  store i32 1, ptr %23, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %18
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %2, align 4, !tbaa !5
  br label %13, !llvm.loop !9

27:                                               ; preds = %13
  %28 = load i32, ptr %1, align 4, !tbaa !5
  %29 = load i32, ptr @k, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [100005 x i32], ptr @prime, i64 0, i64 %30
  store i32 %28, ptr %31, align 4, !tbaa !5
  %32 = load i32, ptr @k, align 4, !tbaa !5
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr @k, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %27, %6
  br label %35

35:                                               ; preds = %34
  %36 = load i32, ptr %1, align 4, !tbaa !5
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %1, align 4, !tbaa !5
  br label %3, !llvm.loop !11

38:                                               ; preds = %3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  ret i32 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

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"

@isprime = external dso_local local_unnamed_addr global [100005 x i32], align 16
@prime = external dso_local local_unnamed_addr global [100005 x i32], align 16
@k = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef i32 @_Z4initv() local_unnamed_addr #0 {
  %k.promoted = load i32, ptr @k, align 4, !tbaa !5
  br label %1

1:                                                ; preds = %0, %14
  %indvars.iv13 = phi i64 [ 2, %0 ], [ %indvars.iv.next14, %14 ]
  %indvars.iv = phi i64 [ 4, %0 ], [ %indvars.iv.next, %14 ]
  %2 = phi i32 [ %k.promoted, %0 ], [ %15, %14 ]
  %3 = getelementptr inbounds [100005 x i32], ptr @isprime, i64 0, i64 %indvars.iv13
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = icmp eq i32 %4, 0
  br i1 %5, label %.preheader, label %14

.preheader:                                       ; preds = %1
  %6 = icmp ult i64 %indvars.iv13, 50000
  br i1 %6, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %indvars.iv17 = phi i64 [ %indvars.iv.next18, %.lr.ph ], [ 2, %.preheader ]
  %indvars.iv15 = phi i64 [ %indvars.iv.next16, %.lr.ph ], [ %indvars.iv, %.preheader ]
  %7 = getelementptr inbounds [100005 x i32], ptr @isprime, i64 0, i64 %indvars.iv15
  store i32 1, ptr %7, align 4, !tbaa !5
  %indvars.iv.next18 = add nuw nsw i64 %indvars.iv17, 1
  %8 = mul nuw nsw i64 %indvars.iv.next18, %indvars.iv13
  %9 = icmp ult i64 %8, 100000
  %indvars.iv.next16 = add nuw nsw i64 %indvars.iv15, %indvars.iv13
  br i1 %9, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %10 = sext i32 %2 to i64
  %11 = getelementptr inbounds [100005 x i32], ptr @prime, i64 0, i64 %10
  %12 = trunc nuw nsw i64 %indvars.iv13 to i32
  store i32 %12, ptr %11, align 4, !tbaa !5
  %13 = add nsw i32 %2, 1
  store i32 %13, ptr @k, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %1, %._crit_edge
  %15 = phi i32 [ %2, %1 ], [ %13, %._crit_edge ]
  %indvars.iv.next14 = add nuw nsw i64 %indvars.iv13, 1
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not = icmp eq i64 %indvars.iv.next14, 100000
  br i1 %exitcond.not, label %16, label %1, !llvm.loop !11

16:                                               ; preds = %14
  ret i32 0
}

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,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass