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

; 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::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@ans = external dso_local global i64, align 8
@n = external dso_local global i64, align 8
@k = external dso_local global i64, align 8
@dp = external dso_local global [1000 x [8 x i64]], align 16
@cow = external dso_local global %"class.std::vector", align 8
@cum = external dso_local global %"class.std::vector", align 8

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z4filliiiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #1

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsv() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #4
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %4

4:                                                ; preds = %32, %0
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = load i64, ptr @n, align 8, !tbaa !9
  %8 = icmp slt i64 %6, %7
  br i1 %8, label %10, label %9

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

10:                                               ; preds = %4
  %11 = load i32, ptr %1, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @cow, i64 noundef %12) #4
  %14 = load i64, ptr %13, align 8, !tbaa !9
  %15 = load i32, ptr %1, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @cum, i64 noundef %16) #4
  store i64 %14, ptr %17, align 8, !tbaa !9
  %18 = load i32, ptr %1, align 4, !tbaa !5
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %31

20:                                               ; preds = %10
  %21 = load i32, ptr %1, align 4, !tbaa !5
  %22 = sub nsw i32 %21, 1
  %23 = sext i32 %22 to i64
  %24 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @cum, i64 noundef %23) #4
  %25 = load i64, ptr %24, align 8, !tbaa !9
  %26 = load i32, ptr %1, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @cum, i64 noundef %27) #4
  %29 = load i64, ptr %28, align 8, !tbaa !9
  %30 = add nsw i64 %29, %25
  store i64 %30, ptr %28, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %20, %10
  br label %32

32:                                               ; preds = %31
  %33 = load i32, ptr %1, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %1, align 4, !tbaa !5
  br label %4, !llvm.loop !11

35:                                               ; preds = %9
  store i64 0, ptr getelementptr inbounds ([8 x i64], ptr @dp, i64 0, i64 1), align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %61, %35
  %37 = load i32, ptr %2, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = load i64, ptr @n, align 8, !tbaa !9
  %40 = icmp slt i64 %38, %39
  br i1 %40, label %42, label %41

41:                                               ; preds = %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %64

42:                                               ; preds = %36
  %43 = load i32, ptr %2, align 4, !tbaa !5
  %44 = sub nsw i32 %43, 1
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [1000 x [8 x i64]], ptr @dp, i64 0, i64 %45
  %47 = getelementptr inbounds [8 x i64], ptr %46, i64 0, i64 1
  %48 = load i64, ptr %47, align 8, !tbaa !9
  %49 = load i32, ptr %2, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = load i32, ptr %2, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @cow, i64 noundef %52) #4
  %54 = load i64, ptr %53, align 8, !tbaa !9
  %55 = mul nsw i64 %50, %54
  %56 = add nsw i64 %48, %55
  %57 = load i32, ptr %2, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [1000 x [8 x i64]], ptr @dp, i64 0, i64 %58
  %60 = getelementptr inbounds [8 x i64], ptr %59, i64 0, i64 1
  store i64 %56, ptr %60, align 8, !tbaa !9
  br label %61

61:                                               ; preds = %42
  %62 = load i32, ptr %2, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %2, align 4, !tbaa !5
  br label %36, !llvm.loop !13

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

65:                                               ; preds = %84, %64
  %66 = load i32, ptr %3, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = load i64, ptr @k, align 8, !tbaa !9
  %69 = add nsw i64 %68, 1
  %70 = icmp slt i64 %67, %69
  br i1 %70, label %72, label %71

71:                                               ; preds = %65
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %87

72:                                               ; preds = %65
  %73 = load i32, ptr %3, align 4, !tbaa !5
  %74 = sub nsw i32 %73, 1
  %75 = load i64, ptr @n, align 8, !tbaa !9
  %76 = sub nsw i64 %75, 1
  %77 = trunc i64 %76 to i32
  %78 = load i32, ptr %3, align 4, !tbaa !5
  %79 = sub nsw i32 %78, 2
  %80 = load i64, ptr @n, align 8, !tbaa !9
  %81 = sub nsw i64 %80, 2
  %82 = trunc i64 %81 to i32
  %83 = load i32, ptr %3, align 4, !tbaa !5
  call void @_Z4filliiiii(i32 noundef %74, i32 noundef %77, i32 noundef %79, i32 noundef %82, i32 noundef %83)
  br label %84

84:                                               ; preds = %72
  %85 = load i32, ptr %3, align 4, !tbaa !5
  %86 = add nsw i32 %85, 1
  store i32 %86, ptr %3, align 4, !tbaa !5
  br label %65, !llvm.loop !14

87:                                               ; preds = %71
  %88 = load i64, ptr @n, align 8, !tbaa !9
  %89 = sub nsw i64 %88, 1
  %90 = getelementptr inbounds [1000 x [8 x i64]], ptr @dp, i64 0, i64 %89
  %91 = load i64, ptr @k, align 8, !tbaa !9
  %92 = getelementptr inbounds [8 x i64], ptr %90, i64 0, i64 %91
  %93 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) @ans, ptr noundef nonnull align 8 dereferenceable(8) %92)
  %94 = load i64, ptr %93, align 8, !tbaa !9
  store i64 %94, ptr @ans, align 8, !tbaa !9
  ret void
}

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

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"}
!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::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl" = type { %"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" }
%"struct.std::_Vector_base<long long, std::allocator<long long>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@ans = external dso_local global i64, align 8
@n = external dso_local local_unnamed_addr global i64, align 8
@k = external dso_local local_unnamed_addr global i64, align 8
@dp = external dso_local global [1000 x [8 x i64]], align 16
@cow = external dso_local global %"class.std::vector", align 8
@cum = external dso_local global %"class.std::vector", align 8

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z4filliiiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsv() local_unnamed_addr #1 {
  %1 = load i64, ptr @n, align 8, !tbaa !5
  %2 = icmp sgt i64 %1, 0
  br i1 %2, label %3, label %._crit_edge.thread

3:                                                ; preds = %0
  %4 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @cow, i64 noundef 0) #3
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @cum, i64 noundef 0) #3
  store i64 %5, ptr %6, align 8, !tbaa !5
  %.pre = load i64, ptr @n, align 8, !tbaa !5
  %7 = icmp sgt i64 %.pre, 1
  br i1 %7, label %.lr.ph.peel.next, label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %0, %3
  %.ph = phi i64 [ %.pre, %3 ], [ %1, %0 ]
  store i64 0, ptr getelementptr inbounds (i8, ptr @dp, i64 8), align 8, !tbaa !5
  br label %.preheader

._crit_edge:                                      ; preds = %.lr.ph.peel.next
  store i64 0, ptr getelementptr inbounds (i8, ptr @dp, i64 8), align 8, !tbaa !5
  %8 = icmp sgt i64 %18, 1
  br i1 %8, label %.lr.ph26, label %.preheader

.lr.ph.peel.next:                                 ; preds = %3, %.lr.ph.peel.next
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph.peel.next ], [ 1, %3 ]
  %9 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @cow, i64 noundef %indvars.iv) #3
  %10 = load i64, ptr %9, align 8, !tbaa !5
  %11 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @cum, i64 noundef %indvars.iv) #3
  store i64 %10, ptr %11, align 8, !tbaa !5
  %12 = add nsw i64 %indvars.iv, -1
  %13 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @cum, i64 noundef %12) #3
  %14 = load i64, ptr %13, align 8, !tbaa !5
  %15 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @cum, i64 noundef %indvars.iv) #3
  %16 = load i64, ptr %15, align 8, !tbaa !5
  %17 = add nsw i64 %16, %14
  store i64 %17, ptr %15, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %18 = load i64, ptr @n, align 8, !tbaa !5
  %19 = icmp sgt i64 %18, %indvars.iv.next
  br i1 %19, label %.lr.ph.peel.next, label %._crit_edge, !llvm.loop !9

.preheader:                                       ; preds = %.lr.ph26, %._crit_edge.thread, %._crit_edge
  %20 = phi i64 [ %18, %._crit_edge ], [ %.ph, %._crit_edge.thread ], [ %28, %.lr.ph26 ]
  %21 = load i64, ptr @k, align 8, !tbaa !5
  %.not27 = icmp slt i64 %21, 2
  br i1 %.not27, label %._crit_edge30, label %.lr.ph29

.lr.ph26:                                         ; preds = %._crit_edge, %.lr.ph26
  %22 = phi i64 [ %26, %.lr.ph26 ], [ 0, %._crit_edge ]
  %indvars.iv34 = phi i64 [ %indvars.iv.next35, %.lr.ph26 ], [ 1, %._crit_edge ]
  %23 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIxSaIxEEixEm(ptr noundef nonnull align 8 dereferenceable(24) @cow, i64 noundef %indvars.iv34) #3
  %24 = load i64, ptr %23, align 8, !tbaa !5
  %25 = mul nsw i64 %24, %indvars.iv34
  %26 = add nsw i64 %25, %22
  %27 = getelementptr inbounds [1000 x [8 x i64]], ptr @dp, i64 0, i64 %indvars.iv34, i64 1
  store i64 %26, ptr %27, align 8, !tbaa !5
  %indvars.iv.next35 = add nuw nsw i64 %indvars.iv34, 1
  %28 = load i64, ptr @n, align 8, !tbaa !5
  %29 = icmp sgt i64 %28, %indvars.iv.next35
  br i1 %29, label %.lr.ph26, label %.preheader, !llvm.loop !12

._crit_edge30.loopexit:                           ; preds = %.lr.ph29
  %.pre40 = load i64, ptr @n, align 8, !tbaa !5
  br label %._crit_edge30

._crit_edge30:                                    ; preds = %._crit_edge30.loopexit, %.preheader
  %30 = phi i64 [ %20, %.preheader ], [ %.pre40, %._crit_edge30.loopexit ]
  %.lcssa = phi i64 [ %21, %.preheader ], [ %41, %._crit_edge30.loopexit ]
  %31 = add nsw i64 %30, -1
  %32 = getelementptr inbounds [1000 x [8 x i64]], ptr @dp, i64 0, i64 %31, i64 %.lcssa
  %33 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) @ans, ptr noundef nonnull align 8 dereferenceable(8) %32)
  %34 = load i64, ptr %33, align 8, !tbaa !5
  store i64 %34, ptr @ans, align 8, !tbaa !5
  ret void

.lr.ph29:                                         ; preds = %.preheader, %.lr.ph29
  %indvars.iv37 = phi i64 [ %indvars.iv.next38, %.lr.ph29 ], [ 2, %.preheader ]
  %indvars39 = trunc i64 %indvars.iv37 to i32
  %35 = add nsw i32 %indvars39, -1
  %36 = load i64, ptr @n, align 8, !tbaa !5
  %37 = trunc i64 %36 to i32
  %38 = add i32 %37, -1
  %39 = add nsw i32 %indvars39, -2
  %40 = add i32 %37, -2
  tail call void @_Z4filliiiii(i32 noundef %35, i32 noundef %38, i32 noundef %39, i32 noundef %40, i32 noundef %indvars39)
  %indvars.iv.next38 = add nuw nsw i64 %indvars.iv37, 1
  %41 = load i64, ptr @k, align 8, !tbaa !5
  %.not.not = icmp sgt i64 %41, %indvars.iv37
  br i1 %.not.not, label %.lr.ph29, label %._crit_edge30.loopexit, !llvm.loop !13
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #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 = { 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10, !11}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.peeled.count", i32 1}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopFullUnrollPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass