; LLVM IR from lzyrapx/Competitive-Programming :: ACdream/1114（莫比乌斯反演）.ll (Z6Mobiusi)

; 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 [222232 x i32], align 16
@mu = external dso_local global [222232 x i32], align 16
@prime = external dso_local global [222232 x i32], align 16
@cnt = external dso_local global i32, align 4

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

5:                                                ; preds = %84, %1
  %6 = load i32, ptr %3, align 4, !tbaa !5
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = icmp sle i32 %6, %7
  br i1 %8, label %9, label %87

9:                                                ; preds = %5
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [222232 x i32], ptr @isprime, 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 %3, 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 [222232 x i32], ptr @prime, i64 0, i64 %19
  store i32 %16, ptr %20, align 4, !tbaa !5
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [222232 x i32], ptr @mu, i64 0, i64 %22
  store i32 -1, ptr %23, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %15, %9
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %80, %24
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = load i32, ptr @cnt, align 4, !tbaa !5
  %28 = icmp slt i32 %26, %27
  br i1 %28, label %29, label %38

29:                                               ; preds = %25
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [222232 x i32], ptr @prime, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = mul nsw i32 %30, %34
  %36 = load i32, ptr %2, align 4, !tbaa !5
  %37 = icmp sle i32 %35, %36
  br label %38

38:                                               ; preds = %29, %25
  %39 = phi i1 [ false, %25 ], [ %37, %29 ]
  br i1 %39, label %40, label %83

40:                                               ; preds = %38
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [222232 x i32], ptr @prime, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = mul nsw i32 %41, %45
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [222232 x i32], ptr @isprime, i64 0, i64 %47
  store i32 1, ptr %48, align 4, !tbaa !5
  %49 = load i32, ptr %3, align 4, !tbaa !5
  %50 = load i32, ptr %4, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [222232 x i32], ptr @prime, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = srem i32 %49, %53
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %56, label %70

56:                                               ; preds = %40
  %57 = load i32, ptr %3, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [222232 x i32], ptr @mu, i64 0, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !5
  %61 = sub nsw i32 0, %60
  %62 = load i32, ptr %3, align 4, !tbaa !5
  %63 = load i32, ptr %4, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [222232 x i32], ptr @prime, i64 0, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !5
  %67 = mul nsw i32 %62, %66
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [222232 x i32], ptr @mu, i64 0, i64 %68
  store i32 %61, ptr %69, align 4, !tbaa !5
  br label %79

70:                                               ; preds = %40
  %71 = load i32, ptr %3, align 4, !tbaa !5
  %72 = load i32, ptr %4, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [222232 x i32], ptr @prime, i64 0, i64 %73
  %75 = load i32, ptr %74, align 4, !tbaa !5
  %76 = mul nsw i32 %71, %75
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [222232 x i32], ptr @mu, i64 0, i64 %77
  store i32 0, ptr %78, align 4, !tbaa !5
  br label %83

79:                                               ; preds = %56
  br label %80

80:                                               ; preds = %79
  %81 = load i32, ptr %4, align 4, !tbaa !5
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %4, align 4, !tbaa !5
  br label %25, !llvm.loop !9

83:                                               ; preds = %70, %38
  br label %84

84:                                               ; preds = %83
  %85 = load i32, ptr %3, align 4, !tbaa !5
  %86 = add nsw i32 %85, 1
  store i32 %86, ptr %3, align 4, !tbaa !5
  br label %5, !llvm.loop !11

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

@isprime = external dso_local local_unnamed_addr global [222232 x i32], align 16
@mu = external dso_local local_unnamed_addr global [222232 x i32], align 16
@prime = external dso_local local_unnamed_addr global [222232 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 @_Z6Mobiusi(i32 noundef %0) local_unnamed_addr #0 {
  store i32 0, ptr @cnt, align 4, !tbaa !5
  store i32 1, ptr getelementptr inbounds (i8, ptr @mu, i64 4), align 4, !tbaa !5
  %.not28 = icmp slt i32 %0, 2
  br i1 %.not28, label %._crit_edge, label %.lr.ph31.preheader

.lr.ph31.preheader:                               ; preds = %1
  %2 = add nuw i32 %0, 1
  %wide.trip.count36 = zext i32 %2 to i64
  br label %.lr.ph31

.lr.ph31:                                         ; preds = %.lr.ph31.preheader, %.critedge
  %indvars.iv33 = phi i64 [ 2, %.lr.ph31.preheader ], [ %indvars.iv.next34, %.critedge ]
  %3 = phi i32 [ 0, %.lr.ph31.preheader ], [ %13, %.critedge ]
  %4 = getelementptr inbounds [222232 x i32], ptr @isprime, i64 0, i64 %indvars.iv33
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %.not23 = icmp eq i32 %5, 0
  br i1 %.not23, label %6, label %12

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

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

.lr.ph:                                           ; preds = %12
  %15 = getelementptr inbounds [222232 x i32], ptr @mu, i64 0, i64 %indvars.iv33
  %wide.trip.count = zext nneg i32 %13 to i64
  %16 = trunc nuw nsw i64 %indvars.iv33 to i32
  br label %17

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

21:                                               ; preds = %17
  %22 = sext i32 %20 to i64
  %23 = getelementptr inbounds [222232 x i32], ptr @isprime, i64 0, i64 %22
  store i32 1, ptr %23, align 4, !tbaa !5
  %24 = srem i32 %16, %19
  %.not25 = icmp eq i32 %24, 0
  br i1 %.not25, label %29, label %25

25:                                               ; preds = %21
  %26 = load i32, ptr %15, align 4, !tbaa !5
  %27 = sub nsw i32 0, %26
  %28 = getelementptr inbounds [222232 x i32], ptr @mu, i64 0, i64 %22
  store i32 %27, ptr %28, 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 %17, !llvm.loop !9

29:                                               ; preds = %21
  %30 = getelementptr inbounds [222232 x i32], ptr @mu, i64 0, i64 %22
  store i32 0, ptr %30, align 4, !tbaa !5
  br label %.critedge

.critedge:                                        ; preds = %25, %17, %12, %29
  %indvars.iv.next34 = add nuw nsw i64 %indvars.iv33, 1
  %exitcond37.not = icmp eq i64 %indvars.iv.next34, %wide.trip.count36
  br i1 %exitcond37.not, label %._crit_edge, label %.lr.ph31, !llvm.loop !11

._crit_edge:                                      ; preds = %.critedge, %1
  ret void
}

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,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass