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

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

; 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 i32 @_ZNK7sc_core13sc_phash_base7do_hashEPKv(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef) #1 align 2

; 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) #1 align 2

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

19:                                               ; preds = %3
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %26

22:                                               ; preds = %19
  %23 = getelementptr inbounds %"class.sc_core::sc_phash_base", ptr %11, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !11
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %24, ptr %25, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %22, %19
  store i32 0, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %36

27:                                               ; preds = %3
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = icmp ne ptr %28, null
  br i1 %29, label %30, label %35

30:                                               ; preds = %27
  %31 = load ptr, ptr %9, align 8, !tbaa !5
  %32 = getelementptr inbounds %"class.sc_core::sc_phash_elem", ptr %31, i32 0, i32 1
  %33 = load ptr, ptr %32, align 8, !tbaa !14
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %33, ptr %34, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %30, %27
  store i32 1, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %36

36:                                               ; preds = %35, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %37 = load i32, ptr %4, align 4
  ret i32 %37
}

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 = { 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_baseE", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !13, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!13 = !{!"double", !7, i64 0}
!14 = !{!15, !6, i64 8}
!15 = !{!"_ZTSN7sc_core13sc_phash_elemE", !6, i64 0, !6, i64 8, !6, i64 16}


; 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 i32 @_ZNK7sc_core13sc_phash_base7do_hashEPKv(ptr noundef nonnull align 8 dereferenceable(56), ptr noundef) local_unnamed_addr #0 align 2

; 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 #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 2) i32 @_ZNK7sc_core13sc_phash_base6lookupEPKvPPv(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef %1, ptr noundef writeonly %2) local_unnamed_addr #0 align 2 {
  %4 = tail call noundef i32 @_ZNK7sc_core13sc_phash_base7do_hashEPKv(ptr noundef nonnull align 8 dereferenceable(56) %0, ptr noundef %1)
  %5 = tail call noundef ptr @_ZNK7sc_core13sc_phash_base10find_entryEjPKvPPPNS_13sc_phash_elemE(ptr noundef nonnull align 8 dereferenceable(56) %0, i32 noundef %4, ptr noundef %1, ptr noundef null)
  %6 = icmp eq ptr %5, null
  %.not12 = icmp eq ptr %2, null
  br i1 %6, label %7, label %8

7:                                                ; preds = %3
  br i1 %.not12, label %12, label %.sink.split

8:                                                ; preds = %3
  br i1 %.not12, label %12, label %9

9:                                                ; preds = %8
  %10 = getelementptr inbounds i8, ptr %5, i64 8
  br label %.sink.split

.sink.split:                                      ; preds = %7, %9
  %.sink13 = phi ptr [ %10, %9 ], [ %0, %7 ]
  %.0.ph = phi i32 [ 1, %9 ], [ 0, %7 ]
  %11 = load ptr, ptr %.sink13, align 8, !tbaa !5
  store ptr %11, ptr %2, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %.sink.split, %8, %7
  %.0 = phi i32 [ 0, %7 ], [ 1, %8 ], [ %.0.ph, %.sink.split ]
  ret i32 %.0
}

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

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


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