; LLVM IR from VastoLorde95/Competitive-Programming :: SPOJ/Week 1/primes (prime)

; 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 [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @is_prime(i64 noundef, ptr noundef, i32 noundef) #0

; 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

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca [9592 x i64], align 16
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 76736, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %8 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %4)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store i64 2, ptr %5, align 8, !tbaa !9
  br label %9

9:                                                ; preds = %25, %0
  %10 = load i64, ptr %5, align 8, !tbaa !9
  %11 = icmp sle i64 %10, 100000
  br i1 %11, label %12, label %28

12:                                               ; preds = %9
  %13 = load i64, ptr %5, align 8, !tbaa !9
  %14 = getelementptr inbounds [9592 x i64], ptr %2, i64 0, i64 0
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = call i32 @is_prime(i64 noundef %13, ptr noundef %14, i32 noundef %15)
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %24

18:                                               ; preds = %12
  %19 = load i64, ptr %5, align 8, !tbaa !9
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr %3, align 4, !tbaa !5
  %22 = sext i32 %20 to i64
  %23 = getelementptr inbounds [9592 x i64], ptr %2, i64 0, i64 %22
  store i64 %19, ptr %23, align 8, !tbaa !11
  br label %24

24:                                               ; preds = %18, %12
  br label %25

25:                                               ; preds = %24
  %26 = load i64, ptr %5, align 8, !tbaa !9
  %27 = add nsw i64 %26, 1
  store i64 %27, ptr %5, align 8, !tbaa !9
  br label %9, !llvm.loop !13

28:                                               ; preds = %9
  br label %29

29:                                               ; preds = %62, %28
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = add nsw i32 %30, -1
  store i32 %31, ptr %4, align 4, !tbaa !5
  %32 = icmp ne i32 %30, 0
  br i1 %32, label %33, label %64

33:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %34 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %6, ptr noundef %7)
  %35 = load i64, ptr %6, align 8, !tbaa !9
  %36 = icmp slt i64 %35, 2
  br i1 %36, label %37, label %38

37:                                               ; preds = %33
  store i64 2, ptr %6, align 8, !tbaa !9
  br label %38

38:                                               ; preds = %37, %33
  %39 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %39, ptr %5, align 8, !tbaa !9
  %40 = load i64, ptr %5, align 8, !tbaa !9
  %41 = srem i64 %40, 2
  %42 = icmp eq i64 %41, 0
  br i1 %42, label %43, label %46

43:                                               ; preds = %38
  %44 = load i64, ptr %5, align 8, !tbaa !9
  %45 = add nsw i64 %44, 1
  store i64 %45, ptr %5, align 8, !tbaa !9
  br label %46

46:                                               ; preds = %43, %38
  br label %47

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

51:                                               ; preds = %47
  %52 = load i64, ptr %5, align 8, !tbaa !9
  %53 = getelementptr inbounds [9592 x i64], ptr %2, i64 0, i64 0
  %54 = call i32 @is_prime(i64 noundef %52, ptr noundef %53, i32 noundef 9592)
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %56, label %59

56:                                               ; preds = %51
  %57 = load i64, ptr %5, align 8, !tbaa !9
  %58 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %57)
  br label %59

59:                                               ; preds = %56, %51
  %60 = load i64, ptr %5, align 8, !tbaa !9
  %61 = add nsw i64 %60, 1
  store i64 %61, ptr %5, align 8, !tbaa !9
  br label %47, !llvm.loop !15

62:                                               ; preds = %47
  %63 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %29, !llvm.loop !16

64:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 76736, ptr %2) #3
  ret i32 0
}

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

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

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 }

!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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !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"

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @is_prime(i64 noundef, ptr noundef, i32 noundef) local_unnamed_addr #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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca [9592 x i64], align 16
  %2 = alloca i32, align 4
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 76736, ptr nonnull %1) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #3
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %2)
  br label %8

.preheader:                                       ; preds = %14
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = add nsw i32 %6, -1
  store i32 %7, ptr %2, align 4, !tbaa !5
  %.not21 = icmp eq i32 %6, 0
  br i1 %.not21, label %._crit_edge23, label %.lr.ph22

8:                                                ; preds = %0, %14
  %.018 = phi i64 [ 2, %0 ], [ %15, %14 ]
  %.01217 = phi i32 [ 0, %0 ], [ %.113, %14 ]
  %9 = call i32 @is_prime(i64 noundef %.018, ptr noundef nonnull %1, i32 noundef %.01217)
  %.not16 = icmp eq i32 %9, 0
  br i1 %.not16, label %14, label %10

10:                                               ; preds = %8
  %11 = add nsw i32 %.01217, 1
  %12 = sext i32 %.01217 to i64
  %13 = getelementptr inbounds [9592 x i64], ptr %1, i64 0, i64 %12
  store i64 %.018, ptr %13, align 8, !tbaa !9
  br label %14

14:                                               ; preds = %8, %10
  %.113 = phi i32 [ %11, %10 ], [ %.01217, %8 ]
  %15 = add nuw nsw i64 %.018, 1
  %exitcond.not = icmp eq i64 %15, 100001
  br i1 %exitcond.not, label %.preheader, label %8, !llvm.loop !11

.lr.ph22:                                         ; preds = %.preheader, %._crit_edge
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  %16 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %17 = load i64, ptr %3, align 8, !tbaa !13
  %18 = icmp slt i64 %17, 2
  br i1 %18, label %19, label %20

19:                                               ; preds = %.lr.ph22
  store i64 2, ptr %3, align 8, !tbaa !13
  br label %20

20:                                               ; preds = %19, %.lr.ph22
  %21 = phi i64 [ 2, %19 ], [ %17, %.lr.ph22 ]
  %spec.select = or i64 %21, 1
  %22 = load i64, ptr %4, align 8, !tbaa !13
  %.not1419 = icmp sgt i64 %spec.select, %22
  br i1 %.not1419, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %20, %26
  %.220 = phi i64 [ %27, %26 ], [ %spec.select, %20 ]
  %23 = call i32 @is_prime(i64 noundef %.220, ptr noundef nonnull %1, i32 noundef 9592)
  %.not15 = icmp eq i32 %23, 0
  br i1 %.not15, label %26, label %24

24:                                               ; preds = %.lr.ph
  %25 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %.220)
  br label %26

26:                                               ; preds = %24, %.lr.ph
  %27 = add nuw nsw i64 %.220, 1
  %28 = load i64, ptr %4, align 8, !tbaa !13
  %.not14.not = icmp slt i64 %.220, %28
  br i1 %.not14.not, label %.lr.ph, label %._crit_edge, !llvm.loop !15

._crit_edge:                                      ; preds = %26, %20
  %29 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = add nsw i32 %30, -1
  store i32 %31, ptr %2, align 4, !tbaa !5
  %.not = icmp eq i32 %30, 0
  br i1 %.not, label %._crit_edge23, label %.lr.ph22, !llvm.loop !16

._crit_edge23:                                    ; preds = %._crit_edge, %.preheader
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 76736, ptr nonnull %1) #3
  ret i32 0
}

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

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

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 }

!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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !14, i64 0}
!14 = !{!"long long", !7, i64 0}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !12}


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