; LLVM IR from Shah-Shishir/Codeforces-Solutions :: 584D. Dima and Lisa.ll (Z5sievev)

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

@prime = external dso_local global [50000 x i8], align 16
@v = external dso_local global %"class.std::vector", align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5sievev() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  store i8 1, ptr getelementptr inbounds ([50000 x i8], ptr @prime, i64 0, i64 1), align 1, !tbaa !5
  store i8 1, ptr @prime, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 2, ptr %3, align 4, !tbaa !9
  call void @_ZNSt6vectorIiSaIiEE9push_backEOi(ptr noundef nonnull align 8 dereferenceable(24) @v, ptr noundef nonnull align 4 dereferenceable(4) %3)
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  store i32 4, ptr %1, align 4, !tbaa !9
  br label %4

4:                                                ; preds = %11, %0
  %5 = load i32, ptr %1, align 4, !tbaa !9
  %6 = icmp slt i32 %5, 50000
  br i1 %6, label %7, label %14

7:                                                ; preds = %4
  %8 = load i32, ptr %1, align 4, !tbaa !9
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [50000 x i8], ptr @prime, i64 0, i64 %9
  store i8 1, ptr %10, align 1, !tbaa !5
  br label %11

11:                                               ; preds = %7
  %12 = load i32, ptr %1, align 4, !tbaa !9
  %13 = add nsw i32 %12, 2
  store i32 %13, ptr %1, align 4, !tbaa !9
  br label %4, !llvm.loop !11

14:                                               ; preds = %4
  store i32 3, ptr %1, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %44, %14
  %16 = load i32, ptr %1, align 4, !tbaa !9
  %17 = load i32, ptr %1, align 4, !tbaa !9
  %18 = mul nsw i32 %16, %17
  %19 = icmp sle i32 %18, 50000
  br i1 %19, label %20, label %47

20:                                               ; preds = %15
  %21 = load i32, ptr %1, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [50000 x i8], ptr @prime, i64 0, i64 %22
  %24 = load i8, ptr %23, align 1, !tbaa !5, !range !13, !noundef !14
  %25 = trunc i8 %24 to i1
  br i1 %25, label %43, label %26

26:                                               ; preds = %20
  %27 = load i32, ptr %1, align 4, !tbaa !9
  %28 = load i32, ptr %1, align 4, !tbaa !9
  %29 = mul nsw i32 %27, %28
  store i32 %29, ptr %2, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %37, %26
  %31 = load i32, ptr %2, align 4, !tbaa !9
  %32 = icmp slt i32 %31, 50000
  br i1 %32, label %33, label %42

33:                                               ; preds = %30
  %34 = load i32, ptr %2, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [50000 x i8], ptr @prime, i64 0, i64 %35
  store i8 1, ptr %36, align 1, !tbaa !5
  br label %37

37:                                               ; preds = %33
  %38 = load i32, ptr %1, align 4, !tbaa !9
  %39 = mul nsw i32 2, %38
  %40 = load i32, ptr %2, align 4, !tbaa !9
  %41 = add nsw i32 %40, %39
  store i32 %41, ptr %2, align 4, !tbaa !9
  br label %30, !llvm.loop !15

42:                                               ; preds = %30
  br label %43

43:                                               ; preds = %42, %20
  br label %44

44:                                               ; preds = %43
  %45 = load i32, ptr %1, align 4, !tbaa !9
  %46 = add nsw i32 %45, 2
  store i32 %46, ptr %1, align 4, !tbaa !9
  br label %15, !llvm.loop !16

47:                                               ; preds = %15
  store i32 3, ptr %1, align 4, !tbaa !9
  br label %48

48:                                               ; preds = %59, %47
  %49 = load i32, ptr %1, align 4, !tbaa !9
  %50 = icmp slt i32 %49, 50000
  br i1 %50, label %51, label %62

51:                                               ; preds = %48
  %52 = load i32, ptr %1, align 4, !tbaa !9
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [50000 x i8], ptr @prime, i64 0, i64 %53
  %55 = load i8, ptr %54, align 1, !tbaa !5, !range !13, !noundef !14
  %56 = trunc i8 %55 to i1
  br i1 %56, label %58, label %57

57:                                               ; preds = %51
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) @v, ptr noundef nonnull align 4 dereferenceable(4) %1)
  br label %58

58:                                               ; preds = %57, %51
  br label %59

59:                                               ; preds = %58
  %60 = load i32, ptr %1, align 4, !tbaa !9
  %61 = add nsw i32 %60, 2
  store i32 %61, ptr %1, align 4, !tbaa !9
  br label %48, !llvm.loop !17

62:                                               ; preds = %48
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  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: 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

; 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 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 = { 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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !12}
!17 = distinct !{!17, !12}


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

@prime = external dso_local local_unnamed_addr global [50000 x i8], align 16
@v = external dso_local global %"class.std::vector", align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5sievev() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #2
  store i8 1, ptr getelementptr inbounds (i8, ptr @prime, i64 1), align 1, !tbaa !5
  store i8 1, ptr @prime, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #2
  store i32 2, ptr %2, align 4, !tbaa !9
  call void @_ZNSt6vectorIiSaIiEE9push_backEOi(ptr noundef nonnull align 8 dereferenceable(24) @v, ptr noundef nonnull align 4 dereferenceable(4) %2)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #2
  br label %3

3:                                                ; preds = %3, %0
  %indvars.iv = phi i64 [ 4, %0 ], [ %indvars.iv.next.1, %3 ]
  %4 = getelementptr inbounds [50000 x i8], ptr @prime, i64 0, i64 %indvars.iv
  store i8 1, ptr %4, align 4, !tbaa !5
  %indvars.iv.next = or disjoint i64 %indvars.iv, 2
  %5 = getelementptr inbounds [50000 x i8], ptr @prime, i64 0, i64 %indvars.iv.next
  store i8 1, ptr %5, align 2, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 4
  %6 = icmp ult i64 %indvars.iv.next, 49998
  br i1 %6, label %3, label %.preheader9, !llvm.loop !11

.preheader:                                       ; preds = %.loopexit
  store i32 3, ptr %1, align 4, !tbaa !9
  br label %19

.preheader9:                                      ; preds = %3, %.loopexit
  %indvars.iv22 = phi i64 [ %indvars.iv.next23, %.loopexit ], [ 3, %3 ]
  %indvars.iv17 = phi i64 [ %indvars.iv.next18, %.loopexit ], [ 6, %3 ]
  %7 = phi i32 [ %18, %.loopexit ], [ 9, %3 ]
  %8 = getelementptr inbounds [50000 x i8], ptr @prime, i64 0, i64 %indvars.iv22
  %9 = load i8, ptr %8, align 1, !tbaa !5, !range !13, !noundef !14
  %10 = trunc nuw i8 %9 to i1
  %11 = icmp ugt i32 %7, 49999
  %or.cond.not = or i1 %11, %10
  br i1 %or.cond.not, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader9
  %12 = zext nneg i32 %7 to i64
  br label %13

13:                                               ; preds = %.lr.ph, %13
  %indvars.iv19 = phi i64 [ %12, %.lr.ph ], [ %indvars.iv.next20, %13 ]
  %14 = getelementptr inbounds [50000 x i8], ptr @prime, i64 0, i64 %indvars.iv19
  store i8 1, ptr %14, align 1, !tbaa !5
  %indvars.iv.next20 = add nuw nsw i64 %indvars.iv19, %indvars.iv17
  %15 = icmp ult i64 %indvars.iv.next20, 50000
  br i1 %15, label %13, label %.loopexit, !llvm.loop !15

.loopexit:                                        ; preds = %13, %.preheader9
  %indvars.iv.next23 = add nuw nsw i64 %indvars.iv22, 2
  %16 = mul nuw nsw i64 %indvars.iv.next23, %indvars.iv.next23
  %17 = icmp ult i64 %16, 50001
  %indvars.iv.next18 = add nuw nsw i64 %indvars.iv17, 4
  %18 = trunc nuw i64 %16 to i32
  br i1 %17, label %.preheader9, label %.preheader, !llvm.loop !16

19:                                               ; preds = %.preheader, %25
  %storemerge714 = phi i32 [ 3, %.preheader ], [ %27, %25 ]
  %20 = sext i32 %storemerge714 to i64
  %21 = getelementptr inbounds [50000 x i8], ptr @prime, i64 0, i64 %20
  %22 = load i8, ptr %21, align 1, !tbaa !5, !range !13, !noundef !14
  %23 = trunc nuw i8 %22 to i1
  br i1 %23, label %25, label %24

24:                                               ; preds = %19
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) @v, ptr noundef nonnull align 4 dereferenceable(4) %1)
  %.pre = load i32, ptr %1, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %19, %24
  %26 = phi i32 [ %storemerge714, %19 ], [ %.pre, %24 ]
  %27 = add nsw i32 %26, 2
  store i32 %27, ptr %1, align 4, !tbaa !9
  %28 = icmp slt i32 %26, 49998
  br i1 %28, label %19, label %29, !llvm.loop !17

29:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #2
  ret void
}

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

; 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 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 = { 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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !12}
!17 = distinct !{!17, !12}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass