; LLVM IR from eyangch/competitive-programming :: USACOcontests/silver/2012.12/crazy.ll (Z3CCWSt4pairIxxES0_S0_)

; 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 nounwind uwtable
define dso_local noundef i64 @_Z3CCWSt4pairIxxES0_S0_(i64 %0, i64 %1, i64 %2, i64 %3, i64 %4, i64 %5) #0 {
  %7 = alloca i64, align 8
  %8 = alloca %"struct.std::pair", align 8
  %9 = alloca %"struct.std::pair", align 8
  %10 = alloca %"struct.std::pair", align 8
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  %13 = getelementptr inbounds { i64, i64 }, ptr %8, i32 0, i32 0
  store i64 %0, ptr %13, align 8
  %14 = getelementptr inbounds { i64, i64 }, ptr %8, i32 0, i32 1
  store i64 %1, ptr %14, align 8
  %15 = getelementptr inbounds { i64, i64 }, ptr %9, i32 0, i32 0
  store i64 %2, ptr %15, align 8
  %16 = getelementptr inbounds { i64, i64 }, ptr %9, i32 0, i32 1
  store i64 %3, ptr %16, align 8
  %17 = getelementptr inbounds { i64, i64 }, ptr %10, i32 0, i32 0
  store i64 %4, ptr %17, align 8
  %18 = getelementptr inbounds { i64, i64 }, ptr %10, i32 0, i32 1
  store i64 %5, ptr %18, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %19 = getelementptr inbounds %"struct.std::pair", ptr %9, i32 0, i32 0
  %20 = load i64, ptr %19, align 8, !tbaa !5
  %21 = getelementptr inbounds %"struct.std::pair", ptr %8, i32 0, i32 0
  %22 = load i64, ptr %21, align 8, !tbaa !5
  %23 = sub nsw i64 %20, %22
  %24 = getelementptr inbounds %"struct.std::pair", ptr %10, i32 0, i32 1
  %25 = load i64, ptr %24, align 8, !tbaa !10
  %26 = getelementptr inbounds %"struct.std::pair", ptr %8, i32 0, i32 1
  %27 = load i64, ptr %26, align 8, !tbaa !10
  %28 = sub nsw i64 %25, %27
  %29 = mul nsw i64 %23, %28
  %30 = getelementptr inbounds %"struct.std::pair", ptr %10, i32 0, i32 0
  %31 = load i64, ptr %30, align 8, !tbaa !5
  %32 = getelementptr inbounds %"struct.std::pair", ptr %8, i32 0, i32 0
  %33 = load i64, ptr %32, align 8, !tbaa !5
  %34 = sub nsw i64 %31, %33
  %35 = getelementptr inbounds %"struct.std::pair", ptr %9, i32 0, i32 1
  %36 = load i64, ptr %35, align 8, !tbaa !10
  %37 = getelementptr inbounds %"struct.std::pair", ptr %8, i32 0, i32 1
  %38 = load i64, ptr %37, align 8, !tbaa !10
  %39 = sub nsw i64 %36, %38
  %40 = mul nsw i64 %34, %39
  %41 = sub nsw i64 %29, %40
  store i64 %41, ptr %11, align 8, !tbaa !11
  %42 = load i64, ptr %11, align 8, !tbaa !11
  %43 = icmp slt i64 %42, 0
  br i1 %43, label %44, label %45

44:                                               ; preds = %6
  store i64 -1, ptr %7, align 8
  store i32 1, ptr %12, align 4
  br label %50

45:                                               ; preds = %6
  %46 = load i64, ptr %11, align 8, !tbaa !11
  %47 = icmp sgt i64 %46, 0
  br i1 %47, label %48, label %49

48:                                               ; preds = %45
  store i64 1, ptr %7, align 8
  store i32 1, ptr %12, align 4
  br label %50

49:                                               ; preds = %45
  store i64 0, ptr %7, align 8
  store i32 1, ptr %12, align 4
  br label %50

50:                                               ; preds = %49, %48, %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  %51 = load i64, ptr %7, align 8
  ret i64 %51
}

; 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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !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 = !{!6, !7, i64 8}
!11 = !{!7, !7, 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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local noundef range(i64 -1, 2) i64 @_Z3CCWSt4pairIxxES0_S0_(i64 %0, i64 %1, i64 %2, i64 %3, i64 %4, i64 %5) local_unnamed_addr #0 {
  %7 = sub nsw i64 %2, %0
  %8 = sub nsw i64 %5, %1
  %9 = mul nsw i64 %8, %7
  %10 = sub nsw i64 %4, %0
  %.neg = sub i64 %1, %3
  %.neg9 = mul i64 %10, %.neg
  %11 = add i64 %9, %.neg9
  %.not = icmp ne i64 %11, 0
  %. = zext i1 %.not to i64
  %.inv = icmp sgt i64 %11, -1
  %.0 = select i1 %.inv, i64 %., i64 -1
  ret i64 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) 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)"}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass