; LLVM IR from FernandoFong/ComputationalGeometry :: ConvexHull/GiftWrapping/GiftWrapping.ll (Z4turnSt4pairIiiES0_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 @_Z4turnSt4pairIiiES0_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
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = 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
  %13 = getelementptr inbounds %"struct.std::pair", ptr %6, i32 0, i32 0
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = getelementptr inbounds %"struct.std::pair", ptr %7, i32 0, i32 1
  %16 = load i32, ptr %15, align 4, !tbaa !10
  %17 = mul nsw i32 %14, %16
  %18 = getelementptr inbounds %"struct.std::pair", ptr %7, i32 0, i32 0
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = getelementptr inbounds %"struct.std::pair", ptr %6, i32 0, i32 1
  %21 = load i32, ptr %20, align 4, !tbaa !10
  %22 = mul nsw i32 %19, %21
  %23 = sub nsw i32 %17, %22
  store i32 %23, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %24 = getelementptr inbounds %"struct.std::pair", ptr %5, i32 0, i32 0
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = getelementptr inbounds %"struct.std::pair", ptr %7, i32 0, i32 1
  %27 = load i32, ptr %26, align 4, !tbaa !10
  %28 = mul nsw i32 %25, %27
  %29 = getelementptr inbounds %"struct.std::pair", ptr %7, i32 0, i32 0
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = getelementptr inbounds %"struct.std::pair", ptr %5, i32 0, i32 1
  %32 = load i32, ptr %31, align 4, !tbaa !10
  %33 = mul nsw i32 %30, %32
  %34 = sub nsw i32 %28, %33
  store i32 %34, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %35 = getelementptr inbounds %"struct.std::pair", ptr %5, i32 0, i32 0
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = getelementptr inbounds %"struct.std::pair", ptr %6, i32 0, i32 1
  %38 = load i32, ptr %37, align 4, !tbaa !10
  %39 = mul nsw i32 %36, %38
  %40 = getelementptr inbounds %"struct.std::pair", ptr %6, i32 0, i32 0
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = getelementptr inbounds %"struct.std::pair", ptr %5, i32 0, i32 1
  %43 = load i32, ptr %42, align 4, !tbaa !10
  %44 = mul nsw i32 %41, %43
  %45 = sub nsw i32 %39, %44
  store i32 %45, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %46 = load i32, ptr %8, align 4, !tbaa !11
  %47 = load i32, ptr %9, align 4, !tbaa !11
  %48 = sub nsw i32 %46, %47
  %49 = load i32, ptr %10, align 4, !tbaa !11
  %50 = add nsw i32 %48, %49
  store i32 %50, ptr %11, align 4, !tbaa !11
  %51 = load i32, ptr %11, align 4, !tbaa !11
  %52 = icmp sgt i32 %51, 0
  br i1 %52, label %53, label %54

53:                                               ; preds = %3
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %59

54:                                               ; preds = %3
  %55 = load i32, ptr %11, align 4, !tbaa !11
  %56 = icmp eq i32 %55, 0
  br i1 %56, label %57, label %58

57:                                               ; preds = %54
  store i32 0, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %59

58:                                               ; preds = %54
  store i32 1, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %59

59:                                               ; preds = %58, %57, %53
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %60 = load i32, ptr %4, align 4
  ret i32 %60
}

; 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 @_Z4turnSt4pairIiiES0_S0_(i64 %0, i64 %1, i64 %2) local_unnamed_addr #0 {
  %.sroa.011.0.extract.trunc = trunc i64 %0 to i32
  %.sroa.313.0.extract.shift = lshr i64 %0, 32
  %.sroa.313.0.extract.trunc = trunc nuw i64 %.sroa.313.0.extract.shift to i32
  %.sroa.07.0.extract.trunc = trunc i64 %1 to i32
  %.sroa.39.0.extract.shift = lshr i64 %1, 32
  %.sroa.39.0.extract.trunc = trunc nuw i64 %.sroa.39.0.extract.shift to i32
  %.sroa.0.0.extract.trunc = trunc i64 %2 to i32
  %.sroa.3.0.extract.shift = lshr i64 %2, 32
  %.sroa.3.0.extract.trunc = trunc nuw i64 %.sroa.3.0.extract.shift to i32
  %4 = mul nsw i32 %.sroa.39.0.extract.trunc, %.sroa.011.0.extract.trunc
  %5 = mul nsw i32 %.sroa.07.0.extract.trunc, %.sroa.313.0.extract.trunc
  %6 = sub nsw i32 %4, %5
  %reass.add = sub i32 %.sroa.07.0.extract.trunc, %.sroa.011.0.extract.trunc
  %reass.mul = mul i32 %reass.add, %.sroa.3.0.extract.trunc
  %reass.add19 = sub i32 %.sroa.313.0.extract.trunc, %.sroa.39.0.extract.trunc
  %reass.mul20 = mul i32 %reass.add19, %.sroa.0.0.extract.trunc
  %7 = add i32 %reass.mul, %6
  %8 = add i32 %7, %reass.mul20
  %9 = icmp sgt i32 %8, 0
  %10 = icmp ne i32 %8, 0
  %. = zext i1 %10 to i32
  %.0 = select i1 %9, i32 -1, i32 %.
  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