; LLVM IR from VastoLorde95/Competitive-Programming :: CodeChef/WF/Medium Hard/LOTERY/A.ll (Z3prei)

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

@isprime = external dso_local global [100001 x i32], align 16
@ppro = external dso_local global [100001 x i32], align 16
@ippro = external dso_local global [100001 x i32], align 16
@invp = external dso_local global [100001 x i32], align 16
@primes = external dso_local global %"class.std::vector", align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3prei(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  store i32 1, ptr getelementptr inbounds ([100001 x i32], ptr @isprime, i64 0, i64 2), align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 3, ptr %3, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %17, %1
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = icmp sle i32 %9, %10
  br i1 %11, label %13, label %12

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

13:                                               ; preds = %8
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [100001 x i32], ptr @isprime, i64 0, i64 %15
  store i32 1, ptr %16, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %13
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = add nsw i32 %18, 2
  store i32 %19, ptr %3, align 4, !tbaa !5
  br label %8, !llvm.loop !9

20:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 3, ptr %4, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %53, %20
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = mul nsw i32 %22, %23
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = icmp sle i32 %24, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %21
  store i32 5, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %56

28:                                               ; preds = %21
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [100001 x i32], ptr @isprime, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %35, label %34

34:                                               ; preds = %28
  br label %53

35:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = mul nsw i32 %36, %37
  store i32 %38, ptr %6, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %48, %35
  %40 = load i32, ptr %6, align 4, !tbaa !5
  %41 = load i32, ptr %2, align 4, !tbaa !5
  %42 = icmp sle i32 %40, %41
  br i1 %42, label %44, label %43

43:                                               ; preds = %39
  store i32 8, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %52

44:                                               ; preds = %39
  %45 = load i32, ptr %6, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [100001 x i32], ptr @isprime, i64 0, i64 %46
  store i32 0, ptr %47, align 4, !tbaa !5
  br label %48

48:                                               ; preds = %44
  %49 = load i32, ptr %4, align 4, !tbaa !5
  %50 = load i32, ptr %6, align 4, !tbaa !5
  %51 = add nsw i32 %50, %49
  store i32 %51, ptr %6, align 4, !tbaa !5
  br label %39, !llvm.loop !11

52:                                               ; preds = %43
  br label %53

53:                                               ; preds = %52, %34
  %54 = load i32, ptr %4, align 4, !tbaa !5
  %55 = add nsw i32 %54, 2
  store i32 %55, ptr %4, align 4, !tbaa !5
  br label %21, !llvm.loop !12

56:                                               ; preds = %27
  store i32 1, ptr @ppro, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 1, ptr %7, align 4, !tbaa !5
  br label %57

57:                                               ; preds = %106, %56
  %58 = load i32, ptr %7, align 4, !tbaa !5
  %59 = load i32, ptr %2, align 4, !tbaa !5
  %60 = icmp sle i32 %58, %59
  br i1 %60, label %62, label %61

61:                                               ; preds = %57
  store i32 11, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %109

62:                                               ; preds = %57
  %63 = load i32, ptr %7, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [100001 x i32], ptr @isprime, i64 0, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !5
  %67 = icmp ne i32 %66, 0
  br i1 %67, label %68, label %88

68:                                               ; preds = %62
  %69 = load i32, ptr %7, align 4, !tbaa !5
  %70 = sub nsw i32 %69, 1
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [100001 x i32], ptr @ppro, i64 0, i64 %71
  %73 = load i32, ptr %72, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = load i32, ptr %7, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = mul nsw i64 %74, %76
  %78 = srem i64 %77, 1000000007
  %79 = trunc i64 %78 to i32
  %80 = load i32, ptr %7, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [100001 x i32], ptr @ppro, i64 0, i64 %81
  store i32 %79, ptr %82, align 4, !tbaa !5
  %83 = load i32, ptr %7, align 4, !tbaa !5
  %84 = call noundef i32 @_Z4fastii(i32 noundef %83, i32 noundef 1000000005)
  %85 = load i32, ptr %7, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [100001 x i32], ptr @invp, i64 0, i64 %86
  store i32 %84, ptr %87, align 4, !tbaa !5
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) @primes, ptr noundef nonnull align 4 dereferenceable(4) %7)
  br label %97

88:                                               ; preds = %62
  %89 = load i32, ptr %7, align 4, !tbaa !5
  %90 = sub nsw i32 %89, 1
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds [100001 x i32], ptr @ppro, i64 0, i64 %91
  %93 = load i32, ptr %92, align 4, !tbaa !5
  %94 = load i32, ptr %7, align 4, !tbaa !5
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds [100001 x i32], ptr @ppro, i64 0, i64 %95
  store i32 %93, ptr %96, align 4, !tbaa !5
  br label %97

97:                                               ; preds = %88, %68
  %98 = load i32, ptr %7, align 4, !tbaa !5
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds [100001 x i32], ptr @ppro, i64 0, i64 %99
  %101 = load i32, ptr %100, align 4, !tbaa !5
  %102 = call noundef i32 @_Z4fastii(i32 noundef %101, i32 noundef 1000000005)
  %103 = load i32, ptr %7, align 4, !tbaa !5
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds [100001 x i32], ptr @ippro, i64 0, i64 %104
  store i32 %102, ptr %105, align 4, !tbaa !5
  br label %106

106:                                              ; preds = %97
  %107 = load i32, ptr %7, align 4, !tbaa !5
  %108 = add nsw i32 %107, 1
  store i32 %108, ptr %7, align 4, !tbaa !5
  br label %57, !llvm.loop !13

109:                                              ; preds = %61
  ret void
}

; 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z4fastii(i32 noundef, i32 noundef) #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 4 dereferenceable(4)) #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 = { inlinehint 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 #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++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !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 }

@isprime = external dso_local local_unnamed_addr global [100001 x i32], align 16
@ppro = external dso_local local_unnamed_addr global [100001 x i32], align 16
@ippro = external dso_local local_unnamed_addr global [100001 x i32], align 16
@invp = external dso_local local_unnamed_addr global [100001 x i32], align 16
@primes = external dso_local global %"class.std::vector", align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3prei(i32 noundef %0) local_unnamed_addr #0 {
  %2 = alloca i32, align 4
  store i32 1, ptr getelementptr inbounds (i8, ptr @isprime, i64 8), align 8, !tbaa !5
  %.not28 = icmp slt i32 %0, 3
  br i1 %.not28, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %1
  %3 = zext nneg i32 %0 to i64
  br label %.lr.ph

.preheader27:                                     ; preds = %.lr.ph
  %.not2233 = icmp slt i32 %0, 9
  br i1 %.not2233, label %._crit_edge, label %.lr.ph35

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 3, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %4 = getelementptr inbounds [100001 x i32], ptr @isprime, i64 0, i64 %indvars.iv
  store i32 1, ptr %4, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 2
  %.not = icmp ugt i64 %indvars.iv.next, %3
  br i1 %.not, label %.preheader27, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.loopexit, %1, %.preheader27
  store i32 1, ptr @ppro, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #3
  store i32 1, ptr %2, align 4, !tbaa !5
  %.not2336 = icmp slt i32 %0, 1
  br i1 %.not2336, label %._crit_edge40, label %.lr.ph39

.lr.ph35:                                         ; preds = %.preheader27, %.loopexit
  %indvars.iv42 = phi i64 [ %indvars.iv.next43, %.loopexit ], [ 3, %.preheader27 ]
  %5 = phi i32 [ %12, %.loopexit ], [ 9, %.preheader27 ]
  %6 = getelementptr inbounds [100001 x i32], ptr @isprime, i64 0, i64 %indvars.iv42
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %.not25 = icmp eq i32 %7, 0
  %.not2630 = icmp sgt i32 %5, %0
  %or.cond = or i1 %.not25, %.not2630
  br i1 %or.cond, label %.loopexit, label %.lr.ph32.preheader

.lr.ph32.preheader:                               ; preds = %.lr.ph35
  %8 = zext nneg i32 %5 to i64
  br label %.lr.ph32

.lr.ph32:                                         ; preds = %.lr.ph32.preheader, %.lr.ph32
  %indvars.iv44 = phi i64 [ %8, %.lr.ph32.preheader ], [ %indvars.iv.next45, %.lr.ph32 ]
  %9 = getelementptr inbounds [100001 x i32], ptr @isprime, i64 0, i64 %indvars.iv44
  store i32 0, ptr %9, align 4, !tbaa !5
  %indvars.iv.next45 = add nuw nsw i64 %indvars.iv44, %indvars.iv42
  %10 = trunc nuw i64 %indvars.iv.next45 to i32
  %.not26 = icmp sgt i32 %10, %0
  br i1 %.not26, label %.loopexit, label %.lr.ph32, !llvm.loop !11

.loopexit:                                        ; preds = %.lr.ph32, %.lr.ph35
  %indvars.iv.next43 = add nuw nsw i64 %indvars.iv42, 2
  %11 = mul nuw nsw i64 %indvars.iv.next43, %indvars.iv.next43
  %12 = trunc nuw i64 %11 to i32
  %.not22 = icmp sgt i32 %12, %0
  br i1 %.not22, label %._crit_edge, label %.lr.ph35, !llvm.loop !12

._crit_edge40:                                    ; preds = %32, %._crit_edge
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #3
  ret void

.lr.ph39:                                         ; preds = %._crit_edge, %32
  %storemerge37 = phi i32 [ %38, %32 ], [ 1, %._crit_edge ]
  %13 = sext i32 %storemerge37 to i64
  %14 = getelementptr inbounds [100001 x i32], ptr @isprime, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %.not24 = icmp eq i32 %15, 0
  %16 = add nsw i32 %storemerge37, -1
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [100001 x i32], ptr @ppro, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  br i1 %.not24, label %30, label %20

20:                                               ; preds = %.lr.ph39
  %21 = sext i32 %19 to i64
  %22 = mul nsw i64 %21, %13
  %23 = srem i64 %22, 1000000007
  %24 = trunc nsw i64 %23 to i32
  %25 = getelementptr inbounds [100001 x i32], ptr @ppro, i64 0, i64 %13
  store i32 %24, ptr %25, align 4, !tbaa !5
  %26 = call noundef i32 @_Z4fastii(i32 noundef %storemerge37, i32 noundef 1000000005)
  %27 = load i32, ptr %2, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [100001 x i32], ptr @invp, i64 0, i64 %28
  store i32 %26, ptr %29, align 4, !tbaa !5
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) @primes, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %.pre = load i32, ptr %2, align 4, !tbaa !5
  %.phi.trans.insert = sext i32 %.pre to i64
  %.phi.trans.insert48 = getelementptr inbounds [100001 x i32], ptr @ppro, i64 0, i64 %.phi.trans.insert
  %.pre49 = load i32, ptr %.phi.trans.insert48, align 4, !tbaa !5
  br label %32

30:                                               ; preds = %.lr.ph39
  %31 = getelementptr inbounds [100001 x i32], ptr @ppro, i64 0, i64 %13
  store i32 %19, ptr %31, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %30, %20
  %33 = phi i32 [ %19, %30 ], [ %.pre49, %20 ]
  %34 = call noundef i32 @_Z4fastii(i32 noundef %33, i32 noundef 1000000005)
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [100001 x i32], ptr @ippro, i64 0, i64 %36
  store i32 %34, ptr %37, align 4, !tbaa !5
  %38 = add nsw i32 %35, 1
  store i32 %38, ptr %2, align 4, !tbaa !5
  %.not23.not = icmp slt i32 %35, %0
  br i1 %.not23.not, label %.lr.ph39, label %._crit_edge40, !llvm.loop !13
}

; 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z4fastii(i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 4 dereferenceable(4)) 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 = { inlinehint 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 #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++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}


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