; LLVM IR from ahr9n/psolving-paradigms :: 4.dynamic-programming/20.building-up/CodeForces 864E - Fire.ll (Z2dpii)

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

@n = external dso_local global i32, align 4
@mem = external dso_local global [105 x [2100 x i32]], align 16
@a = external dso_local global %"class.std::vector", align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z2dpii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = load i32, ptr @n, align 4, !tbaa !5
  %11 = icmp eq i32 %9, %10
  br i1 %11, label %12, label %13

12:                                               ; preds = %2
  store i32 0, ptr %3, align 4
  br label %77

13:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [105 x [2100 x i32]], ptr @mem, i64 0, i64 %15
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [2100 x i32], ptr %16, i64 0, i64 %18
  store ptr %19, ptr %6, align 8, !tbaa !9
  %20 = load ptr, ptr %6, align 8, !tbaa !9
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = xor i32 %21, -1
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %27

24:                                               ; preds = %13
  %25 = load ptr, ptr %6, align 8, !tbaa !9
  %26 = load i32, ptr %25, align 4, !tbaa !5
  store i32 %26, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %76

27:                                               ; preds = %13
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = call noundef i32 @_Z2dpii(i32 noundef %29, i32 noundef %30)
  %32 = load ptr, ptr %6, align 8, !tbaa !9
  store i32 %31, ptr %32, align 4, !tbaa !5
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = call noundef nonnull align 4 dereferenceable(16) ptr @_ZNSt6vectorISt4pairIS0_IiiES1_ESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @a, i64 noundef %34) #4
  %36 = getelementptr inbounds %"struct.std::pair", ptr %35, i32 0, i32 0
  %37 = getelementptr inbounds %"struct.std::pair.0", ptr %36, i32 0, i32 1
  %38 = load i32, ptr %37, align 4, !tbaa !11
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = add nsw i32 %38, %39
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = call noundef nonnull align 4 dereferenceable(16) ptr @_ZNSt6vectorISt4pairIS0_IiiES1_ESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @a, i64 noundef %42) #4
  %44 = getelementptr inbounds %"struct.std::pair", ptr %43, i32 0, i32 0
  %45 = getelementptr inbounds %"struct.std::pair.0", ptr %44, i32 0, i32 0
  %46 = load i32, ptr %45, align 4, !tbaa !14
  %47 = icmp sge i32 %40, %46
  br i1 %47, label %48, label %51

48:                                               ; preds = %27
  %49 = load ptr, ptr %6, align 8, !tbaa !9
  %50 = load i32, ptr %49, align 4, !tbaa !5
  store i32 %50, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %76

51:                                               ; preds = %27
  %52 = load ptr, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %53 = load i32, ptr %4, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = call noundef nonnull align 4 dereferenceable(16) ptr @_ZNSt6vectorISt4pairIS0_IiiES1_ESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @a, i64 noundef %54) #4
  %56 = getelementptr inbounds %"struct.std::pair", ptr %55, i32 0, i32 1
  %57 = getelementptr inbounds %"struct.std::pair.0", ptr %56, i32 0, i32 0
  %58 = load i32, ptr %57, align 4, !tbaa !15
  %59 = load i32, ptr %4, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  %61 = load i32, ptr %5, align 4, !tbaa !5
  %62 = load i32, ptr %4, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = call noundef nonnull align 4 dereferenceable(16) ptr @_ZNSt6vectorISt4pairIS0_IiiES1_ESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @a, i64 noundef %63) #4
  %65 = getelementptr inbounds %"struct.std::pair", ptr %64, i32 0, i32 0
  %66 = getelementptr inbounds %"struct.std::pair.0", ptr %65, i32 0, i32 1
  %67 = load i32, ptr %66, align 4, !tbaa !11
  %68 = add nsw i32 %61, %67
  %69 = call noundef i32 @_Z2dpii(i32 noundef %60, i32 noundef %68)
  %70 = add nsw i32 %58, %69
  store i32 %70, ptr %8, align 4, !tbaa !5
  %71 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %52, ptr noundef nonnull align 4 dereferenceable(4) %8)
  %72 = load i32, ptr %71, align 4, !tbaa !5
  %73 = load ptr, ptr %6, align 8, !tbaa !9
  store i32 %72, ptr %73, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %74 = load ptr, ptr %6, align 8, !tbaa !9
  %75 = load i32, ptr %74, align 4, !tbaa !5
  store i32 %75, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %76

76:                                               ; preds = %51, %48, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %77

77:                                               ; preds = %76, %12
  %78 = load i32, ptr %3, align 4
  ret i32 %78
}

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_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) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = { 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 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 4}
!12 = !{!"_ZTSSt4pairIS_IiiES0_E", !13, i64 0, !13, i64 8}
!13 = !{!"_ZTSSt4pairIiiE", !6, i64 0, !6, i64 4}
!14 = !{!12, !6, i64 0}
!15 = !{!12, !6, i64 8}


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

@n = external dso_local local_unnamed_addr global i32, align 4
@mem = external dso_local global [105 x [2100 x i32]], align 16
@a = external dso_local global %"class.std::vector", align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z2dpii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca i32, align 4
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %5 = icmp eq i32 %4, %0
  br i1 %5, label %common.ret21, label %6

6:                                                ; preds = %2
  %7 = sext i32 %0 to i64
  %8 = sext i32 %1 to i64
  %9 = getelementptr inbounds [105 x [2100 x i32]], ptr @mem, i64 0, i64 %7, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %.not = icmp eq i32 %10, -1
  br i1 %.not, label %11, label %common.ret21

11:                                               ; preds = %6
  %12 = add nsw i32 %0, 1
  %13 = tail call noundef i32 @_Z2dpii(i32 noundef %12, i32 noundef %1)
  store i32 %13, ptr %9, align 4, !tbaa !5
  %14 = tail call noundef nonnull align 4 dereferenceable(16) ptr @_ZNSt6vectorISt4pairIS0_IiiES1_ESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @a, i64 noundef %7) #3
  %15 = getelementptr inbounds i8, ptr %14, i64 4
  %16 = load i32, ptr %15, align 4, !tbaa !9
  %17 = add nsw i32 %16, %1
  %18 = tail call noundef nonnull align 4 dereferenceable(16) ptr @_ZNSt6vectorISt4pairIS0_IiiES1_ESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @a, i64 noundef %7) #3
  %19 = load i32, ptr %18, align 4, !tbaa !12
  %.not20 = icmp slt i32 %17, %19
  br i1 %.not20, label %22, label %20

20:                                               ; preds = %11
  %21 = load i32, ptr %9, align 4, !tbaa !5
  br label %common.ret21

common.ret21:                                     ; preds = %20, %6, %2, %22
  %common.ret21.op = phi i32 [ %33, %22 ], [ 0, %2 ], [ %21, %20 ], [ %10, %6 ]
  ret i32 %common.ret21.op

22:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  %23 = tail call noundef nonnull align 4 dereferenceable(16) ptr @_ZNSt6vectorISt4pairIS0_IiiES1_ESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @a, i64 noundef %7) #3
  %24 = getelementptr inbounds i8, ptr %23, i64 8
  %25 = load i32, ptr %24, align 4, !tbaa !13
  %26 = tail call noundef nonnull align 4 dereferenceable(16) ptr @_ZNSt6vectorISt4pairIS0_IiiES1_ESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @a, i64 noundef %7) #3
  %27 = getelementptr inbounds i8, ptr %26, i64 4
  %28 = load i32, ptr %27, align 4, !tbaa !9
  %29 = add nsw i32 %28, %1
  %30 = tail call noundef i32 @_Z2dpii(i32 noundef %12, i32 noundef %29)
  %31 = add nsw i32 %30, %25
  store i32 %31, ptr %3, align 4, !tbaa !5
  %32 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %9, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %33 = load i32, ptr %32, align 4, !tbaa !5
  store i32 %33, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  br label %common.ret21
}

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_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, !6, i64 4}
!10 = !{!"_ZTSSt4pairIS_IiiES0_E", !11, i64 0, !11, i64 8}
!11 = !{!"_ZTSSt4pairIiiE", !6, i64 0, !6, i64 4}
!12 = !{!10, !6, i64 0}
!13 = !{!10, !6, i64 8}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass