; LLVM IR from abeaumont/competitive-programming :: codeforces/1047/c.ll (Z1fv)

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

@primes = external dso_local global [15000000 x i8], align 16
@p = external dso_local global i32, align 4
@ps = external dso_local global [15000000 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z1fv() #0 {
  %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
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 2, ptr %1, align 4, !tbaa !5
  br label %6

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

9:                                                ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  br label %17

10:                                               ; preds = %6
  %11 = load i32, ptr %1, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [15000000 x i8], ptr @primes, i64 0, i64 %12
  store i8 1, ptr %13, align 1, !tbaa !9
  br label %14

14:                                               ; preds = %10
  %15 = load i32, ptr %1, align 4, !tbaa !5
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr %1, align 4, !tbaa !5
  br label %6, !llvm.loop !11

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

18:                                               ; preds = %45, %17
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = icmp slt i32 %19, 15000000
  br i1 %20, label %22, label %21

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

22:                                               ; preds = %18
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [15000000 x i8], ptr @primes, i64 0, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !9, !range !13, !noundef !14
  %27 = trunc i8 %26 to i1
  br i1 %27, label %28, label %44

28:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = mul nsw i32 2, %29
  store i32 %30, ptr %4, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %39, %28
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = icmp slt i32 %32, 15000000
  br i1 %33, label %35, label %34

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

35:                                               ; preds = %31
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [15000000 x i8], ptr @primes, i64 0, i64 %37
  store i8 0, ptr %38, align 1, !tbaa !9
  br label %39

39:                                               ; preds = %35
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = add nsw i32 %41, %40
  store i32 %42, ptr %4, align 4, !tbaa !5
  br label %31, !llvm.loop !15

43:                                               ; preds = %34
  br label %44

44:                                               ; preds = %43, %22
  br label %45

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

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

49:                                               ; preds = %66, %48
  %50 = load i32, ptr %5, align 4, !tbaa !5
  %51 = icmp slt i32 %50, 15000000
  br i1 %51, label %53, label %52

52:                                               ; preds = %49
  store i32 11, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %69

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

59:                                               ; preds = %53
  %60 = load i32, ptr %5, align 4, !tbaa !5
  %61 = load i32, ptr @p, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr @p, align 4, !tbaa !5
  %63 = sext i32 %61 to i64
  %64 = getelementptr inbounds [15000000 x i32], ptr @ps, i64 0, i64 %63
  store i32 %60, ptr %64, align 4, !tbaa !5
  br label %65

65:                                               ; preds = %59, %53
  br label %66

66:                                               ; preds = %65
  %67 = load i32, ptr %5, align 4, !tbaa !5
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %5, align 4, !tbaa !5
  br label %49, !llvm.loop !17

69:                                               ; preds = %52
  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

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 = { 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 = !{!"bool", !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"

@primes = external dso_local local_unnamed_addr global [15000000 x i8], align 16
@p = external dso_local local_unnamed_addr global i32, align 4
@ps = external dso_local local_unnamed_addr global [15000000 x i32], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z1fv() local_unnamed_addr #0 {
.preheader18.preheader:
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 2 dereferenceable(14999998) getelementptr inbounds (i8, ptr @primes, i64 2), i8 1, i64 14999998, i1 false), !tbaa !5
  br label %.preheader18

.preheader:                                       ; preds = %.loopexit.1
  %p.promoted = load i32, ptr @p, align 4, !tbaa !9
  br label %13

.preheader18:                                     ; preds = %.loopexit.1, %.preheader18.preheader
  %indvars.iv26 = phi i64 [ 2, %.preheader18.preheader ], [ %indvars.iv.next27.1, %.loopexit.1 ]
  %indvars.iv = phi i64 [ 4, %.preheader18.preheader ], [ %indvars.iv.next.1, %.loopexit.1 ]
  %0 = getelementptr inbounds [15000000 x i8], ptr @primes, i64 0, i64 %indvars.iv26
  %1 = load i8, ptr %0, align 2, !tbaa !5, !range !11, !noundef !12
  %2 = trunc nuw i8 %1 to i1
  %3 = icmp ult i64 %indvars.iv26, 7500000
  %or.cond = and i1 %3, %2
  br i1 %or.cond, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader18, %.lr.ph
  %indvars.iv28 = phi i64 [ %indvars.iv.next29, %.lr.ph ], [ %indvars.iv, %.preheader18 ]
  %4 = getelementptr inbounds [15000000 x i8], ptr @primes, i64 0, i64 %indvars.iv28
  store i8 0, ptr %4, align 2, !tbaa !5
  %indvars.iv.next29 = add nuw nsw i64 %indvars.iv28, %indvars.iv26
  %5 = icmp ult i64 %indvars.iv.next29, 15000000
  br i1 %5, label %.lr.ph, label %.loopexit, !llvm.loop !13

.loopexit:                                        ; preds = %.lr.ph, %.preheader18
  %indvars.iv.next27 = or disjoint i64 %indvars.iv26, 1
  %6 = getelementptr inbounds [15000000 x i8], ptr @primes, i64 0, i64 %indvars.iv.next27
  %7 = load i8, ptr %6, align 1, !tbaa !5, !range !11, !noundef !12
  %8 = trunc nuw i8 %7 to i1
  %9 = icmp ult i64 %indvars.iv26, 7500000
  %or.cond.1 = and i1 %9, %8
  br i1 %or.cond.1, label %.lr.ph.preheader.1, label %.loopexit.1

.lr.ph.preheader.1:                               ; preds = %.loopexit
  %indvars.iv.next = or disjoint i64 %indvars.iv, 2
  br label %.lr.ph.1

.lr.ph.1:                                         ; preds = %.lr.ph.1, %.lr.ph.preheader.1
  %indvars.iv28.1 = phi i64 [ %indvars.iv.next29.1, %.lr.ph.1 ], [ %indvars.iv.next, %.lr.ph.preheader.1 ]
  %10 = getelementptr inbounds [15000000 x i8], ptr @primes, i64 0, i64 %indvars.iv28.1
  store i8 0, ptr %10, align 1, !tbaa !5
  %indvars.iv.next29.1 = add nuw nsw i64 %indvars.iv28.1, %indvars.iv.next27
  %11 = icmp ult i64 %indvars.iv.next29.1, 15000000
  br i1 %11, label %.lr.ph.1, label %.loopexit.1, !llvm.loop !13

.loopexit.1:                                      ; preds = %.lr.ph.1, %.loopexit
  %indvars.iv.next27.1 = add nuw nsw i64 %indvars.iv26, 2
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next27.1, 15000000
  br i1 %exitcond.not.1, label %.preheader, label %.preheader18, !llvm.loop !15

12:                                               ; preds = %33
  ret void

13:                                               ; preds = %33, %.preheader
  %indvars.iv32 = phi i64 [ 0, %.preheader ], [ %indvars.iv.next33.1, %33 ]
  %14 = phi i32 [ %p.promoted, %.preheader ], [ %34, %33 ]
  %15 = getelementptr inbounds [15000000 x i8], ptr @primes, i64 0, i64 %indvars.iv32
  %16 = load i8, ptr %15, align 2, !tbaa !5, !range !11, !noundef !12
  %17 = trunc nuw i8 %16 to i1
  br i1 %17, label %18, label %23

18:                                               ; preds = %13
  %19 = add nsw i32 %14, 1
  store i32 %19, ptr @p, align 4, !tbaa !9
  %20 = sext i32 %14 to i64
  %21 = getelementptr inbounds [15000000 x i32], ptr @ps, i64 0, i64 %20
  %22 = trunc nuw nsw i64 %indvars.iv32 to i32
  store i32 %22, ptr %21, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %13, %18
  %24 = phi i32 [ %14, %13 ], [ %19, %18 ]
  %indvars.iv.next33 = or disjoint i64 %indvars.iv32, 1
  %25 = getelementptr inbounds [15000000 x i8], ptr @primes, i64 0, i64 %indvars.iv.next33
  %26 = load i8, ptr %25, align 1, !tbaa !5, !range !11, !noundef !12
  %27 = trunc nuw i8 %26 to i1
  br i1 %27, label %28, label %33

28:                                               ; preds = %23
  %29 = add nsw i32 %24, 1
  store i32 %29, ptr @p, align 4, !tbaa !9
  %30 = sext i32 %24 to i64
  %31 = getelementptr inbounds [15000000 x i32], ptr @ps, i64 0, i64 %30
  %32 = trunc nuw nsw i64 %indvars.iv.next33 to i32
  store i32 %32, ptr %31, align 4, !tbaa !9
  br label %33

33:                                               ; preds = %28, %23
  %34 = phi i32 [ %24, %23 ], [ %29, %28 ]
  %indvars.iv.next33.1 = add nuw nsw i64 %indvars.iv32, 2
  %exitcond35.not.1 = icmp eq i64 %indvars.iv.next33.1, 15000000
  br i1 %exitcond35.not.1, label %12, label %13, !llvm.loop !16
}

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

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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 nounwind willreturn memory(argmem: write) }

!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 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass