; LLVM IR from tangjz/acm-icpc :: 51nod/1781.ll (Z7seg_updiiiSt4pairIxxE)

; 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 { i64, i64 }

@seg = external dso_local global [200007 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7seg_idxii(i32 noundef, i32 noundef) #1

; 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_updiiiSt4pairIxxE(i32 noundef %0, i32 noundef %1, i32 noundef %2, i64 %3, i64 %4) #2 {
  %6 = alloca %"struct.std::pair", align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca %"struct.std::pair", align 8
  %11 = alloca i32, align 4
  %12 = alloca %"struct.std::pair", align 8
  %13 = getelementptr inbounds { i64, i64 }, ptr %6, i32 0, i32 0
  store i64 %3, ptr %13, align 8
  %14 = getelementptr inbounds { i64, i64 }, ptr %6, i32 0, i32 1
  store i64 %4, ptr %14, align 8
  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
  br label %15

15:                                               ; preds = %41, %5
  %16 = load i32, ptr %7, align 4, !tbaa !5
  %17 = load i32, ptr %8, align 4, !tbaa !5
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %19, label %42

19:                                               ; preds = %15
  %20 = load i32, ptr %7, align 4, !tbaa !5
  %21 = load i32, ptr %8, align 4, !tbaa !5
  %22 = call noundef i32 @_Z7seg_idxii(i32 noundef %20, i32 noundef %21)
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [200007 x %"struct.std::pair"], ptr @seg, i64 0, i64 %23
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %10, ptr align 8 %6, i64 16, i1 false)
  %25 = getelementptr inbounds { i64, i64 }, ptr %10, i32 0, i32 0
  %26 = load i64, ptr %25, align 8
  %27 = getelementptr inbounds { i64, i64 }, ptr %10, i32 0, i32 1
  %28 = load i64, ptr %27, align 8
  call void @_Z3updRSt4pairIxxES0_(ptr noundef nonnull align 8 dereferenceable(16) %24, i64 %26, i64 %28)
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  %29 = load i32, ptr %7, align 4, !tbaa !5
  %30 = load i32, ptr %8, align 4, !tbaa !5
  %31 = add nsw i32 %29, %30
  %32 = ashr i32 %31, 1
  store i32 %32, ptr %11, align 4, !tbaa !5
  %33 = load i32, ptr %9, align 4, !tbaa !5
  %34 = load i32, ptr %11, align 4, !tbaa !5
  %35 = icmp sle i32 %33, %34
  br i1 %35, label %36, label %38

36:                                               ; preds = %19
  %37 = load i32, ptr %11, align 4, !tbaa !5
  store i32 %37, ptr %8, align 4, !tbaa !5
  br label %41

38:                                               ; preds = %19
  %39 = load i32, ptr %11, align 4, !tbaa !5
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %7, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %38, %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  br label %15, !llvm.loop !9

42:                                               ; preds = %15
  %43 = load i32, ptr %7, align 4, !tbaa !5
  %44 = load i32, ptr %8, align 4, !tbaa !5
  %45 = call noundef i32 @_Z7seg_idxii(i32 noundef %43, i32 noundef %44)
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [200007 x %"struct.std::pair"], ptr @seg, i64 0, i64 %46
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %12, ptr align 8 %6, i64 16, i1 false)
  %48 = getelementptr inbounds { i64, i64 }, ptr %12, i32 0, i32 0
  %49 = load i64, ptr %48, align 8
  %50 = getelementptr inbounds { i64, i64 }, ptr %12, i32 0, i32 1
  %51 = load i64, ptr %50, align 8
  call void @_Z3updRSt4pairIxxES0_(ptr noundef nonnull align 8 dereferenceable(16) %47, i64 %49, i64 %51)
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z3updRSt4pairIxxES0_(ptr noundef nonnull align 8 dereferenceable(16), i64, i64) #3

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; 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 { i64, i64 }

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7seg_updiiiSt4pairIxxE(i32 noundef %0, i32 noundef %1, i32 noundef %2, i64 %3, i64 %4) local_unnamed_addr #1 {
  %6 = icmp slt i32 %0, %1
  br i1 %6, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %5, %.lr.ph
  %.022 = phi i32 [ %.1, %.lr.ph ], [ %0, %5 ]
  %.01721 = phi i32 [ %.118, %.lr.ph ], [ %1, %5 ]
  %7 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %.022, i32 noundef %.01721)
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [200007 x %"struct.std::pair"], ptr @seg, i64 0, i64 %8
  tail call void @_Z3updRSt4pairIxxES0_(ptr noundef nonnull align 8 dereferenceable(16) %9, i64 %3, i64 %4)
  %10 = add nsw i32 %.022, %.01721
  %11 = ashr i32 %10, 1
  %.not = icmp slt i32 %11, %2
  %12 = add nsw i32 %11, 1
  %.118 = select i1 %.not, i32 %.01721, i32 %11
  %.1 = select i1 %.not, i32 %12, i32 %.022
  %13 = icmp slt i32 %.1, %.118
  br i1 %13, label %.lr.ph, label %._crit_edge, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph, %5
  %.017.lcssa = phi i32 [ %1, %5 ], [ %.118, %.lr.ph ]
  %.0.lcssa = phi i32 [ %0, %5 ], [ %.1, %.lr.ph ]
  %14 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %.0.lcssa, i32 noundef %.017.lcssa)
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [200007 x %"struct.std::pair"], ptr @seg, i64 0, i64 %15
  tail call void @_Z3updRSt4pairIxxES0_(ptr noundef nonnull align 8 dereferenceable(16) %16, i64 %3, i64 %4)
  ret void
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z3updRSt4pairIxxES0_(ptr noundef nonnull align 8 dereferenceable(16), i64, i64) local_unnamed_addr #2

attributes #0 = { 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 #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 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)"}
!5 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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