; LLVM IR from sgtlaugh/algovault :: code_library/mobius_function.ll (Z20generate_mobius_fastv)

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

@len = external dso_local global i32, align 4
@prime = external dso_local global [666666 x i32], align 16
@mu = external dso_local global [10000010 x i8], align 16
@flag = external dso_local global [10000010 x i8], align 16

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

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

7:                                                ; preds = %4
  %8 = load i32, ptr %1, align 4, !tbaa !8
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [10000010 x i8], ptr @flag, i64 0, i64 %9
  %11 = load i8, ptr %10, align 1, !tbaa !5
  %12 = icmp ne i8 %11, 0
  br i1 %12, label %22, label %13

13:                                               ; preds = %7
  %14 = load i32, ptr %1, align 4, !tbaa !8
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [10000010 x i8], ptr @mu, i64 0, i64 %15
  store i8 -1, ptr %16, align 1, !tbaa !5
  %17 = load i32, ptr %1, align 4, !tbaa !8
  %18 = load i32, ptr @len, align 4, !tbaa !8
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr @len, align 4, !tbaa !8
  %20 = sext i32 %18 to i64
  %21 = getelementptr inbounds [666666 x i32], ptr @prime, i64 0, i64 %20
  store i32 %17, ptr %21, align 4, !tbaa !8
  br label %22

22:                                               ; preds = %13, %7
  store i32 0, ptr %2, align 4, !tbaa !8
  br label %23

23:                                               ; preds = %66, %22
  %24 = load i32, ptr %2, align 4, !tbaa !8
  %25 = load i32, ptr @len, align 4, !tbaa !8
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %27, label %35

27:                                               ; preds = %23
  %28 = load i32, ptr %1, align 4, !tbaa !8
  %29 = load i32, ptr %2, align 4, !tbaa !8
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [666666 x i32], ptr @prime, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !8
  %33 = mul nsw i32 %28, %32
  store i32 %33, ptr %3, align 4, !tbaa !8
  %34 = icmp slt i32 %33, 10000010
  br label %35

35:                                               ; preds = %27, %23
  %36 = phi i1 [ false, %23 ], [ %34, %27 ]
  br i1 %36, label %37, label %69

37:                                               ; preds = %35
  %38 = load i32, ptr %3, align 4, !tbaa !8
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [10000010 x i8], ptr @flag, i64 0, i64 %39
  store i8 1, ptr %40, align 1, !tbaa !5
  %41 = load i32, ptr %1, align 4, !tbaa !8
  %42 = load i32, ptr %2, align 4, !tbaa !8
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [666666 x i32], ptr @prime, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !8
  %46 = srem i32 %41, %45
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %52, label %48

48:                                               ; preds = %37
  %49 = load i32, ptr %3, align 4, !tbaa !8
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [10000010 x i8], ptr @mu, i64 0, i64 %50
  store i8 0, ptr %51, align 1, !tbaa !5
  br label %69

52:                                               ; preds = %37
  %53 = load i32, ptr %1, align 4, !tbaa !8
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [10000010 x i8], ptr @mu, i64 0, i64 %54
  %56 = load i8, ptr %55, align 1, !tbaa !5
  %57 = sext i8 %56 to i32
  %58 = load i32, ptr %3, align 4, !tbaa !8
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [10000010 x i8], ptr @mu, i64 0, i64 %59
  %61 = load i8, ptr %60, align 1, !tbaa !5
  %62 = sext i8 %61 to i32
  %63 = sub nsw i32 %62, %57
  %64 = trunc i32 %63 to i8
  store i8 %64, ptr %60, align 1, !tbaa !5
  br label %65

65:                                               ; preds = %52
  br label %66

66:                                               ; preds = %65
  %67 = load i32, ptr %2, align 4, !tbaa !8
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %2, align 4, !tbaa !8
  br label %23, !llvm.loop !10

69:                                               ; preds = %48, %35
  br label %70

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

73:                                               ; preds = %4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


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

@len = external dso_local local_unnamed_addr global i32, align 4
@prime = external dso_local local_unnamed_addr global [666666 x i32], align 16
@mu = external dso_local local_unnamed_addr global [10000010 x i8], align 16
@flag = external dso_local local_unnamed_addr global [10000010 x i8], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z20generate_mobius_fastv() local_unnamed_addr #0 {
  store i8 1, ptr getelementptr inbounds (i8, ptr @mu, i64 1), align 1, !tbaa !5
  %len.promoted = load i32, ptr @len, align 4, !tbaa !8
  br label %1

1:                                                ; preds = %0, %.critedge
  %indvars.iv23 = phi i64 [ 2, %0 ], [ %indvars.iv.next24, %.critedge ]
  %2 = phi i32 [ %len.promoted, %0 ], [ %12, %.critedge ]
  %3 = getelementptr inbounds [10000010 x i8], ptr @flag, i64 0, i64 %indvars.iv23
  %4 = load i8, ptr %3, align 1, !tbaa !5
  %.not = icmp eq i8 %4, 0
  br i1 %.not, label %5, label %11

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

11:                                               ; preds = %5, %1
  %12 = phi i32 [ %7, %5 ], [ %2, %1 ]
  %13 = icmp sgt i32 %12, 0
  br i1 %13, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %11
  %14 = getelementptr inbounds [10000010 x i8], ptr @mu, i64 0, i64 %indvars.iv23
  %wide.trip.count = zext nneg i32 %12 to i64
  %15 = trunc nuw nsw i64 %indvars.iv23 to i32
  br label %16

16:                                               ; preds = %.lr.ph, %27
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %27 ]
  %17 = getelementptr inbounds [666666 x i32], ptr @prime, i64 0, i64 %indvars.iv
  %18 = load i32, ptr %17, align 4, !tbaa !8
  %19 = mul nsw i32 %18, %15
  %20 = icmp slt i32 %19, 10000010
  br i1 %20, label %21, label %.critedge

21:                                               ; preds = %16
  %22 = sext i32 %19 to i64
  %23 = getelementptr inbounds [10000010 x i8], ptr @flag, i64 0, i64 %22
  store i8 1, ptr %23, align 1, !tbaa !5
  %24 = srem i32 %15, %18
  %.not17 = icmp eq i32 %24, 0
  br i1 %.not17, label %25, label %27

25:                                               ; preds = %21
  %26 = getelementptr inbounds [10000010 x i8], ptr @mu, i64 0, i64 %22
  store i8 0, ptr %26, align 1, !tbaa !5
  br label %.critedge

27:                                               ; preds = %21
  %28 = load i8, ptr %14, align 1, !tbaa !5
  %29 = getelementptr inbounds [10000010 x i8], ptr @mu, i64 0, i64 %22
  %30 = load i8, ptr %29, align 1, !tbaa !5
  %31 = sub i8 %30, %28
  store i8 %31, ptr %29, align 1, !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 %16, !llvm.loop !10

.critedge:                                        ; preds = %27, %16, %11, %25
  %indvars.iv.next24 = add nuw nsw i64 %indvars.iv23, 1
  %exitcond26.not = icmp eq i64 %indvars.iv.next24, 10000010
  br i1 %exitcond26.not, label %32, label %1, !llvm.loop !12

32:                                               ; preds = %.critedge
  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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass