; LLVM IR from MinhasKamal/AlgorithmImplementations :: playWithNumbers/primeNumber (AnotherWayOfPrimeNumberHaunting)

; 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.7 = external hidden unnamed_addr constant [6 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

declare i32 @printf(ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
define dso_local void @varify(i64 noundef %0, i64 noundef %1) #2 {
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  store i64 %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %8 = load i64, ptr %3, align 8, !tbaa !5
  %9 = srem i64 %8, 2
  %10 = icmp eq i64 %9, 0
  br i1 %10, label %11, label %14

11:                                               ; preds = %2
  %12 = load i64, ptr %3, align 8, !tbaa !5
  %13 = add nsw i64 %12, 1
  store i64 %13, ptr %5, align 8, !tbaa !5
  br label %16

14:                                               ; preds = %2
  %15 = load i64, ptr %3, align 8, !tbaa !5
  store i64 %15, ptr %5, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %14, %11
  %17 = load i64, ptr %5, align 8, !tbaa !5
  store i64 %17, ptr %3, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %45, %16
  %19 = load i64, ptr %3, align 8, !tbaa !5
  %20 = load i64, ptr %4, align 8, !tbaa !5
  %21 = icmp sle i64 %19, %20
  br i1 %21, label %22, label %48

22:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 1, ptr %7, align 8, !tbaa !5
  store i64 3, ptr %6, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %35, %22
  %24 = load i64, ptr %6, align 8, !tbaa !5
  %25 = load i64, ptr %3, align 8, !tbaa !5
  %26 = sdiv i64 %25, 3
  %27 = icmp sle i64 %24, %26
  br i1 %27, label %28, label %38

28:                                               ; preds = %23
  %29 = load i64, ptr %3, align 8, !tbaa !5
  %30 = load i64, ptr %6, align 8, !tbaa !5
  %31 = srem i64 %29, %30
  %32 = icmp eq i64 %31, 0
  br i1 %32, label %33, label %34

33:                                               ; preds = %28
  store i64 0, ptr %7, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %33, %28
  br label %35

35:                                               ; preds = %34
  %36 = load i64, ptr %6, align 8, !tbaa !5
  %37 = add nsw i64 %36, 2
  store i64 %37, ptr %6, align 8, !tbaa !5
  br label %23, !llvm.loop !9

38:                                               ; preds = %23
  %39 = load i64, ptr %7, align 8, !tbaa !5
  %40 = icmp eq i64 %39, 1
  br i1 %40, label %41, label %44

41:                                               ; preds = %38
  %42 = load i64, ptr %3, align 8, !tbaa !5
  %43 = call i32 (ptr, ...) @printf(ptr noundef @.str.7, i64 noundef %42)
  br label %44

44:                                               ; preds = %41, %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %45

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

48:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 }

!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", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !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"

@.str.7 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: nofree nounwind uwtable
define dso_local void @varify(i64 noundef %0, i64 noundef %1) local_unnamed_addr #1 {
  %.015 = or i64 %0, 1
  %.not21 = icmp sgt i64 %.015, %1
  br i1 %.not21, label %._crit_edge23, label %.preheader

.preheader:                                       ; preds = %2, %9
  %.01622 = phi i64 [ %10, %9 ], [ %.015, %2 ]
  %3 = sdiv i64 %.01622, 3
  %.not1718 = icmp slt i64 %.01622, 9
  br i1 %.not1718, label %._crit_edge.thread, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.020 = phi i64 [ %spec.select, %.lr.ph ], [ 1, %.preheader ]
  %.01419 = phi i64 [ %6, %.lr.ph ], [ 3, %.preheader ]
  %4 = urem i64 %.01622, %.01419
  %5 = icmp eq i64 %4, 0
  %spec.select = select i1 %5, i64 0, i64 %.020
  %6 = add nuw nsw i64 %.01419, 2
  %.not17 = icmp sgt i64 %6, %3
  br i1 %.not17, label %._crit_edge, label %.lr.ph, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph
  %7 = icmp eq i64 %spec.select, 1
  br i1 %7, label %._crit_edge.thread, label %9

._crit_edge.thread:                               ; preds = %.preheader, %._crit_edge
  %8 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, i64 noundef %.01622)
  br label %9

9:                                                ; preds = %._crit_edge.thread, %._crit_edge
  %10 = add nsw i64 %.01622, 2
  %.not = icmp sgt i64 %10, %1
  br i1 %.not, label %._crit_edge23, label %.preheader, !llvm.loop !7

._crit_edge23:                                    ; preds = %9, %2
  ret void
}

attributes #0 = { nofree 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 = { nofree 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" }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass