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

; 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 [10000010 x i8], 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 @_Z15generate_mobiusv() #1 {
  %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
  store i32 1, ptr %1, align 4, !tbaa !8
  br label %4

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

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

8:                                                ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  %9 = load i32, ptr %1, align 4, !tbaa !8
  %10 = load i32, ptr %1, align 4, !tbaa !8
  %11 = add nsw i32 %9, %10
  store i32 %11, ptr %3, align 4, !tbaa !8
  br label %12

12:                                               ; preds = %29, %8
  %13 = load i32, ptr %3, align 4, !tbaa !8
  %14 = icmp slt i32 %13, 10000010
  br i1 %14, label %16, label %15

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

16:                                               ; preds = %12
  %17 = load i32, ptr %1, align 4, !tbaa !8
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [10000010 x i8], ptr @mu, i64 0, i64 %18
  %20 = load i8, ptr %19, align 1, !tbaa !5
  %21 = sext i8 %20 to i32
  %22 = load i32, ptr %3, align 4, !tbaa !8
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [10000010 x i8], ptr @mu, i64 0, i64 %23
  %25 = load i8, ptr %24, align 1, !tbaa !5
  %26 = sext i8 %25 to i32
  %27 = sub nsw i32 %26, %21
  %28 = trunc i32 %27 to i8
  store i8 %28, ptr %24, align 1, !tbaa !5
  br label %29

29:                                               ; preds = %16
  %30 = load i32, ptr %1, align 4, !tbaa !8
  %31 = load i32, ptr %3, align 4, !tbaa !8
  %32 = add nsw i32 %31, %30
  store i32 %32, ptr %3, align 4, !tbaa !8
  br label %12, !llvm.loop !10

33:                                               ; preds = %15
  br label %34

34:                                               ; preds = %33
  %35 = load i32, ptr %1, align 4, !tbaa !8
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %1, align 4, !tbaa !8
  br label %4, !llvm.loop !12

37:                                               ; preds = %7
  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 = !{!"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"

@mu = 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 @_Z15generate_mobiusv() local_unnamed_addr #0 {
  store i8 1, ptr getelementptr inbounds (i8, ptr @mu, i64 1), align 1, !tbaa !5
  br label %2

1:                                                ; preds = %._crit_edge
  ret void

2:                                                ; preds = %0, %._crit_edge
  %indvars.iv12 = phi i64 [ 1, %0 ], [ %indvars.iv.next13, %._crit_edge ]
  %indvars.iv = phi i64 [ 2, %0 ], [ %indvars.iv.next, %._crit_edge ]
  %3 = icmp ult i64 %indvars.iv12, 5000005
  br i1 %3, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2
  %4 = getelementptr inbounds [10000010 x i8], ptr @mu, i64 0, i64 %indvars.iv12
  br label %5

._crit_edge:                                      ; preds = %5, %2
  %indvars.iv.next13 = add nuw nsw i64 %indvars.iv12, 1
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not = icmp eq i64 %indvars.iv.next13, 10000010
  br i1 %exitcond.not, label %1, label %2, !llvm.loop !8

5:                                                ; preds = %.lr.ph, %5
  %indvars.iv14 = phi i64 [ %indvars.iv, %.lr.ph ], [ %indvars.iv.next15, %5 ]
  %6 = load i8, ptr %4, align 1, !tbaa !5
  %7 = getelementptr inbounds [10000010 x i8], ptr @mu, i64 0, i64 %indvars.iv14
  %8 = load i8, ptr %7, align 1, !tbaa !5
  %9 = sub i8 %8, %6
  store i8 %9, ptr %7, align 1, !tbaa !5
  %indvars.iv.next15 = add nuw nsw i64 %indvars.iv14, %indvars.iv12
  %10 = icmp ult i64 %indvars.iv.next15, 10000010
  br i1 %10, label %5, label %._crit_edge, !llvm.loop !10
}

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 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}


; Effective O3 passes: GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass