; LLVM IR from jrouwe/JoltPhysics :: Jolt/Core/Factory.ll (ZN3JPH7Factory8RegisterEPPKNS_4RTTIEj)

; 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.JPH::Factory" = type { %"class.JPH::UnorderedMap", %"class.JPH::UnorderedMap.0" }
%"class.JPH::UnorderedMap" = type { %"class.JPH::HashTable.base", [4 x i8] }
%"class.JPH::HashTable.base" = type <{ ptr, ptr, i32, i32, i32 }>
%"class.JPH::UnorderedMap.0" = type { %"class.JPH::HashTable.base.2", [4 x i8] }
%"class.JPH::HashTable.base.2" = type <{ ptr, ptr, i32, i32, i32 }>

; 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: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN3JPH7Factory8RegisterEPKNS_4RTTIE(ptr noundef nonnull align 8 dereferenceable(64), ptr noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN3JPH7Factory8RegisterEPPKNS_4RTTIEj(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef %1, i32 noundef %2) #1 align 2 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  %10 = load ptr, ptr %5, align 8
  %11 = getelementptr inbounds %"class.JPH::Factory", ptr %10, i32 0, i32 1
  %12 = getelementptr inbounds %"class.JPH::Factory", ptr %10, i32 0, i32 1
  %13 = call noundef i32 @_ZNK3JPH9HashTableIjSt4pairIjPKNS_4RTTIEENS_18UnorderedMapDetailIjS4_EENS_4HashIjEESt8equal_toIjEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(28) %12)
  %14 = load i32, ptr %7, align 4, !tbaa !9
  %15 = add i32 %13, %14
  call void @_ZN3JPH9HashTableIjSt4pairIjPKNS_4RTTIEENS_18UnorderedMapDetailIjS4_EENS_4HashIjEESt8equal_toIjEE7reserveEj(ptr noundef nonnull align 8 dereferenceable(28) %11, i32 noundef %15)
  %16 = getelementptr inbounds %"class.JPH::Factory", ptr %10, i32 0, i32 0
  %17 = getelementptr inbounds %"class.JPH::Factory", ptr %10, i32 0, i32 0
  %18 = call noundef i32 @_ZNK3JPH9HashTableISt17basic_string_viewIcSt11char_traitsIcEESt4pairIS4_PKNS_4RTTIEENS_18UnorderedMapDetailIS4_S8_EENS_4HashIS4_EESt8equal_toIS4_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(28) %17)
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = add i32 %18, %19
  call void @_ZN3JPH9HashTableISt17basic_string_viewIcSt11char_traitsIcEESt4pairIS4_PKNS_4RTTIEENS_18UnorderedMapDetailIS4_S8_EENS_4HashIS4_EESt8equal_toIS4_EE7reserveEj(ptr noundef nonnull align 8 dereferenceable(28) %16, i32 noundef %20)
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %21, ptr %8, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %36, %3
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds ptr, ptr %24, i64 %26
  %28 = icmp ult ptr %23, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %22
  store i32 2, ptr %9, align 4
  br label %39

30:                                               ; preds = %22
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = load ptr, ptr %31, align 8, !tbaa !5
  %33 = call noundef zeroext i1 @_ZN3JPH7Factory8RegisterEPKNS_4RTTIE(ptr noundef nonnull align 8 dereferenceable(64) %10, ptr noundef %32)
  br i1 %33, label %35, label %34

34:                                               ; preds = %30
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %39

35:                                               ; preds = %30
  br label %36

36:                                               ; preds = %35
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = getelementptr inbounds ptr, ptr %37, i32 1
  store ptr %38, ptr %8, align 8, !tbaa !5
  br label %22, !llvm.loop !11

39:                                               ; preds = %34, %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %40 = load i32, ptr %9, align 4
  switch i32 %40, label %44 [
    i32 2, label %41
    i32 1, label %42
  ]

41:                                               ; preds = %39
  store i1 true, ptr %4, align 1
  br label %42

42:                                               ; preds = %41, %39
  %43 = load i1, ptr %4, align 1
  ret i1 %43

44:                                               ; preds = %39
  unreachable
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK3JPH9HashTableIjSt4pairIjPKNS_4RTTIEENS_18UnorderedMapDetailIjS4_EENS_4HashIjEESt8equal_toIjEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(28)) #2 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK3JPH9HashTableISt17basic_string_viewIcSt11char_traitsIcEESt4pairIS4_PKNS_4RTTIEENS_18UnorderedMapDetailIS4_S8_EENS_4HashIS4_EESt8equal_toIS4_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(28)) #2 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #3 = { 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN3JPH7Factory8RegisterEPKNS_4RTTIE(ptr noundef nonnull align 8 dereferenceable(64), ptr noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN3JPH7Factory8RegisterEPPKNS_4RTTIEj(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef readonly %1, i32 noundef %2) local_unnamed_addr #0 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 32
  %5 = tail call noundef i32 @_ZNK3JPH9HashTableIjSt4pairIjPKNS_4RTTIEENS_18UnorderedMapDetailIjS4_EENS_4HashIjEESt8equal_toIjEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(28) %4)
  %6 = add i32 %5, %2
  tail call void @_ZN3JPH9HashTableIjSt4pairIjPKNS_4RTTIEENS_18UnorderedMapDetailIjS4_EENS_4HashIjEESt8equal_toIjEE7reserveEj(ptr noundef nonnull align 8 dereferenceable(28) %4, i32 noundef %6)
  %7 = tail call noundef i32 @_ZNK3JPH9HashTableISt17basic_string_viewIcSt11char_traitsIcEESt4pairIS4_PKNS_4RTTIEENS_18UnorderedMapDetailIS4_S8_EENS_4HashIS4_EESt8equal_toIS4_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(28) %0)
  %8 = add i32 %7, %2
  tail call void @_ZN3JPH9HashTableISt17basic_string_viewIcSt11char_traitsIcEESt4pairIS4_PKNS_4RTTIEENS_18UnorderedMapDetailIS4_S8_EENS_4HashIS4_EESt8equal_toIS4_EE7reserveEj(ptr noundef nonnull align 8 dereferenceable(28) %0, i32 noundef %8)
  %9 = zext i32 %2 to i64
  %10 = getelementptr inbounds ptr, ptr %1, i64 %9
  %11 = icmp eq i32 %2, 0
  br i1 %11, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.01012 = phi ptr [ %14, %.lr.ph ], [ %1, %3 ]
  %12 = load ptr, ptr %.01012, align 8, !tbaa !5
  %13 = tail call noundef zeroext i1 @_ZN3JPH7Factory8RegisterEPKNS_4RTTIE(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr noundef %12)
  %14 = getelementptr inbounds i8, ptr %.01012, i64 8
  %.not = icmp ult ptr %14, %10
  %or.cond = select i1 %13, i1 %.not, i1 false
  br i1 %or.cond, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %3
  %.lcssa = phi i1 [ true, %3 ], [ %13, %.lr.ph ]
  ret i1 %.lcssa
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK3JPH9HashTableIjSt4pairIjPKNS_4RTTIEENS_18UnorderedMapDetailIjS4_EENS_4HashIjEESt8equal_toIjEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(28)) local_unnamed_addr #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK3JPH9HashTableISt17basic_string_viewIcSt11char_traitsIcEESt4pairIS4_PKNS_4RTTIEENS_18UnorderedMapDetailIS4_S8_EENS_4HashIS4_EESt8equal_toIS4_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(28)) local_unnamed_addr #1 align 2

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

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass