; LLVM IR from gem5/gem5 :: ext/systemc/src/sysc/utils/sc_hash.ll (ZN7sc_core13sc_phash_base6removeEPKvPPvS4_)

; 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.sc_core::sc_phash_elem" = type { ptr, ptr, ptr }
%"class.sc_core::sc_phash_base" = type { ptr, i32, i32, i32, i32, double, ptr, ptr, ptr }

@.str.1 = external hidden unnamed_addr constant [82 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [13 x i8], align 1
@__PRETTY_FUNCTION__._ZN7sc_core13sc_phash_base6removeEPKvPPvS4_ = external hidden unnamed_addr constant [67 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: mustprogress nounwind uwtable
declare dso_local void @_ZN7sc_core13sc_phash_elemD2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7sc_core13sc_phash_elemdlEPvm(ptr noundef, i64 noundef) #1 align 2

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7sc_core13sc_phash_base6removeEPKvPPvS4_(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #2 align 2 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  %14 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = call noundef i32 @_ZNK7sc_core13sc_phash_base7do_hashEPKv(ptr noundef nonnull align 8 dereferenceable(56) %14, ptr noundef %15)
  store i32 %16, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %17 = load i32, ptr %10, align 4, !tbaa !9
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = call noundef ptr @_ZNK7sc_core13sc_phash_base10find_entryEjPKvPPPNS_13sc_phash_elemE(ptr noundef nonnull align 8 dereferenceable(56) %14, i32 noundef %17, ptr noundef %18, ptr noundef %11)
  store ptr %19, ptr %12, align 8, !tbaa !5
  %20 = load ptr, ptr %12, align 8, !tbaa !5
  %21 = icmp eq ptr %20, null
  br i1 %21, label %22, label %25

22:                                               ; preds = %4
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr null, ptr %23, align 8, !tbaa !5
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr null, ptr %24, align 8, !tbaa !5
  store i32 0, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %54

25:                                               ; preds = %4
  %26 = load ptr, ptr %12, align 8, !tbaa !5
  %27 = getelementptr inbounds %"class.sc_core::sc_phash_elem", ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %28, ptr %29, align 8, !tbaa !5
  %30 = load ptr, ptr %12, align 8, !tbaa !5
  %31 = getelementptr inbounds %"class.sc_core::sc_phash_elem", ptr %30, i32 0, i32 1
  %32 = load ptr, ptr %31, align 8, !tbaa !13
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %32, ptr %33, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %25
  %35 = load ptr, ptr %11, align 8, !tbaa !5
  %36 = load ptr, ptr %35, align 8, !tbaa !5
  %37 = load ptr, ptr %12, align 8, !tbaa !5
  %38 = icmp eq ptr %36, %37
  br i1 %38, label %39, label %40

39:                                               ; preds = %34
  br label %42

40:                                               ; preds = %34
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 350, ptr noundef @__PRETTY_FUNCTION__._ZN7sc_core13sc_phash_base6removeEPKvPPvS4_) #5
  unreachable

41:                                               ; No predecessors!
  br label %42

42:                                               ; preds = %41, %39
  %43 = load ptr, ptr %12, align 8, !tbaa !5
  %44 = getelementptr inbounds %"class.sc_core::sc_phash_elem", ptr %43, i32 0, i32 2
  %45 = load ptr, ptr %44, align 8, !tbaa !14
  %46 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %45, ptr %46, align 8, !tbaa !5
  %47 = load ptr, ptr %12, align 8, !tbaa !5
  %48 = icmp eq ptr %47, null
  br i1 %48, label %50, label %49

49:                                               ; preds = %42
  call void @_ZN7sc_core13sc_phash_elemD2Ev(ptr noundef nonnull align 8 dereferenceable(24) %47) #4
  call void @_ZN7sc_core13sc_phash_elemdlEPvm(ptr noundef %47, i64 noundef 24) #4
  br label %50

50:                                               ; preds = %49, %42
  %51 = getelementptr inbounds %"class.sc_core::sc_phash_base", ptr %14, i32 0, i32 2
  %52 = load i32, ptr %51, align 4, !tbaa !15
  %53 = add nsw i32 %52, -1
  store i32 %53, ptr %51, align 4, !tbaa !15
  store i32 1, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %54

54:                                               ; preds = %50, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  %55 = load i32, ptr %5, align 4
  ret i32 %55
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 "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 }
attributes #5 = { 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, !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, !6, i64 0}
!12 = !{!"_ZTSN7sc_core13sc_phash_elemE", !6, i64 0, !6, i64 8, !6, i64 16}
!13 = !{!12, !6, i64 8}
!14 = !{!12, !6, i64 16}
!15 = !{!16, !10, i64 12}
!16 = !{!"_ZTSN7sc_core13sc_phash_baseE", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !17, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!17 = !{!"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"

@.str.1 = external hidden unnamed_addr constant [82 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [13 x i8], align 1
@__PRETTY_FUNCTION__._ZN7sc_core13sc_phash_base6removeEPKvPPvS4_ = external hidden unnamed_addr constant [67 x i8], align 1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7sc_core13sc_phash_elemD2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN7sc_core13sc_phash_elemdlEPvm(ptr noundef, i64 noundef) local_unnamed_addr #1 align 2

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 2) i32 @_ZN7sc_core13sc_phash_base6removeEPKvPPvS4_(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef %1, ptr nocapture noundef writeonly %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #2 align 2 {
  %5 = alloca ptr, align 8
  %6 = tail call noundef i32 @_ZNK7sc_core13sc_phash_base7do_hashEPKv(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef %1)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  %7 = call noundef ptr @_ZNK7sc_core13sc_phash_base10find_entryEjPKvPPPNS_13sc_phash_elemE(ptr noundef nonnull align 8 dereferenceable(56) %0, i32 noundef %6, ptr noundef %1, ptr noundef nonnull %5)
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %10

9:                                                ; preds = %4
  store ptr null, ptr %2, align 8, !tbaa !5
  store ptr null, ptr %3, align 8, !tbaa !5
  br label %24

10:                                               ; preds = %4
  %11 = load ptr, ptr %7, align 8, !tbaa !9
  store ptr %11, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %7, i64 8
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  store ptr %13, ptr %3, align 8, !tbaa !5
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = load ptr, ptr %14, align 8, !tbaa !5
  %16 = icmp eq ptr %15, %7
  br i1 %16, label %18, label %17

17:                                               ; preds = %10
  call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 350, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN7sc_core13sc_phash_base6removeEPKvPPvS4_) #5
  unreachable

18:                                               ; preds = %10
  %19 = getelementptr inbounds i8, ptr %7, i64 16
  %20 = load ptr, ptr %19, align 8, !tbaa !12
  store ptr %20, ptr %14, align 8, !tbaa !5
  call void @_ZN7sc_core13sc_phash_elemD2Ev(ptr noundef nonnull align 8 dereferenceable(24) %7) #4
  call void @_ZN7sc_core13sc_phash_elemdlEPvm(ptr noundef nonnull %7, i64 noundef 24) #4
  %21 = getelementptr inbounds i8, ptr %0, i64 12
  %22 = load i32, ptr %21, align 4, !tbaa !13
  %23 = add nsw i32 %22, -1
  store i32 %23, ptr %21, align 4, !tbaa !13
  br label %24

24:                                               ; preds = %18, %9
  %.0 = phi i32 [ 0, %9 ], [ 1, %18 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  ret i32 %.0
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 "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 }
attributes #5 = { 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTSN7sc_core13sc_phash_elemE", !6, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!10, !6, i64 8}
!12 = !{!10, !6, i64 16}
!13 = !{!14, !15, i64 12}
!14 = !{!"_ZTSN7sc_core13sc_phash_baseE", !6, i64 0, !15, i64 8, !15, i64 12, !15, i64 16, !15, i64 20, !16, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!15 = !{!"int", !7, i64 0}
!16 = !{!"double", !7, i64 0}


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