; LLVM IR from tangjz/acm-icpc :: codeforces/complete/1175G.ll (Z7seg_updiiiiSt4pairIiiE)

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

@sR = external dso_local global [40003 x %"class.std::vector"], align 16

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7seg_idxii(i32 noundef, i32 noundef) #3

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

18:                                               ; preds = %5
  %19 = load i32, ptr %8, align 4, !tbaa !5
  %20 = load i32, ptr %10, align 4, !tbaa !5
  %21 = icmp sle i32 %19, %20
  br i1 %21, label %22, label %29

22:                                               ; preds = %18
  %23 = load i32, ptr %7, align 4, !tbaa !5
  %24 = load i32, ptr %8, align 4, !tbaa !5
  %25 = call noundef i32 @_Z7seg_idxii(i32 noundef %23, i32 noundef %24)
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [40003 x %"class.std::vector"], ptr @sR, i64 0, i64 %26
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %11, ptr align 4 %6, i64 8, i1 false)
  %28 = load i64, ptr %11, align 4
  call void @_Z7seg_updRSt6vectorISt4pairIiiESaIS1_EES1_(ptr noundef nonnull align 8 dereferenceable(24) %27, i64 %28)
  br label %55

29:                                               ; preds = %18, %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %30 = load i32, ptr %7, align 4, !tbaa !5
  %31 = load i32, ptr %8, align 4, !tbaa !5
  %32 = add nsw i32 %30, %31
  %33 = ashr i32 %32, 1
  store i32 %33, ptr %12, align 4, !tbaa !5
  %34 = load i32, ptr %9, align 4, !tbaa !5
  %35 = load i32, ptr %12, align 4, !tbaa !5
  %36 = icmp sle i32 %34, %35
  br i1 %36, label %37, label %43

37:                                               ; preds = %29
  %38 = load i32, ptr %7, align 4, !tbaa !5
  %39 = load i32, ptr %12, align 4, !tbaa !5
  %40 = load i32, ptr %9, align 4, !tbaa !5
  %41 = load i32, ptr %10, align 4, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %13, ptr align 4 %6, i64 8, i1 false)
  %42 = load i64, ptr %13, align 4
  call void @_Z7seg_updiiiiSt4pairIiiE(i32 noundef %38, i32 noundef %39, i32 noundef %40, i32 noundef %41, i64 %42)
  br label %43

43:                                               ; preds = %37, %29
  %44 = load i32, ptr %10, align 4, !tbaa !5
  %45 = load i32, ptr %12, align 4, !tbaa !5
  %46 = icmp sgt i32 %44, %45
  br i1 %46, label %47, label %54

47:                                               ; preds = %43
  %48 = load i32, ptr %12, align 4, !tbaa !5
  %49 = add nsw i32 %48, 1
  %50 = load i32, ptr %8, align 4, !tbaa !5
  %51 = load i32, ptr %9, align 4, !tbaa !5
  %52 = load i32, ptr %10, align 4, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %14, ptr align 4 %6, i64 8, i1 false)
  %53 = load i64, ptr %14, align 4
  call void @_Z7seg_updiiiiSt4pairIiiE(i32 noundef %49, i32 noundef %50, i32 noundef %51, i32 noundef %52, i64 %53)
  br label %54

54:                                               ; preds = %47, %43
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %55

55:                                               ; preds = %54, %22
  ret void
}

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 = { nocallback nofree 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"}


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

@sR = external dso_local global [40003 x %"class.std::vector"], align 16

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7seg_idxii(i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7seg_updiiiiSt4pairIiiE(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i64 %4) local_unnamed_addr #0 {
  %.not29 = icmp sgt i32 %1, %3
  %.not36 = icmp sgt i32 %2, %0
  %or.cond37 = or i1 %.not29, %.not36
  br i1 %or.cond37, label %.lr.ph, label %tailrecurse._crit_edge

.lr.ph:                                           ; preds = %5
  br i1 %.not29, label %.lr.ph.split.us, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph, %tailrecurse.us
  %.tr38.us = phi i32 [ %10, %tailrecurse.us ], [ %0, %.lr.ph ]
  %6 = add nsw i32 %.tr38.us, %1
  %7 = ashr i32 %6, 1
  %.not30.us = icmp slt i32 %7, %2
  br i1 %.not30.us, label %tailrecurse.us, label %8

8:                                                ; preds = %.lr.ph.split.us
  tail call void @_Z7seg_updiiiiSt4pairIiiE(i32 noundef %.tr38.us, i32 noundef %7, i32 noundef %2, i32 noundef %3, i64 %4)
  br label %tailrecurse.us

tailrecurse.us:                                   ; preds = %8, %.lr.ph.split.us
  %9 = icmp slt i32 %7, %3
  %10 = add nsw i32 %7, 1
  br i1 %9, label %.lr.ph.split.us, label %.loopexit

tailrecurse:                                      ; preds = %18
  %11 = add nsw i32 %16, 1
  %.not = icmp slt i32 %11, %2
  br i1 %.not, label %.lr.ph.split, label %tailrecurse._crit_edge

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %5
  %.tr.lcssa = phi i32 [ %0, %5 ], [ %11, %tailrecurse ]
  %12 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %.tr.lcssa, i32 noundef %1)
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [40003 x %"class.std::vector"], ptr @sR, i64 0, i64 %13
  tail call void @_Z7seg_updRSt6vectorISt4pairIiiESaIS1_EES1_(ptr noundef nonnull align 8 dereferenceable(24) %14, i64 %4)
  br label %.loopexit

.lr.ph.split:                                     ; preds = %.lr.ph, %tailrecurse
  %.tr38 = phi i32 [ %11, %tailrecurse ], [ %0, %.lr.ph ]
  %15 = add nsw i32 %.tr38, %1
  %16 = ashr i32 %15, 1
  %.not30 = icmp slt i32 %16, %2
  br i1 %.not30, label %18, label %17

17:                                               ; preds = %.lr.ph.split
  tail call void @_Z7seg_updiiiiSt4pairIiiE(i32 noundef %.tr38, i32 noundef %16, i32 noundef %2, i32 noundef %3, i64 %4)
  br label %18

18:                                               ; preds = %17, %.lr.ph.split
  %19 = icmp slt i32 %16, %3
  br i1 %19, label %tailrecurse, label %.loopexit

.loopexit:                                        ; preds = %18, %tailrecurse.us, %tailrecurse._crit_edge
  ret void
}

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 = { 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" }

!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)"}


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