; LLVM IR from tangjz/acm-icpc :: codeforces/complete/700E.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"

%"struct.std::pair" = type { i32, i32 }

@seg = external dso_local global [400003 x %"struct.std::pair"], align 16

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7seg_updiiiiSt4pairIiiE(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i64 %4) #1 {
  %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 i32, 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 %34

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 %34

22:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  %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)
  store i32 %25, ptr %11, align 4, !tbaa !5
  %26 = load i32, ptr %11, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [400003 x %"struct.std::pair"], ptr @seg, i64 0, i64 %27
  %29 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZSt3maxISt4pairIiiEERKT_S4_S4_(ptr noundef nonnull align 4 dereferenceable(8) %28, ptr noundef nonnull align 4 dereferenceable(8) %6)
  %30 = load i32, ptr %11, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [400003 x %"struct.std::pair"], ptr @seg, i64 0, i64 %31
  %33 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt4pairIiiEaSERKS0_(ptr noundef nonnull align 4 dereferenceable(8) %32, ptr noundef nonnull align 4 dereferenceable(8) %29)
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  br label %60

34:                                               ; preds = %18, %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #6
  %35 = load i32, ptr %7, align 4, !tbaa !5
  %36 = load i32, ptr %8, align 4, !tbaa !5
  %37 = add nsw i32 %35, %36
  %38 = ashr i32 %37, 1
  store i32 %38, ptr %12, align 4, !tbaa !5
  %39 = load i32, ptr %9, align 4, !tbaa !5
  %40 = load i32, ptr %12, align 4, !tbaa !5
  %41 = icmp sle i32 %39, %40
  br i1 %41, label %42, label %48

42:                                               ; preds = %34
  %43 = load i32, ptr %7, align 4, !tbaa !5
  %44 = load i32, ptr %12, align 4, !tbaa !5
  %45 = load i32, ptr %9, align 4, !tbaa !5
  %46 = 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)
  %47 = load i64, ptr %13, align 4
  call void @_Z7seg_updiiiiSt4pairIiiE(i32 noundef %43, i32 noundef %44, i32 noundef %45, i32 noundef %46, i64 %47)
  br label %48

48:                                               ; preds = %42, %34
  %49 = load i32, ptr %10, align 4, !tbaa !5
  %50 = load i32, ptr %12, align 4, !tbaa !5
  %51 = icmp sgt i32 %49, %50
  br i1 %51, label %52, label %59

52:                                               ; preds = %48
  %53 = load i32, ptr %12, align 4, !tbaa !5
  %54 = add nsw i32 %53, 1
  %55 = load i32, ptr %8, align 4, !tbaa !5
  %56 = load i32, ptr %9, align 4, !tbaa !5
  %57 = 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)
  %58 = load i64, ptr %14, align 4
  call void @_Z7seg_updiiiiSt4pairIiiE(i32 noundef %54, i32 noundef %55, i32 noundef %56, i32 noundef %57, i64 %58)
  br label %59

59:                                               ; preds = %52, %48
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  br label %60

60:                                               ; preds = %59, %22
  ret void
}

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

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

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

; 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) #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { inlinehint 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 #4 = { 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 #5 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { 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"

%"struct.std::pair" = type { i32, i32 }

@seg = external dso_local global [400003 x %"struct.std::pair"], align 16

; 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 {
  %6 = alloca %"struct.std::pair", align 8
  %.not27 = icmp sgt i32 %1, %3
  %.not35 = icmp sgt i32 %2, %0
  %or.cond36 = or i1 %.not27, %.not35
  br i1 %or.cond36, label %.lr.ph, label %tailrecurse._crit_edge

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

.lr.ph.split.us:                                  ; preds = %.lr.ph, %tailrecurse.us
  %.tr37.us = phi i32 [ %11, %tailrecurse.us ], [ %0, %.lr.ph ]
  %7 = add nsw i32 %.tr37.us, %1
  %8 = ashr i32 %7, 1
  %.not28.us = icmp slt i32 %8, %2
  br i1 %.not28.us, label %tailrecurse.us, label %9

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

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

tailrecurse:                                      ; preds = %21
  %12 = add nsw i32 %19, 1
  %.not = icmp slt i32 %12, %2
  br i1 %.not, label %.lr.ph.split, label %tailrecurse._crit_edge

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %5
  %.tr.lcssa = phi i32 [ %0, %5 ], [ %12, %tailrecurse ]
  store i64 %4, ptr %6, align 8
  %13 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %.tr.lcssa, i32 noundef %1)
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [400003 x %"struct.std::pair"], ptr @seg, i64 0, i64 %14
  %16 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZSt3maxISt4pairIiiEERKT_S4_S4_(ptr noundef nonnull align 4 dereferenceable(8) %15, ptr noundef nonnull align 4 dereferenceable(8) %6)
  %17 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt4pairIiiEaSERKS0_(ptr noundef nonnull align 4 dereferenceable(8) %15, ptr noundef nonnull align 4 dereferenceable(8) %16)
  br label %.loopexit

.lr.ph.split:                                     ; preds = %.lr.ph, %tailrecurse
  %.tr37 = phi i32 [ %12, %tailrecurse ], [ %0, %.lr.ph ]
  %18 = add nsw i32 %.tr37, %1
  %19 = ashr i32 %18, 1
  %.not28 = icmp slt i32 %19, %2
  br i1 %.not28, label %21, label %20

20:                                               ; preds = %.lr.ph.split
  tail call void @_Z7seg_updiiiiSt4pairIiiE(i32 noundef %.tr37, i32 noundef %19, i32 noundef %2, i32 noundef %3, i64 %4)
  br label %21

21:                                               ; preds = %20, %.lr.ph.split
  %22 = icmp slt i32 %19, %3
  br i1 %22, label %tailrecurse, label %.loopexit

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(8) ptr @_ZSt3maxISt4pairIiiEERKT_S4_S4_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt4pairIiiEaSERKS0_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #3 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 = { 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 = { inlinehint 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 #3 = { 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: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass