; LLVM IR from sunkafei/xcpc-algorithm-templates :: 算法/数学算法/欧拉函数.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"

@vis = external dso_local global [1000000 x i32], align 16
@prime = external dso_local global [1000000 x i32], align 16
@phi = external dso_local global [1000000 x i32], align 16
@cnt = external dso_local global i32, align 4

; 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
  call void @llvm.memset.p0.i64(ptr align 16 @vis, i8 0, i64 4000000, i1 false)
  store i32 1, ptr getelementptr inbounds ([1000000 x i32], ptr @phi, i64 0, i64 1), align 4, !tbaa !5
  store i32 0, ptr @cnt, align 4, !tbaa !5
  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 = %97, %0
  %6 = load i32, ptr %1, align 4, !tbaa !5
  %7 = icmp slt i32 %6, 1000000
  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 %100

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

15:                                               ; preds = %9
  %16 = load i32, ptr %1, align 4, !tbaa !5
  %17 = load i32, ptr @cnt, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr @cnt, align 4, !tbaa !5
  %19 = sext i32 %17 to i64
  %20 = getelementptr inbounds [1000000 x i32], ptr @prime, i64 0, i64 %19
  store i32 %16, ptr %20, align 4, !tbaa !5
  %21 = load i32, ptr %1, align 4, !tbaa !5
  %22 = sub nsw i32 %21, 1
  %23 = load i32, ptr %1, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [1000000 x i32], ptr @phi, i64 0, i64 %24
  store i32 %22, ptr %25, align 4, !tbaa !5
  br label %26

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

27:                                               ; preds = %92, %26
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = load i32, ptr @cnt, align 4, !tbaa !5
  %30 = icmp slt i32 %28, %29
  br i1 %30, label %31, label %39

31:                                               ; preds = %27
  %32 = load i32, ptr %1, align 4, !tbaa !5
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [1000000 x i32], ptr @prime, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = mul nsw i32 %32, %36
  %38 = icmp slt i32 %37, 1000000
  br label %39

39:                                               ; preds = %31, %27
  %40 = phi i1 [ false, %27 ], [ %38, %31 ]
  br i1 %40, label %42, label %41

41:                                               ; preds = %39
  store i32 5, ptr %2, align 4
  br label %95

42:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %43 = load i32, ptr %1, align 4, !tbaa !5
  %44 = load i32, ptr %3, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [1000000 x i32], ptr @prime, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = mul nsw i32 %43, %47
  store i32 %48, ptr %4, align 4, !tbaa !5
  %49 = load i32, ptr %4, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [1000000 x i32], ptr @vis, i64 0, i64 %50
  store i32 1, ptr %51, align 4, !tbaa !5
  %52 = load i32, ptr %1, align 4, !tbaa !5
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [1000000 x i32], ptr @prime, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = srem i32 %52, %56
  %58 = icmp eq i32 %57, 0
  br i1 %58, label %59, label %72

59:                                               ; preds = %42
  %60 = load i32, ptr %1, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [1000000 x i32], ptr @phi, i64 0, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !5
  %64 = load i32, ptr %3, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [1000000 x i32], ptr @prime, i64 0, i64 %65
  %67 = load i32, ptr %66, align 4, !tbaa !5
  %68 = mul nsw i32 %63, %67
  %69 = load i32, ptr %4, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [1000000 x i32], ptr @phi, i64 0, i64 %70
  store i32 %68, ptr %71, align 4, !tbaa !5
  store i32 5, ptr %2, align 4
  br label %89

72:                                               ; preds = %42
  %73 = load i32, ptr %1, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [1000000 x i32], ptr @phi, i64 0, i64 %74
  %76 = load i32, ptr %75, align 4, !tbaa !5
  %77 = load i32, ptr %3, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [1000000 x i32], ptr @prime, i64 0, i64 %78
  %80 = load i32, ptr %79, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [1000000 x i32], ptr @phi, i64 0, i64 %81
  %83 = load i32, ptr %82, align 4, !tbaa !5
  %84 = mul nsw i32 %76, %83
  %85 = load i32, ptr %4, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [1000000 x i32], ptr @phi, i64 0, i64 %86
  store i32 %84, ptr %87, align 4, !tbaa !5
  br label %88

88:                                               ; preds = %72
  store i32 0, ptr %2, align 4
  br label %89

89:                                               ; preds = %88, %59
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %90 = load i32, ptr %2, align 4
  switch i32 %90, label %95 [
    i32 0, label %91
  ]

91:                                               ; preds = %89
  br label %92

92:                                               ; preds = %91
  %93 = load i32, ptr %3, align 4, !tbaa !5
  %94 = add nsw i32 %93, 1
  store i32 %94, ptr %3, align 4, !tbaa !5
  br label %27, !llvm.loop !9

95:                                               ; preds = %89, %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %96

96:                                               ; preds = %95
  br label %97

97:                                               ; preds = %96
  %98 = load i32, ptr %1, align 4, !tbaa !5
  %99 = add nsw i32 %98, 1
  store i32 %99, ptr %1, align 4, !tbaa !5
  br label %5, !llvm.loop !11

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

@vis = external dso_local local_unnamed_addr global [1000000 x i32], align 16
@prime = external dso_local local_unnamed_addr global [1000000 x i32], align 16
@phi = external dso_local local_unnamed_addr global [1000000 x i32], align 16
@cnt = 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 void @_Z4initv() local_unnamed_addr #0 {
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(4000000) @vis, i8 0, i64 4000000, i1 false)
  store i32 1, ptr getelementptr inbounds (i8, ptr @phi, i64 4), align 4, !tbaa !5
  store i32 0, ptr @cnt, align 4, !tbaa !5
  br label %2

1:                                                ; preds = %.critedge
  ret void

2:                                                ; preds = %0, %.critedge
  %indvars.iv34 = phi i64 [ 2, %0 ], [ %indvars.iv.next35, %.critedge ]
  %3 = phi i32 [ 0, %0 ], [ %15, %.critedge ]
  %4 = getelementptr inbounds [1000000 x i32], ptr @vis, i64 0, i64 %indvars.iv34
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %6, label %14

6:                                                ; preds = %2
  %7 = add nsw i32 %3, 1
  store i32 %7, ptr @cnt, align 4, !tbaa !5
  %8 = sext i32 %3 to i64
  %9 = getelementptr inbounds [1000000 x i32], ptr @prime, i64 0, i64 %8
  %10 = trunc nuw nsw i64 %indvars.iv34 to i32
  store i32 %10, ptr %9, align 4, !tbaa !5
  %11 = getelementptr inbounds [1000000 x i32], ptr @phi, i64 0, i64 %indvars.iv34
  %12 = trunc i64 %indvars.iv34 to i32
  %13 = add i32 %12, -1
  store i32 %13, ptr %11, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %6, %2
  %15 = phi i32 [ %7, %6 ], [ %3, %2 ]
  %16 = icmp sgt i32 %15, 0
  br i1 %16, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %14
  %17 = getelementptr inbounds [1000000 x i32], ptr @phi, i64 0, i64 %indvars.iv34
  %wide.trip.count = zext nneg i32 %15 to i64
  %18 = trunc nuw nsw i64 %indvars.iv34 to i32
  br label %19

19:                                               ; preds = %.lr.ph, %31
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %31 ]
  %20 = getelementptr inbounds [1000000 x i32], ptr @prime, i64 0, i64 %indvars.iv
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = mul nsw i32 %21, %18
  %23 = icmp slt i32 %22, 1000000
  br i1 %23, label %24, label %.critedge

24:                                               ; preds = %19
  %25 = sext i32 %22 to i64
  %26 = getelementptr inbounds [1000000 x i32], ptr @vis, i64 0, i64 %25
  store i32 1, ptr %26, align 4, !tbaa !5
  %27 = srem i32 %18, %21
  %.not25 = icmp eq i32 %27, 0
  %28 = load i32, ptr %17, align 4, !tbaa !5
  br i1 %.not25, label %.thread, label %31

.thread:                                          ; preds = %24
  %29 = mul nsw i32 %28, %21
  %30 = getelementptr inbounds [1000000 x i32], ptr @phi, i64 0, i64 %25
  store i32 %29, ptr %30, align 4, !tbaa !5
  br label %.critedge

31:                                               ; preds = %24
  %32 = sext i32 %21 to i64
  %33 = getelementptr inbounds [1000000 x i32], ptr @phi, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = mul nsw i32 %34, %28
  %36 = getelementptr inbounds [1000000 x i32], ptr @phi, i64 0, i64 %25
  store i32 %35, ptr %36, 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 %.critedge, label %19, !llvm.loop !9

.critedge:                                        ; preds = %31, %19, %14, %.thread
  %indvars.iv.next35 = add nuw nsw i64 %indvars.iv34, 1
  %exitcond37.not = icmp eq i64 %indvars.iv.next35, 1000000
  br i1 %exitcond37.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,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass