; LLVM IR from tangjz/acm-icpc :: lydsy/4217.ll (Z6modifyRiPSt4pairIxxEx)

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6modifyRiPSt4pairIxxEx(ptr noundef nonnull align 4 dereferenceable(4) %0, ptr noundef %1, i64 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !11
  br label %12

12:                                               ; preds = %87, %3
  %13 = load i32, ptr %8, align 4, !tbaa !11
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = icmp slt i32 %13, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %12
  store i32 2, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %90

18:                                               ; preds = %12
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = load i32, ptr %8, align 4, !tbaa !11
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds %"struct.std::pair", ptr %19, i64 %21
  %23 = getelementptr inbounds %"struct.std::pair", ptr %22, i32 0, i32 1
  %24 = load i64, ptr %23, align 8, !tbaa !13
  %25 = icmp ne i64 %24, 0
  br i1 %25, label %27, label %26

26:                                               ; preds = %18
  br label %87

27:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = load i32, ptr %8, align 4, !tbaa !11
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds %"struct.std::pair", ptr %28, i64 %30
  %32 = getelementptr inbounds %"struct.std::pair", ptr %31, i32 0, i32 0
  %33 = load i64, ptr %32, align 8, !tbaa !15
  %34 = load i64, ptr %6, align 8, !tbaa !9
  %35 = add nsw i64 %33, %34
  store i64 %35, ptr %11, align 8, !tbaa !9
  br label %36

36:                                               ; preds = %54, %27
  %37 = load i32, ptr %9, align 4, !tbaa !11
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = load i32, ptr %38, align 4, !tbaa !11
  %40 = icmp slt i32 %37, %39
  br i1 %40, label %41, label %50

41:                                               ; preds = %36
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = load i32, ptr %9, align 4, !tbaa !11
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds %"struct.std::pair", ptr %42, i64 %44
  %46 = getelementptr inbounds %"struct.std::pair", ptr %45, i32 0, i32 0
  %47 = load i64, ptr %46, align 8, !tbaa !15
  %48 = load i64, ptr %11, align 8, !tbaa !9
  %49 = icmp slt i64 %47, %48
  br label %50

50:                                               ; preds = %41, %36
  %51 = phi i1 [ false, %36 ], [ %49, %41 ]
  br i1 %51, label %53, label %52

52:                                               ; preds = %50
  store i32 5, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  br label %57

53:                                               ; preds = %50
  br label %54

54:                                               ; preds = %53
  %55 = load i32, ptr %9, align 4, !tbaa !11
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %9, align 4, !tbaa !11
  br label %36, !llvm.loop !16

57:                                               ; preds = %52
  %58 = load i32, ptr %9, align 4, !tbaa !11
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = load i32, ptr %59, align 4, !tbaa !11
  %61 = icmp slt i32 %58, %60
  br i1 %61, label %62, label %76

62:                                               ; preds = %57
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = load i32, ptr %8, align 4, !tbaa !11
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds %"struct.std::pair", ptr %63, i64 %65
  %67 = getelementptr inbounds %"struct.std::pair", ptr %66, i32 0, i32 1
  %68 = load i64, ptr %67, align 8, !tbaa !13
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = load i32, ptr %9, align 4, !tbaa !11
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds %"struct.std::pair", ptr %69, i64 %71
  %73 = getelementptr inbounds %"struct.std::pair", ptr %72, i32 0, i32 1
  %74 = load i64, ptr %73, align 8, !tbaa !13
  %75 = sub nsw i64 %74, %68
  store i64 %75, ptr %73, align 8, !tbaa !13
  br label %76

76:                                               ; preds = %62, %57
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = load i32, ptr %8, align 4, !tbaa !11
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds %"struct.std::pair", ptr %77, i64 %79
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = load i32, ptr %7, align 4, !tbaa !11
  %83 = add nsw i32 %82, 1
  store i32 %83, ptr %7, align 4, !tbaa !11
  %84 = sext i32 %82 to i64
  %85 = getelementptr inbounds %"struct.std::pair", ptr %81, i64 %84
  %86 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt4pairIxxEaSERKS0_(ptr noundef nonnull align 8 dereferenceable(16) %85, ptr noundef nonnull align 8 dereferenceable(16) %80)
  br label %87

87:                                               ; preds = %76, %26
  %88 = load i32, ptr %8, align 4, !tbaa !11
  %89 = add nsw i32 %88, 1
  store i32 %89, ptr %8, align 4, !tbaa !11
  br label %12, !llvm.loop !18

90:                                               ; preds = %17
  %91 = load i32, ptr %7, align 4, !tbaa !11
  %92 = load ptr, ptr %4, align 8, !tbaa !5
  store i32 %91, ptr %92, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret void
}

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt4pairIxxEaSERKS0_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 8}
!14 = !{!"_ZTSSt4pairIxxE", !10, i64 0, !10, i64 8}
!15 = !{!14, !10, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z6modifyRiPSt4pairIxxEx(ptr nocapture noundef nonnull align 4 dereferenceable(4) %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = load i32, ptr %0, align 4, !tbaa !5
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph34, label %._crit_edge

._crit_edge:                                      ; preds = %29, %3
  %.0.lcssa = phi i32 [ 0, %3 ], [ %.1, %29 ]
  store i32 %.0.lcssa, ptr %0, align 4, !tbaa !5
  ret void

.lr.ph34:                                         ; preds = %3, %29
  %6 = phi i32 [ %30, %29 ], [ %4, %3 ]
  %indvars.iv38 = phi i64 [ %indvars.iv.next39, %29 ], [ 0, %3 ]
  %.033 = phi i32 [ %.1, %29 ], [ 0, %3 ]
  %.02532 = phi i32 [ %.2, %29 ], [ 0, %3 ]
  %7 = getelementptr inbounds %"struct.std::pair", ptr %1, i64 %indvars.iv38
  %8 = getelementptr inbounds i8, ptr %7, i64 8
  %9 = load i64, ptr %8, align 8, !tbaa !9
  %.not = icmp eq i64 %9, 0
  br i1 %.not, label %29, label %10

10:                                               ; preds = %.lr.ph34
  %11 = load i64, ptr %7, align 8, !tbaa !12
  %12 = add nsw i64 %11, %2
  %13 = icmp slt i32 %.02532, %6
  br i1 %13, label %.lr.ph.preheader, label %.critedge

.lr.ph.preheader:                                 ; preds = %10
  %14 = sext i32 %.02532 to i64
  %wide.trip.count = sext i32 %6 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %18
  %indvars.iv = phi i64 [ %14, %.lr.ph.preheader ], [ %indvars.iv.next, %18 ]
  %15 = getelementptr inbounds %"struct.std::pair", ptr %1, i64 %indvars.iv
  %16 = load i64, ptr %15, align 8, !tbaa !12
  %17 = icmp slt i64 %16, %12
  br i1 %17, label %18, label %19

18:                                               ; preds = %.lr.ph
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.critedge, label %.lr.ph, !llvm.loop !13

19:                                               ; preds = %.lr.ph
  %20 = trunc nsw i64 %indvars.iv to i32
  %sext = shl i64 %indvars.iv, 32
  %21 = ashr exact i64 %sext, 32
  %22 = getelementptr inbounds %"struct.std::pair", ptr %1, i64 %21, i32 1
  %23 = load i64, ptr %22, align 8, !tbaa !9
  %24 = sub nsw i64 %23, %9
  store i64 %24, ptr %22, align 8, !tbaa !9
  br label %.critedge

.critedge:                                        ; preds = %18, %10, %19
  %.12629 = phi i32 [ %20, %19 ], [ %.02532, %10 ], [ %6, %18 ]
  %25 = add nsw i32 %.033, 1
  %26 = sext i32 %.033 to i64
  %27 = getelementptr inbounds %"struct.std::pair", ptr %1, i64 %26
  %28 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt4pairIxxEaSERKS0_(ptr noundef nonnull align 8 dereferenceable(16) %27, ptr noundef nonnull align 8 dereferenceable(16) %7)
  %.pre = load i32, ptr %0, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %.lr.ph34, %.critedge
  %30 = phi i32 [ %.pre, %.critedge ], [ %6, %.lr.ph34 ]
  %.2 = phi i32 [ %.12629, %.critedge ], [ %.02532, %.lr.ph34 ]
  %.1 = phi i32 [ %25, %.critedge ], [ %.033, %.lr.ph34 ]
  %indvars.iv.next39 = add nuw nsw i64 %indvars.iv38, 1
  %31 = sext i32 %30 to i64
  %32 = icmp slt i64 %indvars.iv.next39, %31
  br i1 %32, label %.lr.ph34, label %._crit_edge, !llvm.loop !15
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt4pairIxxEaSERKS0_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0 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" }

!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, !11, i64 8}
!10 = !{!"_ZTSSt4pairIxxE", !11, i64 0, !11, i64 8}
!11 = !{!"long long", !7, i64 0}
!12 = !{!10, !11, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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