; LLVM IR from bqi343/cp-notebook :: Contests/USACO Solutions/2019-20/Open/Plat/exercise_3000_dwr.ll (Z10precomputev)

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

@N = external dso_local global i32, align 4
@ch = external dso_local global [5001 x [5001 x i32]], align 16
@prime = external dso_local global [5001 x i8], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z4multii(i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z10precomputev() #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
  %6 = 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 %7

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

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

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

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

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

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

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

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

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

32:                                               ; preds = %40, %29
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = icmp slt i32 %33, 5001
  br i1 %34, label %36, label %35

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

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

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

44:                                               ; preds = %35
  br label %45

45:                                               ; preds = %44, %23
  br label %46

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

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

50:                                               ; preds = %89, %49
  %51 = load i32, ptr %5, align 4, !tbaa !5
  %52 = load i32, ptr @N, align 4, !tbaa !5
  %53 = icmp sle i32 %51, %52
  br i1 %53, label %55, label %54

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

55:                                               ; preds = %50
  %56 = load i32, ptr %5, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [5001 x [5001 x i32]], ptr @ch, i64 0, i64 %57
  %59 = getelementptr inbounds [5001 x i32], ptr %58, i64 0, i64 0
  store i32 1, ptr %59, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 1, ptr %6, align 4, !tbaa !5
  br label %60

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

64:                                               ; preds = %60
  store i32 14, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %88

65:                                               ; preds = %60
  %66 = load i32, ptr %5, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [5001 x [5001 x i32]], ptr @ch, i64 0, i64 %67
  %69 = load i32, ptr %6, align 4, !tbaa !5
  %70 = sub nsw i32 %69, 1
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [5001 x i32], ptr %68, i64 0, i64 %71
  %73 = load i32, ptr %72, align 4, !tbaa !5
  %74 = load i32, ptr %5, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  %76 = load i32, ptr %6, align 4, !tbaa !5
  %77 = sub nsw i32 %75, %76
  %78 = call noundef i32 @_Z4multii(i32 noundef %73, i32 noundef %77)
  %79 = load i32, ptr %5, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [5001 x [5001 x i32]], ptr @ch, i64 0, i64 %80
  %82 = load i32, ptr %6, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [5001 x i32], ptr %81, i64 0, i64 %83
  store i32 %78, ptr %84, align 4, !tbaa !5
  br label %85

85:                                               ; preds = %65
  %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 %60, !llvm.loop !17

88:                                               ; preds = %64
  br label %89

89:                                               ; preds = %88
  %90 = load i32, ptr %5, align 4, !tbaa !5
  %91 = add nsw i32 %90, 1
  store i32 %91, ptr %5, align 4, !tbaa !5
  br label %50, !llvm.loop !18

92:                                               ; preds = %54
  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}
!18 = distinct !{!18, !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"

@N = external dso_local local_unnamed_addr global i32, align 4
@ch = external dso_local local_unnamed_addr global [5001 x [5001 x i32]], align 16
@prime = external dso_local local_unnamed_addr global [5001 x i8], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z4multii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z10precomputev() local_unnamed_addr #0 {
.preheader28.preheader:
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 2 dereferenceable(4999) getelementptr inbounds (i8, ptr @prime, i64 2), i8 1, i64 4999, i1 false), !tbaa !5
  br label %.preheader28

.preheader:                                       ; preds = %.loopexit
  %0 = load i32, ptr @N, align 4, !tbaa !9
  %.not36 = icmp slt i32 %0, 0
  br i1 %.not36, label %._crit_edge39, label %.lr.ph38

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

.lr.ph:                                           ; preds = %.preheader28, %.lr.ph
  %indvars.iv44 = phi i64 [ %indvars.iv.next45, %.lr.ph ], [ %indvars.iv, %.preheader28 ]
  %5 = getelementptr inbounds [5001 x i8], ptr @prime, i64 0, i64 %indvars.iv44
  store i8 0, ptr %5, align 2, !tbaa !5
  %indvars.iv.next45 = add nuw nsw i64 %indvars.iv44, %indvars.iv42
  %6 = icmp ult i64 %indvars.iv.next45, 5001
  br i1 %6, label %.lr.ph, label %.loopexit, !llvm.loop !13

.loopexit:                                        ; preds = %.lr.ph, %.preheader28
  %indvars.iv.next43 = or disjoint i64 %indvars.iv42, 1
  %indvars.iv.next = or disjoint i64 %indvars.iv, 2
  %exitcond.not = icmp eq i64 %indvars.iv42, 5000
  br i1 %exitcond.not, label %.preheader, label %.preheader28.1, !llvm.loop !15

.preheader28.1:                                   ; preds = %.loopexit
  %7 = getelementptr inbounds [5001 x i8], ptr @prime, i64 0, i64 %indvars.iv.next43
  %8 = load i8, ptr %7, align 1, !tbaa !5, !range !11, !noundef !12
  %9 = trunc nuw i8 %8 to i1
  %10 = icmp ult i64 %indvars.iv.next43, 2501
  %or.cond.1 = and i1 %10, %9
  br i1 %or.cond.1, label %.lr.ph.1, label %.loopexit.1

.lr.ph.1:                                         ; preds = %.preheader28.1, %.lr.ph.1
  %indvars.iv44.1 = phi i64 [ %indvars.iv.next45.1, %.lr.ph.1 ], [ %indvars.iv.next, %.preheader28.1 ]
  %11 = getelementptr inbounds [5001 x i8], ptr @prime, i64 0, i64 %indvars.iv44.1
  store i8 0, ptr %11, align 1, !tbaa !5
  %indvars.iv.next45.1 = add nuw nsw i64 %indvars.iv44.1, %indvars.iv.next43
  %12 = icmp ult i64 %indvars.iv.next45.1, 5001
  br i1 %12, label %.lr.ph.1, label %.loopexit.1, !llvm.loop !13

.loopexit.1:                                      ; preds = %.lr.ph.1, %.preheader28.1
  %indvars.iv.next43.1 = add nuw nsw i64 %indvars.iv42, 2
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 4
  br label %.preheader28

._crit_edge39:                                    ; preds = %._crit_edge, %.preheader
  ret void

.lr.ph38:                                         ; preds = %.preheader, %._crit_edge
  %13 = phi i32 [ %16, %._crit_edge ], [ %0, %.preheader ]
  %indvars.iv56 = phi i64 [ %indvars.iv.next57.pre-phi, %._crit_edge ], [ 0, %.preheader ]
  %indvars.iv54 = phi i64 [ %indvars.iv.next55, %._crit_edge ], [ 1, %.preheader ]
  %14 = getelementptr inbounds [5001 x [5001 x i32]], ptr @ch, i64 0, i64 %indvars.iv56
  store i32 1, ptr %14, align 4, !tbaa !9
  %.not2733 = icmp eq i64 %indvars.iv56, 0
  br i1 %.not2733, label %._crit_edge, label %.lr.ph35

.lr.ph35:                                         ; preds = %.lr.ph38
  %15 = add nuw nsw i64 %indvars.iv56, 1
  br label %18

._crit_edge.loopexit:                             ; preds = %18
  %.pre61 = load i32, ptr @N, align 4, !tbaa !9
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph38, %._crit_edge.loopexit
  %indvars.iv.next57.pre-phi = phi i64 [ %15, %._crit_edge.loopexit ], [ 1, %.lr.ph38 ]
  %16 = phi i32 [ %.pre61, %._crit_edge.loopexit ], [ %13, %.lr.ph38 ]
  %17 = sext i32 %16 to i64
  %.not.not = icmp slt i64 %indvars.iv56, %17
  %indvars.iv.next55 = add nuw nsw i64 %indvars.iv54, 1
  br i1 %.not.not, label %.lr.ph38, label %._crit_edge39, !llvm.loop !16

18:                                               ; preds = %.lr.ph35, %18
  %19 = phi i32 [ 1, %.lr.ph35 ], [ %22, %18 ]
  %indvars.iv48 = phi i64 [ 1, %.lr.ph35 ], [ %indvars.iv.next49, %18 ]
  %20 = sub nsw i64 %15, %indvars.iv48
  %21 = trunc nsw i64 %20 to i32
  %22 = tail call noundef i32 @_Z4multii(i32 noundef %19, i32 noundef %21)
  %23 = getelementptr inbounds [5001 x [5001 x i32]], ptr @ch, i64 0, i64 %indvars.iv56, i64 %indvars.iv48
  store i32 %22, ptr %23, align 4, !tbaa !9
  %indvars.iv.next49 = add nuw nsw i64 %indvars.iv48, 1
  %exitcond53.not = icmp eq i64 %indvars.iv.next49, %indvars.iv54
  br i1 %exitcond53.not, label %._crit_edge.loopexit, label %18, !llvm.loop !17
}

; 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 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 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}
!17 = distinct !{!17, !14}


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