; LLVM IR from eyangch/competitive-programming :: Codeforces/1474 (b)

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

@T = external dso_local global i64, align 8
@sieve = external dso_local global [500000 x i8], align 16
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  %8 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) @T)
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  store i64 2, ptr %2, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %34, %0
  %10 = load i64, ptr %2, align 8, !tbaa !5
  %11 = icmp slt i64 %10, 500000
  br i1 %11, label %13, label %12

12:                                               ; preds = %9
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  br label %37

13:                                               ; preds = %9
  %14 = load i64, ptr %2, align 8, !tbaa !5
  %15 = getelementptr inbounds [500000 x i8], ptr @sieve, i64 0, i64 %14
  %16 = load i8, ptr %15, align 1, !tbaa !9, !range !11, !noundef !12
  %17 = trunc i8 %16 to i1
  br i1 %17, label %18, label %19

18:                                               ; preds = %13
  br label %34

19:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %20 = load i64, ptr %2, align 8, !tbaa !5
  %21 = mul nsw i64 2, %20
  store i64 %21, ptr %4, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %29, %19
  %23 = load i64, ptr %4, align 8, !tbaa !5
  %24 = icmp slt i64 %23, 500000
  br i1 %24, label %26, label %25

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

26:                                               ; preds = %22
  %27 = load i64, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds [500000 x i8], ptr @sieve, i64 0, i64 %27
  store i8 1, ptr %28, align 1, !tbaa !9
  br label %29

29:                                               ; preds = %26
  %30 = load i64, ptr %2, align 8, !tbaa !5
  %31 = load i64, ptr %4, align 8, !tbaa !5
  %32 = add nsw i64 %31, %30
  store i64 %32, ptr %4, align 8, !tbaa !5
  br label %22, !llvm.loop !13

33:                                               ; preds = %25
  br label %34

34:                                               ; preds = %33, %18
  %35 = load i64, ptr %2, align 8, !tbaa !5
  %36 = add nsw i64 %35, 1
  store i64 %36, ptr %2, align 8, !tbaa !5
  br label %9, !llvm.loop !15

37:                                               ; preds = %12
  br label %38

38:                                               ; preds = %68, %37
  %39 = load i64, ptr @T, align 8, !tbaa !5
  %40 = add nsw i64 %39, -1
  store i64 %40, ptr @T, align 8, !tbaa !5
  %41 = icmp ne i64 %39, 0
  br i1 %41, label %42, label %74

42:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %43 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %5)
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %44 = load i64, ptr %5, align 8, !tbaa !5
  %45 = add nsw i64 %44, 1
  store i64 %45, ptr %6, align 8, !tbaa !5
  br label %46

46:                                               ; preds = %52, %42
  %47 = load i64, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds [500000 x i8], ptr @sieve, i64 0, i64 %47
  %49 = load i8, ptr %48, align 1, !tbaa !9, !range !11, !noundef !12
  %50 = trunc i8 %49 to i1
  br i1 %50, label %51, label %55

51:                                               ; preds = %46
  br label %52

52:                                               ; preds = %51
  %53 = load i64, ptr %6, align 8, !tbaa !5
  %54 = add nsw i64 %53, 1
  store i64 %54, ptr %6, align 8, !tbaa !5
  br label %46, !llvm.loop !16

55:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %56 = load i64, ptr %6, align 8, !tbaa !5
  %57 = load i64, ptr %5, align 8, !tbaa !5
  %58 = add nsw i64 %56, %57
  store i64 %58, ptr %7, align 8, !tbaa !5
  br label %59

59:                                               ; preds = %65, %55
  %60 = load i64, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds [500000 x i8], ptr @sieve, i64 0, i64 %60
  %62 = load i8, ptr %61, align 1, !tbaa !9, !range !11, !noundef !12
  %63 = trunc i8 %62 to i1
  br i1 %63, label %64, label %68

64:                                               ; preds = %59
  br label %65

65:                                               ; preds = %64
  %66 = load i64, ptr %7, align 8, !tbaa !5
  %67 = add nsw i64 %66, 1
  store i64 %67, ptr %7, align 8, !tbaa !5
  br label %59, !llvm.loop !17

68:                                               ; preds = %59
  %69 = load i64, ptr %6, align 8, !tbaa !5
  %70 = load i64, ptr %7, align 8, !tbaa !5
  %71 = mul nsw i64 %69, %70
  %72 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %71)
  %73 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %72, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %38, !llvm.loop !18

74:                                               ; preds = %38
  %75 = load i32, ptr %1, align 4
  ret i32 %75
}

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(8)) #1 align 2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

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

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #1 align 2

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

attributes #0 = { 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 #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}
!17 = distinct !{!17, !14}
!18 = distinct !{!18, !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"

%"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" }

@T = external dso_local global i64, align 8
@sieve = external dso_local local_unnamed_addr global [500000 x i8], align 16
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i64, align 8
  %2 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) @T)
  br label %5

.preheader:                                       ; preds = %.loopexit.1
  %3 = load i64, ptr @T, align 8, !tbaa !5
  %4 = add nsw i64 %3, -1
  store i64 %4, ptr @T, align 8, !tbaa !5
  %.not21 = icmp eq i64 %3, 0
  br i1 %.not21, label %._crit_edge, label %.lr.ph22

5:                                                ; preds = %.loopexit.1, %0
  %.01820 = phi i64 [ 2, %0 ], [ %23, %.loopexit.1 ]
  %6 = getelementptr inbounds [500000 x i8], ptr @sieve, i64 0, i64 %.01820
  %7 = load i8, ptr %6, align 2, !tbaa !9, !range !11, !noundef !12
  %8 = trunc nuw i8 %7 to i1
  %9 = icmp ugt i64 %.01820, 249999
  %or.cond.not = or i1 %9, %8
  br i1 %or.cond.not, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %5
  %10 = shl nuw nsw i64 %.01820, 1
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.01719 = phi i64 [ %12, %.lr.ph ], [ %10, %.lr.ph.preheader ]
  %11 = getelementptr inbounds [500000 x i8], ptr @sieve, i64 0, i64 %.01719
  store i8 1, ptr %11, align 2, !tbaa !9
  %12 = add nuw nsw i64 %.01719, %.01820
  %13 = icmp ult i64 %12, 500000
  br i1 %13, label %.lr.ph, label %.loopexit, !llvm.loop !13

.loopexit:                                        ; preds = %.lr.ph, %5
  %14 = or disjoint i64 %.01820, 1
  %15 = getelementptr inbounds [500000 x i8], ptr @sieve, i64 0, i64 %14
  %16 = load i8, ptr %15, align 1, !tbaa !9, !range !11, !noundef !12
  %17 = trunc nuw i8 %16 to i1
  %18 = icmp ugt i64 %.01820, 249999
  %or.cond.not.1 = or i1 %18, %17
  br i1 %or.cond.not.1, label %.loopexit.1, label %.lr.ph.preheader.1

.lr.ph.preheader.1:                               ; preds = %.loopexit
  %19 = shl nuw nsw i64 %14, 1
  br label %.lr.ph.1

.lr.ph.1:                                         ; preds = %.lr.ph.1, %.lr.ph.preheader.1
  %.01719.1 = phi i64 [ %21, %.lr.ph.1 ], [ %19, %.lr.ph.preheader.1 ]
  %20 = getelementptr inbounds [500000 x i8], ptr @sieve, i64 0, i64 %.01719.1
  store i8 1, ptr %20, align 1, !tbaa !9
  %21 = add nuw nsw i64 %.01719.1, %14
  %22 = icmp ult i64 %21, 500000
  br i1 %22, label %.lr.ph.1, label %.loopexit.1, !llvm.loop !13

.loopexit.1:                                      ; preds = %.lr.ph.1, %.loopexit
  %23 = add nuw nsw i64 %.01820, 2
  %exitcond.not.1 = icmp eq i64 %23, 500000
  br i1 %exitcond.not.1, label %.preheader, label %5, !llvm.loop !15

.lr.ph22:                                         ; preds = %.preheader, %37
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  %24 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %1)
  %25 = load i64, ptr %1, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %26, %.lr.ph22
  %.016.in = phi i64 [ %25, %.lr.ph22 ], [ %.016, %26 ]
  %.016 = add nsw i64 %.016.in, 1
  %27 = getelementptr inbounds [500000 x i8], ptr @sieve, i64 0, i64 %.016
  %28 = load i8, ptr %27, align 1, !tbaa !9, !range !11, !noundef !12
  %29 = trunc nuw i8 %28 to i1
  br i1 %29, label %26, label %30, !llvm.loop !16

30:                                               ; preds = %26
  %31 = add nsw i64 %.016, %25
  br label %32

32:                                               ; preds = %32, %30
  %.0 = phi i64 [ %31, %30 ], [ %36, %32 ]
  %33 = getelementptr inbounds [500000 x i8], ptr @sieve, i64 0, i64 %.0
  %34 = load i8, ptr %33, align 1, !tbaa !9, !range !11, !noundef !12
  %35 = trunc nuw i8 %34 to i1
  %36 = add nsw i64 %.0, 1
  br i1 %35, label %32, label %37, !llvm.loop !17

37:                                               ; preds = %32
  %38 = mul nsw i64 %.0, %.016
  %39 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %38)
  %40 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %39, ptr noundef nonnull @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #4
  %41 = load i64, ptr @T, align 8, !tbaa !5
  %42 = add nsw i64 %41, -1
  store i64 %42, ptr @T, align 8, !tbaa !5
  %.not = icmp eq i64 %41, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph22, !llvm.loop !18

._crit_edge:                                      ; preds = %37, %.preheader
  ret i32 0
}

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

; 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 #1 align 2

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

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

attributes #0 = { 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 #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}
!17 = distinct !{!17, !14}
!18 = distinct !{!18, !14}


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