; LLVM IR from bqi343/cp-notebook :: Contests/USACO Solutions/2015-16/Feb 2016/Plat/cbarn_dc.ll (Z4filliiiii)

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

@inf = external dso_local global i64, align 8
@dp = external dso_local global [1000 x [8 x i64]], align 16

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z4filliiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #1 {
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store i32 %0, ptr %6, align 4, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !5
  store i32 %4, ptr %10, align 4, !tbaa !5
  %15 = load i32, ptr %6, align 4, !tbaa !5
  %16 = load i32, ptr %7, align 4, !tbaa !5
  %17 = icmp sgt i32 %15, %16
  br i1 %17, label %18, label %19

18:                                               ; preds = %5
  br label %100

19:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %20 = load i32, ptr %6, align 4, !tbaa !5
  %21 = load i32, ptr %7, align 4, !tbaa !5
  %22 = add nsw i32 %20, %21
  %23 = sdiv i32 %22, 2
  store i32 %23, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 0, ptr %12, align 4, !tbaa !5
  %24 = load i64, ptr @inf, align 8, !tbaa !9
  %25 = load i32, ptr %11, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [1000 x [8 x i64]], ptr @dp, i64 0, i64 %26
  %28 = load i32, ptr %10, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [8 x i64], ptr %27, i64 0, i64 %29
  store i64 %24, ptr %30, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %31 = load i32, ptr %8, align 4, !tbaa !5
  store i32 %31, ptr %13, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %84, %19
  %33 = load i32, ptr %13, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %34 = load i32, ptr %9, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %14, align 4, !tbaa !5
  %36 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %11, ptr noundef nonnull align 4 dereferenceable(4) %14)
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = icmp slt i32 %33, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  br i1 %38, label %40, label %39

39:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  br label %87

40:                                               ; preds = %32
  %41 = load i32, ptr %13, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [1000 x [8 x i64]], ptr @dp, i64 0, i64 %42
  %44 = load i32, ptr %10, align 4, !tbaa !5
  %45 = sub nsw i32 %44, 1
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [8 x i64], ptr %43, i64 0, i64 %46
  %48 = load i64, ptr %47, align 8, !tbaa !9
  %49 = load i32, ptr %13, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  %51 = load i32, ptr %11, align 4, !tbaa !5
  %52 = call noundef i64 @_Z3getii(i32 noundef %50, i32 noundef %51)
  %53 = add nsw i64 %48, %52
  %54 = load i32, ptr %11, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [1000 x [8 x i64]], ptr @dp, i64 0, i64 %55
  %57 = load i32, ptr %10, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [8 x i64], ptr %56, i64 0, i64 %58
  %60 = load i64, ptr %59, align 8, !tbaa !9
  %61 = icmp slt i64 %53, %60
  br i1 %61, label %62, label %83

62:                                               ; preds = %40
  %63 = load i32, ptr %13, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [1000 x [8 x i64]], ptr @dp, i64 0, i64 %64
  %66 = load i32, ptr %10, align 4, !tbaa !5
  %67 = sub nsw i32 %66, 1
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [8 x i64], ptr %65, i64 0, i64 %68
  %70 = load i64, ptr %69, align 8, !tbaa !9
  %71 = load i32, ptr %13, align 4, !tbaa !5
  %72 = add nsw i32 %71, 1
  %73 = load i32, ptr %11, align 4, !tbaa !5
  %74 = call noundef i64 @_Z3getii(i32 noundef %72, i32 noundef %73)
  %75 = add nsw i64 %70, %74
  %76 = load i32, ptr %11, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [1000 x [8 x i64]], ptr @dp, i64 0, i64 %77
  %79 = load i32, ptr %10, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [8 x i64], ptr %78, i64 0, i64 %80
  store i64 %75, ptr %81, align 8, !tbaa !9
  %82 = load i32, ptr %13, align 4, !tbaa !5
  store i32 %82, ptr %12, align 4, !tbaa !5
  br label %83

83:                                               ; preds = %62, %40
  br label %84

84:                                               ; preds = %83
  %85 = load i32, ptr %13, align 4, !tbaa !5
  %86 = add nsw i32 %85, 1
  store i32 %86, ptr %13, align 4, !tbaa !5
  br label %32, !llvm.loop !11

87:                                               ; preds = %39
  %88 = load i32, ptr %6, align 4, !tbaa !5
  %89 = load i32, ptr %11, align 4, !tbaa !5
  %90 = sub nsw i32 %89, 1
  %91 = load i32, ptr %8, align 4, !tbaa !5
  %92 = load i32, ptr %12, align 4, !tbaa !5
  %93 = load i32, ptr %10, align 4, !tbaa !5
  call void @_Z4filliiiii(i32 noundef %88, i32 noundef %90, i32 noundef %91, i32 noundef %92, i32 noundef %93)
  %94 = load i32, ptr %11, align 4, !tbaa !5
  %95 = add nsw i32 %94, 1
  %96 = load i32, ptr %7, align 4, !tbaa !5
  %97 = load i32, ptr %12, align 4, !tbaa !5
  %98 = load i32, ptr %9, align 4, !tbaa !5
  %99 = load i32, ptr %10, align 4, !tbaa !5
  call void @_Z4filliiiii(i32 noundef %95, i32 noundef %96, i32 noundef %97, i32 noundef %98, i32 noundef %99)
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %100

100:                                              ; preds = %87, %18
  ret void
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #3

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

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 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint 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 #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, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

@inf = external dso_local local_unnamed_addr global i64, align 8
@dp = external dso_local local_unnamed_addr global [1000 x [8 x i64]], align 16

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z4filliiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = icmp sgt i32 %0, %1
  br i1 %8, label %52, label %9

9:                                                ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #3
  %10 = add nsw i32 %1, %0
  %11 = sdiv i32 %10, 2
  store i32 %11, ptr %6, align 4, !tbaa !5
  %12 = load i64, ptr @inf, align 8, !tbaa !9
  %13 = sext i32 %11 to i64
  %14 = sext i32 %4 to i64
  %15 = getelementptr inbounds [1000 x [8 x i64]], ptr @dp, i64 0, i64 %13, i64 %14
  store i64 %12, ptr %15, align 8, !tbaa !9
  %16 = add nsw i32 %3, 1
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #3
  store i32 %16, ptr %7, align 4, !tbaa !5
  %17 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %6, ptr noundef nonnull align 4 dereferenceable(4) %7)
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = icmp sgt i32 %18, %2
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #3
  br i1 %19, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %9
  %20 = add nsw i32 %4, -1
  %21 = sext i32 %20 to i64
  %22 = sext i32 %2 to i64
  br label %27

._crit_edge:                                      ; preds = %47, %9
  %.026.lcssa = phi i32 [ 0, %9 ], [ %.1, %47 ]
  %23 = load i32, ptr %6, align 4, !tbaa !5
  %24 = add nsw i32 %23, -1
  call void @_Z4filliiiii(i32 noundef %0, i32 noundef %24, i32 noundef %2, i32 noundef %.026.lcssa, i32 noundef %4)
  %25 = load i32, ptr %6, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  call void @_Z4filliiiii(i32 noundef %26, i32 noundef %1, i32 noundef %.026.lcssa, i32 noundef %3, i32 noundef %4)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #3
  br label %52

27:                                               ; preds = %.lr.ph, %47
  %indvars.iv = phi i64 [ %22, %.lr.ph ], [ %indvars.iv.next, %47 ]
  %.02629 = phi i32 [ 0, %.lr.ph ], [ %.1, %47 ]
  %28 = getelementptr inbounds [1000 x [8 x i64]], ptr @dp, i64 0, i64 %indvars.iv, i64 %21
  %29 = load i64, ptr %28, align 8, !tbaa !9
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %30 = load i32, ptr %6, align 4, !tbaa !5
  %31 = trunc nsw i64 %indvars.iv.next to i32
  %32 = call noundef i64 @_Z3getii(i32 noundef %31, i32 noundef %30)
  %33 = add nsw i64 %32, %29
  %34 = load i32, ptr %6, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [1000 x [8 x i64]], ptr @dp, i64 0, i64 %35, i64 %14
  %37 = load i64, ptr %36, align 8, !tbaa !9
  %38 = icmp slt i64 %33, %37
  br i1 %38, label %39, label %47

39:                                               ; preds = %27
  %40 = load i64, ptr %28, align 8, !tbaa !9
  %41 = call noundef i64 @_Z3getii(i32 noundef %31, i32 noundef %34)
  %42 = add nsw i64 %41, %40
  %43 = load i32, ptr %6, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [1000 x [8 x i64]], ptr @dp, i64 0, i64 %44, i64 %14
  store i64 %42, ptr %45, align 8, !tbaa !9
  %46 = trunc nsw i64 %indvars.iv to i32
  br label %47

47:                                               ; preds = %27, %39
  %.1 = phi i32 [ %46, %39 ], [ %.02629, %27 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #3
  store i32 %16, ptr %7, align 4, !tbaa !5
  %48 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %6, ptr noundef nonnull align 4 dereferenceable(4) %7)
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = icmp slt i64 %indvars.iv.next, %50
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #3
  br i1 %51, label %27, label %._crit_edge, !llvm.loop !11

52:                                               ; preds = %5, %._crit_edge
  ret void
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2

; Function Attrs: mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 #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"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass