; LLVM IR from tangjz/acm-icpc :: usaco/dec22-gold/B.ll (Z6segAddiiiRK5Point)

; 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, %struct.Point }
%struct.Point = type { i32, i32 }

@seg = external dso_local global [4019 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 @_Z6segIdxii(i32 noundef, i32 noundef) #1

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

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

21:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 12, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 1, ptr %11, align 4, !tbaa !5
  %22 = load ptr, ptr %8, align 8, !tbaa !9
  call void @_ZNSt4pairIi5PointEC2IiRKS0_TnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS6_S7_EEEbE4typeELb1EEEOS6_OS7_(ptr noundef nonnull align 4 dereferenceable(12) %10, ptr noundef nonnull align 4 dereferenceable(4) %11, ptr noundef nonnull align 4 dereferenceable(8) %22)
  %23 = load i32, ptr %9, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [4019 x %"struct.std::pair"], ptr @seg, i64 0, i64 %24
  %26 = call noundef nonnull align 4 dereferenceable(12) ptr @_ZNSt4pairIi5PointEaSEOS1_(ptr noundef nonnull align 4 dereferenceable(12) %25, ptr noundef nonnull align 4 dereferenceable(12) %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 12, ptr %10) #4
  br label %98

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

35:                                               ; preds = %27
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = load i32, ptr %12, align 4, !tbaa !5
  %38 = load i32, ptr %7, align 4, !tbaa !5
  %39 = load ptr, ptr %8, align 8, !tbaa !9
  %40 = call noundef i32 @_Z6segAddiiiRK5Point(i32 noundef %36, i32 noundef %37, i32 noundef %38, ptr noundef nonnull align 4 dereferenceable(8) %39)
  br label %45

41:                                               ; preds = %27
  %42 = load i32, ptr %5, align 4, !tbaa !5
  %43 = load i32, ptr %12, align 4, !tbaa !5
  %44 = call noundef i32 @_Z6segIdxii(i32 noundef %42, i32 noundef %43)
  br label %45

45:                                               ; preds = %41, %35
  %46 = phi i32 [ %40, %35 ], [ %44, %41 ]
  store i32 %46, ptr %13, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %47 = load i32, ptr %7, align 4, !tbaa !5
  %48 = load i32, ptr %12, align 4, !tbaa !5
  %49 = icmp sle i32 %47, %48
  br i1 %49, label %50, label %55

50:                                               ; preds = %45
  %51 = load i32, ptr %12, align 4, !tbaa !5
  %52 = add nsw i32 %51, 1
  %53 = load i32, ptr %6, align 4, !tbaa !5
  %54 = call noundef i32 @_Z6segIdxii(i32 noundef %52, i32 noundef %53)
  br label %62

55:                                               ; preds = %45
  %56 = load i32, ptr %12, align 4, !tbaa !5
  %57 = add nsw i32 %56, 1
  %58 = load i32, ptr %6, align 4, !tbaa !5
  %59 = load i32, ptr %7, align 4, !tbaa !5
  %60 = load ptr, ptr %8, align 8, !tbaa !9
  %61 = call noundef i32 @_Z6segAddiiiRK5Point(i32 noundef %57, i32 noundef %58, i32 noundef %59, ptr noundef nonnull align 4 dereferenceable(8) %60)
  br label %62

62:                                               ; preds = %55, %50
  %63 = phi i32 [ %54, %50 ], [ %61, %55 ]
  store i32 %63, ptr %14, align 4, !tbaa !5
  %64 = load i32, ptr %14, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [4019 x %"struct.std::pair"], ptr @seg, i64 0, i64 %65
  %67 = getelementptr inbounds %"struct.std::pair", ptr %66, i32 0, i32 0
  %68 = load i32, ptr %67, align 4, !tbaa !11
  %69 = icmp ne i32 %68, 0
  br i1 %69, label %70, label %89

70:                                               ; preds = %62
  %71 = load i32, ptr %14, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [4019 x %"struct.std::pair"], ptr @seg, i64 0, i64 %72
  %74 = load i32, ptr %9, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [4019 x %"struct.std::pair"], ptr @seg, i64 0, i64 %75
  %77 = call noundef nonnull align 4 dereferenceable(12) ptr @_ZNSt4pairIi5PointEaSERKS1_(ptr noundef nonnull align 4 dereferenceable(12) %76, ptr noundef nonnull align 4 dereferenceable(12) %73)
  %78 = load i32, ptr %13, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [4019 x %"struct.std::pair"], ptr @seg, i64 0, i64 %79
  %81 = getelementptr inbounds %"struct.std::pair", ptr %80, i32 0, i32 0
  %82 = load i32, ptr %81, align 4, !tbaa !11
  %83 = load i32, ptr %9, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [4019 x %"struct.std::pair"], ptr @seg, i64 0, i64 %84
  %86 = getelementptr inbounds %"struct.std::pair", ptr %85, i32 0, i32 0
  %87 = load i32, ptr %86, align 4, !tbaa !11
  %88 = add nsw i32 %87, %82
  store i32 %88, ptr %86, align 4, !tbaa !11
  br label %97

89:                                               ; preds = %62
  %90 = load i32, ptr %13, align 4, !tbaa !5
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds [4019 x %"struct.std::pair"], ptr @seg, i64 0, i64 %91
  %93 = load i32, ptr %9, align 4, !tbaa !5
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds [4019 x %"struct.std::pair"], ptr @seg, i64 0, i64 %94
  %96 = call noundef nonnull align 4 dereferenceable(12) ptr @_ZNSt4pairIi5PointEaSERKS1_(ptr noundef nonnull align 4 dereferenceable(12) %95, ptr noundef nonnull align 4 dereferenceable(12) %92)
  br label %97

97:                                               ; preds = %89, %70
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %98

98:                                               ; preds = %97, %21
  %99 = load i32, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  ret i32 %99
}

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

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

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 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 = { 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 = { 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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTSSt4pairIi5PointE", !6, i64 0, !13, i64 4}
!13 = !{!"_ZTS5Point", !6, i64 0, !6, i64 4}


; 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, %struct.Point }
%struct.Point = type { i32, i32 }

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

; Function Attrs: mustprogress 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 @_Z6segIdxii(i32 noundef, i32 noundef) local_unnamed_addr #1

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z6segAddiiiRK5Point(i32 noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef nonnull align 4 dereferenceable(8) %3) local_unnamed_addr #2 {
  %5 = alloca %"struct.std::pair", align 4
  %6 = alloca i32, align 4
  %7 = tail call noundef i32 @_Z6segIdxii(i32 noundef %0, i32 noundef %1)
  %8 = icmp eq i32 %0, %1
  br i1 %8, label %9, label %13

9:                                                ; preds = %4
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #3
  store i32 1, ptr %6, align 4, !tbaa !5
  call void @_ZNSt4pairIi5PointEC2IiRKS0_TnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS6_S7_EEEbE4typeELb1EEEOS6_OS7_(ptr noundef nonnull align 4 dereferenceable(12) %5, ptr noundef nonnull align 4 dereferenceable(4) %6, ptr noundef nonnull align 4 dereferenceable(8) %3)
  %10 = sext i32 %7 to i64
  %11 = getelementptr inbounds [4019 x %"struct.std::pair"], ptr @seg, i64 0, i64 %10
  %12 = call noundef nonnull align 4 dereferenceable(12) ptr @_ZNSt4pairIi5PointEaSEOS1_(ptr noundef nonnull align 4 dereferenceable(12) %11, ptr noundef nonnull align 4 dereferenceable(12) %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %5) #3
  br label %44

13:                                               ; preds = %4
  %14 = add nsw i32 %1, %0
  %15 = ashr i32 %14, 1
  %.not = icmp slt i32 %15, %2
  %16 = add nsw i32 %15, 1
  br i1 %.not, label %20, label %17

17:                                               ; preds = %13
  %18 = tail call noundef i32 @_Z6segAddiiiRK5Point(i32 noundef %0, i32 noundef %15, i32 noundef %2, ptr noundef nonnull align 4 dereferenceable(8) %3)
  %19 = tail call noundef i32 @_Z6segIdxii(i32 noundef %16, i32 noundef %1)
  br label %23

20:                                               ; preds = %13
  %21 = tail call noundef i32 @_Z6segIdxii(i32 noundef %0, i32 noundef %15)
  %22 = tail call noundef i32 @_Z6segAddiiiRK5Point(i32 noundef %16, i32 noundef %1, i32 noundef %2, ptr noundef nonnull align 4 dereferenceable(8) %3)
  br label %23

23:                                               ; preds = %20, %17
  %24 = phi i32 [ %18, %17 ], [ %21, %20 ]
  %25 = phi i32 [ %19, %17 ], [ %22, %20 ]
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [4019 x %"struct.std::pair"], ptr @seg, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !9
  %.not35 = icmp eq i32 %28, 0
  br i1 %.not35, label %38, label %29

29:                                               ; preds = %23
  %30 = sext i32 %7 to i64
  %31 = getelementptr inbounds [4019 x %"struct.std::pair"], ptr @seg, i64 0, i64 %30
  %32 = tail call noundef nonnull align 4 dereferenceable(12) ptr @_ZNSt4pairIi5PointEaSERKS1_(ptr noundef nonnull align 4 dereferenceable(12) %31, ptr noundef nonnull align 4 dereferenceable(12) %27)
  %33 = sext i32 %24 to i64
  %34 = getelementptr inbounds [4019 x %"struct.std::pair"], ptr @seg, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !9
  %36 = load i32, ptr %31, align 4, !tbaa !9
  %37 = add nsw i32 %36, %35
  store i32 %37, ptr %31, align 4, !tbaa !9
  br label %44

38:                                               ; preds = %23
  %39 = sext i32 %24 to i64
  %40 = getelementptr inbounds [4019 x %"struct.std::pair"], ptr @seg, i64 0, i64 %39
  %41 = sext i32 %7 to i64
  %42 = getelementptr inbounds [4019 x %"struct.std::pair"], ptr @seg, i64 0, i64 %41
  %43 = tail call noundef nonnull align 4 dereferenceable(12) ptr @_ZNSt4pairIi5PointEaSERKS1_(ptr noundef nonnull align 4 dereferenceable(12) %42, ptr noundef nonnull align 4 dereferenceable(12) %40)
  br label %44

44:                                               ; preds = %29, %38, %9
  ret i32 %7
}

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

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

attributes #0 = { mustprogress 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 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTSSt4pairIi5PointE", !6, i64 0, !11, i64 4}
!11 = !{!"_ZTS5Point", !6, i64 0, !6, i64 4}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass