; LLVM IR from ShahjalalShohag/code-library :: Math/Polynomial Factorization.ll (Z7precompv)

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

@.str.2 = external hidden unnamed_addr constant [96 x i8], align 1
@isPrime = external dso_local global [110000 x i8], align 16
@mu = external dso_local global [110000 x i32], align 16
@.str.7 = external hidden unnamed_addr constant [11 x i8], align 1
@__PRETTY_FUNCTION__._Z7precompv = external hidden unnamed_addr constant [15 x i8], align 1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; 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 @_Z7precompv() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  store i32 1, ptr %1, align 4, !tbaa !5
  br label %5

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

8:                                                ; preds = %5
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  br label %19

9:                                                ; preds = %5
  %10 = load i32, ptr %1, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [110000 x i8], ptr @isPrime, i64 0, i64 %11
  store i8 1, ptr %12, align 1, !tbaa !9
  %13 = load i32, ptr %1, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [110000 x i32], ptr @mu, i64 0, i64 %14
  store i32 1, ptr %15, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %9
  %17 = load i32, ptr %1, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr %1, align 4, !tbaa !5
  br label %5, !llvm.loop !11

19:                                               ; preds = %8
  store i8 0, ptr getelementptr inbounds ([110000 x i8], ptr @isPrime, i64 0, i64 1), align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 2, ptr %2, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %79, %19
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = icmp slt i32 %21, 110000
  br i1 %22, label %24, label %23

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

24:                                               ; preds = %20
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [110000 x i8], ptr @isPrime, i64 0, i64 %26
  %28 = load i8, ptr %27, align 1, !tbaa !9, !range !13, !noundef !14
  %29 = trunc i8 %28 to i1
  br i1 %29, label %31, label %30

30:                                               ; preds = %24
  br label %79

31:                                               ; preds = %24
  %32 = load i32, ptr %2, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [110000 x i32], ptr @mu, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = icmp eq i32 %35, 1
  br i1 %36, label %37, label %38

37:                                               ; preds = %31
  br label %40

38:                                               ; preds = %31
  call void @__assert_fail(ptr noundef @.str.7, ptr noundef @.str.2, i32 noundef 66, ptr noundef @__PRETTY_FUNCTION__._Z7precompv) #4
  unreachable

39:                                               ; No predecessors!
  br label %40

40:                                               ; preds = %39, %37
  %41 = load i32, ptr %2, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [110000 x i32], ptr @mu, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = mul nsw i32 %44, -1
  store i32 %45, ptr %43, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %46 = load i32, ptr %2, align 4, !tbaa !5
  %47 = load i32, ptr %2, align 4, !tbaa !5
  %48 = add nsw i32 %46, %47
  store i32 %48, ptr %4, align 4, !tbaa !5
  br label %49

49:                                               ; preds = %74, %40
  %50 = load i32, ptr %4, align 4, !tbaa !5
  %51 = icmp slt i32 %50, 110000
  br i1 %51, label %53, label %52

52:                                               ; preds = %49
  store i32 8, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %78

53:                                               ; preds = %49
  %54 = load i32, ptr %4, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [110000 x i8], ptr @isPrime, i64 0, i64 %55
  store i8 0, ptr %56, align 1, !tbaa !9
  %57 = load i32, ptr %4, align 4, !tbaa !5
  %58 = load i32, ptr %2, align 4, !tbaa !5
  %59 = sdiv i32 %57, %58
  %60 = load i32, ptr %2, align 4, !tbaa !5
  %61 = srem i32 %59, %60
  %62 = icmp eq i32 %61, 0
  br i1 %62, label %63, label %67

63:                                               ; preds = %53
  %64 = load i32, ptr %4, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [110000 x i32], ptr @mu, i64 0, i64 %65
  store i32 0, ptr %66, align 4, !tbaa !5
  br label %73

67:                                               ; preds = %53
  %68 = load i32, ptr %4, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [110000 x i32], ptr @mu, i64 0, i64 %69
  %71 = load i32, ptr %70, align 4, !tbaa !5
  %72 = mul nsw i32 %71, -1
  store i32 %72, ptr %70, align 4, !tbaa !5
  br label %73

73:                                               ; preds = %67, %63
  br label %74

74:                                               ; preds = %73
  %75 = load i32, ptr %2, align 4, !tbaa !5
  %76 = load i32, ptr %4, align 4, !tbaa !5
  %77 = add nsw i32 %76, %75
  store i32 %77, ptr %4, align 4, !tbaa !5
  br label %49, !llvm.loop !15

78:                                               ; preds = %52
  br label %79

79:                                               ; preds = %78, %30
  %80 = load i32, ptr %2, align 4, !tbaa !5
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %2, align 4, !tbaa !5
  br label %20, !llvm.loop !16

82:                                               ; preds = %23
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn nounwind "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 = { 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 #3 = { nounwind }
attributes #4 = { noreturn 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 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !12}


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

@.str.2 = external hidden unnamed_addr constant [96 x i8], align 1
@isPrime = external dso_local local_unnamed_addr global [110000 x i8], align 16
@mu = external dso_local local_unnamed_addr global [110000 x i32], align 16
@.str.7 = external hidden unnamed_addr constant [11 x i8], align 1
@__PRETTY_FUNCTION__._Z7precompv = external hidden unnamed_addr constant [15 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z7precompv() local_unnamed_addr #1 {
vector.ph:
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 2 dereferenceable(109999) getelementptr inbounds (i8, ptr @isPrime, i64 2), i8 1, i64 109998, i1 false), !tbaa !5
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next.2, %vector.body ]
  %offset.idx = or disjoint i64 %index, 1
  %0 = getelementptr inbounds [110000 x i32], ptr @mu, i64 0, i64 %offset.idx
  %1 = getelementptr inbounds i8, ptr %0, i64 16
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr %0, align 4, !tbaa !9
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr %1, align 4, !tbaa !9
  %offset.idx.1 = add nuw nsw i64 %index, 9
  %2 = getelementptr inbounds [110000 x i32], ptr @mu, i64 0, i64 %offset.idx.1
  %3 = getelementptr inbounds i8, ptr %2, i64 16
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr %2, align 4, !tbaa !9
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr %3, align 4, !tbaa !9
  %offset.idx.2 = add nuw nsw i64 %index, 17
  %4 = getelementptr inbounds [110000 x i32], ptr @mu, i64 0, i64 %offset.idx.2
  %5 = getelementptr inbounds i8, ptr %4, i64 16
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr %4, align 4, !tbaa !9
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr %5, align 4, !tbaa !9
  %index.next.2 = add nuw nsw i64 %index, 24
  %6 = icmp eq i64 %index.next.2, 109992
  br i1 %6, label %scalar.ph, label %vector.body, !llvm.loop !11

scalar.ph:                                        ; preds = %vector.body
  store i32 1, ptr getelementptr inbounds (i8, ptr @mu, i64 439972), align 4, !tbaa !9
  store i32 1, ptr getelementptr inbounds (i8, ptr @mu, i64 439976), align 8, !tbaa !9
  store i32 1, ptr getelementptr inbounds (i8, ptr @mu, i64 439980), align 4, !tbaa !9
  store i32 1, ptr getelementptr inbounds (i8, ptr @mu, i64 439984), align 16, !tbaa !9
  store i32 1, ptr getelementptr inbounds (i8, ptr @mu, i64 439988), align 4, !tbaa !9
  store i32 1, ptr getelementptr inbounds (i8, ptr @mu, i64 439992), align 8, !tbaa !9
  store i32 1, ptr getelementptr inbounds (i8, ptr @mu, i64 439996), align 4, !tbaa !9
  store i8 0, ptr getelementptr inbounds (i8, ptr @isPrime, i64 1), align 1, !tbaa !5
  br label %8

7:                                                ; preds = %.loopexit
  ret void

8:                                                ; preds = %scalar.ph, %.loopexit
  %indvars.iv30 = phi i64 [ 2, %scalar.ph ], [ %indvars.iv.next31, %.loopexit ]
  %indvars.iv28 = phi i64 [ 4, %scalar.ph ], [ %indvars.iv.next29, %.loopexit ]
  %9 = getelementptr inbounds [110000 x i8], ptr @isPrime, i64 0, i64 %indvars.iv30
  %10 = load i8, ptr %9, align 1, !tbaa !5, !range !15, !noundef !16
  %11 = trunc nuw i8 %10 to i1
  br i1 %11, label %12, label %.loopexit

12:                                               ; preds = %8
  %13 = getelementptr inbounds [110000 x i32], ptr @mu, i64 0, i64 %indvars.iv30
  %14 = load i32, ptr %13, align 4, !tbaa !9
  %15 = icmp eq i32 %14, 1
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  tail call void @__assert_fail(ptr noundef nonnull @.str.7, ptr noundef nonnull @.str.2, i32 noundef 66, ptr noundef nonnull @__PRETTY_FUNCTION__._Z7precompv) #3
  unreachable

17:                                               ; preds = %12
  store i32 -1, ptr %13, align 4, !tbaa !9
  %18 = icmp ult i64 %indvars.iv30, 55000
  br i1 %18, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %17
  %19 = trunc nuw nsw i64 %indvars.iv30 to i32
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %29
  %indvars.iv32 = phi i64 [ %indvars.iv28, %.lr.ph.preheader ], [ %indvars.iv.next33, %29 ]
  %20 = getelementptr inbounds [110000 x i8], ptr @isPrime, i64 0, i64 %indvars.iv32
  store i8 0, ptr %20, align 1, !tbaa !5
  %21 = trunc nuw nsw i64 %indvars.iv32 to i32
  %22 = udiv i32 %21, %19
  %23 = urem i32 %22, %19
  %24 = icmp eq i32 %23, 0
  %25 = getelementptr inbounds [110000 x i32], ptr @mu, i64 0, i64 %indvars.iv32
  br i1 %24, label %29, label %26

26:                                               ; preds = %.lr.ph
  %27 = load i32, ptr %25, align 4, !tbaa !9
  %28 = sub nsw i32 0, %27
  br label %29

29:                                               ; preds = %.lr.ph, %26
  %.sink = phi i32 [ %28, %26 ], [ 0, %.lr.ph ]
  store i32 %.sink, ptr %25, align 4, !tbaa !9
  %indvars.iv.next33 = add nuw nsw i64 %indvars.iv32, %indvars.iv30
  %30 = icmp ult i64 %indvars.iv.next33, 110000
  br i1 %30, label %.lr.ph, label %.loopexit, !llvm.loop !17

.loopexit:                                        ; preds = %29, %17, %8
  %indvars.iv.next31 = add nuw nsw i64 %indvars.iv30, 1
  %indvars.iv.next29 = add nuw nsw i64 %indvars.iv28, 2
  %exitcond36.not = icmp eq i64 %indvars.iv.next31, 110000
  br i1 %exitcond36.not, label %7, label %8, !llvm.loop !18
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

attributes #0 = { noreturn nounwind "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 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { noreturn 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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12, !13, !14}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!"llvm.loop.isvectorized", i32 1}
!14 = !{!"llvm.loop.unroll.runtime.disable"}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = distinct !{!17, !12}
!18 = distinct !{!18, !12}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopIdiomRecognizePass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,SROAPass,SimplifyCFGPass,TailCallElimPass