; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/198 Division 2/Problem B/B.ll (Z3ccwSt4pairIiiES0_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 { i32, i32 }

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

35:                                               ; preds = %3
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %42

36:                                               ; preds = %3
  %37 = load i32, ptr %8, align 4, !tbaa !11
  %38 = icmp slt i32 %37, 0
  br i1 %38, label %39, label %40

39:                                               ; preds = %36
  store i32 1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %42

40:                                               ; preds = %36
  br label %41

41:                                               ; preds = %40
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %42

42:                                               ; preds = %41, %39, %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %43 = load i32, ptr %4, align 4
  ret i32 %43
}

; 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 = !{!"_ZTSSt4pairIiiE", !7, i64 0, !7, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 4}
!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(i32 -1, 2) i32 @_Z3ccwSt4pairIiiES0_S0_(i64 %0, i64 %1, i64 %2) local_unnamed_addr #0 {
  %.sroa.04.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.02.0.extract.trunc = trunc i64 %1 to i32
  %.sroa.23.0.extract.shift = lshr i64 %1, 32
  %.sroa.23.0.extract.trunc = trunc nuw i64 %.sroa.23.0.extract.shift to i32
  %.sroa.0.0.extract.trunc = trunc i64 %2 to i32
  %.sroa.2.0.extract.shift = lshr i64 %2, 32
  %.sroa.2.0.extract.trunc = trunc nuw i64 %.sroa.2.0.extract.shift to i32
  %4 = sub nsw i32 %.sroa.02.0.extract.trunc, %.sroa.04.0.extract.trunc
  %5 = sub nsw i32 %.sroa.2.0.extract.trunc, %.sroa.3.0.extract.trunc
  %6 = mul nsw i32 %5, %4
  %7 = sub nsw i32 %.sroa.23.0.extract.trunc, %.sroa.3.0.extract.trunc
  %.neg = sub i32 %.sroa.04.0.extract.trunc, %.sroa.0.0.extract.trunc
  %.neg9 = mul i32 %.neg, %7
  %8 = add i32 %6, %.neg9
  %9 = icmp sgt i32 %8, 0
  %.lobit = lshr i32 %8, 31
  %.0 = select i1 %9, i32 -1, i32 %.lobit
  ret i32 %.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