; LLVM IR from VastoLorde95/Competitive-Programming :: CodeChef/WF/Easy Medium/COPRIME3/A.ll (Z3prev)

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

@p = external dso_local global [1001000 x i32], align 16
@mu = external dso_local global [1001000 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3prev() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 1, ptr %1, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %19, %0
  %9 = load i32, ptr %1, align 4, !tbaa !5
  %10 = icmp slt i32 %9, 1001000
  br i1 %10, label %12, label %11

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

12:                                               ; preds = %8
  %13 = load i32, ptr %1, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [1001000 x i32], ptr @p, i64 0, i64 %14
  store i32 1, ptr %15, align 4, !tbaa !5
  %16 = load i32, ptr %1, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [1001000 x i32], ptr @mu, i64 0, i64 %17
  store i32 1, ptr %18, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %12
  %20 = load i32, ptr %1, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr %1, align 4, !tbaa !5
  br label %8, !llvm.loop !9

22:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  store i32 2, ptr %2, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %87, %22
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = icmp slt i32 %24, 1001000
  br i1 %25, label %27, label %26

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

27:                                               ; preds = %23
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [1001000 x i32], ptr @p, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %34, label %33

33:                                               ; preds = %27
  br label %87

34:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = mul nsw i64 1, %36
  %38 = load i32, ptr %2, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = mul nsw i64 %37, %39
  store i64 %40, ptr %4, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %41 = load i64, ptr %4, align 8, !tbaa !11
  store i64 %41, ptr %5, align 8, !tbaa !11
  br label %42

42:                                               ; preds = %49, %34
  %43 = load i64, ptr %5, align 8, !tbaa !11
  %44 = icmp slt i64 %43, 1001000
  br i1 %44, label %46, label %45

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

46:                                               ; preds = %42
  %47 = load i64, ptr %5, align 8, !tbaa !11
  %48 = getelementptr inbounds [1001000 x i32], ptr @p, i64 0, i64 %47
  store i32 0, ptr %48, align 4, !tbaa !5
  br label %49

49:                                               ; preds = %46
  %50 = load i32, ptr %2, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = load i64, ptr %5, align 8, !tbaa !11
  %53 = add nsw i64 %52, %51
  store i64 %53, ptr %5, align 8, !tbaa !11
  br label %42, !llvm.loop !13

54:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %55 = load i32, ptr %2, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  store i64 %56, ptr %6, align 8, !tbaa !11
  br label %57

57:                                               ; preds = %68, %54
  %58 = load i64, ptr %6, align 8, !tbaa !11
  %59 = icmp slt i64 %58, 1001000
  br i1 %59, label %61, label %60

60:                                               ; preds = %57
  store i32 11, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %73

61:                                               ; preds = %57
  %62 = load i64, ptr %6, align 8, !tbaa !11
  %63 = getelementptr inbounds [1001000 x i32], ptr @mu, i64 0, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !5
  %65 = sub nsw i32 0, %64
  %66 = load i64, ptr %6, align 8, !tbaa !11
  %67 = getelementptr inbounds [1001000 x i32], ptr @mu, i64 0, i64 %66
  store i32 %65, ptr %67, align 4, !tbaa !5
  br label %68

68:                                               ; preds = %61
  %69 = load i32, ptr %2, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = load i64, ptr %6, align 8, !tbaa !11
  %72 = add nsw i64 %71, %70
  store i64 %72, ptr %6, align 8, !tbaa !11
  br label %57, !llvm.loop !14

73:                                               ; preds = %60
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %74 = load i64, ptr %4, align 8, !tbaa !11
  store i64 %74, ptr %7, align 8, !tbaa !11
  br label %75

75:                                               ; preds = %82, %73
  %76 = load i64, ptr %7, align 8, !tbaa !11
  %77 = icmp slt i64 %76, 1001000
  br i1 %77, label %79, label %78

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

79:                                               ; preds = %75
  %80 = load i64, ptr %7, align 8, !tbaa !11
  %81 = getelementptr inbounds [1001000 x i32], ptr @mu, i64 0, i64 %80
  store i32 0, ptr %81, align 4, !tbaa !5
  br label %82

82:                                               ; preds = %79
  %83 = load i64, ptr %4, align 8, !tbaa !11
  %84 = load i64, ptr %7, align 8, !tbaa !11
  %85 = add nsw i64 %84, %83
  store i64 %85, ptr %7, align 8, !tbaa !11
  br label %75, !llvm.loop !15

86:                                               ; preds = %78
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  br label %87

87:                                               ; preds = %86, %33
  %88 = load i32, ptr %2, align 4, !tbaa !5
  %89 = add nsw i32 %88, 1
  store i32 %89, ptr %2, align 4, !tbaa !5
  br label %23, !llvm.loop !16

90:                                               ; preds = %26
  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 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10}
!16 = distinct !{!16, !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"

@p = external dso_local local_unnamed_addr global [1001000 x i32], align 16
@mu = external dso_local local_unnamed_addr global [1001000 x i32], align 16

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

scalar.ph:                                        ; preds = %vector.body
  store i32 1, ptr getelementptr inbounds (i8, ptr @p, i64 4003972), align 4, !tbaa !5
  store i32 1, ptr getelementptr inbounds (i8, ptr @mu, i64 4003972), align 4, !tbaa !5
  store i32 1, ptr getelementptr inbounds (i8, ptr @p, i64 4003976), align 8, !tbaa !5
  store i32 1, ptr getelementptr inbounds (i8, ptr @mu, i64 4003976), align 8, !tbaa !5
  store i32 1, ptr getelementptr inbounds (i8, ptr @p, i64 4003980), align 4, !tbaa !5
  store i32 1, ptr getelementptr inbounds (i8, ptr @mu, i64 4003980), align 4, !tbaa !5
  store i32 1, ptr getelementptr inbounds (i8, ptr @p, i64 4003984), align 16, !tbaa !5
  store i32 1, ptr getelementptr inbounds (i8, ptr @mu, i64 4003984), align 16, !tbaa !5
  store i32 1, ptr getelementptr inbounds (i8, ptr @p, i64 4003988), align 4, !tbaa !5
  store i32 1, ptr getelementptr inbounds (i8, ptr @mu, i64 4003988), align 4, !tbaa !5
  store i32 1, ptr getelementptr inbounds (i8, ptr @p, i64 4003992), align 8, !tbaa !5
  store i32 1, ptr getelementptr inbounds (i8, ptr @mu, i64 4003992), align 8, !tbaa !5
  store i32 1, ptr getelementptr inbounds (i8, ptr @p, i64 4003996), align 4, !tbaa !5
  store i32 1, ptr getelementptr inbounds (i8, ptr @mu, i64 4003996), align 4, !tbaa !5
  br label %.preheader30

13:                                               ; preds = %.loopexit
  ret void

.preheader30:                                     ; preds = %scalar.ph, %.loopexit
  %indvars.iv39 = phi i64 [ %indvars.iv.next40, %.loopexit ], [ 2, %scalar.ph ]
  %14 = getelementptr inbounds [1001000 x i32], ptr @p, i64 0, i64 %indvars.iv39
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %.not = icmp eq i32 %15, 0
  br i1 %.not, label %.loopexit, label %16

16:                                               ; preds = %.preheader30
  %17 = mul nuw nsw i64 %indvars.iv39, %indvars.iv39
  %18 = icmp ult i64 %17, 1001000
  br i1 %18, label %.lr.ph, label %.lr.ph34.preheader

.lr.ph34.preheader:                               ; preds = %.lr.ph, %16
  br label %.lr.ph34

.lr.ph:                                           ; preds = %16, %.lr.ph
  %.02632 = phi i64 [ %20, %.lr.ph ], [ %17, %16 ]
  %19 = getelementptr inbounds [1001000 x i32], ptr @p, i64 0, i64 %.02632
  store i32 0, ptr %19, align 4, !tbaa !5
  %20 = add nuw nsw i64 %.02632, %indvars.iv39
  %21 = icmp ult i64 %20, 1001000
  br i1 %21, label %.lr.ph, label %.lr.ph34.preheader, !llvm.loop !13

.preheader:                                       ; preds = %.lr.ph34
  br i1 %18, label %.lr.ph36, label %.loopexit

.lr.ph34:                                         ; preds = %.lr.ph34.preheader, %.lr.ph34
  %.02533 = phi i64 [ %25, %.lr.ph34 ], [ %indvars.iv39, %.lr.ph34.preheader ]
  %22 = getelementptr inbounds [1001000 x i32], ptr @mu, i64 0, i64 %.02533
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = sub nsw i32 0, %23
  store i32 %24, ptr %22, align 4, !tbaa !5
  %25 = add nuw nsw i64 %.02533, %indvars.iv39
  %26 = icmp ult i64 %25, 1001000
  br i1 %26, label %.lr.ph34, label %.preheader, !llvm.loop !14

.lr.ph36:                                         ; preds = %.preheader, %.lr.ph36
  %.035 = phi i64 [ %28, %.lr.ph36 ], [ %17, %.preheader ]
  %27 = getelementptr inbounds [1001000 x i32], ptr @mu, i64 0, i64 %.035
  store i32 0, ptr %27, align 4, !tbaa !5
  %28 = add nuw nsw i64 %.035, %17
  %29 = icmp ult i64 %28, 1001000
  br i1 %29, label %.lr.ph36, label %.loopexit, !llvm.loop !15

.loopexit:                                        ; preds = %.lr.ph36, %.preheader, %.preheader30
  %indvars.iv.next40 = add nuw nsw i64 %indvars.iv39, 1
  %exitcond42.not = icmp eq i64 %indvars.iv.next40, 1001000
  br i1 %exitcond42.not, label %13, label %.preheader30, !llvm.loop !16
}

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, !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: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass