; LLVM IR from mitdbg/deneva :: storage/index_hash.ll (ZN12BucketHeader9read_itemEmjRP8itemid_t)

; 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.BucketHeader = type { ptr, i64, i8 }
%class.BucketNode = type { i64, ptr, ptr }

@.str.2 = external hidden unnamed_addr constant [70 x i8], align 1
@stdout = external global ptr, align 8
@.str.5 = external hidden unnamed_addr constant [29 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [21 x i8], align 1
@__PRETTY_FUNCTION__._ZN12BucketHeader9read_itemEmjRP8itemid_t = external hidden unnamed_addr constant [63 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
define dso_local void @_ZN12BucketHeader9read_itemEmjRP8itemid_t(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %1, i32 noundef %2, ptr noundef nonnull align 8 dereferenceable(8) %3) #2 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !11
  store ptr %3, ptr %8, align 8, !tbaa !5
  %12 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %13 = getelementptr inbounds %class.BucketHeader, ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  store ptr %14, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  store i32 0, ptr %10, align 4, !tbaa !11
  br label %15

15:                                               ; preds = %32, %4
  %16 = load ptr, ptr %9, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %36

18:                                               ; preds = %15
  %19 = load ptr, ptr %9, align 8, !tbaa !5
  %20 = getelementptr inbounds %class.BucketNode, ptr %19, i32 0, i32 0
  %21 = load i64, ptr %20, align 8, !tbaa !16
  %22 = load i64, ptr %6, align 8, !tbaa !9
  %23 = icmp eq i64 %21, %22
  br i1 %23, label %24, label %32

24:                                               ; preds = %18
  %25 = load i32, ptr %10, align 4, !tbaa !11
  %26 = load i32, ptr %7, align 4, !tbaa !11
  %27 = icmp eq i32 %25, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %24
  br label %36

29:                                               ; preds = %24
  %30 = load i32, ptr %10, align 4, !tbaa !11
  %31 = add i32 %30, 1
  store i32 %31, ptr %10, align 4, !tbaa !11
  br label %32

32:                                               ; preds = %29, %18
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = getelementptr inbounds %class.BucketNode, ptr %33, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !18
  store ptr %35, ptr %9, align 8, !tbaa !5
  br label %15, !llvm.loop !19

36:                                               ; preds = %28, %15
  %37 = load ptr, ptr %9, align 8, !tbaa !5
  %38 = icmp eq ptr %37, null
  br i1 %38, label %39, label %41

39:                                               ; preds = %36
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr null, ptr %40, align 8, !tbaa !5
  store i32 1, ptr %11, align 4
  br label %72

41:                                               ; preds = %36
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = icmp ne ptr %42, null
  br i1 %43, label %58, label %44

44:                                               ; preds = %41
  %45 = load ptr, ptr @stdout, align 8, !tbaa !5
  %46 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %45, ptr noundef @.str.5, ptr noundef @.str.2, i32 noundef 250) #5
  %47 = load ptr, ptr @stdout, align 8, !tbaa !5
  %48 = load i64, ptr %6, align 8, !tbaa !9
  %49 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %47, ptr noundef @.str.6, i64 noundef %48) #5
  %50 = load ptr, ptr @stdout, align 8, !tbaa !5
  %51 = call i32 @fflush(ptr noundef %50)
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = icmp ne ptr %52, null
  br i1 %53, label %54, label %55

54:                                               ; preds = %44
  br label %57

55:                                               ; preds = %44
  call void @__assert_fail(ptr noundef @.str.7, ptr noundef @.str.2, i32 noundef 250, ptr noundef @__PRETTY_FUNCTION__._ZN12BucketHeader9read_itemEmjRP8itemid_t) #6
  unreachable

56:                                               ; No predecessors!
  br label %57

57:                                               ; preds = %56, %54
  br label %58

58:                                               ; preds = %57, %41
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  %60 = getelementptr inbounds %class.BucketNode, ptr %59, i32 0, i32 0
  %61 = load i64, ptr %60, align 8, !tbaa !16
  %62 = load i64, ptr %6, align 8, !tbaa !9
  %63 = icmp eq i64 %61, %62
  br i1 %63, label %64, label %65

64:                                               ; preds = %58
  br label %67

65:                                               ; preds = %58
  call void @__assert_fail(ptr noundef @.str.8, ptr noundef @.str.2, i32 noundef 251, ptr noundef @__PRETTY_FUNCTION__._ZN12BucketHeader9read_itemEmjRP8itemid_t) #6
  unreachable

66:                                               ; No predecessors!
  br label %67

67:                                               ; preds = %66, %64
  %68 = load ptr, ptr %9, align 8, !tbaa !5
  %69 = getelementptr inbounds %class.BucketNode, ptr %68, i32 0, i32 2
  %70 = load ptr, ptr %69, align 8, !tbaa !21
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %70, ptr %71, align 8, !tbaa !5
  store i32 0, ptr %11, align 4
  br label %72

72:                                               ; preds = %67, %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  %73 = load i32, ptr %11, align 4
  switch i32 %73, label %75 [
    i32 0, label %74
    i32 1, label %74
  ]

74:                                               ; preds = %72, %72
  ret void

75:                                               ; preds = %72
  unreachable
}

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #3

declare i32 @fflush(ptr noundef) #4

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 = { 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 = { "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 }
attributes #6 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"_ZTS12BucketHeader", !6, i64 0, !10, i64 8, !15, i64 16}
!15 = !{!"bool", !7, i64 0}
!16 = !{!17, !10, i64 0}
!17 = !{!"_ZTS10BucketNode", !10, i64 0, !6, i64 8, !6, i64 16}
!18 = !{!17, !6, i64 8}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!17, !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 nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @_ZN12BucketHeader9read_itemEmjRP8itemid_t(ptr nocapture noundef nonnull readonly align 8 dereferenceable(24) %0, i64 noundef %1, i32 noundef %2, ptr nocapture noundef nonnull writeonly align 8 dereferenceable(8) %3) local_unnamed_addr #0 align 2 {
  %.01618 = load ptr, ptr %0, align 8, !tbaa !5
  %cond19 = icmp eq ptr %.01618, null
  br i1 %cond19, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %4, %11
  %.01621 = phi ptr [ %.016, %11 ], [ %.01618, %4 ]
  %.020 = phi i32 [ %.1, %11 ], [ 0, %4 ]
  %5 = load i64, ptr %.01621, align 8, !tbaa !9
  %6 = icmp eq i64 %5, %1
  br i1 %6, label %7, label %11

7:                                                ; preds = %.lr.ph
  %8 = icmp eq i32 %.020, %2
  br i1 %8, label %13, label %9

9:                                                ; preds = %7
  %10 = add i32 %.020, 1
  br label %11

11:                                               ; preds = %9, %.lr.ph
  %.1 = phi i32 [ %10, %9 ], [ %.020, %.lr.ph ]
  %12 = getelementptr inbounds i8, ptr %.01621, i64 8
  %.016 = load ptr, ptr %12, align 8, !tbaa !5
  %cond = icmp eq ptr %.016, null
  br i1 %cond, label %.loopexit, label %.lr.ph, !llvm.loop !12

13:                                               ; preds = %7
  %14 = getelementptr inbounds i8, ptr %.01621, i64 16
  %15 = load ptr, ptr %14, align 8, !tbaa !14
  br label %.loopexit

.loopexit:                                        ; preds = %11, %4, %13
  %storemerge = phi ptr [ %15, %13 ], [ null, %4 ], [ null, %11 ]
  store ptr %storemerge, ptr %3, align 8, !tbaa !5
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) 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 = !{!10, !11, i64 0}
!10 = !{!"_ZTS10BucketNode", !11, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!"long", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!10, !6, i64 16}


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