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

; 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 }
%"class.std::vector.2" = type { %"struct.std::_Vector_base.3" }
%"struct.std::_Vector_base.3" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<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
@items = external dso_local global %"class.std::vector.2", align 8

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

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

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

8:                                                ; preds = %2
  br label %86

9:                                                ; preds = %2
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [105 x [2100 x i32]], ptr @mem, i64 0, i64 %11
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [2100 x i32], ptr %12, i64 0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = call noundef i32 @_Z2dpii(i32 noundef %18, i32 noundef %19)
  %21 = icmp eq i32 %16, %20
  br i1 %21, label %22, label %26

22:                                               ; preds = %9
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  %25 = load i32, ptr %4, align 4, !tbaa !5
  call void @_Z5buildii(i32 noundef %24, i32 noundef %25)
  br label %86

26:                                               ; preds = %9
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = call noundef nonnull align 4 dereferenceable(16) ptr @_ZNSt6vectorISt4pairIS0_IiiES1_ESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @a, i64 noundef %28) #2
  %30 = getelementptr inbounds %"struct.std::pair", ptr %29, i32 0, i32 0
  %31 = getelementptr inbounds %"struct.std::pair.0", ptr %30, i32 0, i32 1
  %32 = load i32, ptr %31, align 4, !tbaa !9
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = add nsw i32 %32, %33
  %35 = load i32, ptr %3, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = call noundef nonnull align 4 dereferenceable(16) ptr @_ZNSt6vectorISt4pairIS0_IiiES1_ESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @a, i64 noundef %36) #2
  %38 = getelementptr inbounds %"struct.std::pair", ptr %37, i32 0, i32 0
  %39 = getelementptr inbounds %"struct.std::pair.0", ptr %38, i32 0, i32 0
  %40 = load i32, ptr %39, align 4, !tbaa !12
  %41 = icmp slt i32 %34, %40
  br i1 %41, label %42, label %85

42:                                               ; preds = %26
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [105 x [2100 x i32]], ptr @mem, i64 0, i64 %44
  %46 = load i32, ptr %4, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [2100 x i32], ptr %45, i64 0, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = call noundef nonnull align 4 dereferenceable(16) ptr @_ZNSt6vectorISt4pairIS0_IiiES1_ESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @a, i64 noundef %51) #2
  %53 = getelementptr inbounds %"struct.std::pair", ptr %52, i32 0, i32 1
  %54 = getelementptr inbounds %"struct.std::pair.0", ptr %53, i32 0, i32 0
  %55 = load i32, ptr %54, align 4, !tbaa !13
  %56 = load i32, ptr %3, align 4, !tbaa !5
  %57 = add nsw i32 %56, 1
  %58 = load i32, ptr %4, align 4, !tbaa !5
  %59 = load i32, ptr %3, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = call noundef nonnull align 4 dereferenceable(16) ptr @_ZNSt6vectorISt4pairIS0_IiiES1_ESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @a, i64 noundef %60) #2
  %62 = getelementptr inbounds %"struct.std::pair", ptr %61, i32 0, i32 0
  %63 = getelementptr inbounds %"struct.std::pair.0", ptr %62, i32 0, i32 1
  %64 = load i32, ptr %63, align 4, !tbaa !9
  %65 = add nsw i32 %58, %64
  %66 = call noundef i32 @_Z2dpii(i32 noundef %57, i32 noundef %65)
  %67 = add nsw i32 %55, %66
  %68 = icmp eq i32 %49, %67
  br i1 %68, label %69, label %85

69:                                               ; preds = %42
  %70 = load i32, ptr %3, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = call noundef nonnull align 4 dereferenceable(16) ptr @_ZNSt6vectorISt4pairIS0_IiiES1_ESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @a, i64 noundef %71) #2
  %73 = getelementptr inbounds %"struct.std::pair", ptr %72, i32 0, i32 1
  %74 = getelementptr inbounds %"struct.std::pair.0", ptr %73, i32 0, i32 1
  call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) @items, ptr noundef nonnull align 4 dereferenceable(4) %74)
  %75 = load i32, ptr %3, align 4, !tbaa !5
  %76 = add nsw i32 %75, 1
  %77 = load i32, ptr %4, align 4, !tbaa !5
  %78 = load i32, ptr %3, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = call noundef nonnull align 4 dereferenceable(16) ptr @_ZNSt6vectorISt4pairIS0_IiiES1_ESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @a, i64 noundef %79) #2
  %81 = getelementptr inbounds %"struct.std::pair", ptr %80, i32 0, i32 0
  %82 = getelementptr inbounds %"struct.std::pair.0", ptr %81, i32 0, i32 1
  %83 = load i32, ptr %82, align 4, !tbaa !9
  %84 = add nsw i32 %77, %83
  call void @_Z5buildii(i32 noundef %76, i32 noundef %84)
  br label %85

85:                                               ; preds = %69, %42, %26
  br label %86

86:                                               ; preds = %85, %22, %8
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 4 dereferenceable(4)) #0 align 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 = { 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 = { 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}


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

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5buildii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  br label %tailrecurse.outer

tailrecurse.outer:                                ; preds = %34, %2
  %.tr.ph = phi i32 [ %11, %34 ], [ %0, %2 ]
  %.tr20.ph = phi i32 [ %40, %34 ], [ %1, %2 ]
  %3 = sext i32 %.tr20.ph to i64
  %4 = sext i32 %.tr.ph to i64
  br label %tailrecurse

tailrecurse:                                      ; preds = %tailrecurse.outer, %8
  %indvars.iv = phi i64 [ %4, %tailrecurse.outer ], [ %indvars.iv.next, %8 ]
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %6 = trunc nsw i64 %indvars.iv to i32
  %7 = icmp eq i32 %5, %6
  br i1 %7, label %.loopexit, label %8

8:                                                ; preds = %tailrecurse
  %9 = getelementptr inbounds [105 x [2100 x i32]], ptr @mem, i64 0, i64 %indvars.iv, i64 %3
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %11 = trunc nsw i64 %indvars.iv.next to i32
  %12 = tail call noundef i32 @_Z2dpii(i32 noundef %11, i32 noundef %.tr20.ph)
  %13 = icmp eq i32 %10, %12
  br i1 %13, label %tailrecurse, label %14

14:                                               ; preds = %8
  %15 = tail call noundef nonnull align 4 dereferenceable(16) ptr @_ZNSt6vectorISt4pairIS0_IiiES1_ESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @a, i64 noundef %indvars.iv) #2
  %16 = getelementptr inbounds i8, ptr %15, i64 4
  %17 = load i32, ptr %16, align 4, !tbaa !9
  %18 = add nsw i32 %17, %.tr20.ph
  %19 = tail call noundef nonnull align 4 dereferenceable(16) ptr @_ZNSt6vectorISt4pairIS0_IiiES1_ESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @a, i64 noundef %indvars.iv) #2
  %20 = load i32, ptr %19, align 4, !tbaa !12
  %21 = icmp slt i32 %18, %20
  br i1 %21, label %22, label %.loopexit

22:                                               ; preds = %14
  %23 = load i32, ptr %9, align 4, !tbaa !5
  %24 = tail call noundef nonnull align 4 dereferenceable(16) ptr @_ZNSt6vectorISt4pairIS0_IiiES1_ESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @a, i64 noundef %indvars.iv) #2
  %25 = getelementptr inbounds i8, ptr %24, i64 8
  %26 = load i32, ptr %25, align 4, !tbaa !13
  %27 = tail call noundef nonnull align 4 dereferenceable(16) ptr @_ZNSt6vectorISt4pairIS0_IiiES1_ESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @a, i64 noundef %indvars.iv) #2
  %28 = getelementptr inbounds i8, ptr %27, i64 4
  %29 = load i32, ptr %28, align 4, !tbaa !9
  %30 = add nsw i32 %29, %.tr20.ph
  %31 = tail call noundef i32 @_Z2dpii(i32 noundef %11, i32 noundef %30)
  %32 = add nsw i32 %31, %26
  %33 = icmp eq i32 %23, %32
  br i1 %33, label %34, label %.loopexit

34:                                               ; preds = %22
  %35 = tail call noundef nonnull align 4 dereferenceable(16) ptr @_ZNSt6vectorISt4pairIS0_IiiES1_ESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @a, i64 noundef %indvars.iv) #2
  %36 = getelementptr inbounds i8, ptr %35, i64 12
  tail call void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24) @items, ptr noundef nonnull align 4 dereferenceable(4) %36)
  %37 = tail call noundef nonnull align 4 dereferenceable(16) ptr @_ZNSt6vectorISt4pairIS0_IiiES1_ESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @a, i64 noundef %indvars.iv) #2
  %38 = getelementptr inbounds i8, ptr %37, i64 4
  %39 = load i32, ptr %38, align 4, !tbaa !9
  %40 = add nsw i32 %39, %.tr20.ph
  br label %tailrecurse.outer

.loopexit:                                        ; preds = %14, %22, %tailrecurse
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorIiSaIiEE9push_backERKi(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #0 align 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 = { 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 = { 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,GVNPass,GlobalOptPass,IndVarSimplifyPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass