; LLVM IR from AdarshGaur/Competitive-Programming :: SPOJ/PRIME1 - Prime Generator.ll (Z16calculate_primesRSt6vectorIiSaIiEE)

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

; 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 @_Z16calculate_primesRSt6vectorIiSaIiEE(ptr noundef nonnull align 8 dereferenceable(24) %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %6, i64 noundef 0) #2
  store i32 0, ptr %7, align 4, !tbaa !9
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %8, i64 noundef 1) #2
  store i32 0, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  store i64 2, ptr %3, align 8, !tbaa !11
  br label %10

10:                                               ; preds = %32, %1
  %11 = load i64, ptr %3, align 8, !tbaa !11
  %12 = icmp sle i64 %11, 32000
  br i1 %12, label %14, label %13

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

14:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %15 = load i64, ptr %3, align 8, !tbaa !11
  store i64 %15, ptr %4, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %16 = load i64, ptr %4, align 8, !tbaa !11
  %17 = load i64, ptr %3, align 8, !tbaa !11
  %18 = mul nsw i64 %16, %17
  store i64 %18, ptr %5, align 8, !tbaa !11
  br label %19

19:                                               ; preds = %22, %14
  %20 = load i64, ptr %5, align 8, !tbaa !11
  %21 = icmp sle i64 %20, 32000
  br i1 %21, label %22, label %31

22:                                               ; preds = %19
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = load i64, ptr %5, align 8, !tbaa !11
  %25 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %23, i64 noundef %24) #2
  store i32 0, ptr %25, align 4, !tbaa !9
  %26 = load i64, ptr %4, align 8, !tbaa !11
  %27 = add nsw i64 %26, 1
  store i64 %27, ptr %4, align 8, !tbaa !11
  %28 = load i64, ptr %4, align 8, !tbaa !11
  %29 = load i64, ptr %3, align 8, !tbaa !11
  %30 = mul nsw i64 %28, %29
  store i64 %30, ptr %5, align 8, !tbaa !11
  br label %19, !llvm.loop !13

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

32:                                               ; preds = %31
  %33 = load i64, ptr %3, align 8, !tbaa !11
  %34 = add nsw i64 %33, 1
  store i64 %34, ptr %3, align 8, !tbaa !11
  br label %10, !llvm.loop !15

35:                                               ; preds = %13
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 align 2

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z16calculate_primesRSt6vectorIiSaIiEE(ptr noundef nonnull align 8 dereferenceable(24) %0) local_unnamed_addr #0 {
  %2 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef 0) #1
  store i32 0, ptr %2, align 4, !tbaa !5
  %3 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef 1) #1
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %1, %._crit_edge
  %.01317 = phi i64 [ 2, %1 ], [ %9, %._crit_edge ]
  %.014 = mul nuw nsw i64 %.01317, %.01317
  %4 = icmp ult i64 %.014, 32001
  br i1 %4, label %.lr.ph, label %._crit_edge

5:                                                ; preds = %._crit_edge
  ret void

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.016 = phi i64 [ %.0, %.lr.ph ], [ %.014, %.preheader ]
  %.01215 = phi i64 [ %7, %.lr.ph ], [ %.01317, %.preheader ]
  %6 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %.016) #1
  store i32 0, ptr %6, align 4, !tbaa !5
  %7 = add nuw nsw i64 %.01215, 1
  %.0 = mul nuw nsw i64 %7, %.01317
  %8 = icmp ult i64 %.0, 32001
  br i1 %8, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %9 = add nuw nsw i64 %.01317, 1
  %exitcond.not = icmp eq i64 %9, 32001
  br i1 %exitcond.not, label %5, label %.preheader, !llvm.loop !11
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

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 = { 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 = distinct !{!11, !10}


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