; LLVM IR from eyangch/competitive-programming :: USACOcontests/silver/2020.03/socdist.ll (Z5worksxxPSt4pairIxxEx)

; 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 noundef zeroext i1 @_Z5worksxxPSt4pairIxxEx(i64 noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3) #0 {
  %5 = alloca i1, align 1
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i64, align 8
  %15 = alloca %"struct.std::pair", align 8
  %16 = alloca i32, align 4
  store i64 %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !9
  store i64 %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %17 = load ptr, ptr %8, align 8, !tbaa !9
  %18 = getelementptr inbounds %"struct.std::pair", ptr %17, i64 0
  %19 = getelementptr inbounds %"struct.std::pair", ptr %18, i32 0, i32 0
  %20 = load i64, ptr %19, align 8, !tbaa !11
  store i64 %20, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store i64 0, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 0, ptr %12, align 4, !tbaa !13
  br label %21

21:                                               ; preds = %93, %4
  %22 = load i32, ptr %12, align 4, !tbaa !13
  %23 = sext i32 %22 to i64
  %24 = load i64, ptr %6, align 8, !tbaa !5
  %25 = icmp slt i64 %23, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %21
  store i32 2, ptr %13, align 4
  br label %96

27:                                               ; preds = %21
  %28 = load i64, ptr %10, align 8, !tbaa !5
  %29 = load ptr, ptr %8, align 8, !tbaa !9
  %30 = load i64, ptr %7, align 8, !tbaa !5
  %31 = sub nsw i64 %30, 1
  %32 = getelementptr inbounds %"struct.std::pair", ptr %29, i64 %31
  %33 = getelementptr inbounds %"struct.std::pair", ptr %32, i32 0, i32 1
  %34 = load i64, ptr %33, align 8, !tbaa !15
  %35 = icmp sgt i64 %28, %34
  br i1 %35, label %36, label %37

36:                                               ; preds = %27
  store i1 false, ptr %5, align 1
  store i32 1, ptr %13, align 4
  br label %96

37:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %38 = load ptr, ptr %8, align 8, !tbaa !9
  %39 = load i64, ptr %11, align 8, !tbaa !5
  %40 = getelementptr inbounds %"struct.std::pair", ptr %38, i64 %39
  %41 = load ptr, ptr %8, align 8, !tbaa !9
  %42 = load i64, ptr %7, align 8, !tbaa !5
  %43 = getelementptr inbounds %"struct.std::pair", ptr %41, i64 %42
  call void @llvm.lifetime.start.p0(i64 16, ptr %15) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  store i32 0, ptr %16, align 4, !tbaa !13
  call void @_ZNSt4pairIxxEC2IRxiTnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS4_S5_EEEbE4typeELb1EEEOS4_OS5_(ptr noundef nonnull align 8 dereferenceable(16) %15, ptr noundef nonnull align 8 dereferenceable(8) %10, ptr noundef nonnull align 4 dereferenceable(4) %16)
  %44 = call noundef ptr @_ZSt11lower_boundIPSt4pairIxxES1_ET_S3_S3_RKT0_(ptr noundef %40, ptr noundef %43, ptr noundef nonnull align 8 dereferenceable(16) %15)
  %45 = load ptr, ptr %8, align 8, !tbaa !9
  %46 = ptrtoint ptr %44 to i64
  %47 = ptrtoint ptr %45 to i64
  %48 = sub i64 %46, %47
  %49 = sdiv exact i64 %48, 16
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %15) #4
  store i64 %49, ptr %14, align 8, !tbaa !5
  %50 = load i64, ptr %14, align 8, !tbaa !5
  %51 = icmp sgt i64 %50, 0
  br i1 %51, label %52, label %64

52:                                               ; preds = %37
  %53 = load ptr, ptr %8, align 8, !tbaa !9
  %54 = load i64, ptr %14, align 8, !tbaa !5
  %55 = sub nsw i64 %54, 1
  %56 = getelementptr inbounds %"struct.std::pair", ptr %53, i64 %55
  %57 = getelementptr inbounds %"struct.std::pair", ptr %56, i32 0, i32 1
  %58 = load i64, ptr %57, align 8, !tbaa !15
  %59 = load i64, ptr %10, align 8, !tbaa !5
  %60 = icmp sge i64 %58, %59
  br i1 %60, label %61, label %64

61:                                               ; preds = %52
  %62 = load i64, ptr %14, align 8, !tbaa !5
  %63 = add nsw i64 %62, -1
  store i64 %63, ptr %14, align 8, !tbaa !5
  br label %88

64:                                               ; preds = %52, %37
  %65 = load ptr, ptr %8, align 8, !tbaa !9
  %66 = load i64, ptr %14, align 8, !tbaa !5
  %67 = getelementptr inbounds %"struct.std::pair", ptr %65, i64 %66
  %68 = getelementptr inbounds %"struct.std::pair", ptr %67, i32 0, i32 0
  %69 = load i64, ptr %68, align 8, !tbaa !11
  %70 = load i64, ptr %11, align 8, !tbaa !5
  %71 = icmp sgt i64 %69, %70
  br i1 %71, label %72, label %87

72:                                               ; preds = %64
  %73 = load ptr, ptr %8, align 8, !tbaa !9
  %74 = load i64, ptr %14, align 8, !tbaa !5
  %75 = sub nsw i64 %74, 1
  %76 = getelementptr inbounds %"struct.std::pair", ptr %73, i64 %75
  %77 = getelementptr inbounds %"struct.std::pair", ptr %76, i32 0, i32 1
  %78 = load i64, ptr %77, align 8, !tbaa !15
  %79 = load i64, ptr %10, align 8, !tbaa !5
  %80 = icmp slt i64 %78, %79
  br i1 %80, label %81, label %87

81:                                               ; preds = %72
  %82 = load ptr, ptr %8, align 8, !tbaa !9
  %83 = load i64, ptr %14, align 8, !tbaa !5
  %84 = getelementptr inbounds %"struct.std::pair", ptr %82, i64 %83
  %85 = getelementptr inbounds %"struct.std::pair", ptr %84, i32 0, i32 0
  %86 = load i64, ptr %85, align 8, !tbaa !11
  store i64 %86, ptr %10, align 8, !tbaa !5
  br label %87

87:                                               ; preds = %81, %72, %64
  br label %88

88:                                               ; preds = %87, %61
  %89 = load i64, ptr %14, align 8, !tbaa !5
  store i64 %89, ptr %11, align 8, !tbaa !5
  %90 = load i64, ptr %9, align 8, !tbaa !5
  %91 = load i64, ptr %10, align 8, !tbaa !5
  %92 = add nsw i64 %91, %90
  store i64 %92, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  br label %93

93:                                               ; preds = %88
  %94 = load i32, ptr %12, align 4, !tbaa !13
  %95 = add nsw i32 %94, 1
  store i32 %95, ptr %12, align 4, !tbaa !13
  br label %21, !llvm.loop !16

96:                                               ; preds = %36, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  %97 = load i32, ptr %13, align 4
  switch i32 %97, label %99 [
    i32 2, label %98
  ]

98:                                               ; preds = %96
  store i1 true, ptr %5, align 1
  store i32 1, ptr %13, align 4
  br label %99

99:                                               ; preds = %98, %96
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %100 = load i1, ptr %5, align 1
  ret i1 %100
}

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt4pairIxxEC2IRxiTnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS4_S5_EEEbE4typeELb1EEEOS4_OS5_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(4)) unnamed_addr #3 align 2

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

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 = { 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" }
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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTSSt4pairIxxE", !6, i64 0, !6, i64 8}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!12, !6, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"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 }

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z5worksxxPSt4pairIxxEx(i64 noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3) local_unnamed_addr #0 {
  %5 = alloca i64, align 8
  %6 = alloca %"struct.std::pair", align 8
  %7 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  %8 = load i64, ptr %2, align 8, !tbaa !5
  store i64 %8, ptr %5, align 8, !tbaa !10
  %invariant.gep = getelementptr i8, ptr %2, i64 -8
  %.not3132 = icmp slt i64 %0, 1
  br i1 %.not3132, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %4
  %9 = getelementptr %"struct.std::pair", ptr %2, i64 %1
  %10 = getelementptr i8, ptr %9, i64 -8
  %11 = ptrtoint ptr %2 to i64
  %12 = load i64, ptr %10, align 8, !tbaa !11
  %13 = icmp sgt i64 %8, %12
  br i1 %13, label %.critedge, label %.lr.ph40

14:                                               ; preds = %35
  %15 = load i64, ptr %10, align 8, !tbaa !11
  %16 = icmp sgt i64 %37, %15
  br i1 %16, label %.critedge.loopexit, label %.lr.ph40, !llvm.loop !12

.lr.ph40:                                         ; preds = %.lr.ph, %14
  %.0273339 = phi i64 [ %.0, %14 ], [ 0, %.lr.ph ]
  %indvars.iv38 = phi i64 [ %indvars.iv.next, %14 ], [ 0, %.lr.ph ]
  %17 = getelementptr inbounds %"struct.std::pair", ptr %2, i64 %.0273339
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #4
  store i32 0, ptr %7, align 4, !tbaa !14
  call void @_ZNSt4pairIxxEC2IRxiTnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS4_S5_EEEbE4typeELb1EEEOS4_OS5_(ptr noundef nonnull align 8 dereferenceable(16) %6, ptr noundef nonnull align 8 dereferenceable(8) %5, ptr noundef nonnull align 4 dereferenceable(4) %7)
  %18 = call noundef ptr @_ZSt11lower_boundIPSt4pairIxxES1_ET_S3_S3_RKT0_(ptr noundef nonnull %17, ptr noundef nonnull %9, ptr noundef nonnull align 8 dereferenceable(16) %6)
  %19 = ptrtoint ptr %18 to i64
  %20 = sub i64 %19, %11
  %21 = ashr exact i64 %20, 4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #4
  %22 = icmp sgt i64 %21, 0
  %.pre.pre = load i64, ptr %5, align 8, !tbaa !10
  br i1 %22, label %23, label %27

23:                                               ; preds = %.lr.ph40
  %gep = getelementptr i8, ptr %invariant.gep, i64 %20
  %24 = load i64, ptr %gep, align 8, !tbaa !11
  %.not = icmp slt i64 %24, %.pre.pre
  br i1 %.not, label %27, label %25

25:                                               ; preds = %23
  %26 = add nsw i64 %21, -1
  br label %35

27:                                               ; preds = %23, %.lr.ph40
  %28 = getelementptr inbounds i8, ptr %2, i64 %20
  %29 = load i64, ptr %28, align 8, !tbaa !5
  %30 = icmp sgt i64 %29, %.0273339
  br i1 %30, label %31, label %35

31:                                               ; preds = %27
  %32 = getelementptr i8, ptr %28, i64 -8
  %33 = load i64, ptr %32, align 8, !tbaa !11
  %34 = icmp slt i64 %33, %.pre.pre
  %spec.select = select i1 %34, i64 %29, i64 %.pre.pre
  br label %35

35:                                               ; preds = %31, %27, %25
  %36 = phi i64 [ %.pre.pre, %25 ], [ %.pre.pre, %27 ], [ %spec.select, %31 ]
  %.0 = phi i64 [ %26, %25 ], [ %21, %27 ], [ %21, %31 ]
  %37 = add nsw i64 %36, %3
  store i64 %37, ptr %5, align 8, !tbaa !10
  %indvars.iv.next = add nuw nsw i64 %indvars.iv38, 1
  %exitcond = icmp eq i64 %indvars.iv.next, %0
  br i1 %exitcond, label %.critedge.loopexit, label %14, !llvm.loop !12

.critedge.loopexit:                               ; preds = %14, %35
  %.not31.le = icmp sge i64 %indvars.iv.next, %0
  br label %.critedge

.critedge:                                        ; preds = %.critedge.loopexit, %.lr.ph, %4
  %.not31.lcssa = phi i1 [ true, %4 ], [ false, %.lr.ph ], [ %.not31.le, %.critedge.loopexit ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  ret i1 %.not31.lcssa
}

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt4pairIxxEC2IRxiTnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS4_S5_EEEbE4typeELb1EEEOS4_OS5_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(4)) unnamed_addr #3 align 2

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

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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
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, !7, i64 0}
!6 = !{!"_ZTSSt4pairIxxE", !7, i64 0, !7, i64 8}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!7, !7, i64 0}
!11 = !{!6, !7, i64 8}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !15, i64 0}
!15 = !{!"int", !8, i64 0}


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