; LLVM IR from ADJA/algos :: Geometry/ConvexHull.ll (Z12getPerimeterSt6vectorI5pointSaIS0_EE)

; 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 { double, double }

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorI5pointSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorI5pointSaIS0_EE4backEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorI5pointSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_Z4dist5pointS_(double, double, double, double) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_Z12getPerimeterSt6vectorI5pointSaIS0_EE(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca double, align 8
  %4 = alloca i32, align 4
  %5 = alloca %struct.point, align 8
  %6 = alloca %struct.point, align 8
  %7 = alloca %struct.point, align 8
  %8 = alloca %struct.point, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  store double 0.000000e+00, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 1, ptr %4, align 4, !tbaa !11
  br label %9

9:                                                ; preds = %34, %1
  %10 = load i32, ptr %4, align 4, !tbaa !11
  %11 = call noundef i64 @_ZNKSt6vectorI5pointSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #3
  %12 = trunc i64 %11 to i32
  %13 = icmp slt i32 %10, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %37

15:                                               ; preds = %9
  %16 = load i32, ptr %4, align 4, !tbaa !11
  %17 = sub nsw i32 %16, 1
  %18 = sext i32 %17 to i64
  %19 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorI5pointSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %18) #3
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %5, ptr align 8 %19, i64 16, i1 false), !tbaa.struct !13
  %20 = load i32, ptr %4, align 4, !tbaa !11
  %21 = sext i32 %20 to i64
  %22 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorI5pointSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %21) #3
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %6, ptr align 8 %22, i64 16, i1 false), !tbaa.struct !13
  %23 = getelementptr inbounds { double, double }, ptr %5, i32 0, i32 0
  %24 = load double, ptr %23, align 8
  %25 = getelementptr inbounds { double, double }, ptr %5, i32 0, i32 1
  %26 = load double, ptr %25, align 8
  %27 = getelementptr inbounds { double, double }, ptr %6, i32 0, i32 0
  %28 = load double, ptr %27, align 8
  %29 = getelementptr inbounds { double, double }, ptr %6, i32 0, i32 1
  %30 = load double, ptr %29, align 8
  %31 = call noundef double @_Z4dist5pointS_(double %24, double %26, double %28, double %30)
  %32 = load double, ptr %3, align 8, !tbaa !9
  %33 = fadd double %32, %31
  store double %33, ptr %3, align 8, !tbaa !9
  br label %34

34:                                               ; preds = %15
  %35 = load i32, ptr %4, align 4, !tbaa !11
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %4, align 4, !tbaa !11
  br label %9, !llvm.loop !14

37:                                               ; preds = %14
  %38 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorI5pointSaIS0_EE4backEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #3
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %7, ptr align 8 %38, i64 16, i1 false), !tbaa.struct !13
  %39 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorI5pointSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef 0) #3
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %8, ptr align 8 %39, i64 16, i1 false), !tbaa.struct !13
  %40 = getelementptr inbounds { double, double }, ptr %7, i32 0, i32 0
  %41 = load double, ptr %40, align 8
  %42 = getelementptr inbounds { double, double }, ptr %7, i32 0, i32 1
  %43 = load double, ptr %42, align 8
  %44 = getelementptr inbounds { double, double }, ptr %8, i32 0, i32 0
  %45 = load double, ptr %44, align 8
  %46 = getelementptr inbounds { double, double }, ptr %8, i32 0, i32 1
  %47 = load double, ptr %46, align 8
  %48 = call noundef double @_Z4dist5pointS_(double %41, double %43, double %45, double %47)
  %49 = load double, ptr %3, align 8, !tbaa !9
  %50 = fadd double %49, %48
  store double %50, ptr %3, align 8, !tbaa !9
  %51 = load double, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret double %51
}

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


; 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 nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorI5pointSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorI5pointSaIS0_EE4backEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorI5pointSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_Z4dist5pointS_(double, double, double, double) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_Z12getPerimeterSt6vectorI5pointSaIS0_EE(ptr noundef nonnull %0) local_unnamed_addr #0 {
  %2 = tail call noundef i64 @_ZNKSt6vectorI5pointSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #1
  %3 = trunc i64 %2 to i32
  %4 = icmp sgt i32 %3, 1
  br i1 %4, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %1
  %.0.lcssa = phi double [ 0.000000e+00, %1 ], [ %13, %.lr.ph ]
  %5 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorI5pointSaIS0_EE4backEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #1
  %.sroa.01.0.copyload = load double, ptr %5, align 8, !tbaa !5
  %.sroa.22.0..sroa_idx = getelementptr inbounds i8, ptr %5, i64 8
  %.sroa.22.0.copyload = load double, ptr %.sroa.22.0..sroa_idx, align 8, !tbaa !5
  %6 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorI5pointSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef 0) #1
  %.sroa.0.0.copyload = load double, ptr %6, align 8, !tbaa !5
  %.sroa.2.0..sroa_idx = getelementptr inbounds i8, ptr %6, i64 8
  %.sroa.2.0.copyload = load double, ptr %.sroa.2.0..sroa_idx, align 8, !tbaa !5
  %7 = tail call noundef double @_Z4dist5pointS_(double %.sroa.01.0.copyload, double %.sroa.22.0.copyload, double %.sroa.0.0.copyload, double %.sroa.2.0.copyload)
  %8 = fadd double %.0.lcssa, %7
  ret double %8

.lr.ph:                                           ; preds = %1, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %1 ]
  %.014 = phi double [ %13, %.lr.ph ], [ 0.000000e+00, %1 ]
  %9 = add nsw i64 %indvars.iv, -1
  %10 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorI5pointSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %9) #1
  %.sroa.05.0.copyload = load double, ptr %10, align 8, !tbaa !5
  %.sroa.26.0..sroa_idx = getelementptr inbounds i8, ptr %10, i64 8
  %.sroa.26.0.copyload = load double, ptr %.sroa.26.0..sroa_idx, align 8, !tbaa !5
  %11 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorI5pointSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %indvars.iv) #1
  %.sroa.03.0.copyload = load double, ptr %11, align 8, !tbaa !5
  %.sroa.24.0..sroa_idx = getelementptr inbounds i8, ptr %11, i64 8
  %.sroa.24.0.copyload = load double, ptr %.sroa.24.0..sroa_idx, align 8, !tbaa !5
  %12 = tail call noundef double @_Z4dist5pointS_(double %.sroa.05.0.copyload, double %.sroa.26.0.copyload, double %.sroa.03.0.copyload, double %.sroa.24.0.copyload)
  %13 = fadd double %.014, %12
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %14 = tail call noundef i64 @_ZNKSt6vectorI5pointSaIS0_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %0) #1
  %sext = shl i64 %14, 32
  %15 = ashr exact i64 %sext, 32
  %16 = icmp slt i64 %indvars.iv.next, %15
  br i1 %16, label %.lr.ph, label %._crit_edge, !llvm.loop !9
}

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 = { 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass