; LLVM IR from bqi343/cp-notebook :: Contests/USACO Solutions/2019-20/Feb/Plat/help_NKlogN+K^2.ll (Z4pushiii)

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

%"struct.std::array" = type { [11 x %struct.mi] }
%struct.mi = type { i32 }

@K = external dso_local global i32, align 4
@seg = external dso_local global [262144 x %"struct.std::array"], align 16
@lazy = external dso_local global [262144 x %struct.mi], align 16

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN2miC2Ex(ptr noundef nonnull align 4 dereferenceable(4), i64 noundef) unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local i32 @_Zml2miS_(i32, i32) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z4pushiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca %struct.mi, align 4
  %9 = alloca %struct.mi, align 4
  %10 = alloca %struct.mi, align 4
  %11 = alloca %struct.mi, align 4
  %12 = alloca %struct.mi, align 4
  %13 = alloca %struct.mi, align 4
  %14 = alloca %struct.mi, align 4
  %15 = alloca %struct.mi, align 4
  %16 = alloca %struct.mi, align 4
  %17 = alloca %struct.mi, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [262144 x %struct.mi], ptr @lazy, i64 0, i64 %19
  %21 = getelementptr inbounds %struct.mi, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %21, align 4, !tbaa !9
  %23 = icmp eq i32 %22, 1
  br i1 %23, label %24, label %25

24:                                               ; preds = %3
  br label %101

25:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %53, %25
  %27 = load i32, ptr %7, align 4, !tbaa !5
  %28 = load i32, ptr @K, align 4, !tbaa !5
  %29 = icmp sle i32 %27, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %56

31:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [262144 x %"struct.std::array"], ptr @seg, i64 0, i64 %33
  %35 = load i32, ptr %7, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt5arrayI2miLm11EEixEm(ptr noundef nonnull align 4 dereferenceable(44) %34, i64 noundef %36) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %9, ptr align 4 %37, i64 4, i1 false), !tbaa.struct !11
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [262144 x %struct.mi], ptr @lazy, i64 0, i64 %39
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 4 %40, i64 4, i1 false), !tbaa.struct !11
  %41 = getelementptr inbounds %struct.mi, ptr %9, i32 0, i32 0
  %42 = load i32, ptr %41, align 4
  %43 = getelementptr inbounds %struct.mi, ptr %10, i32 0, i32 0
  %44 = load i32, ptr %43, align 4
  %45 = call i32 @_Zml2miS_(i32 %42, i32 %44)
  %46 = getelementptr inbounds %struct.mi, ptr %8, i32 0, i32 0
  store i32 %45, ptr %46, align 4
  %47 = load i32, ptr %4, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [262144 x %"struct.std::array"], ptr @seg, i64 0, i64 %48
  %50 = load i32, ptr %7, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt5arrayI2miLm11EEixEm(ptr noundef nonnull align 4 dereferenceable(44) %49, i64 noundef %51) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %52, ptr align 4 %8, i64 4, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %53

53:                                               ; preds = %31
  %54 = load i32, ptr %7, align 4, !tbaa !5
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %7, align 4, !tbaa !5
  br label %26, !llvm.loop !12

56:                                               ; preds = %30
  %57 = load i32, ptr %5, align 4, !tbaa !5
  %58 = load i32, ptr %6, align 4, !tbaa !5
  %59 = icmp ne i32 %57, %58
  br i1 %59, label %60, label %97

60:                                               ; preds = %56
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %61 = load i32, ptr %4, align 4, !tbaa !5
  %62 = mul nsw i32 2, %61
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [262144 x %struct.mi], ptr @lazy, i64 0, i64 %63
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %12, ptr align 4 %64, i64 4, i1 false), !tbaa.struct !11
  %65 = load i32, ptr %4, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [262144 x %struct.mi], ptr @lazy, i64 0, i64 %66
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %13, ptr align 4 %67, i64 4, i1 false), !tbaa.struct !11
  %68 = getelementptr inbounds %struct.mi, ptr %12, i32 0, i32 0
  %69 = load i32, ptr %68, align 4
  %70 = getelementptr inbounds %struct.mi, ptr %13, i32 0, i32 0
  %71 = load i32, ptr %70, align 4
  %72 = call i32 @_Zml2miS_(i32 %69, i32 %71)
  %73 = getelementptr inbounds %struct.mi, ptr %11, i32 0, i32 0
  store i32 %72, ptr %73, align 4
  %74 = load i32, ptr %4, align 4, !tbaa !5
  %75 = mul nsw i32 2, %74
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [262144 x %struct.mi], ptr @lazy, i64 0, i64 %76
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %77, ptr align 4 %11, i64 4, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %78 = load i32, ptr %4, align 4, !tbaa !5
  %79 = mul nsw i32 2, %78
  %80 = add nsw i32 %79, 1
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [262144 x %struct.mi], ptr @lazy, i64 0, i64 %81
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %15, ptr align 4 %82, i64 4, i1 false), !tbaa.struct !11
  %83 = load i32, ptr %4, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [262144 x %struct.mi], ptr @lazy, i64 0, i64 %84
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %16, ptr align 4 %85, i64 4, i1 false), !tbaa.struct !11
  %86 = getelementptr inbounds %struct.mi, ptr %15, i32 0, i32 0
  %87 = load i32, ptr %86, align 4
  %88 = getelementptr inbounds %struct.mi, ptr %16, i32 0, i32 0
  %89 = load i32, ptr %88, align 4
  %90 = call i32 @_Zml2miS_(i32 %87, i32 %89)
  %91 = getelementptr inbounds %struct.mi, ptr %14, i32 0, i32 0
  store i32 %90, ptr %91, align 4
  %92 = load i32, ptr %4, align 4, !tbaa !5
  %93 = mul nsw i32 2, %92
  %94 = add nsw i32 %93, 1
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds [262144 x %struct.mi], ptr @lazy, i64 0, i64 %95
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %96, ptr align 4 %14, i64 4, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  br label %97

97:                                               ; preds = %60, %56
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #4
  call void @_ZN2miC2Ex(ptr noundef nonnull align 4 dereferenceable(4) %17, i64 noundef 1)
  %98 = load i32, ptr %4, align 4, !tbaa !5
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds [262144 x %struct.mi], ptr @lazy, i64 0, i64 %99
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %100, ptr align 4 %17, i64 4, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #4
  br label %101

101:                                              ; preds = %97, %24
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt5arrayI2miLm11EEixEm(ptr noundef nonnull align 4 dereferenceable(44), i64 noundef) #1 align 2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTS2mi", !6, i64 0}
!11 = !{i64 0, i64 4, !5}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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

%"struct.std::array" = type { [11 x %struct.mi] }
%struct.mi = type { i32 }

@K = external dso_local local_unnamed_addr global i32, align 4
@seg = external dso_local global [262144 x %"struct.std::array"], align 16
@lazy = external dso_local local_unnamed_addr global [262144 x %struct.mi], align 16

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN2miC2Ex(ptr noundef nonnull align 4 dereferenceable(4), i64 noundef) unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local i32 @_Zml2miS_(i32, i32) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z4pushiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #2 {
  %4 = alloca %struct.mi, align 4
  %5 = sext i32 %0 to i64
  %6 = getelementptr inbounds [262144 x %struct.mi], ptr @lazy, i64 0, i64 %5
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = icmp eq i32 %7, 1
  br i1 %8, label %28, label %.preheader

.preheader:                                       ; preds = %3
  %9 = load i32, ptr @K, align 4, !tbaa !10
  %.not26 = icmp slt i32 %9, 0
  br i1 %.not26, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %10 = getelementptr inbounds [262144 x %"struct.std::array"], ptr @seg, i64 0, i64 %5
  br label %11

._crit_edge:                                      ; preds = %11, %.preheader
  %.not25 = icmp eq i32 %1, %2
  br i1 %.not25, label %26, label %17

11:                                               ; preds = %.lr.ph, %11
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %11 ]
  %12 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt5arrayI2miLm11EEixEm(ptr noundef nonnull align 4 dereferenceable(44) %10, i64 noundef %indvars.iv) #3
  %.sroa.07.0.copyload = load i32, ptr %12, align 4, !tbaa !10
  %.sroa.06.0.copyload = load i32, ptr %6, align 4, !tbaa !10
  %13 = tail call i32 @_Zml2miS_(i32 %.sroa.07.0.copyload, i32 %.sroa.06.0.copyload)
  %14 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt5arrayI2miLm11EEixEm(ptr noundef nonnull align 4 dereferenceable(44) %10, i64 noundef %indvars.iv) #3
  store i32 %13, ptr %14, align 4, !tbaa !10
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %15 = load i32, ptr @K, align 4, !tbaa !10
  %16 = sext i32 %15 to i64
  %.not.not = icmp slt i64 %indvars.iv, %16
  br i1 %.not.not, label %11, label %._crit_edge, !llvm.loop !11

17:                                               ; preds = %._crit_edge
  %18 = shl nsw i32 %0, 1
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [262144 x %struct.mi], ptr @lazy, i64 0, i64 %19
  %.sroa.04.0.copyload = load i32, ptr %20, align 8, !tbaa !10
  %.sroa.03.0.copyload = load i32, ptr %6, align 4, !tbaa !10
  %21 = tail call i32 @_Zml2miS_(i32 %.sroa.04.0.copyload, i32 %.sroa.03.0.copyload)
  store i32 %21, ptr %20, align 8, !tbaa !10
  %22 = or disjoint i32 %18, 1
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [262144 x %struct.mi], ptr @lazy, i64 0, i64 %23
  %.sroa.01.0.copyload = load i32, ptr %24, align 4, !tbaa !10
  %.sroa.0.0.copyload = load i32, ptr %6, align 4, !tbaa !10
  %25 = tail call i32 @_Zml2miS_(i32 %.sroa.01.0.copyload, i32 %.sroa.0.0.copyload)
  store i32 %25, ptr %24, align 4, !tbaa !10
  br label %26

26:                                               ; preds = %17, %._crit_edge
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  call void @_ZN2miC2Ex(ptr noundef nonnull align 4 dereferenceable(4) %4, i64 noundef 1)
  %27 = load i32, ptr %4, align 4, !tbaa !10
  store i32 %27, ptr %6, align 4, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  br label %28

28:                                               ; preds = %3, %26
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt5arrayI2miLm11EEixEm(ptr noundef nonnull align 4 dereferenceable(44), i64 noundef) local_unnamed_addr #1 align 2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #3 = { 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, !7, i64 0}
!6 = !{!"_ZTS2mi", !7, i64 0}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!7, !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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