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

; 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"

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

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

; 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) #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 uwtable
declare dso_local void @_ZN7MinHeap7heapifyEii(ptr noundef nonnull align 8 dereferenceable(28), i32 noundef, i32 noundef) #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local i64 @_ZN7MinHeap10extractMinEv(ptr noundef nonnull align 8 dereferenceable(28) %0) #3 align 2 {
  %2 = alloca %class.Point, align 4
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = load ptr, ptr %3, align 8
  call void @_ZN5PointC1Eii(ptr noundef nonnull align 4 dereferenceable(8) %2, i32 noundef -1, i32 noundef -1)
  %5 = getelementptr inbounds %class.MinHeap, ptr %4, i32 0, i32 1
  %6 = load i32, ptr %5, align 8, !tbaa !9
  %7 = icmp ne i32 %6, 0
  br i1 %7, label %9, label %8

8:                                                ; preds = %1
  br label %26

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

25:                                               ; preds = %9
  br label %26

26:                                               ; preds = %25, %8
  %27 = load i64, ptr %2, align 4
  ret i64 %27
}

attributes #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 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 = { 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 #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, !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}
!17 = !{!15, !15, i64 0}
!18 = !{i64 0, i64 4, !17, i64 4, i64 4, !17, i64 8, i64 8, !19}
!19 = !{!20, !20, i64 0}
!20 = !{!"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"

%class.Point = type { i32, i32 }

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local i64 @_ZN7MinHeap10extractMinEv(ptr noundef nonnull align 8 dereferenceable(28) %0) local_unnamed_addr #3 align 2 {
  %2 = alloca %class.Point, align 8
  call void @_ZN5PointC1Eii(ptr noundef nonnull align 4 dereferenceable(8) %2, i32 noundef -1, i32 noundef -1)
  %3 = getelementptr inbounds i8, ptr %0, i64 24
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %14, label %5

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

14:                                               ; preds = %1, %5
  %15 = load i64, ptr %2, align 8
  ret i64 %15
}

attributes #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 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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, !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}


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