; LLVM IR from mtsamis/box2d-optimized :: src/dynamics/b2_world.ll (ZN12b2TOIMinHeap6DeleteEi)

; 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.b2HeapNode = type { float, i32, ptr }
%class.b2TOIMinHeap = type { i32, i32, ptr }

@.str.1 = external hidden unnamed_addr constant [83 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [12 x i8], align 1
@__PRETTY_FUNCTION__._ZN12b2TOIMinHeap6DeleteEi = external hidden unnamed_addr constant [39 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [26 x i8], align 1

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

; 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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local { i64, ptr } @_ZN12b2TOIMinHeap6DeleteEi(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1) #3 align 2 {
  %3 = alloca %struct.b2HeapNode, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %7 = load ptr, ptr %4, align 8
  %8 = getelementptr inbounds %class.b2TOIMinHeap, ptr %7, i32 0, i32 0
  %9 = load i32, ptr %8, align 8, !tbaa !11
  %10 = icmp sgt i32 %9, 0
  br i1 %10, label %11, label %12

11:                                               ; preds = %2
  br label %14

12:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str.7, ptr noundef @.str.1, i32 noundef 752, ptr noundef @__PRETTY_FUNCTION__._ZN12b2TOIMinHeap6DeleteEi) #4
  unreachable

13:                                               ; No predecessors!
  br label %14

14:                                               ; preds = %13, %11
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = icmp sge i32 %15, 0
  br i1 %16, label %17, label %22

17:                                               ; preds = %14
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = getelementptr inbounds %class.b2TOIMinHeap, ptr %7, i32 0, i32 0
  %20 = load i32, ptr %19, align 8, !tbaa !11
  %21 = icmp slt i32 %18, %20
  br label %22

22:                                               ; preds = %17, %14
  %23 = phi i1 [ false, %14 ], [ %21, %17 ]
  br i1 %23, label %24, label %25

24:                                               ; preds = %22
  br label %27

25:                                               ; preds = %22
  call void @__assert_fail(ptr noundef @.str.8, ptr noundef @.str.1, i32 noundef 753, ptr noundef @__PRETTY_FUNCTION__._ZN12b2TOIMinHeap6DeleteEi) #4
  unreachable

26:                                               ; No predecessors!
  br label %27

27:                                               ; preds = %26, %24
  %28 = getelementptr inbounds %class.b2TOIMinHeap, ptr %7, i32 0, i32 2
  %29 = load ptr, ptr %28, align 8, !tbaa !13
  %30 = load i32, ptr %5, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds %struct.b2HeapNode, ptr %29, i64 %31
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %3, ptr align 8 %32, i64 16, i1 false), !tbaa.struct !14
  %33 = getelementptr inbounds %class.b2TOIMinHeap, ptr %7, i32 0, i32 0
  %34 = load i32, ptr %33, align 8, !tbaa !11
  %35 = add nsw i32 %34, -1
  store i32 %35, ptr %33, align 8, !tbaa !11
  %36 = load i32, ptr %5, align 4, !tbaa !9
  %37 = getelementptr inbounds %class.b2TOIMinHeap, ptr %7, i32 0, i32 0
  %38 = load i32, ptr %37, align 8, !tbaa !11
  %39 = icmp ne i32 %36, %38
  br i1 %39, label %40, label %78

40:                                               ; preds = %27
  %41 = getelementptr inbounds %class.b2TOIMinHeap, ptr %7, i32 0, i32 2
  %42 = load ptr, ptr %41, align 8, !tbaa !13
  %43 = getelementptr inbounds %class.b2TOIMinHeap, ptr %7, i32 0, i32 0
  %44 = load i32, ptr %43, align 8, !tbaa !11
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds %struct.b2HeapNode, ptr %42, i64 %45
  %47 = getelementptr inbounds %class.b2TOIMinHeap, ptr %7, i32 0, i32 2
  %48 = load ptr, ptr %47, align 8, !tbaa !13
  %49 = load i32, ptr %5, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds %struct.b2HeapNode, ptr %48, i64 %50
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %51, ptr align 8 %46, i64 16, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %52 = load i32, ptr %5, align 4, !tbaa !9
  %53 = sub nsw i32 %52, 1
  %54 = sdiv i32 %53, 2
  store i32 %54, ptr %6, align 4, !tbaa !9
  %55 = load i32, ptr %5, align 4, !tbaa !9
  %56 = icmp eq i32 %55, 0
  br i1 %56, label %73, label %57

57:                                               ; preds = %40
  %58 = getelementptr inbounds %class.b2TOIMinHeap, ptr %7, i32 0, i32 2
  %59 = load ptr, ptr %58, align 8, !tbaa !13
  %60 = load i32, ptr %6, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds %struct.b2HeapNode, ptr %59, i64 %61
  %63 = getelementptr inbounds %struct.b2HeapNode, ptr %62, i32 0, i32 0
  %64 = load float, ptr %63, align 8, !tbaa !17
  %65 = getelementptr inbounds %class.b2TOIMinHeap, ptr %7, i32 0, i32 2
  %66 = load ptr, ptr %65, align 8, !tbaa !13
  %67 = load i32, ptr %5, align 4, !tbaa !9
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds %struct.b2HeapNode, ptr %66, i64 %68
  %70 = getelementptr inbounds %struct.b2HeapNode, ptr %69, i32 0, i32 0
  %71 = load float, ptr %70, align 8, !tbaa !17
  %72 = fcmp olt float %64, %71
  br i1 %72, label %73, label %75

73:                                               ; preds = %57, %40
  %74 = load i32, ptr %5, align 4, !tbaa !9
  call void @_ZN12b2TOIMinHeap11HeapifyDownEi(ptr noundef nonnull align 8 dereferenceable(16) %7, i32 noundef %74)
  br label %77

75:                                               ; preds = %57
  %76 = load i32, ptr %5, align 4, !tbaa !9
  call void @_ZN12b2TOIMinHeap9HeapifyUpEi(ptr noundef nonnull align 8 dereferenceable(16) %7, i32 noundef %76)
  br label %77

77:                                               ; preds = %75, %73
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %78

78:                                               ; preds = %77, %27
  %79 = load { i64, ptr }, ptr %3, align 8
  ret { i64, ptr } %79
}

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

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

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { noreturn nounwind "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 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 = { noreturn nounwind }
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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_ZTS12b2TOIMinHeap", !10, i64 0, !10, i64 4, !6, i64 8}
!13 = !{!12, !6, i64 8}
!14 = !{i64 0, i64 4, !15, i64 4, i64 4, !9, i64 8, i64 8, !5}
!15 = !{!16, !16, i64 0}
!16 = !{!"float", !7, i64 0}
!17 = !{!18, !16, i64 0}
!18 = !{!"_ZTS10b2HeapNode", !16, i64 0, !10, i64 4, !6, i64 8}


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

@.str.1 = external hidden unnamed_addr constant [83 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [12 x i8], align 1
@__PRETTY_FUNCTION__._ZN12b2TOIMinHeap6DeleteEi = external hidden unnamed_addr constant [39 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [26 x i8], align 1

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local { i64, ptr } @_ZN12b2TOIMinHeap6DeleteEi(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1) local_unnamed_addr #2 align 2 {
  %3 = load i32, ptr %0, align 8, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %6, label %5

5:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str.7, ptr noundef nonnull @.str.1, i32 noundef 752, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN12b2TOIMinHeap6DeleteEi) #3
  unreachable

6:                                                ; preds = %2
  %or.cond = icmp ugt i32 %3, %1
  br i1 %or.cond, label %7, label %.critedge

.critedge:                                        ; preds = %6
  tail call void @__assert_fail(ptr noundef nonnull @.str.8, ptr noundef nonnull @.str.1, i32 noundef 753, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN12b2TOIMinHeap6DeleteEi) #3
  unreachable

7:                                                ; preds = %6
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  %10 = zext nneg i32 %1 to i64
  %11 = getelementptr inbounds %struct.b2HeapNode, ptr %9, i64 %10
  %.sroa.0.0.copyload = load i64, ptr %11, align 8
  %.sroa.2.0..sroa_idx = getelementptr inbounds i8, ptr %11, i64 8
  %.sroa.2.0.copyload = load ptr, ptr %.sroa.2.0..sroa_idx, align 8, !tbaa !12
  %12 = add nsw i32 %3, -1
  store i32 %12, ptr %0, align 8, !tbaa !5
  %.not = icmp eq i32 %12, %1
  br i1 %.not, label %29, label %13

13:                                               ; preds = %7
  %14 = zext nneg i32 %12 to i64
  %15 = getelementptr inbounds %struct.b2HeapNode, ptr %9, i64 %14
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %11, ptr noundef nonnull align 8 dereferenceable(16) %15, i64 16, i1 false), !tbaa.struct !13
  %16 = icmp eq i32 %1, 0
  br i1 %16, label %27, label %17

17:                                               ; preds = %13
  %18 = add nsw i32 %1, -1
  %19 = lshr i32 %18, 1
  %20 = load ptr, ptr %8, align 8, !tbaa !11
  %21 = zext nneg i32 %19 to i64
  %22 = getelementptr inbounds %struct.b2HeapNode, ptr %20, i64 %21
  %23 = load float, ptr %22, align 8, !tbaa !17
  %24 = getelementptr inbounds %struct.b2HeapNode, ptr %20, i64 %10
  %25 = load float, ptr %24, align 8, !tbaa !17
  %26 = fcmp olt float %23, %25
  br i1 %26, label %27, label %28

27:                                               ; preds = %17, %13
  tail call void @_ZN12b2TOIMinHeap11HeapifyDownEi(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1)
  br label %29

28:                                               ; preds = %17
  tail call void @_ZN12b2TOIMinHeap9HeapifyUpEi(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1)
  br label %29

29:                                               ; preds = %27, %28, %7
  %.fca.0.insert = insertvalue { i64, ptr } poison, i64 %.sroa.0.0.copyload, 0
  %.fca.1.insert = insertvalue { i64, ptr } %.fca.0.insert, ptr %.sroa.2.0.copyload, 1
  ret { i64, ptr } %.fca.1.insert
}

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

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

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn nounwind "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 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 = { noreturn 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, !7, i64 0}
!6 = !{!"_ZTS12b2TOIMinHeap", !7, i64 0, !7, i64 4, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!10, !10, i64 0}
!13 = !{i64 0, i64 4, !14, i64 4, i64 4, !16, i64 8, i64 8, !12}
!14 = !{!15, !15, i64 0}
!15 = !{!"float", !8, i64 0}
!16 = !{!7, !7, i64 0}
!17 = !{!18, !15, i64 0}
!18 = !{!"_ZTS10b2HeapNode", !15, i64 0, !7, i64 4, !10, i64 8}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass