; LLVM IR from VAR-solutions/Algorithms :: Mathematics/ConvexHull/cpp (JarvisMarchAlgorithm)

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

55:                                               ; preds = %4
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %16, align 4
  br label %63

56:                                               ; preds = %4
  %57 = load i32, ptr %14, align 4, !tbaa !12
  %58 = load i32, ptr %15, align 4, !tbaa !12
  %59 = icmp eq i32 %57, %58
  br i1 %59, label %60, label %61

60:                                               ; preds = %56
  store i32 0, ptr %5, align 4
  store i32 1, ptr %16, align 4
  br label %63

61:                                               ; preds = %56
  br label %62

62:                                               ; preds = %61
  store i32 1, ptr %5, align 4
  store i32 1, ptr %16, align 4
  br label %63

63:                                               ; preds = %62, %60, %55
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  %64 = load i32, ptr %5, align 4
  ret i32 %64
}

; 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 4}
!10 = !{!"_ZTSSt4pairIiiE", !11, i64 0, !11, i64 4}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, 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 @_ZN10ConvexHull8distanceESt4pairIiiES1_S1_(ptr nocapture noundef nonnull readnone align 1 dereferenceable(1) %0, i64 %1, i64 %2, i64 %3) local_unnamed_addr #0 align 2 {
  %.sroa.014.0.extract.trunc = trunc i64 %1 to i32
  %.sroa.3.0.extract.shift = lshr i64 %1, 32
  %.sroa.3.0.extract.trunc = trunc nuw i64 %.sroa.3.0.extract.shift to i32
  %.sroa.012.0.extract.trunc = trunc i64 %2 to i32
  %.sroa.213.0.extract.shift = lshr i64 %2, 32
  %.sroa.213.0.extract.trunc = trunc nuw i64 %.sroa.213.0.extract.shift to i32
  %.sroa.0.0.extract.trunc = trunc i64 %3 to i32
  %.sroa.2.0.extract.shift = lshr i64 %3, 32
  %.sroa.2.0.extract.trunc = trunc nuw i64 %.sroa.2.0.extract.shift to i32
  %5 = sub nsw i32 %.sroa.3.0.extract.trunc, %.sroa.213.0.extract.trunc
  %6 = sub nsw i32 %.sroa.3.0.extract.trunc, %.sroa.2.0.extract.trunc
  %7 = sub nsw i32 %.sroa.014.0.extract.trunc, %.sroa.012.0.extract.trunc
  %8 = sub nsw i32 %.sroa.014.0.extract.trunc, %.sroa.0.0.extract.trunc
  %9 = mul nsw i32 %5, %5
  %10 = mul nsw i32 %7, %7
  %11 = add nuw nsw i32 %9, %10
  %12 = mul nsw i32 %6, %6
  %13 = mul nsw i32 %8, %8
  %14 = add nuw nsw i32 %12, %13
  %15 = icmp ult i32 %11, %14
  %16 = icmp ne i32 %11, %14
  %. = zext i1 %16 to i32
  %.0 = select i1 %15, 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,SROAPass,SimplifyCFGPass