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

@tot = external dso_local global i32, align 4
@pr = external dso_local global [283147 x i32], align 16
@_ZZ4initvE1d = external hidden global [4000001 x i32], align 16

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

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

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

9:                                                ; preds = %5
  %10 = load i32, ptr %1, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [4000001 x i32], ptr @_ZZ4initvE1d, i64 0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %24, label %15

15:                                               ; preds = %9
  %16 = load i32, ptr %1, align 4, !tbaa !5
  %17 = load i32, ptr %1, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [4000001 x i32], ptr @_ZZ4initvE1d, i64 0, i64 %18
  store i32 %16, ptr %19, align 4, !tbaa !5
  %20 = load i32, ptr @tot, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr @tot, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [283147 x i32], ptr @pr, i64 0, i64 %22
  store i32 %16, ptr %23, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %15, %9
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 1, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  br label %25

25:                                               ; preds = %53, %24
  %26 = load i32, ptr %1, align 4, !tbaa !5
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [283147 x i32], ptr @pr, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = mul nsw i32 %26, %30
  store i32 %31, ptr %4, align 4, !tbaa !5
  %32 = icmp slt i32 %31, 4000001
  br i1 %32, label %34, label %33

33:                                               ; preds = %25
  store i32 5, ptr %2, align 4
  br label %56

34:                                               ; preds = %25
  %35 = load i32, ptr %3, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [283147 x i32], ptr @pr, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [4000001 x i32], ptr @_ZZ4initvE1d, i64 0, i64 %40
  store i32 %38, ptr %41, align 4, !tbaa !5
  %42 = load i32, ptr %1, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [4000001 x i32], ptr @_ZZ4initvE1d, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = load i32, ptr %3, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [283147 x i32], ptr @pr, i64 0, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = icmp eq i32 %45, %49
  br i1 %50, label %51, label %52

51:                                               ; preds = %34
  store i32 5, ptr %2, align 4
  br label %56

52:                                               ; preds = %34
  br label %53

53:                                               ; preds = %52
  %54 = load i32, ptr %3, align 4, !tbaa !5
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %3, align 4, !tbaa !5
  br label %25, !llvm.loop !9

56:                                               ; preds = %51, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %57

57:                                               ; preds = %56
  br label %58

58:                                               ; preds = %57
  %59 = load i32, ptr %1, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %1, align 4, !tbaa !5
  br label %5, !llvm.loop !11

61:                                               ; preds = %8
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

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

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 nounwind willreturn memory(argmem: write) }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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"

@tot = external dso_local local_unnamed_addr global i32, align 4
@pr = external dso_local local_unnamed_addr global [283147 x i32], align 16
@_ZZ4initvE1d = external hidden local_unnamed_addr global [4000001 x i32], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z4initv() local_unnamed_addr #0 {
  store i32 0, ptr @tot, align 4, !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(16000004) @_ZZ4initvE1d, i8 0, i64 16000004, i1 false)
  br label %2

1:                                                ; preds = %._crit_edge
  ret void

2:                                                ; preds = %0, %._crit_edge
  %indvars.iv18 = phi i64 [ 2, %0 ], [ %indvars.iv.next19, %._crit_edge ]
  %3 = phi i32 [ 0, %0 ], [ %11, %._crit_edge ]
  %4 = getelementptr inbounds [4000001 x i32], ptr @_ZZ4initvE1d, i64 0, i64 %indvars.iv18
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %.not = icmp eq i32 %5, 0
  %6 = trunc nuw nsw i64 %indvars.iv18 to i32
  br i1 %.not, label %7, label %._crit_edge21

7:                                                ; preds = %2
  store i32 %6, ptr %4, align 4, !tbaa !5
  %8 = add nsw i32 %3, 1
  store i32 %8, ptr @tot, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [283147 x i32], ptr @pr, i64 0, i64 %9
  store i32 %6, ptr %10, align 4, !tbaa !5
  br label %._crit_edge21

._crit_edge21:                                    ; preds = %2, %7
  %11 = phi i32 [ %8, %7 ], [ %3, %2 ]
  %12 = load i32, ptr getelementptr inbounds (i8, ptr @pr, i64 4), align 4, !tbaa !5
  %13 = mul nsw i32 %12, %6
  %14 = icmp slt i32 %13, 4000001
  br i1 %14, label %.lr.ph, label %._crit_edge

15:                                               ; preds = %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %16 = getelementptr inbounds [283147 x i32], ptr @pr, i64 0, i64 %indvars.iv.next
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = mul nsw i32 %17, %6
  %19 = icmp slt i32 %18, 4000001
  br i1 %19, label %.lr.ph, label %._crit_edge, !llvm.loop !9

.lr.ph:                                           ; preds = %._crit_edge21, %15
  %indvars.iv = phi i64 [ %indvars.iv.next, %15 ], [ 1, %._crit_edge21 ]
  %20 = phi i32 [ %18, %15 ], [ %13, %._crit_edge21 ]
  %21 = phi i32 [ %17, %15 ], [ %12, %._crit_edge21 ]
  %22 = sext i32 %20 to i64
  %23 = getelementptr inbounds [4000001 x i32], ptr @_ZZ4initvE1d, i64 0, i64 %22
  store i32 %21, ptr %23, align 4, !tbaa !5
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = icmp eq i32 %24, %21
  br i1 %25, label %._crit_edge, label %15

._crit_edge:                                      ; preds = %15, %.lr.ph, %._crit_edge21
  %indvars.iv.next19 = add nuw nsw i64 %indvars.iv18, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next19, 4000001
  br i1 %exitcond.not, label %1, label %2, !llvm.loop !11
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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" }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }

!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,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass