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

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

@.str.1 = external hidden unnamed_addr constant [83 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [26 x i8], align 1
@__PRETTY_FUNCTION__._ZN12b2TOIMinHeap6SetKeyEif = external hidden unnamed_addr constant [40 x i8], align 1

; 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN12b2TOIMinHeap6SetKeyEif(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1, float noundef %2) #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca float, align 4
  %7 = alloca i8, align 1
  %8 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store float %2, ptr %6, align 4, !tbaa !11
  %9 = load ptr, ptr %4, align 8
  %10 = load i32, ptr %5, align 4, !tbaa !9
  %11 = icmp sge i32 %10, 0
  br i1 %11, label %12, label %17

12:                                               ; preds = %3
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = getelementptr inbounds %class.b2TOIMinHeap, ptr %9, i32 0, i32 0
  %15 = load i32, ptr %14, align 8, !tbaa !13
  %16 = icmp slt i32 %13, %15
  br label %17

17:                                               ; preds = %12, %3
  %18 = phi i1 [ false, %3 ], [ %16, %12 ]
  br i1 %18, label %19, label %20

19:                                               ; preds = %17
  br label %22

20:                                               ; preds = %17
  call void @__assert_fail(ptr noundef @.str.8, ptr noundef @.str.1, i32 noundef 786, ptr noundef @__PRETTY_FUNCTION__._ZN12b2TOIMinHeap6SetKeyEif) #3
  unreachable

21:                                               ; No predecessors!
  br label %22

22:                                               ; preds = %21, %19
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #4
  %23 = load float, ptr %6, align 4, !tbaa !11
  %24 = getelementptr inbounds %class.b2TOIMinHeap, ptr %9, i32 0, i32 2
  %25 = load ptr, ptr %24, align 8, !tbaa !15
  %26 = load i32, ptr %5, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds %struct.b2HeapNode, ptr %25, i64 %27
  %29 = getelementptr inbounds %struct.b2HeapNode, ptr %28, i32 0, i32 0
  %30 = load float, ptr %29, align 8, !tbaa !16
  %31 = fcmp olt float %23, %30
  %32 = zext i1 %31 to i8
  store i8 %32, ptr %7, align 1, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #4
  %33 = load float, ptr %6, align 4, !tbaa !11
  %34 = getelementptr inbounds %class.b2TOIMinHeap, ptr %9, i32 0, i32 2
  %35 = load ptr, ptr %34, align 8, !tbaa !15
  %36 = load i32, ptr %5, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds %struct.b2HeapNode, ptr %35, i64 %37
  %39 = getelementptr inbounds %struct.b2HeapNode, ptr %38, i32 0, i32 0
  %40 = load float, ptr %39, align 8, !tbaa !16
  %41 = fcmp ogt float %33, %40
  %42 = zext i1 %41 to i8
  store i8 %42, ptr %8, align 1, !tbaa !18
  %43 = load float, ptr %6, align 4, !tbaa !11
  %44 = getelementptr inbounds %class.b2TOIMinHeap, ptr %9, i32 0, i32 2
  %45 = load ptr, ptr %44, align 8, !tbaa !15
  %46 = load i32, ptr %5, align 4, !tbaa !9
  %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 0
  store float %43, ptr %49, align 8, !tbaa !16
  %50 = load i8, ptr %7, align 1, !tbaa !18, !range !20, !noundef !21
  %51 = trunc i8 %50 to i1
  br i1 %51, label %52, label %54

52:                                               ; preds = %22
  %53 = load i32, ptr %5, align 4, !tbaa !9
  call void @_ZN12b2TOIMinHeap9HeapifyUpEi(ptr noundef nonnull align 8 dereferenceable(16) %9, i32 noundef %53)
  br label %60

54:                                               ; preds = %22
  %55 = load i8, ptr %8, align 1, !tbaa !18, !range !20, !noundef !21
  %56 = trunc i8 %55 to i1
  br i1 %56, label %57, label %59

57:                                               ; preds = %54
  %58 = load i32, ptr %5, align 4, !tbaa !9
  call void @_ZN12b2TOIMinHeap11HeapifyDownEi(ptr noundef nonnull align 8 dereferenceable(16) %9, i32 noundef %58)
  br label %59

59:                                               ; preds = %57, %54
  br label %60

60:                                               ; preds = %59, %52
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #4
  ret void
}

attributes #0 = { nocallback nofree nosync 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 }
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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"_ZTS12b2TOIMinHeap", !10, i64 0, !10, i64 4, !6, i64 8}
!15 = !{!14, !6, i64 8}
!16 = !{!17, !12, i64 0}
!17 = !{!"_ZTS10b2HeapNode", !12, i64 0, !10, i64 4, !6, i64 8}
!18 = !{!19, !19, i64 0}
!19 = !{!"bool", !7, i64 0}
!20 = !{i8 0, i8 2}
!21 = !{}


; 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.8 = external hidden unnamed_addr constant [26 x i8], align 1
@__PRETTY_FUNCTION__._ZN12b2TOIMinHeap6SetKeyEif = external hidden unnamed_addr constant [40 x i8], align 1

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN12b2TOIMinHeap6SetKeyEif(ptr noundef nonnull align 8 dereferenceable(16) %0, i32 noundef %1, float noundef %2) local_unnamed_addr #1 align 2 {
  %4 = icmp sgt i32 %1, -1
  %5 = load i32, ptr %0, align 8
  %6 = icmp sgt i32 %5, %1
  %or.cond = select i1 %4, i1 %6, i1 false
  br i1 %or.cond, label %7, label %.critedge

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

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %10 = zext nneg i32 %1 to i64
  %11 = getelementptr inbounds %struct.b2HeapNode, ptr %9, i64 %10
  %12 = load float, ptr %11, align 8, !tbaa !11
  %13 = fcmp ogt float %12, %2
  store float %2, ptr %11, align 8, !tbaa !11
  br i1 %13, label %14, label %15

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

15:                                               ; preds = %7
  %16 = fcmp olt float %12, %2
  br i1 %16, label %17, label %18

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

18:                                               ; preds = %15, %17, %14
  ret void
}

attributes #0 = { 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 #1 = { 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 = { 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, !10, i64 8}
!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 = !{!12, !13, i64 0}
!12 = !{!"_ZTS10b2HeapNode", !13, i64 0, !7, i64 4, !10, i64 8}
!13 = !{!"float", !8, i64 0}


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