; LLVM IR from Aryansh-S/USACO :: algo_ds/more-segtree/CSES/hotel_queries.ll (Z3ansii)

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

%struct.SEG = type { i32, i32, %"class.std::vector" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = 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 }

@second = external dso_local global %struct.SEG, align 8

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z3ansii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %6 = load i32, ptr %4, align 4, !tbaa !5
  %7 = load i32, ptr getelementptr inbounds (%struct.SEG, ptr @second, i32 0, i32 1), align 4, !tbaa !9
  %8 = icmp sge i32 %6, %7
  br i1 %8, label %9, label %13

9:                                                ; preds = %2
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = load i32, ptr getelementptr inbounds (%struct.SEG, ptr @second, i32 0, i32 1), align 4, !tbaa !9
  %12 = sub nsw i32 %10, %11
  store i32 %12, ptr %3, align 4
  br label %40

13:                                               ; preds = %2
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = call noundef i32 @_ZN3SEGIiE2lcEi(ptr noundef nonnull align 8 dereferenceable(32) @second, i32 noundef %14)
  %16 = sext i32 %15 to i64
  %17 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) getelementptr inbounds (%struct.SEG, ptr @second, i32 0, i32 2), i64 noundef %16) #3
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = load i32, ptr %5, align 4, !tbaa !5
  %20 = icmp sge i32 %18, %19
  br i1 %20, label %21, label %26

21:                                               ; preds = %13
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = call noundef i32 @_ZN3SEGIiE2lcEi(ptr noundef nonnull align 8 dereferenceable(32) @second, i32 noundef %22)
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = call noundef i32 @_Z3ansii(i32 noundef %23, i32 noundef %24)
  store i32 %25, ptr %3, align 4
  br label %40

26:                                               ; preds = %13
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = call noundef i32 @_ZN3SEGIiE2rcEi(ptr noundef nonnull align 8 dereferenceable(32) @second, i32 noundef %27)
  %29 = sext i32 %28 to i64
  %30 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) getelementptr inbounds (%struct.SEG, ptr @second, i32 0, i32 2), i64 noundef %29) #3
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = load i32, ptr %5, align 4, !tbaa !5
  %33 = icmp sge i32 %31, %32
  br i1 %33, label %34, label %39

34:                                               ; preds = %26
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = call noundef i32 @_ZN3SEGIiE2rcEi(ptr noundef nonnull align 8 dereferenceable(32) @second, i32 noundef %35)
  %37 = load i32, ptr %5, align 4, !tbaa !5
  %38 = call noundef i32 @_Z3ansii(i32 noundef %36, i32 noundef %37)
  store i32 %38, ptr %3, align 4
  br label %40

39:                                               ; preds = %26
  store i32 -1, ptr %3, align 4
  br label %40

40:                                               ; preds = %39, %34, %21, %9
  %41 = load i32, ptr %3, align 4
  ret i32 %41
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN3SEGIiE2lcEi(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef) #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN3SEGIiE2rcEi(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef) #2 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 = { 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 = !{!"_ZTS3SEGIiE", !6, i64 0, !6, i64 4, !11, i64 8}
!11 = !{!"_ZTSSt6vectorIiSaIiEE", !12, i64 0}
!12 = !{!"_ZTSSt12_Vector_baseIiSaIiEE", !13, i64 0}
!13 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE12_Vector_implE", !14, i64 0}
!14 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE17_Vector_impl_dataE", !15, i64 0, !15, i64 8, !15, i64 16}
!15 = !{!"any pointer", !7, i64 0}


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

%struct.SEG = type { i32, i32, %"class.std::vector" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = 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 }

@second = external dso_local global %struct.SEG, align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z3ansii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr getelementptr inbounds (i8, ptr @second, i64 4), align 4, !tbaa !5
  %.not20 = icmp sgt i32 %3, %0
  br i1 %.not20, label %.lr.ph, label %tailrecurse._crit_edge

tailrecurse._crit_edge:                           ; preds = %tailrecurse.backedge, %2
  %.tr.lcssa = phi i32 [ %0, %2 ], [ %.tr.be, %tailrecurse.backedge ]
  %.lcssa = phi i32 [ %3, %2 ], [ %11, %tailrecurse.backedge ]
  %4 = sub nsw i32 %.tr.lcssa, %.lcssa
  br label %.loopexit

.lr.ph:                                           ; preds = %2, %tailrecurse.backedge
  %.tr21 = phi i32 [ %.tr.be, %tailrecurse.backedge ], [ %0, %2 ]
  %5 = tail call noundef i32 @_ZN3SEGIiE2lcEi(ptr noundef nonnull align 8 dereferenceable(32) @second, i32 noundef %.tr21)
  %6 = sext i32 %5 to i64
  %7 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) getelementptr inbounds (i8, ptr @second, i64 8), i64 noundef %6) #2
  %8 = load i32, ptr %7, align 4, !tbaa !15
  %.not15 = icmp slt i32 %8, %1
  br i1 %.not15, label %12, label %9

9:                                                ; preds = %.lr.ph
  %10 = tail call noundef i32 @_ZN3SEGIiE2lcEi(ptr noundef nonnull align 8 dereferenceable(32) @second, i32 noundef %.tr21)
  br label %tailrecurse.backedge

tailrecurse.backedge:                             ; preds = %9, %17
  %.tr.be = phi i32 [ %10, %9 ], [ %18, %17 ]
  %11 = load i32, ptr getelementptr inbounds (i8, ptr @second, i64 4), align 4, !tbaa !5
  %.not = icmp sgt i32 %11, %.tr.be
  br i1 %.not, label %.lr.ph, label %tailrecurse._crit_edge

12:                                               ; preds = %.lr.ph
  %13 = tail call noundef i32 @_ZN3SEGIiE2rcEi(ptr noundef nonnull align 8 dereferenceable(32) @second, i32 noundef %.tr21)
  %14 = sext i32 %13 to i64
  %15 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(ptr noundef nonnull align 8 dereferenceable(24) getelementptr inbounds (i8, ptr @second, i64 8), i64 noundef %14) #2
  %16 = load i32, ptr %15, align 4, !tbaa !15
  %.not16 = icmp slt i32 %16, %1
  br i1 %.not16, label %.loopexit, label %17

17:                                               ; preds = %12
  %18 = tail call noundef i32 @_ZN3SEGIiE2rcEi(ptr noundef nonnull align 8 dereferenceable(32) @second, i32 noundef %.tr21)
  br label %tailrecurse.backedge

.loopexit:                                        ; preds = %12, %tailrecurse._crit_edge
  %.0 = phi i32 [ %4, %tailrecurse._crit_edge ], [ -1, %12 ]
  ret i32 %.0
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorIiSaIiEEixEm(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 i32 @_ZN3SEGIiE2lcEi(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN3SEGIiE2rcEi(ptr noundef nonnull align 8 dereferenceable(32), i32 noundef) local_unnamed_addr #1 align 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 = { 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 #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, !7, i64 4}
!6 = !{!"_ZTS3SEGIiE", !7, i64 0, !7, i64 4, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSSt6vectorIiSaIiEE", !11, i64 0}
!11 = !{!"_ZTSSt12_Vector_baseIiSaIiEE", !12, i64 0}
!12 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE12_Vector_implE", !13, i64 0}
!13 = !{!"_ZTSNSt12_Vector_baseIiSaIiEE17_Vector_impl_dataE", !14, i64 0, !14, i64 8, !14, i64 16}
!14 = !{!"any pointer", !8, i64 0}
!15 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass