; LLVM IR from bqi343/cp-notebook :: Contests/USACO Solutions/2011-12/Feb/12 Feb G2.ll (Z3colSt4pairIiiES0_)

; 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 { %"struct.std::pair.3", i32 }
%"struct.std::pair.3" = type { i32, i32 }

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt4pairIiiEC2IiiTnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS3_S4_EEEbE4typeELb1EEEOS3_OS4_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) unnamed_addr #1 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 nounwind uwtable
declare dso_local noundef i32 @_ZSt5__gcdIiET_S0_S0_(i32 noundef, i32 noundef) #1

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

; Function Attrs: mustprogress uwtable
define dso_local { i64, i32 } @_Z3colSt4pairIiiES0_(i64 %0, i64 %1) #3 {
  %3 = alloca %"struct.std::pair", align 4
  %4 = alloca %"struct.std::pair.3", align 4
  %5 = alloca %"struct.std::pair.3", align 4
  %6 = alloca %"struct.std::pair.3", align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca { i64, i32 }, align 8
  store i64 %0, ptr %4, align 4
  store i64 %1, ptr %5, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %12 = getelementptr inbounds %"struct.std::pair.3", ptr %5, i32 0, i32 0
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = getelementptr inbounds %"struct.std::pair.3", ptr %4, i32 0, i32 0
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = sub nsw i32 %13, %15
  store i32 %16, ptr %7, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %17 = getelementptr inbounds %"struct.std::pair.3", ptr %5, i32 0, i32 1
  %18 = load i32, ptr %17, align 4, !tbaa !11
  %19 = getelementptr inbounds %"struct.std::pair.3", ptr %4, i32 0, i32 1
  %20 = load i32, ptr %19, align 4, !tbaa !11
  %21 = sub nsw i32 %18, %20
  store i32 %21, ptr %8, align 4, !tbaa !10
  call void @_ZNSt4pairIiiEC2IiiTnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS3_S4_EEEbE4typeELb1EEEOS3_OS4_(ptr noundef nonnull align 4 dereferenceable(8) %6, ptr noundef nonnull align 4 dereferenceable(4) %7, ptr noundef nonnull align 4 dereferenceable(4) %8)
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %22 = getelementptr inbounds %"struct.std::pair.3", ptr %6, i32 0, i32 0
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = getelementptr inbounds %"struct.std::pair.3", ptr %6, i32 0, i32 1
  %25 = load i32, ptr %24, align 4, !tbaa !11
  %26 = call noundef i32 @_ZSt5__gcdIiET_S0_S0_(i32 noundef %23, i32 noundef %25)
  store i32 %26, ptr %9, align 4, !tbaa !10
  %27 = load i32, ptr %9, align 4, !tbaa !10
  %28 = getelementptr inbounds %"struct.std::pair.3", ptr %6, i32 0, i32 0
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = sdiv i32 %29, %27
  store i32 %30, ptr %28, align 4, !tbaa !5
  %31 = load i32, ptr %9, align 4, !tbaa !10
  %32 = getelementptr inbounds %"struct.std::pair.3", ptr %6, i32 0, i32 1
  %33 = load i32, ptr %32, align 4, !tbaa !11
  %34 = sdiv i32 %33, %31
  store i32 %34, ptr %32, align 4, !tbaa !11
  %35 = getelementptr inbounds %"struct.std::pair.3", ptr %6, i32 0, i32 0
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = icmp slt i32 %36, 0
  br i1 %37, label %46, label %38

38:                                               ; preds = %2
  %39 = getelementptr inbounds %"struct.std::pair.3", ptr %6, i32 0, i32 0
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = icmp eq i32 %40, 0
  br i1 %41, label %42, label %53

42:                                               ; preds = %38
  %43 = getelementptr inbounds %"struct.std::pair.3", ptr %6, i32 0, i32 1
  %44 = load i32, ptr %43, align 4, !tbaa !11
  %45 = icmp slt i32 %44, 0
  br i1 %45, label %46, label %53

46:                                               ; preds = %42, %2
  %47 = getelementptr inbounds %"struct.std::pair.3", ptr %6, i32 0, i32 0
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = mul nsw i32 %48, -1
  store i32 %49, ptr %47, align 4, !tbaa !5
  %50 = getelementptr inbounds %"struct.std::pair.3", ptr %6, i32 0, i32 1
  %51 = load i32, ptr %50, align 4, !tbaa !11
  %52 = mul nsw i32 %51, -1
  store i32 %52, ptr %50, align 4, !tbaa !11
  br label %53

53:                                               ; preds = %46, %42, %38
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %54 = getelementptr inbounds %"struct.std::pair.3", ptr %6, i32 0, i32 1
  %55 = load i32, ptr %54, align 4, !tbaa !11
  %56 = getelementptr inbounds %"struct.std::pair.3", ptr %4, i32 0, i32 0
  %57 = load i32, ptr %56, align 4, !tbaa !5
  %58 = mul nsw i32 %55, %57
  %59 = mul nsw i32 %58, 2
  %60 = getelementptr inbounds %"struct.std::pair.3", ptr %6, i32 0, i32 0
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = getelementptr inbounds %"struct.std::pair.3", ptr %4, i32 0, i32 1
  %63 = load i32, ptr %62, align 4, !tbaa !11
  %64 = mul nsw i32 %61, %63
  %65 = mul nsw i32 %64, 2
  %66 = sub nsw i32 %59, %65
  store i32 %66, ptr %10, align 4, !tbaa !10
  call void @_ZNSt4pairIS_IiiEiEC2IRS0_iTnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS5_S6_EEEbE4typeELb1EEEOS5_OS6_(ptr noundef nonnull align 4 dereferenceable(12) %3, ptr noundef nonnull align 4 dereferenceable(8) %6, ptr noundef nonnull align 4 dereferenceable(4) %10)
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %11, ptr align 4 %3, i64 12, i1 false)
  %67 = load { i64, i32 }, ptr %11, align 8
  ret { i64, i32 } %67
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !7, i64 0}
!6 = !{!"_ZTSSt4pairIiiE", !7, i64 0, !7, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!7, !7, i64 0}
!11 = !{!6, !7, 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 { %"struct.std::pair.3", i32 }
%"struct.std::pair.3" = type { i32, i32 }

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt4pairIiiEC2IiiTnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS3_S4_EEEbE4typeELb1EEEOS3_OS4_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) unnamed_addr #1 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
declare dso_local noundef i32 @_ZSt5__gcdIiET_S0_S0_(i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local { i64, i32 } @_Z3colSt4pairIiiES0_(i64 %0, i64 %1) local_unnamed_addr #1 {
  %3 = alloca %"struct.std::pair", align 8
  %4 = alloca %"struct.std::pair.3", align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %.sroa.06.0.extract.trunc = trunc i64 %0 to i32
  %.sroa.3.0.extract.shift = lshr i64 %0, 32
  %.sroa.3.0.extract.trunc = trunc nuw i64 %.sroa.3.0.extract.shift to i32
  %.sroa.04.0.extract.trunc = trunc i64 %1 to i32
  %.sroa.25.0.extract.shift = lshr i64 %1, 32
  %.sroa.25.0.extract.trunc = trunc nuw i64 %.sroa.25.0.extract.shift to i32
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #2
  %8 = sub nsw i32 %.sroa.04.0.extract.trunc, %.sroa.06.0.extract.trunc
  store i32 %8, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #2
  %9 = sub nsw i32 %.sroa.25.0.extract.trunc, %.sroa.3.0.extract.trunc
  store i32 %9, ptr %6, align 4, !tbaa !5
  call void @_ZNSt4pairIiiEC2IiiTnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS3_S4_EEEbE4typeELb1EEEOS3_OS4_(ptr noundef nonnull align 4 dereferenceable(8) %4, ptr noundef nonnull align 4 dereferenceable(4) %5, ptr noundef nonnull align 4 dereferenceable(4) %6)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #2
  %10 = load i32, ptr %4, align 4, !tbaa !9
  %11 = getelementptr inbounds i8, ptr %4, i64 4
  %12 = load i32, ptr %11, align 4, !tbaa !11
  %13 = call noundef i32 @_ZSt5__gcdIiET_S0_S0_(i32 noundef %10, i32 noundef %12)
  %14 = load i32, ptr %4, align 4, !tbaa !9
  %15 = sdiv i32 %14, %13
  store i32 %15, ptr %4, align 4, !tbaa !9
  %16 = load i32, ptr %11, align 4, !tbaa !11
  %17 = sdiv i32 %16, %13
  store i32 %17, ptr %11, align 4, !tbaa !11
  %18 = icmp slt i32 %15, 0
  br i1 %18, label %22, label %19

19:                                               ; preds = %2
  %20 = icmp eq i32 %15, 0
  %21 = icmp slt i32 %17, 0
  %or.cond = select i1 %20, i1 %21, i1 false
  br i1 %or.cond, label %22, label %25

22:                                               ; preds = %19, %2
  %23 = sub nsw i32 0, %15
  store i32 %23, ptr %4, align 4, !tbaa !9
  %24 = sub nsw i32 0, %17
  store i32 %24, ptr %11, align 4, !tbaa !11
  br label %25

25:                                               ; preds = %22, %19
  %26 = phi i32 [ %23, %22 ], [ %15, %19 ]
  %27 = phi i32 [ %24, %22 ], [ %17, %19 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #2
  %28 = mul nsw i32 %27, %.sroa.06.0.extract.trunc
  %29 = mul nsw i32 %26, %.sroa.3.0.extract.trunc
  %30 = sub nsw i32 %28, %29
  %31 = shl nsw i32 %30, 1
  store i32 %31, ptr %7, align 4, !tbaa !5
  call void @_ZNSt4pairIS_IiiEiEC2IRS0_iTnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS5_S6_EEEbE4typeELb1EEEOS5_OS6_(ptr noundef nonnull align 4 dereferenceable(12) %3, ptr noundef nonnull align 4 dereferenceable(8) %4, ptr noundef nonnull align 4 dereferenceable(4) %7)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #2
  %.sroa.0.0.copyload = load i64, ptr %3, align 8
  %.sroa.2.0..sroa_idx = getelementptr inbounds i8, ptr %3, i64 8
  %.sroa.2.0.copyload = load i32, ptr %.sroa.2.0..sroa_idx, align 8
  %.fca.0.insert = insertvalue { i64, i32 } poison, i64 %.sroa.0.0.copyload, 0
  %.fca.1.insert = insertvalue { i64, i32 } %.fca.0.insert, i32 %.sroa.2.0.copyload, 1
  ret { i64, i32 } %.fca.1.insert
}

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 = !{!"_ZTSSt4pairIiiE", !6, i64 0, !6, i64 4}
!11 = !{!10, !6, i64 4}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass