; LLVM IR from bqi343/cp-notebook :: Contests/USACO Solutions/2016-17/Dec 2016/Plat/roboherd_slow.ll (Z5inputv)

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

@N = external dso_local global i64, align 8
@K = external dso_local global i64, align 8
@sum = external dso_local global i64, align 8
@mx = external dso_local global i64, align 8
@model = external dso_local global [100000 x [10 x i64]], align 16
@M = external dso_local global [100000 x i64], align 16
@_ZSt3cin = external global %"class.std::basic_istream", align 8

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

8:                                                ; preds = %98, %0
  %9 = load i32, ptr %1, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = load i64, ptr @N, align 8, !tbaa !9
  %12 = icmp slt i64 %10, %11
  br i1 %12, label %14, label %13

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

14:                                               ; preds = %8
  %15 = load i32, ptr %1, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [100000 x i64], ptr @M, i64 0, i64 %16
  %18 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %17)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %36, %14
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = load i32, ptr %1, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [100000 x i64], ptr @M, i64 0, i64 %23
  %25 = load i64, ptr %24, align 8, !tbaa !9
  %26 = icmp slt i64 %21, %25
  br i1 %26, label %28, label %27

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

28:                                               ; preds = %19
  %29 = load i32, ptr %1, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [100000 x [10 x i64]], ptr @model, i64 0, i64 %30
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [10 x i64], ptr %31, i64 0, i64 %33
  %35 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %34)
  br label %36

36:                                               ; preds = %28
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %3, align 4, !tbaa !5
  br label %19, !llvm.loop !11

39:                                               ; preds = %27
  %40 = load i32, ptr %1, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [100000 x [10 x i64]], ptr @model, i64 0, i64 %41
  %43 = getelementptr inbounds [10 x i64], ptr %42, i64 0, i64 0
  %44 = load i32, ptr %1, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [100000 x [10 x i64]], ptr @model, i64 0, i64 %45
  %47 = getelementptr inbounds [10 x i64], ptr %46, i64 0, i64 0
  %48 = load i32, ptr %1, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [100000 x i64], ptr @M, i64 0, i64 %49
  %51 = load i64, ptr %50, align 8, !tbaa !9
  %52 = getelementptr inbounds i64, ptr %47, i64 %51
  call void @_ZSt4sortIPxEvT_S1_(ptr noundef %43, ptr noundef %52)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %53 = load i32, ptr %1, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [100000 x [10 x i64]], ptr @model, i64 0, i64 %54
  %56 = getelementptr inbounds [10 x i64], ptr %55, i64 0, i64 0
  %57 = load i64, ptr %56, align 16, !tbaa !9
  store i64 %57, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %58

58:                                               ; preds = %77, %39
  %59 = load i32, ptr %5, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = load i32, ptr %1, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [100000 x i64], ptr @M, i64 0, i64 %62
  %64 = load i64, ptr %63, align 8, !tbaa !9
  %65 = icmp slt i64 %60, %64
  br i1 %65, label %67, label %66

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

67:                                               ; preds = %58
  %68 = load i64, ptr %4, align 8, !tbaa !9
  %69 = load i32, ptr %1, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [100000 x [10 x i64]], ptr @model, i64 0, i64 %70
  %72 = load i32, ptr %5, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [10 x i64], ptr %71, i64 0, i64 %73
  %75 = load i64, ptr %74, align 8, !tbaa !9
  %76 = sub nsw i64 %75, %68
  store i64 %76, ptr %74, align 8, !tbaa !9
  br label %77

77:                                               ; preds = %67
  %78 = load i32, ptr %5, align 4, !tbaa !5
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %5, align 4, !tbaa !5
  br label %58, !llvm.loop !13

80:                                               ; preds = %66
  %81 = load i64, ptr @K, align 8, !tbaa !9
  %82 = load i64, ptr %4, align 8, !tbaa !9
  %83 = mul nsw i64 %81, %82
  %84 = load i64, ptr @sum, align 8, !tbaa !9
  %85 = add nsw i64 %84, %83
  store i64 %85, ptr @sum, align 8, !tbaa !9
  %86 = load i32, ptr %1, align 4, !tbaa !5
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [100000 x [10 x i64]], ptr @model, i64 0, i64 %87
  %89 = load i32, ptr %1, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [100000 x i64], ptr @M, i64 0, i64 %90
  %92 = load i64, ptr %91, align 8, !tbaa !9
  %93 = sub nsw i64 %92, 1
  %94 = getelementptr inbounds [10 x i64], ptr %88, i64 0, i64 %93
  %95 = load i64, ptr %94, align 8, !tbaa !9
  %96 = load i64, ptr @mx, align 8, !tbaa !9
  %97 = add nsw i64 %96, %95
  store i64 %97, ptr @mx, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %98

98:                                               ; preds = %80
  %99 = load i32, ptr %1, align 4, !tbaa !5
  %100 = add nsw i32 %99, 1
  store i32 %100, ptr %1, align 4, !tbaa !5
  br label %8, !llvm.loop !14

101:                                              ; preds = %13
  ret void
}

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

; 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: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPxEvT_S1_(ptr noundef, ptr noundef) #2

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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, !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 long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !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 }

@N = external dso_local global i64, align 8
@K = external dso_local global i64, align 8
@sum = external dso_local local_unnamed_addr global i64, align 8
@mx = external dso_local local_unnamed_addr global i64, align 8
@model = external dso_local global [100000 x [10 x i64]], align 16
@M = external dso_local global [100000 x i64], align 16
@_ZSt3cin = external global %"class.std::basic_istream", align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5inputv() local_unnamed_addr #0 {
  %1 = 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) @N)
  %2 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %1, ptr noundef nonnull align 8 dereferenceable(8) @K)
  %3 = load i64, ptr @N, align 8, !tbaa !5
  %4 = icmp sgt i64 %3, 0
  br i1 %4, label %.lr.ph36, label %._crit_edge37

._crit_edge37:                                    ; preds = %._crit_edge32, %0
  ret void

.lr.ph36:                                         ; preds = %0, %._crit_edge32
  %indvars.iv43 = phi i64 [ %indvars.iv.next44, %._crit_edge32 ], [ 0, %0 ]
  %5 = getelementptr inbounds [100000 x i64], ptr @M, i64 0, i64 %indvars.iv43
  %6 = 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) %5)
  %7 = load i64, ptr %5, align 8, !tbaa !5
  %8 = icmp sgt i64 %7, 0
  br i1 %8, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph36
  %.lcssa = phi i64 [ %7, %.lr.ph36 ], [ %21, %.lr.ph ]
  %9 = getelementptr inbounds [100000 x [10 x i64]], ptr @model, i64 0, i64 %indvars.iv43
  %10 = getelementptr inbounds i64, ptr %9, i64 %.lcssa
  tail call void @_ZSt4sortIPxEvT_S1_(ptr noundef nonnull %9, ptr noundef nonnull %10)
  %11 = load i64, ptr %9, align 16, !tbaa !5
  %12 = load i64, ptr %5, align 8, !tbaa !5
  %13 = icmp sgt i64 %12, 0
  br i1 %13, label %.lr.ph31.preheader, label %._crit_edge32

.lr.ph31.preheader:                               ; preds = %._crit_edge
  %min.iters.check = icmp ult i64 %12, 4
  br i1 %min.iters.check, label %.lr.ph31.preheader49, label %vector.ph

.lr.ph31.preheader49:                             ; preds = %middle.block, %.lr.ph31.preheader
  %indvars.iv40.ph = phi i64 [ 0, %.lr.ph31.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph31

vector.ph:                                        ; preds = %.lr.ph31.preheader
  %n.vec = and i64 %12, 9223372036854775804
  %broadcast.splatinsert = insertelement <2 x i64> poison, i64 %11, i64 0
  %broadcast.splat = shufflevector <2 x i64> %broadcast.splatinsert, <2 x i64> poison, <2 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %14 = getelementptr inbounds [100000 x [10 x i64]], ptr @model, i64 0, i64 %indvars.iv43, i64 %index
  %15 = getelementptr inbounds i8, ptr %14, i64 16
  %wide.load = load <2 x i64>, ptr %14, align 16, !tbaa !5
  %wide.load48 = load <2 x i64>, ptr %15, align 16, !tbaa !5
  %16 = sub nsw <2 x i64> %wide.load, %broadcast.splat
  %17 = sub nsw <2 x i64> %wide.load48, %broadcast.splat
  store <2 x i64> %16, ptr %14, align 16, !tbaa !5
  store <2 x i64> %17, ptr %15, align 16, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %18 = icmp eq i64 %index.next, %n.vec
  br i1 %18, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %12, %n.vec
  br i1 %cmp.n, label %._crit_edge32, label %.lr.ph31.preheader49

.lr.ph:                                           ; preds = %.lr.ph36, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.lr.ph36 ]
  %19 = getelementptr inbounds [100000 x [10 x i64]], ptr @model, i64 0, i64 %indvars.iv43, i64 %indvars.iv
  %20 = 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) %19)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %21 = load i64, ptr %5, align 8, !tbaa !5
  %22 = icmp sgt i64 %21, %indvars.iv.next
  br i1 %22, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge32:                                    ; preds = %.lr.ph31, %middle.block, %._crit_edge
  %23 = load i64, ptr @K, align 8, !tbaa !5
  %24 = mul nsw i64 %23, %11
  %25 = load i64, ptr @sum, align 8, !tbaa !5
  %26 = add nsw i64 %25, %24
  store i64 %26, ptr @sum, align 8, !tbaa !5
  %27 = add nsw i64 %12, -1
  %28 = getelementptr inbounds [100000 x [10 x i64]], ptr @model, i64 0, i64 %indvars.iv43, i64 %27
  %29 = load i64, ptr %28, align 8, !tbaa !5
  %30 = load i64, ptr @mx, align 8, !tbaa !5
  %31 = add nsw i64 %30, %29
  store i64 %31, ptr @mx, align 8, !tbaa !5
  %indvars.iv.next44 = add nuw nsw i64 %indvars.iv43, 1
  %32 = load i64, ptr @N, align 8, !tbaa !5
  %33 = icmp sgt i64 %32, %indvars.iv.next44
  br i1 %33, label %.lr.ph36, label %._crit_edge37, !llvm.loop !14

.lr.ph31:                                         ; preds = %.lr.ph31.preheader49, %.lr.ph31
  %indvars.iv40 = phi i64 [ %indvars.iv.next41, %.lr.ph31 ], [ %indvars.iv40.ph, %.lr.ph31.preheader49 ]
  %34 = getelementptr inbounds [100000 x [10 x i64]], ptr @model, i64 0, i64 %indvars.iv43, i64 %indvars.iv40
  %35 = load i64, ptr %34, align 8, !tbaa !5
  %36 = sub nsw i64 %35, %11
  store i64 %36, ptr %34, align 8, !tbaa !5
  %indvars.iv.next41 = add nuw nsw i64 %indvars.iv40, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next41, %12
  br i1 %exitcond.not, label %._crit_edge32, label %.lr.ph31, !llvm.loop !15
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPxEvT_S1_(ptr noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { 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 #1 = { 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" }

!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 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10, !12, !11}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,SROAPass,SimplifyCFGPass,TailCallElimPass