; LLVM IR from bqi343/cp-notebook :: Contests/USACO Training/Ch 1/1.5 sprime.ll (Z6searchii)

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

%"class.std::basic_ofstream" = type { %"class.std::basic_ostream.base", %"class.std::basic_filebuf", %"class.std::basic_ios" }
%"class.std::basic_ostream.base" = type { ptr }
%"class.std::basic_filebuf" = type { %"class.std::basic_streambuf", %union.pthread_mutex_t, %"class.std::__basic_file", i32, %struct.__mbstate_t, %struct.__mbstate_t, %struct.__mbstate_t, ptr, i64, i8, i8, i8, i8, ptr, ptr, i8, ptr, ptr, i64, ptr, ptr }
%"class.std::basic_streambuf" = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, %"class.std::locale" }
%"class.std::locale" = type { ptr }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }
%"class.std::__basic_file" = type <{ ptr, i8, [7 x i8] }>
%struct.__mbstate_t = type { i32, %union.anon }
%union.anon = type { i32 }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }

@n = external dso_local global i32, align 4
@cout = external dso_local global %"class.std::basic_ofstream", align 8
@.str.6 = external hidden unnamed_addr constant [2 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

; 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
declare dso_local noundef i32 @_Z7isprimei(i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6searchii(i32 noundef %0, i32 noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  %7 = load i32, ptr %4, align 4, !tbaa !5
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = icmp eq i32 %7, %8
  br i1 %9, label %10, label %14

10:                                               ; preds = %2
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @cout, i32 noundef %11)
  %13 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %12, ptr noundef @.str.6)
  br label %35

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

15:                                               ; preds = %32, %14
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = icmp slt i32 %16, 10
  br i1 %17, label %19, label %18

18:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %35

19:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = mul nsw i32 10, %20
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = add nsw i32 %21, %22
  store i32 %23, ptr %6, align 4, !tbaa !5
  %24 = load i32, ptr %6, align 4, !tbaa !5
  %25 = call noundef i32 @_Z7isprimei(i32 noundef %24)
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %31

27:                                               ; preds = %19
  %28 = load i32, ptr %6, align 4, !tbaa !5
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  call void @_Z6searchii(i32 noundef %28, i32 noundef %30)
  br label %31

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

32:                                               ; preds = %31
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %5, align 4, !tbaa !5
  br label %15, !llvm.loop !9

35:                                               ; preds = %18, %10
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #3

declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) #4

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


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

%"class.std::basic_ofstream" = type { %"class.std::basic_ostream.base", %"class.std::basic_filebuf", %"class.std::basic_ios" }
%"class.std::basic_ostream.base" = type { ptr }
%"class.std::basic_filebuf" = type { %"class.std::basic_streambuf", %union.pthread_mutex_t, %"class.std::__basic_file", i32, %struct.__mbstate_t, %struct.__mbstate_t, %struct.__mbstate_t, ptr, i64, i8, i8, i8, i8, ptr, ptr, i8, ptr, ptr, i64, ptr, ptr }
%"class.std::basic_streambuf" = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, %"class.std::locale" }
%"class.std::locale" = type { ptr }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }
%"class.std::__basic_file" = type <{ ptr, i8, [7 x i8] }>
%struct.__mbstate_t = type { i32, %union.anon }
%union.anon = type { i32 }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }

@n = external dso_local local_unnamed_addr global i32, align 4
@cout = external dso_local global %"class.std::basic_ofstream", align 8
@.str.6 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7isprimei(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6searchii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  br label %tailrecurse

tailrecurse:                                      ; preds = %44, %2
  %.tr = phi i32 [ %0, %2 ], [ %45, %44 ]
  %.tr11 = phi i32 [ %1, %2 ], [ %6, %44 ]
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %4 = icmp eq i32 %3, %.tr11
  br i1 %4, label %8, label %.preheader

.preheader:                                       ; preds = %tailrecurse
  %5 = mul nsw i32 %.tr, 10
  %6 = add nsw i32 %.tr11, 1
  %7 = tail call noundef i32 @_Z7isprimei(i32 noundef %5)
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %12, label %11

8:                                                ; preds = %tailrecurse
  %9 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @cout, i32 noundef %.tr)
  %10 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %9, ptr noundef nonnull @.str.6)
  br label %.loopexit

11:                                               ; preds = %.preheader
  tail call void @_Z6searchii(i32 noundef %5, i32 noundef %6)
  br label %12

12:                                               ; preds = %11, %.preheader
  %13 = or disjoint i32 %5, 1
  %14 = tail call noundef i32 @_Z7isprimei(i32 noundef %13)
  %.not.1 = icmp eq i32 %14, 0
  br i1 %.not.1, label %16, label %15

15:                                               ; preds = %12
  tail call void @_Z6searchii(i32 noundef %13, i32 noundef %6)
  br label %16

16:                                               ; preds = %15, %12
  %17 = add nsw i32 %5, 2
  %18 = tail call noundef i32 @_Z7isprimei(i32 noundef %17)
  %.not.2 = icmp eq i32 %18, 0
  br i1 %.not.2, label %20, label %19

19:                                               ; preds = %16
  tail call void @_Z6searchii(i32 noundef %17, i32 noundef %6)
  br label %20

20:                                               ; preds = %19, %16
  %21 = add nsw i32 %5, 3
  %22 = tail call noundef i32 @_Z7isprimei(i32 noundef %21)
  %.not.3 = icmp eq i32 %22, 0
  br i1 %.not.3, label %24, label %23

23:                                               ; preds = %20
  tail call void @_Z6searchii(i32 noundef %21, i32 noundef %6)
  br label %24

24:                                               ; preds = %23, %20
  %25 = add nsw i32 %5, 4
  %26 = tail call noundef i32 @_Z7isprimei(i32 noundef %25)
  %.not.4 = icmp eq i32 %26, 0
  br i1 %.not.4, label %28, label %27

27:                                               ; preds = %24
  tail call void @_Z6searchii(i32 noundef %25, i32 noundef %6)
  br label %28

28:                                               ; preds = %27, %24
  %29 = add nsw i32 %5, 5
  %30 = tail call noundef i32 @_Z7isprimei(i32 noundef %29)
  %.not.5 = icmp eq i32 %30, 0
  br i1 %.not.5, label %32, label %31

31:                                               ; preds = %28
  tail call void @_Z6searchii(i32 noundef %29, i32 noundef %6)
  br label %32

32:                                               ; preds = %31, %28
  %33 = add nsw i32 %5, 6
  %34 = tail call noundef i32 @_Z7isprimei(i32 noundef %33)
  %.not.6 = icmp eq i32 %34, 0
  br i1 %.not.6, label %36, label %35

35:                                               ; preds = %32
  tail call void @_Z6searchii(i32 noundef %33, i32 noundef %6)
  br label %36

36:                                               ; preds = %35, %32
  %37 = add nsw i32 %5, 7
  %38 = tail call noundef i32 @_Z7isprimei(i32 noundef %37)
  %.not.7 = icmp eq i32 %38, 0
  br i1 %.not.7, label %40, label %39

39:                                               ; preds = %36
  tail call void @_Z6searchii(i32 noundef %37, i32 noundef %6)
  br label %40

40:                                               ; preds = %39, %36
  %41 = add nsw i32 %5, 8
  %42 = tail call noundef i32 @_Z7isprimei(i32 noundef %41)
  %.not.8 = icmp eq i32 %42, 0
  br i1 %.not.8, label %44, label %43

43:                                               ; preds = %40
  tail call void @_Z6searchii(i32 noundef %41, i32 noundef %6)
  br label %44

44:                                               ; preds = %43, %40
  %45 = add nsw i32 %5, 9
  %46 = tail call noundef i32 @_Z7isprimei(i32 noundef %45)
  %.not.9 = icmp eq i32 %46, 0
  br i1 %.not.9, label %.loopexit, label %tailrecurse

.loopexit:                                        ; preds = %44, %8
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #2

declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) local_unnamed_addr #3

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 = { mustprogress 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 = { inlinehint mustprogress 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 = { "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"}


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