; LLVM IR from iksha-rudra/Computational-Geometry :: CGAlgorithms/DataStructures/minheap.ll (ZN7MinHeap10extractMinER5PointRd)

; 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.MinHeap::Node" = type { %class.Point, double }
%class.Point = type { i32, i32 }
%class.MinHeap = type <{ %"class.std::vector", i32, [4 x i8] }>
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<MinHeap::Node, std::allocator<MinHeap::Node>>::_Vector_impl" }
%"struct.std::_Vector_base<MinHeap::Node, std::allocator<MinHeap::Node>>::_Vector_impl" = type { %"struct.std::_Vector_base<MinHeap::Node, std::allocator<MinHeap::Node>>::_Vector_impl_data" }
%"struct.std::_Vector_base<MinHeap::Node, std::allocator<MinHeap::Node>>::_Vector_impl_data" = type { ptr, ptr, ptr }

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN7MinHeap10extractMinER5PointRd(ptr noundef nonnull align 8 dereferenceable(28) %0, ptr noundef nonnull align 4 dereferenceable(8) %1, ptr noundef nonnull align 8 dereferenceable(8) %2) #0 align 2 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca %"struct.MinHeap::Node", align 8
  %9 = alloca %class.Point, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %11 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #5
  call void @_ZN5PointC1Eii(ptr noundef nonnull align 4 dereferenceable(8) %9, i32 noundef -1, i32 noundef -1)
  %12 = load i64, ptr %9, align 4
  call void @_ZN7MinHeap4NodeC2E5Pointi(ptr noundef nonnull align 8 dereferenceable(16) %8, i64 %12, i32 noundef -1)
  %13 = getelementptr inbounds %class.MinHeap, ptr %11, i32 0, i32 1
  %14 = load i32, ptr %13, align 8, !tbaa !9
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %17, label %16

16:                                               ; preds = %3
  store i1 false, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %38

17:                                               ; preds = %3
  %18 = getelementptr inbounds %class.MinHeap, ptr %11, i32 0, i32 0
  %19 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN7MinHeap4NodeESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %18, i64 noundef 0) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %8, ptr align 8 %19, i64 16, i1 false), !tbaa.struct !16
  %20 = getelementptr inbounds %class.MinHeap, ptr %11, i32 0, i32 1
  %21 = load i32, ptr %20, align 8, !tbaa !9
  %22 = add nsw i32 %21, -1
  store i32 %22, ptr %20, align 8, !tbaa !9
  %23 = getelementptr inbounds %class.MinHeap, ptr %11, i32 0, i32 0
  %24 = getelementptr inbounds %class.MinHeap, ptr %11, i32 0, i32 1
  %25 = load i32, ptr %24, align 8, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN7MinHeap4NodeESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %23, i64 noundef %26) #5
  %28 = getelementptr inbounds %class.MinHeap, ptr %11, i32 0, i32 0
  %29 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN7MinHeap4NodeESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %28, i64 noundef 0) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %29, ptr align 8 %27, i64 16, i1 false), !tbaa.struct !16
  %30 = getelementptr inbounds %class.MinHeap, ptr %11, i32 0, i32 1
  %31 = load i32, ptr %30, align 8, !tbaa !9
  call void @_ZN7MinHeap7heapifyEii(ptr noundef nonnull align 8 dereferenceable(28) %11, i32 noundef 0, i32 noundef %31)
  br label %32

32:                                               ; preds = %17
  %33 = getelementptr inbounds %"struct.MinHeap::Node", ptr %8, i32 0, i32 0
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %34, ptr align 8 %33, i64 8, i1 false), !tbaa.struct !20
  %35 = getelementptr inbounds %"struct.MinHeap::Node", ptr %8, i32 0, i32 1
  %36 = load double, ptr %35, align 8, !tbaa !21
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  store double %36, ptr %37, align 8, !tbaa !18
  store i1 true, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %38

38:                                               ; preds = %32, %16
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #5
  %39 = load i1, ptr %4, align 1
  ret i1 %39
}

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

declare void @_ZN5PointC1Eii(ptr noundef nonnull align 4 dereferenceable(8), i32 noundef, i32 noundef) unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7MinHeap4NodeC2E5Pointi(ptr noundef nonnull align 8 dereferenceable(16), i64, i32 noundef) unnamed_addr #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN7MinHeap4NodeESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #3 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) #4

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7MinHeap7heapifyEii(ptr noundef nonnull align 8 dereferenceable(28), i32 noundef, i32 noundef) #0 align 2

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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, !15, i64 24}
!10 = !{!"_ZTS7MinHeap", !11, i64 0, !15, i64 24}
!11 = !{!"_ZTSSt6vectorIN7MinHeap4NodeESaIS1_EE", !12, i64 0}
!12 = !{!"_ZTSSt12_Vector_baseIN7MinHeap4NodeESaIS1_EE", !13, i64 0}
!13 = !{!"_ZTSNSt12_Vector_baseIN7MinHeap4NodeESaIS1_EE12_Vector_implE", !14, i64 0}
!14 = !{!"_ZTSNSt12_Vector_baseIN7MinHeap4NodeESaIS1_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!15 = !{!"int", !7, i64 0}
!16 = !{i64 0, i64 4, !17, i64 4, i64 4, !17, i64 8, i64 8, !18}
!17 = !{!15, !15, i64 0}
!18 = !{!19, !19, i64 0}
!19 = !{!"double", !7, i64 0}
!20 = !{i64 0, i64 4, !17, i64 4, i64 4, !17}
!21 = !{!22, !19, i64 8}
!22 = !{!"_ZTSN7MinHeap4NodeE", !23, i64 0, !19, i64 8}
!23 = !{!"_ZTS5Point", !15, i64 0, !15, i64 4}


; 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.MinHeap::Node" = type { %class.Point, double }
%class.Point = type { i32, i32 }

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN7MinHeap10extractMinER5PointRd(ptr noundef nonnull align 8 dereferenceable(28) %0, ptr nocapture noundef nonnull writeonly align 4 dereferenceable(8) %1, ptr nocapture noundef nonnull writeonly align 8 dereferenceable(8) %2) local_unnamed_addr #0 align 2 {
  %4 = alloca %"struct.MinHeap::Node", align 8
  %5 = alloca %class.Point, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #5
  call void @_ZN5PointC1Eii(ptr noundef nonnull align 4 dereferenceable(8) %5, i32 noundef -1, i32 noundef -1)
  %6 = load i64, ptr %5, align 8
  call void @_ZN7MinHeap4NodeC2E5Pointi(ptr noundef nonnull align 8 dereferenceable(16) %4, i64 %6, i32 noundef -1)
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  %8 = load i32, ptr %7, align 8, !tbaa !5
  %.not = icmp ne i32 %8, 0
  br i1 %.not, label %9, label %20

9:                                                ; preds = %3
  %10 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN7MinHeap4NodeESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef 0) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %4, ptr noundef nonnull align 8 dereferenceable(16) %10, i64 16, i1 false), !tbaa.struct !15
  %11 = load i32, ptr %7, align 8, !tbaa !5
  %12 = add nsw i32 %11, -1
  store i32 %12, ptr %7, align 8, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN7MinHeap4NodeESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %13) #5
  %15 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorIN7MinHeap4NodeESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef 0) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %15, ptr noundef nonnull align 8 dereferenceable(16) %14, i64 16, i1 false), !tbaa.struct !15
  %16 = load i32, ptr %7, align 8, !tbaa !5
  call void @_ZN7MinHeap7heapifyEii(ptr noundef nonnull align 8 dereferenceable(28) %0, i32 noundef 0, i32 noundef %16)
  %17 = load i64, ptr %4, align 8
  store i64 %17, ptr %1, align 4
  %18 = getelementptr inbounds i8, ptr %4, i64 8
  %19 = load double, ptr %18, align 8, !tbaa !19
  store double %19, ptr %2, align 8, !tbaa !17
  br label %20

20:                                               ; preds = %3, %9
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #5
  ret i1 %.not
}

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

declare void @_ZN5PointC1Eii(ptr noundef nonnull align 4 dereferenceable(8), i32 noundef, i32 noundef) unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7MinHeap4NodeC2E5Pointi(ptr noundef nonnull align 8 dereferenceable(16), i64, i32 noundef) unnamed_addr #3 align 2

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

; Function Attrs: mustprogress 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) #4

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7MinHeap7heapifyEii(ptr noundef nonnull align 8 dereferenceable(28), i32 noundef, i32 noundef) local_unnamed_addr #0 align 2

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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, !14, i64 24}
!6 = !{!"_ZTS7MinHeap", !7, i64 0, !14, i64 24}
!7 = !{!"_ZTSSt6vectorIN7MinHeap4NodeESaIS1_EE", !8, i64 0}
!8 = !{!"_ZTSSt12_Vector_baseIN7MinHeap4NodeESaIS1_EE", !9, i64 0}
!9 = !{!"_ZTSNSt12_Vector_baseIN7MinHeap4NodeESaIS1_EE12_Vector_implE", !10, i64 0}
!10 = !{!"_ZTSNSt12_Vector_baseIN7MinHeap4NodeESaIS1_EE17_Vector_impl_dataE", !11, i64 0, !11, i64 8, !11, i64 16}
!11 = !{!"any pointer", !12, i64 0}
!12 = !{!"omnipotent char", !13, i64 0}
!13 = !{!"Simple C++ TBAA"}
!14 = !{!"int", !12, i64 0}
!15 = !{i64 0, i64 4, !16, i64 4, i64 4, !16, i64 8, i64 8, !17}
!16 = !{!14, !14, i64 0}
!17 = !{!18, !18, i64 0}
!18 = !{!"double", !12, i64 0}
!19 = !{!20, !18, i64 8}
!20 = !{!"_ZTSN7MinHeap4NodeE", !21, i64 0, !18, i64 8}
!21 = !{!"_ZTS5Point", !14, i64 0, !14, i64 4}


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