; LLVM IR from Izaron/ACM-ICPC :: Timus Online Judge/Volume 6/1586. Threeprime Numbers (main)

; 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::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"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 }
%"class.std::locale" = type { ptr }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }

@nxt = external dso_local global [10 x [10 x %"class.std::vector"]], align 16
@n = external dso_local global i32, align 4
@ansi = external dso_local global [10005 x [10 x [10 x i64]]], align 16
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z3dfsiii(i32 noundef, i32 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: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z7isPrimei(i32 noundef) #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 0, ptr %2, align 4, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 16 @ansi, i8 -1, i64 8004000, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 100, ptr %3, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %31, %0
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = icmp sle i32 %10, 999
  br i1 %11, label %13, label %12

12:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  br label %34

13:                                               ; preds = %9
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = call noundef zeroext i1 @_Z7isPrimei(i32 noundef %14)
  br i1 %15, label %16, label %30

16:                                               ; preds = %13
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = sdiv i32 %17, 100
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [10 x [10 x %"class.std::vector"]], ptr @nxt, i64 0, i64 %19
  %21 = load i32, ptr %3, align 4, !tbaa !5
  %22 = sdiv i32 %21, 10
  %23 = srem i32 %22, 10
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [10 x %"class.std::vector"], ptr %20, i64 0, i64 %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = srem i32 %26, 10
  store i32 %27, ptr %4, align 4, !tbaa !5
  call void @_ZNSt6vectorIiSaIiEE9push_backEOi(ptr noundef nonnull align 8 dereferenceable(24) %25, ptr noundef nonnull align 4 dereferenceable(4) %4)
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %2, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %16, %13
  br label %31

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

34:                                               ; preds = %12
  %35 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) @n)
  %36 = load i32, ptr @n, align 4, !tbaa !5
  %37 = icmp eq i32 %36, 3
  br i1 %37, label %38, label %41

38:                                               ; preds = %34
  %39 = load i32, ptr %2, align 4, !tbaa !5
  %40 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %39)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %5, align 4
  br label %69

41:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  store i64 0, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 1, ptr %7, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %63, %41
  %43 = load i32, ptr %7, align 4, !tbaa !5
  %44 = icmp slt i32 %43, 10
  br i1 %44, label %46, label %45

45:                                               ; preds = %42
  store i32 5, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %66

46:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 1, ptr %8, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %59, %46
  %48 = load i32, ptr %8, align 4, !tbaa !5
  %49 = icmp slt i32 %48, 10
  br i1 %49, label %51, label %50

50:                                               ; preds = %47
  store i32 8, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %62

51:                                               ; preds = %47
  %52 = load i32, ptr %7, align 4, !tbaa !5
  %53 = load i32, ptr %8, align 4, !tbaa !5
  %54 = call noundef i64 @_Z3dfsiii(i32 noundef 2, i32 noundef %52, i32 noundef %53)
  %55 = load i64, ptr %6, align 8, !tbaa !11
  %56 = add nsw i64 %55, %54
  store i64 %56, ptr %6, align 8, !tbaa !11
  %57 = load i64, ptr %6, align 8, !tbaa !11
  %58 = srem i64 %57, 1000000009
  store i64 %58, ptr %6, align 8, !tbaa !11
  br label %59

59:                                               ; preds = %51
  %60 = load i32, ptr %8, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %8, align 4, !tbaa !5
  br label %47, !llvm.loop !13

62:                                               ; preds = %50
  br label %63

63:                                               ; preds = %62
  %64 = load i32, ptr %7, align 4, !tbaa !5
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %7, align 4, !tbaa !5
  br label %42, !llvm.loop !14

66:                                               ; preds = %45
  %67 = load i64, ptr %6, align 8, !tbaa !11
  %68 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %67)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  store i32 0, ptr %5, align 4
  br label %69

69:                                               ; preds = %66, %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  %70 = load i32, ptr %5, align 4
  switch i32 %70, label %73 [
    i32 0, label %71
    i32 1, label %71
  ]

71:                                               ; preds = %69, %69
  %72 = load i32, ptr %1, align 4
  ret i32 %72

73:                                               ; preds = %69
  unreachable
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIiSaIiEE9push_backEOi(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 4 dereferenceable(4)) #0 align 2

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(4)) #4

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

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) #0 align 2

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress norecurse 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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"}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !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"

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"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 }
%"class.std::locale" = type { ptr }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }

@nxt = external dso_local global [10 x [10 x %"class.std::vector"]], align 16
@n = external dso_local global i32, align 4
@ansi = external dso_local local_unnamed_addr global [10005 x [10 x [10 x i64]]], align 16
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z3dfsiii(i32 noundef, i32 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: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z7isPrimei(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = alloca i32, align 4
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(8004000) @ansi, i8 -1, i64 8004000, i1 false)
  br label %6

2:                                                ; preds = %17
  %3 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) @n)
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %5 = icmp eq i32 %4, 3
  br i1 %5, label %19, label %.preheader

6:                                                ; preds = %0, %17
  %.02032 = phi i32 [ 100, %0 ], [ %18, %17 ]
  %.02131 = phi i32 [ 0, %0 ], [ %.122, %17 ]
  %7 = call noundef zeroext i1 @_Z7isPrimei(i32 noundef %.02032)
  br i1 %7, label %8, label %17

8:                                                ; preds = %6
  %.lhs.trunc = trunc nuw i32 %.02032 to i16
  %9 = udiv i16 %.lhs.trunc, 100
  %10 = zext nneg i16 %9 to i64
  %11 = udiv i16 %.lhs.trunc, 10
  %.lhs.trunc26 = trunc nuw i16 %11 to i8
  %12 = urem i8 %.lhs.trunc26, 10
  %13 = zext nneg i8 %12 to i64
  %14 = getelementptr inbounds [10 x [10 x %"class.std::vector"]], ptr @nxt, i64 0, i64 %10, i64 %13
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #5
  %15 = urem i16 %.lhs.trunc, 10
  %.zext29 = zext nneg i16 %15 to i32
  store i32 %.zext29, ptr %1, align 4, !tbaa !5
  call void @_ZNSt6vectorIiSaIiEE9push_backEOi(ptr noundef nonnull align 8 dereferenceable(24) %14, ptr noundef nonnull align 4 dereferenceable(4) %1)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #5
  %16 = add nsw i32 %.02131, 1
  br label %17

17:                                               ; preds = %6, %8
  %.122 = phi i32 [ %16, %8 ], [ %.02131, %6 ]
  %18 = add nuw nsw i32 %.02032, 1
  %exitcond.not = icmp eq i32 %18, 1000
  br i1 %exitcond.not, label %2, label %6, !llvm.loop !9

19:                                               ; preds = %2
  %20 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %.122)
  br label %51

.preheader:                                       ; preds = %2, %.preheader
  %.01836 = phi i32 [ %48, %.preheader ], [ 1, %2 ]
  %.01935 = phi i64 [ %47, %.preheader ], [ 0, %2 ]
  %21 = call noundef i64 @_Z3dfsiii(i32 noundef 2, i32 noundef %.01836, i32 noundef 1)
  %22 = add nsw i64 %21, %.01935
  %23 = srem i64 %22, 1000000009
  %24 = call noundef i64 @_Z3dfsiii(i32 noundef 2, i32 noundef %.01836, i32 noundef 2)
  %25 = add nsw i64 %24, %23
  %26 = srem i64 %25, 1000000009
  %27 = call noundef i64 @_Z3dfsiii(i32 noundef 2, i32 noundef %.01836, i32 noundef 3)
  %28 = add nsw i64 %27, %26
  %29 = srem i64 %28, 1000000009
  %30 = call noundef i64 @_Z3dfsiii(i32 noundef 2, i32 noundef %.01836, i32 noundef 4)
  %31 = add nsw i64 %30, %29
  %32 = srem i64 %31, 1000000009
  %33 = call noundef i64 @_Z3dfsiii(i32 noundef 2, i32 noundef %.01836, i32 noundef 5)
  %34 = add nsw i64 %33, %32
  %35 = srem i64 %34, 1000000009
  %36 = call noundef i64 @_Z3dfsiii(i32 noundef 2, i32 noundef %.01836, i32 noundef 6)
  %37 = add nsw i64 %36, %35
  %38 = srem i64 %37, 1000000009
  %39 = call noundef i64 @_Z3dfsiii(i32 noundef 2, i32 noundef %.01836, i32 noundef 7)
  %40 = add nsw i64 %39, %38
  %41 = srem i64 %40, 1000000009
  %42 = call noundef i64 @_Z3dfsiii(i32 noundef 2, i32 noundef %.01836, i32 noundef 8)
  %43 = add nsw i64 %42, %41
  %44 = srem i64 %43, 1000000009
  %45 = call noundef i64 @_Z3dfsiii(i32 noundef 2, i32 noundef %.01836, i32 noundef 9)
  %46 = add nsw i64 %45, %44
  %47 = srem i64 %46, 1000000009
  %48 = add nuw nsw i32 %.01836, 1
  %exitcond38.not = icmp eq i32 %48, 10
  br i1 %exitcond38.not, label %49, label %.preheader, !llvm.loop !11

49:                                               ; preds = %.preheader
  %50 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %47)
  br label %51

51:                                               ; preds = %49, %19
  ret i32 0
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #4

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

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress norecurse 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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"}
!11 = distinct !{!11, !10}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass