; LLVM IR from bqi343/cp-notebook :: Contests/Other Solutions/VT HSPC/2017/Criss-Cross.ll (Z8simplifySt4pairIS_IxxExE)

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z8simplifySt4pairIS_IxxExE(ptr dead_on_unwind noalias writable sret(%"struct.std::pair.0") align 8 %0, ptr noundef byval(%"struct.std::pair.0") align 8 %1) #0 {
  %3 = alloca i64, align 8
  %4 = getelementptr inbounds %"struct.std::pair.0", ptr %1, i32 0, i32 1
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = icmp slt i64 %5, 0
  br i1 %6, label %7, label %19

7:                                                ; preds = %2
  %8 = getelementptr inbounds %"struct.std::pair.0", ptr %1, i32 0, i32 0
  %9 = getelementptr inbounds %"struct.std::pair", ptr %8, i32 0, i32 0
  %10 = load i64, ptr %9, align 8, !tbaa !11
  %11 = mul nsw i64 %10, -1
  store i64 %11, ptr %9, align 8, !tbaa !11
  %12 = getelementptr inbounds %"struct.std::pair.0", ptr %1, i32 0, i32 0
  %13 = getelementptr inbounds %"struct.std::pair", ptr %12, i32 0, i32 1
  %14 = load i64, ptr %13, align 8, !tbaa !12
  %15 = mul nsw i64 %14, -1
  store i64 %15, ptr %13, align 8, !tbaa !12
  %16 = getelementptr inbounds %"struct.std::pair.0", ptr %1, i32 0, i32 1
  %17 = load i64, ptr %16, align 8, !tbaa !5
  %18 = mul nsw i64 %17, -1
  store i64 %18, ptr %16, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %7, %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %20 = getelementptr inbounds %"struct.std::pair.0", ptr %1, i32 0, i32 0
  %21 = getelementptr inbounds %"struct.std::pair", ptr %20, i32 0, i32 0
  %22 = load i64, ptr %21, align 8, !tbaa !11
  %23 = getelementptr inbounds %"struct.std::pair.0", ptr %1, i32 0, i32 0
  %24 = getelementptr inbounds %"struct.std::pair", ptr %23, i32 0, i32 1
  %25 = load i64, ptr %24, align 8, !tbaa !12
  %26 = call noundef i64 @_ZSt5__gcdIxET_S0_S0_(i64 noundef %22, i64 noundef %25)
  %27 = getelementptr inbounds %"struct.std::pair.0", ptr %1, i32 0, i32 1
  %28 = load i64, ptr %27, align 8, !tbaa !5
  %29 = call noundef i64 @_ZSt5__gcdIxET_S0_S0_(i64 noundef %26, i64 noundef %28)
  %30 = call noundef i64 @_ZSt3absx(i64 noundef %29)
  store i64 %30, ptr %3, align 8, !tbaa !13
  %31 = load i64, ptr %3, align 8, !tbaa !13
  %32 = getelementptr inbounds %"struct.std::pair.0", ptr %1, i32 0, i32 0
  %33 = getelementptr inbounds %"struct.std::pair", ptr %32, i32 0, i32 0
  %34 = load i64, ptr %33, align 8, !tbaa !11
  %35 = sdiv i64 %34, %31
  store i64 %35, ptr %33, align 8, !tbaa !11
  %36 = load i64, ptr %3, align 8, !tbaa !13
  %37 = getelementptr inbounds %"struct.std::pair.0", ptr %1, i32 0, i32 0
  %38 = getelementptr inbounds %"struct.std::pair", ptr %37, i32 0, i32 1
  %39 = load i64, ptr %38, align 8, !tbaa !12
  %40 = sdiv i64 %39, %36
  store i64 %40, ptr %38, align 8, !tbaa !12
  %41 = load i64, ptr %3, align 8, !tbaa !13
  %42 = getelementptr inbounds %"struct.std::pair.0", ptr %1, i32 0, i32 1
  %43 = load i64, ptr %42, align 8, !tbaa !5
  %44 = sdiv i64 %43, %41
  store i64 %44, ptr %42, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %0, ptr align 8 %1, i64 24, i1 false)
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZSt3absx(i64 noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZSt5__gcdIxET_S0_S0_(i64 noundef, i64 noundef) #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

; 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 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 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 = { 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, !8, i64 16}
!6 = !{!"_ZTSSt4pairIS_IxxExE", !7, i64 0, !8, i64 16}
!7 = !{!"_ZTSSt4pairIxxE", !8, i64 0, !8, i64 8}
!8 = !{!"long long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!6, !8, i64 0}
!12 = !{!6, !8, i64 8}
!13 = !{!8, !8, i64 0}


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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z8simplifySt4pairIS_IxxExE(ptr dead_on_unwind noalias nocapture writable writeonly sret(%"struct.std::pair.0") align 8 %0, ptr nocapture noundef byval(%"struct.std::pair.0") align 8 %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %1, i64 16
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %5 = icmp slt i64 %4, 0
  %.pre = load i64, ptr %1, align 8, !tbaa !11
  br i1 %5, label %6, label %._crit_edge

._crit_edge:                                      ; preds = %2
  %.phi.trans.insert = getelementptr inbounds i8, ptr %1, i64 8
  %.pre3 = load i64, ptr %.phi.trans.insert, align 8, !tbaa !12
  br label %12

6:                                                ; preds = %2
  %7 = sub nsw i64 0, %.pre
  %8 = getelementptr inbounds i8, ptr %1, i64 8
  %9 = load i64, ptr %8, align 8, !tbaa !12
  %10 = sub nsw i64 0, %9
  %11 = sub nsw i64 0, %4
  br label %12

12:                                               ; preds = %._crit_edge, %6
  %13 = phi i64 [ %11, %6 ], [ %4, %._crit_edge ]
  %14 = phi i64 [ %10, %6 ], [ %.pre3, %._crit_edge ]
  %15 = phi i64 [ %7, %6 ], [ %.pre, %._crit_edge ]
  %16 = getelementptr inbounds i8, ptr %1, i64 8
  %17 = tail call noundef i64 @_ZSt5__gcdIxET_S0_S0_(i64 noundef %15, i64 noundef %14)
  %18 = tail call noundef i64 @_ZSt5__gcdIxET_S0_S0_(i64 noundef %17, i64 noundef %13)
  %19 = tail call noundef i64 @_ZSt3absx(i64 noundef %18)
  %20 = sdiv i64 %15, %19
  store i64 %20, ptr %1, align 8, !tbaa !11
  %21 = sdiv i64 %14, %19
  store i64 %21, ptr %16, align 8, !tbaa !12
  %22 = sdiv i64 %13, %19
  store i64 %22, ptr %3, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(24) %1, i64 24, i1 false)
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZSt3absx(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZSt5__gcdIxET_S0_S0_(i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress 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

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" }
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 nocallback nofree nounwind willreturn memory(argmem: readwrite) }

!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, !8, i64 16}
!6 = !{!"_ZTSSt4pairIS_IxxExE", !7, i64 0, !8, i64 16}
!7 = !{!"_ZTSSt4pairIxxE", !8, i64 0, !8, i64 8}
!8 = !{!"long long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!6, !8, i64 0}
!12 = !{!6, !8, i64 8}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass