; LLVM IR from codeIIEST/Algorithms :: Competitive Coding/Geometry/Convex hull/convex hull jarvis march.ll (Z6closerP5pointiii)

; 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.point = type { i32, i32 }

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; 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) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z6closerP5pointiii(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #2 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca %struct.point, align 4
  %11 = alloca %struct.point, align 4
  %12 = alloca %struct.point, align 4
  %13 = alloca double, align 8
  %14 = alloca double, align 8
  %15 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds %struct.point, ptr %16, i64 %18
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 4 %19, i64 8, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = load i32, ptr %8, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds %struct.point, ptr %20, i64 %22
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %11, ptr align 4 %23, i64 8, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds %struct.point, ptr %24, i64 %26
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %12, ptr align 4 %27, i64 8, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %28 = getelementptr inbounds %struct.point, ptr %10, i32 0, i32 0
  %29 = load i32, ptr %28, align 4, !tbaa !12
  %30 = getelementptr inbounds %struct.point, ptr %11, i32 0, i32 0
  %31 = load i32, ptr %30, align 4, !tbaa !12
  %32 = sub nsw i32 %29, %31
  %33 = getelementptr inbounds %struct.point, ptr %10, i32 0, i32 0
  %34 = load i32, ptr %33, align 4, !tbaa !12
  %35 = getelementptr inbounds %struct.point, ptr %11, i32 0, i32 0
  %36 = load i32, ptr %35, align 4, !tbaa !12
  %37 = sub nsw i32 %34, %36
  %38 = mul nsw i32 %32, %37
  %39 = getelementptr inbounds %struct.point, ptr %10, i32 0, i32 1
  %40 = load i32, ptr %39, align 4, !tbaa !14
  %41 = getelementptr inbounds %struct.point, ptr %11, i32 0, i32 1
  %42 = load i32, ptr %41, align 4, !tbaa !14
  %43 = sub nsw i32 %40, %42
  %44 = getelementptr inbounds %struct.point, ptr %10, i32 0, i32 1
  %45 = load i32, ptr %44, align 4, !tbaa !14
  %46 = getelementptr inbounds %struct.point, ptr %11, i32 0, i32 1
  %47 = load i32, ptr %46, align 4, !tbaa !14
  %48 = sub nsw i32 %45, %47
  %49 = mul nsw i32 %43, %48
  %50 = sub nsw i32 %38, %49
  %51 = call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %50)
  store double %51, ptr %13, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %52 = getelementptr inbounds %struct.point, ptr %10, i32 0, i32 0
  %53 = load i32, ptr %52, align 4, !tbaa !12
  %54 = getelementptr inbounds %struct.point, ptr %12, i32 0, i32 0
  %55 = load i32, ptr %54, align 4, !tbaa !12
  %56 = sub nsw i32 %53, %55
  %57 = getelementptr inbounds %struct.point, ptr %10, i32 0, i32 0
  %58 = load i32, ptr %57, align 4, !tbaa !12
  %59 = getelementptr inbounds %struct.point, ptr %12, i32 0, i32 0
  %60 = load i32, ptr %59, align 4, !tbaa !12
  %61 = sub nsw i32 %58, %60
  %62 = mul nsw i32 %56, %61
  %63 = getelementptr inbounds %struct.point, ptr %10, i32 0, i32 1
  %64 = load i32, ptr %63, align 4, !tbaa !14
  %65 = getelementptr inbounds %struct.point, ptr %12, i32 0, i32 1
  %66 = load i32, ptr %65, align 4, !tbaa !14
  %67 = sub nsw i32 %64, %66
  %68 = getelementptr inbounds %struct.point, ptr %10, i32 0, i32 1
  %69 = load i32, ptr %68, align 4, !tbaa !14
  %70 = getelementptr inbounds %struct.point, ptr %12, i32 0, i32 1
  %71 = load i32, ptr %70, align 4, !tbaa !14
  %72 = sub nsw i32 %69, %71
  %73 = mul nsw i32 %67, %72
  %74 = sub nsw i32 %62, %73
  %75 = call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %74)
  store double %75, ptr %14, align 8, !tbaa !15
  %76 = load double, ptr %13, align 8, !tbaa !15
  %77 = load double, ptr %14, align 8, !tbaa !15
  %78 = fcmp olt double %76, %77
  br i1 %78, label %79, label %81

79:                                               ; preds = %4
  %80 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %80, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %83

81:                                               ; preds = %4
  %82 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %82, ptr %5, align 4
  store i32 1, ptr %15, align 4
  br label %83

83:                                               ; preds = %81, %79
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %84 = load i32, ptr %5, align 4
  ret i32 %84
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #4 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{i64 0, i64 4, !9, i64 4, i64 4, !9}
!12 = !{!13, !10, i64 0}
!13 = !{!"_ZTS5point", !10, i64 0, !10, i64 4}
!14 = !{!13, !10, i64 4}
!15 = !{!16, !16, i64 0}
!16 = !{!"double", !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"

%struct.point = type { i32, i32 }

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z6closerP5pointiii(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = sext i32 %1 to i64
  %6 = getelementptr inbounds %struct.point, ptr %0, i64 %5
  %.sroa.08.0.copyload = load i32, ptr %6, align 4, !tbaa !5
  %.sroa.7.0..sroa_idx = getelementptr inbounds i8, ptr %6, i64 4
  %.sroa.7.0.copyload = load i32, ptr %.sroa.7.0..sroa_idx, align 4, !tbaa !5
  %7 = sext i32 %2 to i64
  %8 = getelementptr inbounds %struct.point, ptr %0, i64 %7
  %.sroa.04.0.copyload = load i32, ptr %8, align 4, !tbaa !5
  %.sroa.56.0..sroa_idx = getelementptr inbounds i8, ptr %8, i64 4
  %.sroa.56.0.copyload = load i32, ptr %.sroa.56.0..sroa_idx, align 4, !tbaa !5
  %9 = sext i32 %3 to i64
  %10 = getelementptr inbounds %struct.point, ptr %0, i64 %9
  %.sroa.0.0.copyload = load i32, ptr %10, align 4, !tbaa !5
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %10, i64 4
  %.sroa.5.0.copyload = load i32, ptr %.sroa.5.0..sroa_idx, align 4, !tbaa !5
  %11 = sub nsw i32 %.sroa.08.0.copyload, %.sroa.04.0.copyload
  %12 = sub nsw i32 %.sroa.7.0.copyload, %.sroa.56.0.copyload
  %add = add nsw i32 %12, %11
  %sub = sub nsw i32 %11, %12
  %13 = mul nsw i32 %add, %sub
  %14 = tail call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %13)
  %15 = sub nsw i32 %.sroa.08.0.copyload, %.sroa.0.0.copyload
  %16 = sub nsw i32 %.sroa.7.0.copyload, %.sroa.5.0.copyload
  %add23 = add nsw i32 %16, %15
  %sub24 = sub nsw i32 %15, %16
  %17 = mul nsw i32 %add23, %sub24
  %18 = tail call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %17)
  %19 = fcmp olt double %14, %18
  %. = select i1 %19, i32 %2, i32 %3
  ret i32 %.
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef) local_unnamed_addr #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 = { 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" }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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