; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/315 Division 1/Problem A (A)

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

@sieve = external dso_local global [10000001 x i32], align 16
@c1 = external dso_local global [2001000 x i32], align 16
@c2 = external dso_local global [2001000 x i32], align 16
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z8getSievev() #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 nounwind uwtable
declare dso_local noundef zeroext i1 @_Z5ispali(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 x86_fp80, align 16
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = 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.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 0, ptr %3, align 4, !tbaa !5
  %8 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %9 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %8, ptr noundef nonnull align 4 dereferenceable(4) %3)
  call void @_Z8getSievev()
  call void @llvm.lifetime.start.p0(i64 16, ptr %4) #5
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = sitofp i32 %10 to x86_fp80
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = sitofp i32 %12 to x86_fp80
  %14 = fdiv x86_fp80 %11, %13
  store x86_fp80 %14, ptr %4, align 16, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 1, ptr %5, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %58, %0
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = icmp sle i32 %16, 2000000
  br i1 %17, label %19, label %18

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

19:                                               ; preds = %15
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = sub nsw i32 %20, 1
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [2001000 x i32], ptr @c1, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = load i32, ptr %5, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [2001000 x i32], ptr @c1, i64 0, i64 %26
  store i32 %24, ptr %27, align 4, !tbaa !5
  %28 = load i32, ptr %5, align 4, !tbaa !5
  %29 = sub nsw i32 %28, 1
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [2001000 x i32], ptr @c2, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [2001000 x i32], ptr @c2, i64 0, i64 %34
  store i32 %32, ptr %35, align 4, !tbaa !5
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = call noundef zeroext i1 @_Z5ispali(i32 noundef %36)
  br i1 %37, label %38, label %44

38:                                               ; preds = %19
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [2001000 x i32], ptr @c1, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %41, align 4, !tbaa !5
  br label %44

44:                                               ; preds = %38, %19
  %45 = load i32, ptr %5, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [10000001 x i32], ptr @sieve, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = load i32, ptr %5, align 4, !tbaa !5
  %50 = icmp eq i32 %48, %49
  br i1 %50, label %51, label %57

51:                                               ; preds = %44
  %52 = load i32, ptr %5, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [2001000 x i32], ptr @c2, i64 0, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %54, align 4, !tbaa !5
  br label %57

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

58:                                               ; preds = %57
  %59 = load i32, ptr %5, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %5, align 4, !tbaa !5
  br label %15, !llvm.loop !11

61:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 2000000, ptr %6, align 4, !tbaa !5
  br label %62

62:                                               ; preds = %85, %61
  %63 = load i32, ptr %6, align 4, !tbaa !5
  %64 = icmp sge i32 %63, 1
  br i1 %64, label %66, label %65

65:                                               ; preds = %62
  store i32 5, ptr %7, align 4
  br label %88

66:                                               ; preds = %62
  %67 = load i32, ptr %6, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [2001000 x i32], ptr @c2, i64 0, i64 %68
  %70 = load i32, ptr %69, align 4, !tbaa !5
  %71 = sitofp i32 %70 to x86_fp80
  %72 = load x86_fp80, ptr %4, align 16, !tbaa !9
  %73 = load i32, ptr %6, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [2001000 x i32], ptr @c1, i64 0, i64 %74
  %76 = load i32, ptr %75, align 4, !tbaa !5
  %77 = sitofp i32 %76 to x86_fp80
  %78 = fmul x86_fp80 %72, %77
  %79 = fcmp ole x86_fp80 %71, %78
  br i1 %79, label %80, label %84

80:                                               ; preds = %66
  %81 = load i32, ptr %6, align 4, !tbaa !5
  %82 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %81)
  %83 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %82, ptr noundef @.str)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %7, align 4
  br label %88

84:                                               ; preds = %66
  br label %85

85:                                               ; preds = %84
  %86 = load i32, ptr %6, align 4, !tbaa !5
  %87 = add nsw i32 %86, -1
  store i32 %87, ptr %6, align 4, !tbaa !5
  br label %62, !llvm.loop !13

88:                                               ; preds = %80, %65
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  %89 = load i32, ptr %7, align 4
  switch i32 %89, label %91 [
    i32 5, label %90
  ]

90:                                               ; preds = %88
  store i32 0, ptr %1, align 4
  store i32 1, ptr %7, align 4
  br label %91

91:                                               ; preds = %90, %88
  call void @llvm.lifetime.end.p0(i64 16, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  %92 = load i32, ptr %1, align 4
  ret i32 %92
}

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

; 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) #4

declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) #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 = { 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 = { "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 = { 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 #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 = !{!10, !10, i64 0}
!10 = !{!"long double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !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::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" }

@sieve = external dso_local local_unnamed_addr global [10000001 x i32], align 16
@c1 = external dso_local local_unnamed_addr global [2001000 x i32], align 16
@c2 = external dso_local local_unnamed_addr global [2001000 x i32], align 16
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z8getSievev() 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 nounwind uwtable
declare dso_local noundef zeroext i1 @_Z5ispali(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
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #5
  store i32 0, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #5
  store i32 0, ptr %2, align 4, !tbaa !5
  %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) %1)
  %4 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %3, ptr noundef nonnull align 4 dereferenceable(4) %2)
  call void @_Z8getSievev()
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = sitofp i32 %6 to x86_fp80
  br label %8

8:                                                ; preds = %0, %29
  %indvars.iv = phi i64 [ 1, %0 ], [ %indvars.iv.next, %29 ]
  %9 = add nsw i64 %indvars.iv, -1
  %10 = getelementptr inbounds [2001000 x i32], ptr @c1, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = getelementptr inbounds [2001000 x i32], ptr @c1, i64 0, i64 %indvars.iv
  store i32 %11, ptr %12, align 4, !tbaa !5
  %13 = getelementptr inbounds [2001000 x i32], ptr @c2, i64 0, i64 %9
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = getelementptr inbounds [2001000 x i32], ptr @c2, i64 0, i64 %indvars.iv
  store i32 %14, ptr %15, align 4, !tbaa !5
  %16 = trunc nuw nsw i64 %indvars.iv to i32
  %17 = call noundef zeroext i1 @_Z5ispali(i32 noundef %16)
  br i1 %17, label %18, label %21

18:                                               ; preds = %8
  %19 = load i32, ptr %12, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %12, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %18, %8
  %22 = getelementptr inbounds [10000001 x i32], ptr @sieve, i64 0, i64 %indvars.iv
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = zext i32 %23 to i64
  %25 = icmp eq i64 %indvars.iv, %24
  br i1 %25, label %26, label %29

26:                                               ; preds = %21
  %27 = load i32, ptr %15, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %15, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %21, %26
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 2000001
  br i1 %exitcond.not, label %.preheader.preheader, label %8, !llvm.loop !9

.preheader.preheader:                             ; preds = %29
  %30 = sitofp i32 %5 to x86_fp80
  %31 = fdiv x86_fp80 %30, %7
  br label %.preheader

.preheader:                                       ; preds = %52, %.preheader.preheader
  %indvars.iv26 = phi i64 [ 2000000, %.preheader.preheader ], [ %indvars.iv.next27.1, %52 ]
  %32 = getelementptr inbounds [2001000 x i32], ptr @c2, i64 0, i64 %indvars.iv26
  %33 = load i32, ptr %32, align 8, !tbaa !5
  %34 = sitofp i32 %33 to x86_fp80
  %35 = getelementptr inbounds [2001000 x i32], ptr @c1, i64 0, i64 %indvars.iv26
  %36 = load i32, ptr %35, align 8, !tbaa !5
  %37 = sitofp i32 %36 to x86_fp80
  %38 = fmul x86_fp80 %31, %37
  %39 = fcmp ult x86_fp80 %38, %34
  br i1 %39, label %.preheader.1, label %40

40:                                               ; preds = %.preheader.1, %.preheader
  %indvars.iv26.lcssa = phi i64 [ %indvars.iv26, %.preheader ], [ %indvars.iv.next27, %.preheader.1 ]
  %41 = trunc nuw nsw i64 %indvars.iv26.lcssa to i32
  %42 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %41)
  %43 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %42, ptr noundef nonnull @.str)
  br label %.critedge

.preheader.1:                                     ; preds = %.preheader
  %indvars.iv.next27 = add nsw i64 %indvars.iv26, -1
  %44 = getelementptr inbounds [2001000 x i32], ptr @c2, i64 0, i64 %indvars.iv.next27
  %45 = load i32, ptr %44, align 4, !tbaa !5
  %46 = sitofp i32 %45 to x86_fp80
  %47 = getelementptr inbounds [2001000 x i32], ptr @c1, i64 0, i64 %indvars.iv.next27
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = sitofp i32 %48 to x86_fp80
  %50 = fmul x86_fp80 %31, %49
  %51 = fcmp ult x86_fp80 %50, %46
  br i1 %51, label %52, label %40

52:                                               ; preds = %.preheader.1
  %indvars.iv.next27.1 = add nsw i64 %indvars.iv26, -2
  %53 = icmp eq i64 %indvars.iv.next27, 1
  br i1 %53, label %.critedge, label %.preheader, !llvm.loop !11

.critedge:                                        ; preds = %52, %40
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #5
  ret i32 0
}

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 #3

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

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 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 = { "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 = { 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 #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: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass