; LLVM IR from lzyrapx/Competitive-Programming :: 百度之星/2020/第一场/H.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"

@mu = external dso_local global [1234567 x i32], align 16
@f = external dso_local global [1234567 x i32], align 16
@prime = external dso_local global [1234567 x i32], 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 nounwind uwtable
define dso_local void @_Z4initv() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 1, ptr getelementptr inbounds ([1234567 x i32], ptr @mu, i64 0, i64 1), align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 0, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  store i32 2, ptr %2, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %70, %0
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = icmp slt i32 %7, 1234567
  br i1 %8, label %10, label %9

9:                                                ; preds = %6
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  br label %73

10:                                               ; preds = %6
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [1234567 x i32], ptr @f, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %25, label %16

16:                                               ; preds = %10
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = load i32, ptr %1, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr %1, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [1234567 x i32], ptr @prime, i64 0, i64 %20
  store i32 %17, ptr %21, align 4, !tbaa !5
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [1234567 x i32], ptr @mu, i64 0, i64 %23
  store i32 -1, ptr %24, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %16, %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %65, %25
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = load i32, ptr %1, align 4, !tbaa !5
  %29 = icmp sle i32 %27, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %26
  store i32 5, ptr %3, align 4
  br label %68

31:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %32 = load i32, ptr %2, align 4, !tbaa !5
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [1234567 x i32], ptr @prime, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = mul nsw i32 %32, %36
  store i32 %37, ptr %5, align 4, !tbaa !5
  %38 = load i32, ptr %5, align 4, !tbaa !5
  %39 = icmp sge i32 %38, 1234567
  br i1 %39, label %40, label %41

40:                                               ; preds = %31
  store i32 5, ptr %3, align 4
  br label %62

41:                                               ; preds = %31
  %42 = load i32, ptr %5, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [1234567 x i32], ptr @f, i64 0, i64 %43
  store i32 1, ptr %44, align 4, !tbaa !5
  %45 = load i32, ptr %2, align 4, !tbaa !5
  %46 = load i32, ptr %4, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [1234567 x i32], ptr @prime, i64 0, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = srem i32 %45, %49
  %51 = icmp eq i32 %50, 0
  br i1 %51, label %52, label %53

52:                                               ; preds = %41
  store i32 5, ptr %3, align 4
  br label %62

53:                                               ; preds = %41
  %54 = load i32, ptr %2, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [1234567 x i32], ptr @mu, i64 0, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !5
  %58 = sub nsw i32 0, %57
  %59 = load i32, ptr %5, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [1234567 x i32], ptr @mu, i64 0, i64 %60
  store i32 %58, ptr %61, align 4, !tbaa !5
  store i32 0, ptr %3, align 4
  br label %62

62:                                               ; preds = %53, %52, %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  %63 = load i32, ptr %3, align 4
  switch i32 %63, label %68 [
    i32 0, label %64
  ]

64:                                               ; preds = %62
  br label %65

65:                                               ; preds = %64
  %66 = load i32, ptr %4, align 4, !tbaa !5
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %4, align 4, !tbaa !5
  br label %26, !llvm.loop !9

68:                                               ; preds = %62, %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %69

69:                                               ; preds = %68
  br label %70

70:                                               ; preds = %69
  %71 = load i32, ptr %2, align 4, !tbaa !5
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %2, align 4, !tbaa !5
  br label %6, !llvm.loop !11

73:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  ret void
}

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

@mu = external dso_local local_unnamed_addr global [1234567 x i32], align 16
@f = external dso_local local_unnamed_addr global [1234567 x i32], align 16
@prime = external dso_local local_unnamed_addr global [1234567 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 1, ptr getelementptr inbounds (i8, ptr @mu, i64 4), align 4, !tbaa !5
  br label %2

1:                                                ; preds = %._crit_edge
  ret void

2:                                                ; preds = %0, %._crit_edge
  %indvars.iv30 = phi i64 [ 2, %0 ], [ %indvars.iv.next31, %._crit_edge ]
  %.028 = phi i32 [ 0, %0 ], [ %.1, %._crit_edge ]
  %3 = getelementptr inbounds [1234567 x i32], ptr @f, i64 0, i64 %indvars.iv30
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %5, label %11

5:                                                ; preds = %2
  %6 = add nsw i32 %.028, 1
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [1234567 x i32], ptr @prime, i64 0, i64 %7
  %9 = trunc nuw nsw i64 %indvars.iv30 to i32
  store i32 %9, ptr %8, align 4, !tbaa !5
  %10 = getelementptr inbounds [1234567 x i32], ptr @mu, i64 0, i64 %indvars.iv30
  store i32 -1, ptr %10, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %5, %2
  %.1 = phi i32 [ %.028, %2 ], [ %6, %5 ]
  %.not2223 = icmp slt i32 %.1, 1
  br i1 %.not2223, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %11
  %12 = getelementptr inbounds [1234567 x i32], ptr @mu, i64 0, i64 %indvars.iv30
  %13 = add nuw i32 %.1, 1
  %wide.trip.count = zext i32 %13 to i64
  %14 = trunc nuw nsw i64 %indvars.iv30 to i32
  br label %15

15:                                               ; preds = %.lr.ph, %.critedge
  %indvars.iv = phi i64 [ 1, %.lr.ph ], [ %indvars.iv.next, %.critedge ]
  %16 = getelementptr inbounds [1234567 x i32], ptr @prime, i64 0, i64 %indvars.iv
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = mul nsw i32 %17, %14
  %19 = icmp sgt i32 %18, 1234566
  br i1 %19, label %._crit_edge, label %20

20:                                               ; preds = %15
  %21 = sext i32 %18 to i64
  %22 = getelementptr inbounds [1234567 x i32], ptr @f, i64 0, i64 %21
  store i32 1, ptr %22, align 4, !tbaa !5
  %23 = srem i32 %14, %17
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %._crit_edge, label %.critedge

.critedge:                                        ; preds = %20
  %25 = load i32, ptr %12, align 4, !tbaa !5
  %26 = sub nsw i32 0, %25
  %27 = getelementptr inbounds [1234567 x i32], ptr @mu, i64 0, i64 %21
  store i32 %26, ptr %27, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %15, !llvm.loop !9

._crit_edge:                                      ; preds = %.critedge, %20, %15, %11
  %indvars.iv.next31 = add nuw nsw i64 %indvars.iv30, 1
  %exitcond33.not = icmp eq i64 %indvars.iv.next31, 1234567
  br i1 %exitcond33.not, label %1, label %2, !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,ReassociatePass,SROAPass,SimplifyCFGPass