; LLVM IR from abhisheknaiidu/dsa :: Other/Hackerearth/Maths/micro-and-prime-prime.ll (Z4isppv)

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

@a = external dso_local global [1000001 x i64], align 16
@pp = external dso_local global [1000001 x i64], 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 @_Z4isppv() #1 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #2
  store i64 1000000, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #2
  store i64 2, ptr %2, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %17, %0
  %10 = load i64, ptr %2, align 8, !tbaa !5
  %11 = load i64, ptr %1, align 8, !tbaa !5
  %12 = icmp sle i64 %10, %11
  br i1 %12, label %14, label %13

13:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #2
  br label %20

14:                                               ; preds = %9
  %15 = load i64, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds [1000001 x i64], ptr @a, i64 0, i64 %15
  store i64 1, ptr %16, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %14
  %18 = load i64, ptr %2, align 8, !tbaa !5
  %19 = add nsw i64 %18, 1
  store i64 %19, ptr %2, align 8, !tbaa !5
  br label %9, !llvm.loop !9

20:                                               ; preds = %13
  store i64 0, ptr getelementptr inbounds ([1000001 x i64], ptr @a, i64 0, i64 1), align 8, !tbaa !5
  store i64 0, ptr @a, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  store i64 2, ptr %3, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %51, %20
  %22 = load i64, ptr %3, align 8, !tbaa !5
  %23 = load i64, ptr %3, align 8, !tbaa !5
  %24 = mul nsw i64 %22, %23
  %25 = load i64, ptr %1, align 8, !tbaa !5
  %26 = icmp sle i64 %24, %25
  br i1 %26, label %28, label %27

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

28:                                               ; preds = %21
  %29 = load i64, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds [1000001 x i64], ptr @a, i64 0, i64 %29
  %31 = load i64, ptr %30, align 8, !tbaa !5
  %32 = icmp ne i64 %31, 0
  br i1 %32, label %33, label %50

33:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %34 = load i64, ptr %3, align 8, !tbaa !5
  %35 = load i64, ptr %3, align 8, !tbaa !5
  %36 = mul nsw i64 %34, %35
  store i64 %36, ptr %5, align 8, !tbaa !5
  br label %37

37:                                               ; preds = %45, %33
  %38 = load i64, ptr %5, align 8, !tbaa !5
  %39 = load i64, ptr %1, align 8, !tbaa !5
  %40 = icmp sle i64 %38, %39
  br i1 %40, label %42, label %41

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

42:                                               ; preds = %37
  %43 = load i64, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds [1000001 x i64], ptr @a, i64 0, i64 %43
  store i64 0, ptr %44, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %42
  %46 = load i64, ptr %3, align 8, !tbaa !5
  %47 = load i64, ptr %5, align 8, !tbaa !5
  %48 = add nsw i64 %47, %46
  store i64 %48, ptr %5, align 8, !tbaa !5
  br label %37, !llvm.loop !11

49:                                               ; preds = %41
  br label %50

50:                                               ; preds = %49, %28
  br label %51

51:                                               ; preds = %50
  %52 = load i64, ptr %3, align 8, !tbaa !5
  %53 = add nsw i64 %52, 1
  store i64 %53, ptr %3, align 8, !tbaa !5
  br label %21, !llvm.loop !12

54:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store i64 0, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store i64 1, ptr %7, align 8, !tbaa !5
  br label %55

55:                                               ; preds = %80, %54
  %56 = load i64, ptr %7, align 8, !tbaa !5
  %57 = load i64, ptr %1, align 8, !tbaa !5
  %58 = icmp sle i64 %56, %57
  br i1 %58, label %60, label %59

59:                                               ; preds = %55
  store i32 11, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  br label %83

60:                                               ; preds = %55
  %61 = load i64, ptr %7, align 8, !tbaa !5
  %62 = getelementptr inbounds [1000001 x i64], ptr @a, i64 0, i64 %61
  %63 = load i64, ptr %62, align 8, !tbaa !5
  %64 = icmp ne i64 %63, 0
  br i1 %64, label %65, label %68

65:                                               ; preds = %60
  %66 = load i64, ptr %6, align 8, !tbaa !5
  %67 = add nsw i64 %66, 1
  store i64 %67, ptr %6, align 8, !tbaa !5
  br label %68

68:                                               ; preds = %65, %60
  %69 = load i64, ptr %6, align 8, !tbaa !5
  %70 = getelementptr inbounds [1000001 x i64], ptr @a, i64 0, i64 %69
  %71 = load i64, ptr %70, align 8, !tbaa !5
  %72 = icmp ne i64 %71, 0
  br i1 %72, label %73, label %76

73:                                               ; preds = %68
  %74 = load i64, ptr %7, align 8, !tbaa !5
  %75 = getelementptr inbounds [1000001 x i64], ptr @pp, i64 0, i64 %74
  store i64 1, ptr %75, align 8, !tbaa !5
  br label %79

76:                                               ; preds = %68
  %77 = load i64, ptr %7, align 8, !tbaa !5
  %78 = getelementptr inbounds [1000001 x i64], ptr @pp, i64 0, i64 %77
  store i64 0, ptr %78, align 8, !tbaa !5
  br label %79

79:                                               ; preds = %76, %73
  br label %80

80:                                               ; preds = %79
  %81 = load i64, ptr %7, align 8, !tbaa !5
  %82 = add nsw i64 %81, 1
  store i64 %82, ptr %7, align 8, !tbaa !5
  br label %55, !llvm.loop !13

83:                                               ; preds = %59
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  store i64 1, ptr %8, align 8, !tbaa !5
  br label %84

84:                                               ; preds = %98, %83
  %85 = load i64, ptr %8, align 8, !tbaa !5
  %86 = load i64, ptr %1, align 8, !tbaa !5
  %87 = icmp sle i64 %85, %86
  br i1 %87, label %89, label %88

88:                                               ; preds = %84
  store i32 14, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %101

89:                                               ; preds = %84
  %90 = load i64, ptr %8, align 8, !tbaa !5
  %91 = sub nsw i64 %90, 1
  %92 = getelementptr inbounds [1000001 x i64], ptr @pp, i64 0, i64 %91
  %93 = load i64, ptr %92, align 8, !tbaa !5
  %94 = load i64, ptr %8, align 8, !tbaa !5
  %95 = getelementptr inbounds [1000001 x i64], ptr @pp, i64 0, i64 %94
  %96 = load i64, ptr %95, align 8, !tbaa !5
  %97 = add nsw i64 %96, %93
  store i64 %97, ptr %95, align 8, !tbaa !5
  br label %98

98:                                               ; preds = %89
  %99 = load i64, ptr %8, align 8, !tbaa !5
  %100 = add nsw i64 %99, 1
  store i64 %100, ptr %8, align 8, !tbaa !5
  br label %84, !llvm.loop !14

101:                                              ; preds = %88
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #2
  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 = !{!"long long", !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}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !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"

@a = external dso_local local_unnamed_addr global [1000001 x i64], align 16
@pp = external dso_local local_unnamed_addr global [1000001 x i64], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z4isppv() local_unnamed_addr #0 {
vector.ph:
  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, 2
  %0 = getelementptr inbounds [1000001 x i64], ptr @a, i64 0, i64 %offset.idx
  %1 = getelementptr inbounds i8, ptr %0, i64 16
  store <2 x i64> <i64 1, i64 1>, ptr %0, align 16, !tbaa !5
  store <2 x i64> <i64 1, i64 1>, ptr %1, align 16, !tbaa !5
  %offset.idx.1 = add nuw nsw i64 %index, 6
  %2 = getelementptr inbounds [1000001 x i64], ptr @a, i64 0, i64 %offset.idx.1
  %3 = getelementptr inbounds i8, ptr %2, i64 16
  store <2 x i64> <i64 1, i64 1>, ptr %2, align 16, !tbaa !5
  store <2 x i64> <i64 1, i64 1>, ptr %3, align 16, !tbaa !5
  %offset.idx.2 = add nuw nsw i64 %index, 10
  %4 = getelementptr inbounds [1000001 x i64], ptr @a, i64 0, i64 %offset.idx.2
  %5 = getelementptr inbounds i8, ptr %4, i64 16
  store <2 x i64> <i64 1, i64 1>, ptr %4, align 16, !tbaa !5
  store <2 x i64> <i64 1, i64 1>, ptr %5, align 16, !tbaa !5
  %index.next.2 = add nuw nsw i64 %index, 12
  %6 = icmp eq i64 %index.next.2, 999996
  br i1 %6, label %scalar.ph, label %vector.body, !llvm.loop !9

scalar.ph:                                        ; preds = %vector.body
  store i64 1, ptr getelementptr inbounds (i8, ptr @a, i64 7999984), align 16, !tbaa !5
  store i64 1, ptr getelementptr inbounds (i8, ptr @a, i64 7999992), align 8, !tbaa !5
  store i64 1, ptr getelementptr inbounds (i8, ptr @a, i64 8000000), align 16, !tbaa !5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) @a, i8 0, i64 16, i1 false)
  br label %7

7:                                                ; preds = %scalar.ph, %.loopexit
  %8 = phi i64 [ 4, %scalar.ph ], [ %16, %.loopexit ]
  %.03241 = phi i64 [ 2, %scalar.ph ], [ %15, %.loopexit ]
  %9 = getelementptr inbounds [1000001 x i64], ptr @a, i64 0, i64 %.03241
  %10 = load i64, ptr %9, align 8, !tbaa !5
  %.not36 = icmp ne i64 %10, 0
  %11 = icmp ult i64 %8, 1000001
  %or.cond = and i1 %.not36, %11
  br i1 %or.cond, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %7, %.lr.ph
  %.03140 = phi i64 [ %13, %.lr.ph ], [ %8, %7 ]
  %12 = getelementptr inbounds [1000001 x i64], ptr @a, i64 0, i64 %.03140
  store i64 0, ptr %12, align 8, !tbaa !5
  %13 = add nuw nsw i64 %.03140, %.03241
  %14 = icmp ult i64 %13, 1000001
  br i1 %14, label %.lr.ph, label %.loopexit, !llvm.loop !13

.loopexit:                                        ; preds = %.lr.ph, %7
  %15 = add nuw nsw i64 %.03241, 1
  %16 = mul nuw nsw i64 %15, %15
  %exitcond45.not = icmp eq i64 %15, 1001
  br i1 %exitcond45.not, label %.preheader37, label %7, !llvm.loop !14

.preheader37:                                     ; preds = %.loopexit, %.preheader37
  %.02943 = phi i64 [ %30, %.preheader37 ], [ 1, %.loopexit ]
  %.03042 = phi i64 [ %spec.select.1, %.preheader37 ], [ 0, %.loopexit ]
  %17 = getelementptr inbounds [1000001 x i64], ptr @a, i64 0, i64 %.02943
  %18 = load i64, ptr %17, align 8, !tbaa !5
  %.not = icmp ne i64 %18, 0
  %19 = zext i1 %.not to i64
  %spec.select = add nuw nsw i64 %.03042, %19
  %20 = getelementptr inbounds [1000001 x i64], ptr @a, i64 0, i64 %spec.select
  %21 = load i64, ptr %20, align 8, !tbaa !5
  %.not35 = icmp ne i64 %21, 0
  %spec.select48 = zext i1 %.not35 to i64
  %22 = getelementptr inbounds [1000001 x i64], ptr @pp, i64 0, i64 %.02943
  store i64 %spec.select48, ptr %22, align 8
  %23 = add nuw nsw i64 %.02943, 1
  %24 = getelementptr inbounds [1000001 x i64], ptr @a, i64 0, i64 %23
  %25 = load i64, ptr %24, align 8, !tbaa !5
  %.not.1 = icmp ne i64 %25, 0
  %26 = zext i1 %.not.1 to i64
  %spec.select.1 = add nuw nsw i64 %spec.select, %26
  %27 = getelementptr inbounds [1000001 x i64], ptr @a, i64 0, i64 %spec.select.1
  %28 = load i64, ptr %27, align 8, !tbaa !5
  %.not35.1 = icmp ne i64 %28, 0
  %spec.select48.1 = zext i1 %.not35.1 to i64
  %29 = getelementptr inbounds [1000001 x i64], ptr @pp, i64 0, i64 %23
  store i64 %spec.select48.1, ptr %29, align 8
  %30 = add nuw nsw i64 %.02943, 2
  %exitcond46.not.1 = icmp eq i64 %30, 1000001
  br i1 %exitcond46.not.1, label %.preheader.preheader, label %.preheader37, !llvm.loop !15

.preheader.preheader:                             ; preds = %.preheader37
  %.pre = load i64, ptr @pp, align 16, !tbaa !5
  br label %.preheader

31:                                               ; preds = %.preheader
  ret void

.preheader:                                       ; preds = %.preheader, %.preheader.preheader
  %32 = phi i64 [ %.pre, %.preheader.preheader ], [ %51, %.preheader ]
  %.044 = phi i64 [ 1, %.preheader.preheader ], [ %52, %.preheader ]
  %33 = getelementptr inbounds [1000001 x i64], ptr @pp, i64 0, i64 %.044
  %34 = load i64, ptr %33, align 8, !tbaa !5
  %35 = add nsw i64 %34, %32
  store i64 %35, ptr %33, align 8, !tbaa !5
  %36 = add nuw nsw i64 %.044, 1
  %37 = getelementptr inbounds [1000001 x i64], ptr @pp, i64 0, i64 %36
  %38 = load i64, ptr %37, align 8, !tbaa !5
  %39 = add nsw i64 %38, %35
  store i64 %39, ptr %37, align 8, !tbaa !5
  %40 = add nuw nsw i64 %.044, 2
  %41 = getelementptr inbounds [1000001 x i64], ptr @pp, i64 0, i64 %40
  %42 = load i64, ptr %41, align 8, !tbaa !5
  %43 = add nsw i64 %42, %39
  store i64 %43, ptr %41, align 8, !tbaa !5
  %44 = add nuw nsw i64 %.044, 3
  %45 = getelementptr inbounds [1000001 x i64], ptr @pp, i64 0, i64 %44
  %46 = load i64, ptr %45, align 8, !tbaa !5
  %47 = add nsw i64 %46, %43
  store i64 %47, ptr %45, align 8, !tbaa !5
  %48 = add nuw nsw i64 %.044, 4
  %49 = getelementptr inbounds [1000001 x i64], ptr @pp, i64 0, i64 %48
  %50 = load i64, ptr %49, align 8, !tbaa !5
  %51 = add nsw i64 %50, %47
  store i64 %51, ptr %49, align 8, !tbaa !5
  %52 = add nuw nsw i64 %.044, 5
  %exitcond47.not.4 = icmp eq i64 %52, 1000001
  br i1 %exitcond47.not.4, label %31, label %.preheader, !llvm.loop !16
}

; Function Attrs: 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 = { 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10}
!16 = distinct !{!16, !10}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,MemCpyOptPass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass