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

; 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 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [49 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [61 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %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
  %8 = alloca i64, align 8
  %9 = alloca i8, align 1
  %10 = alloca i8, align 1
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %11 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  %12 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %4)
  %13 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %5)
  %15 = call i64 @clock() #4
  store i64 %15, ptr %2, align 8, !tbaa !5
  %16 = load i64, ptr %4, align 8, !tbaa !9
  %17 = load i64, ptr %5, align 8, !tbaa !9
  %18 = icmp ugt i64 %16, %17
  br i1 %18, label %19, label %21

19:                                               ; preds = %0
  %20 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  br label %85

21:                                               ; preds = %0
  %22 = load i64, ptr %4, align 8, !tbaa !9
  %23 = icmp ult i64 %22, 1
  br i1 %23, label %27, label %24

24:                                               ; preds = %21
  %25 = load i64, ptr %5, align 8, !tbaa !9
  %26 = icmp ult i64 %25, 2
  br i1 %26, label %27, label %29

27:                                               ; preds = %24, %21
  %28 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  br label %84

29:                                               ; preds = %24
  %30 = load i64, ptr %4, align 8, !tbaa !9
  %31 = urem i64 %30, 2
  %32 = icmp eq i64 %31, 0
  br i1 %32, label %33, label %36

33:                                               ; preds = %29
  %34 = load i64, ptr %4, align 8, !tbaa !9
  %35 = add i64 %34, 1
  store i64 %35, ptr %4, align 8, !tbaa !9
  br label %36

36:                                               ; preds = %33, %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #4
  store i8 0, ptr %9, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #4
  %37 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  %38 = load i64, ptr %4, align 8, !tbaa !9
  store i64 %38, ptr %6, align 8, !tbaa !9
  br label %39

39:                                               ; preds = %79, %36
  %40 = load i64, ptr %6, align 8, !tbaa !9
  %41 = load i64, ptr %5, align 8, !tbaa !9
  %42 = icmp ule i64 %40, %41
  br i1 %42, label %43, label %82

43:                                               ; preds = %39
  %44 = load i64, ptr %6, align 8, !tbaa !9
  %45 = uitofp i64 %44 to double
  %46 = call double @sqrt(double noundef %45) #4
  %47 = fptosi double %46 to i64
  store i64 %47, ptr %8, align 8, !tbaa !9
  store i8 1, ptr %10, align 1, !tbaa !11
  store i64 3, ptr %7, align 8, !tbaa !9
  br label %48

48:                                               ; preds = %59, %43
  %49 = load i64, ptr %7, align 8, !tbaa !9
  %50 = load i64, ptr %8, align 8, !tbaa !9
  %51 = icmp sle i64 %49, %50
  br i1 %51, label %52, label %62

52:                                               ; preds = %48
  %53 = load i64, ptr %6, align 8, !tbaa !9
  %54 = load i64, ptr %7, align 8, !tbaa !9
  %55 = urem i64 %53, %54
  %56 = icmp eq i64 %55, 0
  br i1 %56, label %57, label %58

57:                                               ; preds = %52
  store i8 0, ptr %10, align 1, !tbaa !11
  br label %62

58:                                               ; preds = %52
  br label %59

59:                                               ; preds = %58
  %60 = load i64, ptr %7, align 8, !tbaa !9
  %61 = add nsw i64 %60, 2
  store i64 %61, ptr %7, align 8, !tbaa !9
  br label %48, !llvm.loop !12

62:                                               ; preds = %57, %48
  %63 = load i8, ptr %10, align 1, !tbaa !11
  %64 = sext i8 %63 to i32
  %65 = icmp eq i32 %64, 1
  br i1 %65, label %66, label %78

66:                                               ; preds = %62
  %67 = load i64, ptr %6, align 8, !tbaa !9
  %68 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, i64 noundef %67)
  %69 = load i8, ptr %9, align 1, !tbaa !11
  %70 = add i8 %69, 1
  store i8 %70, ptr %9, align 1, !tbaa !11
  %71 = load i8, ptr %9, align 1, !tbaa !11
  %72 = sext i8 %71 to i32
  %73 = srem i32 %72, 10
  %74 = icmp eq i32 %73, 0
  br i1 %74, label %75, label %77

75:                                               ; preds = %66
  %76 = call i32 (ptr, ...) @printf(ptr noundef @.str.7)
  store i8 0, ptr %9, align 1, !tbaa !11
  br label %77

77:                                               ; preds = %75, %66
  br label %78

78:                                               ; preds = %77, %62
  br label %79

79:                                               ; preds = %78
  %80 = load i64, ptr %6, align 8, !tbaa !9
  %81 = add i64 %80, 2
  store i64 %81, ptr %6, align 8, !tbaa !9
  br label %39, !llvm.loop !14

82:                                               ; preds = %39
  %83 = call i32 (ptr, ...) @printf(ptr noundef @.str.8)
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %84

84:                                               ; preds = %82, %27
  br label %85

85:                                               ; preds = %84, %19
  %86 = call i64 @clock() #4
  store i64 %86, ptr %3, align 8, !tbaa !5
  %87 = load i64, ptr %3, align 8, !tbaa !5
  %88 = load i64, ptr %2, align 8, !tbaa !5
  %89 = sub nsw i64 %87, %88
  %90 = sdiv i64 %89, 1000
  %91 = load i64, ptr %3, align 8, !tbaa !5
  %92 = load i64, ptr %2, align 8, !tbaa !5
  %93 = sub nsw i64 %91, %92
  %94 = srem i64 %93, 1000
  %95 = call i32 (ptr, ...) @printf(ptr noundef @.str.9, i64 noundef %90, i64 noundef %94)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  ret i32 0
}

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

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

declare i32 @__isoc99_scanf(ptr noundef, ...) #2

; Function Attrs: nounwind
declare i64 @clock() #3

; Function Attrs: nounwind
declare double @sqrt(double noundef) #3

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

attributes #0 = { 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 = { "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 "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 #4 = { 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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


; 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 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [49 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [61 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %3 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1)
  %5 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %2)
  %7 = call i64 @clock() #5
  %8 = load i64, ptr %1, align 8, !tbaa !5
  %9 = load i64, ptr %2, align 8
  %10 = icmp ugt i64 %8, %9
  br i1 %10, label %._crit_edge, label %11

11:                                               ; preds = %0
  %12 = icmp eq i64 %8, 0
  %13 = icmp ult i64 %9, 2
  %or.cond = or i1 %12, %13
  br i1 %or.cond, label %._crit_edge, label %14

14:                                               ; preds = %11
  %15 = and i64 %8, 1
  %16 = icmp eq i64 %15, 0
  br i1 %16, label %17, label %19

17:                                               ; preds = %14
  %18 = or disjoint i64 %8, 1
  store i64 %18, ptr %1, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %17, %14
  %20 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5)
  %21 = load i64, ptr %1, align 8, !tbaa !5
  %22 = load i64, ptr %2, align 8, !tbaa !5
  %.not25 = icmp ugt i64 %21, %22
  br i1 %.not25, label %._crit_edge, label %.lr.ph28

.lr.ph28:                                         ; preds = %19, %.loopexit
  %.01727 = phi i8 [ %.1, %.loopexit ], [ 0, %19 ]
  %.01826 = phi i64 [ %35, %.loopexit ], [ %21, %19 ]
  %23 = uitofp i64 %.01826 to double
  %sqrt = call double @llvm.sqrt.f64(double %23)
  %24 = fptosi double %sqrt to i64
  %.not2223 = icmp slt i64 %24, 3
  br i1 %.not2223, label %.critedge, label %.lr.ph

25:                                               ; preds = %.lr.ph
  %26 = add nuw nsw i64 %.01924, 2
  %.not22 = icmp sgt i64 %26, %24
  br i1 %.not22, label %.critedge, label %.lr.ph, !llvm.loop !9

.lr.ph:                                           ; preds = %.lr.ph28, %25
  %.01924 = phi i64 [ %26, %25 ], [ 3, %.lr.ph28 ]
  %27 = urem i64 %.01826, %.01924
  %28 = icmp eq i64 %27, 0
  br i1 %28, label %.loopexit, label %25

.critedge:                                        ; preds = %25, %.lr.ph28
  %29 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, i64 noundef %.01826)
  %30 = add i8 %.01727, 1
  %31 = srem i8 %30, 10
  %32 = icmp eq i8 %31, 0
  br i1 %32, label %33, label %.loopexit

33:                                               ; preds = %.critedge
  %34 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7)
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %33, %.critedge
  %.1 = phi i8 [ 0, %33 ], [ %30, %.critedge ], [ %.01727, %.lr.ph ]
  %35 = add i64 %.01826, 2
  %36 = load i64, ptr %2, align 8, !tbaa !5
  %.not = icmp ugt i64 %35, %36
  br i1 %.not, label %._crit_edge, label %.lr.ph28, !llvm.loop !11

._crit_edge:                                      ; preds = %.loopexit, %19, %11, %0
  %.str.4.sink = phi ptr [ @.str.3, %0 ], [ @.str.4, %11 ], [ @.str.8, %19 ], [ @.str.8, %.loopexit ]
  %37 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.4.sink)
  %38 = call i64 @clock() #5
  %39 = sub nsw i64 %38, %7
  %40 = sdiv i64 %39, 1000
  %41 = srem i64 %39, 1000
  %42 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.9, i64 noundef %40, i64 noundef %41)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #5
  ret i32 0
}

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

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

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

; Function Attrs: nounwind
declare i64 @clock() local_unnamed_addr #3

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.sqrt.f64(double) #4

attributes #0 = { 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


; Effective O3 passes: AggressiveInstCombinePass,CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass