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

; 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.b2TOIMinHeap = type { i32, i32, ptr }
%struct.b2HeapNode = type { float, i32, ptr }
%class.b2Contact = type { ptr, ptr, ptr, ptr, ptr, %struct.b2Manifold, i32, i32, float, float, float, float }
%struct.b2Manifold = type { [2 x %struct.b2ManifoldPoint], %struct.b2Vec2, %struct.b2Vec2, i32, i32 }
%struct.b2ManifoldPoint = type { %struct.b2Vec2, float, float, %union.b2ContactID }
%union.b2ContactID = type { i32 }
%struct.b2Vec2 = type { float, float }

; 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: inlinehint mustprogress uwtable
declare dso_local void @_Z6b2FreePv(ptr noundef) #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_Z7b2Alloci(i32 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN12b2TOIMinHeap6InsertEP9b2Contact(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef %1) #3 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca float, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = call noundef float @_ZN9b2Contact12CalculateTOIEv(ptr noundef nonnull align 8 dereferenceable(128) %9)
  store float %10, ptr %5, align 4, !tbaa !9
  %11 = load float, ptr %5, align 4, !tbaa !9
  %12 = fcmp olt float %11, 1.000000e+00
  br i1 %12, label %13, label %70

13:                                               ; preds = %2
  %14 = getelementptr inbounds %class.b2TOIMinHeap, ptr %8, i32 0, i32 0
  %15 = load i32, ptr %14, align 8, !tbaa !11
  %16 = getelementptr inbounds %class.b2TOIMinHeap, ptr %8, i32 0, i32 1
  %17 = load i32, ptr %16, align 4, !tbaa !14
  %18 = icmp eq i32 %15, %17
  br i1 %18, label %19, label %40

19:                                               ; preds = %13
  %20 = getelementptr inbounds %class.b2TOIMinHeap, ptr %8, i32 0, i32 1
  %21 = load i32, ptr %20, align 4, !tbaa !14
  %22 = mul nsw i32 %21, 2
  store i32 %22, ptr %20, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %23 = getelementptr inbounds %class.b2TOIMinHeap, ptr %8, i32 0, i32 2
  %24 = load ptr, ptr %23, align 8, !tbaa !15
  store ptr %24, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %class.b2TOIMinHeap, ptr %8, i32 0, i32 1
  %26 = load i32, ptr %25, align 4, !tbaa !14
  %27 = sext i32 %26 to i64
  %28 = mul i64 %27, 16
  %29 = trunc i64 %28 to i32
  %30 = call noundef ptr @_Z7b2Alloci(i32 noundef %29)
  %31 = getelementptr inbounds %class.b2TOIMinHeap, ptr %8, i32 0, i32 2
  store ptr %30, ptr %31, align 8, !tbaa !15
  %32 = getelementptr inbounds %class.b2TOIMinHeap, ptr %8, i32 0, i32 2
  %33 = load ptr, ptr %32, align 8, !tbaa !15
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %class.b2TOIMinHeap, ptr %8, i32 0, i32 0
  %36 = load i32, ptr %35, align 8, !tbaa !11
  %37 = sext i32 %36 to i64
  %38 = mul i64 %37, 16
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %33, ptr align 8 %34, i64 %38, i1 false)
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_Z6b2FreePv(ptr noundef %39)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  br label %40

40:                                               ; preds = %19, %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %41 = getelementptr inbounds %class.b2TOIMinHeap, ptr %8, i32 0, i32 0
  %42 = load i32, ptr %41, align 8, !tbaa !11
  store i32 %42, ptr %7, align 4, !tbaa !16
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %class.b2TOIMinHeap, ptr %8, i32 0, i32 2
  %45 = load ptr, ptr %44, align 8, !tbaa !15
  %46 = load i32, ptr %7, align 4, !tbaa !16
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds %struct.b2HeapNode, ptr %45, i64 %47
  %49 = getelementptr inbounds %struct.b2HeapNode, ptr %48, i32 0, i32 2
  store ptr %43, ptr %49, align 8, !tbaa !17
  %50 = load float, ptr %5, align 4, !tbaa !9
  %51 = getelementptr inbounds %class.b2TOIMinHeap, ptr %8, i32 0, i32 2
  %52 = load ptr, ptr %51, align 8, !tbaa !15
  %53 = load i32, ptr %7, align 4, !tbaa !16
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds %struct.b2HeapNode, ptr %52, i64 %54
  %56 = getelementptr inbounds %struct.b2HeapNode, ptr %55, i32 0, i32 0
  store float %50, ptr %56, align 8, !tbaa !19
  %57 = getelementptr inbounds %class.b2TOIMinHeap, ptr %8, i32 0, i32 2
  %58 = load ptr, ptr %57, align 8, !tbaa !15
  %59 = load i32, ptr %7, align 4, !tbaa !16
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds %struct.b2HeapNode, ptr %58, i64 %60
  %62 = getelementptr inbounds %struct.b2HeapNode, ptr %61, i32 0, i32 1
  store i32 0, ptr %62, align 4, !tbaa !20
  %63 = load i32, ptr %7, align 4, !tbaa !16
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %class.b2Contact, ptr %64, i32 0, i32 7
  store i32 %63, ptr %65, align 4, !tbaa !21
  %66 = getelementptr inbounds %class.b2TOIMinHeap, ptr %8, i32 0, i32 0
  %67 = load i32, ptr %66, align 8, !tbaa !11
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %66, align 8, !tbaa !11
  %69 = load i32, ptr %7, align 4, !tbaa !16
  call void @_ZN12b2TOIMinHeap9HeapifyUpEi(ptr noundef nonnull align 8 dereferenceable(16) %8, i32 noundef %69)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %70

70:                                               ; preds = %40, %2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  ret void
}

declare noundef float @_ZN9b2Contact12CalculateTOIEv(ptr noundef nonnull align 8 dereferenceable(128)) #4

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN12b2TOIMinHeap9HeapifyUpEi(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 = { inlinehint 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 = { 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 = { "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 #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 = !{!"float", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTS12b2TOIMinHeap", !13, i64 0, !13, i64 4, !6, i64 8}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !13, i64 4}
!15 = !{!12, !6, i64 8}
!16 = !{!13, !13, i64 0}
!17 = !{!18, !6, i64 8}
!18 = !{!"_ZTS10b2HeapNode", !10, i64 0, !13, i64 4, !6, i64 8}
!19 = !{!18, !10, i64 0}
!20 = !{!18, !13, i64 4}
!21 = !{!22, !13, i64 108}
!22 = !{!"_ZTS9b2Contact", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !23, i64 40, !13, i64 104, !13, i64 108, !10, i64 112, !10, i64 116, !10, i64 120, !10, i64 124}
!23 = !{!"_ZTS10b2Manifold", !7, i64 0, !24, i64 40, !24, i64 48, !25, i64 56, !13, i64 60}
!24 = !{!"_ZTS6b2Vec2", !10, i64 0, !10, i64 4}
!25 = !{!"_ZTSN10b2Manifold4TypeE", !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.b2HeapNode = type { float, i32, ptr }

; 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: inlinehint mustprogress uwtable
declare dso_local void @_Z6b2FreePv(ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_Z7b2Alloci(i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN12b2TOIMinHeap6InsertEP9b2Contact(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull %1) local_unnamed_addr #2 align 2 {
  %3 = tail call noundef float @_ZN9b2Contact12CalculateTOIEv(ptr noundef nonnull align 8 dereferenceable(128) %1)
  %4 = fcmp olt float %3, 1.000000e+00
  br i1 %4, label %5, label %29

5:                                                ; preds = %2
  %6 = load i32, ptr %0, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 4
  %8 = load i32, ptr %7, align 4, !tbaa !11
  %9 = icmp eq i32 %6, %8
  br i1 %9, label %10, label %19

10:                                               ; preds = %5
  %11 = shl nsw i32 %6, 1
  store i32 %11, ptr %7, align 4, !tbaa !11
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = load ptr, ptr %12, align 8, !tbaa !12
  %14 = shl i32 %6, 5
  %15 = tail call noundef ptr @_Z7b2Alloci(i32 noundef %14)
  store ptr %15, ptr %12, align 8, !tbaa !12
  %16 = load i32, ptr %0, align 8, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = shl nsw i64 %17, 4
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 8 %15, ptr align 8 %13, i64 %18, i1 false)
  tail call void @_Z6b2FreePv(ptr noundef %13)
  %.pre = load i32, ptr %0, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %10, %5
  %20 = phi i32 [ %.pre, %10 ], [ %6, %5 ]
  %21 = getelementptr inbounds i8, ptr %0, i64 8
  %22 = load ptr, ptr %21, align 8, !tbaa !12
  %23 = sext i32 %20 to i64
  %24 = getelementptr inbounds %struct.b2HeapNode, ptr %22, i64 %23, i32 2
  store ptr %1, ptr %24, align 8, !tbaa !13
  %25 = getelementptr inbounds %struct.b2HeapNode, ptr %22, i64 %23
  store float %3, ptr %25, align 8, !tbaa !16
  %26 = getelementptr inbounds %struct.b2HeapNode, ptr %22, i64 %23, i32 1
  store i32 0, ptr %26, align 4, !tbaa !17
  %27 = getelementptr inbounds i8, ptr %1, i64 108
  store i32 %20, ptr %27, align 4, !tbaa !18
  %28 = add nsw i32 %20, 1
  store i32 %28, ptr %0, align 8, !tbaa !5
  tail call void @_ZN12b2TOIMinHeap9HeapifyUpEi(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %20)
  br label %29

29:                                               ; preds = %19, %2
  ret void
}

declare noundef float @_ZN9b2Contact12CalculateTOIEv(ptr noundef nonnull align 8 dereferenceable(128)) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN12b2TOIMinHeap9HeapifyUpEi(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 = { inlinehint 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 #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 = { "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, !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, !7, i64 4}
!12 = !{!6, !10, i64 8}
!13 = !{!14, !10, i64 8}
!14 = !{!"_ZTS10b2HeapNode", !15, i64 0, !7, i64 4, !10, i64 8}
!15 = !{!"float", !8, i64 0}
!16 = !{!14, !15, i64 0}
!17 = !{!14, !7, i64 4}
!18 = !{!19, !7, i64 108}
!19 = !{!"_ZTS9b2Contact", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !20, i64 40, !7, i64 104, !7, i64 108, !15, i64 112, !15, i64 116, !15, i64 120, !15, i64 124}
!20 = !{!"_ZTS10b2Manifold", !8, i64 0, !21, i64 40, !21, i64 48, !22, i64 56, !7, i64 60}
!21 = !{!"_ZTS6b2Vec2", !15, i64 0, !15, i64 4}
!22 = !{!"_ZTSN10b2Manifold4TypeE", !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass