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

; 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.mem_alloc = type { i8 }
%class.BucketHeader = type { ptr, i64, i8 }
%class.BucketNode = type { i64, ptr, ptr }
%class.itemid_t = type <{ i32, [4 x i8], ptr, ptr, i8, [7 x i8] }>

@mem_allocator = external global %class.mem_alloc, align 1

declare noundef ptr @_ZN9mem_alloc5allocEm(ptr noundef nonnull align 1 dereferenceable(1), i64 noundef) #0

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN12BucketHeader11insert_itemEmP8itemid_ti(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %1, ptr noundef %2, i32 noundef %3) #2 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !11
  %12 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %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 8, ptr %10) #4
  store ptr null, ptr %10, align 8, !tbaa !5
  br label %15

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

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 %25

24:                                               ; preds = %18
  br label %30

25:                                               ; preds = %18
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %26, ptr %10, align 8, !tbaa !5
  %27 = load ptr, ptr %9, align 8, !tbaa !5
  %28 = getelementptr inbounds %class.BucketNode, ptr %27, i32 0, i32 1
  %29 = load ptr, ptr %28, align 8, !tbaa !18
  store ptr %29, ptr %9, align 8, !tbaa !5
  br label %15, !llvm.loop !19

30:                                               ; preds = %24, %15
  %31 = load ptr, ptr %9, align 8, !tbaa !5
  %32 = icmp eq ptr %31, null
  br i1 %32, label %33, label %59

33:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %34 = call noundef ptr @_ZN9mem_alloc5allocEm(ptr noundef nonnull align 1 dereferenceable(1) @mem_allocator, i64 noundef 24)
  store ptr %34, ptr %11, align 8, !tbaa !5
  %35 = load ptr, ptr %11, align 8, !tbaa !5
  %36 = load i64, ptr %6, align 8, !tbaa !9
  call void @_ZN10BucketNode4initEm(ptr noundef nonnull align 8 dereferenceable(24) %35, i64 noundef %36)
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = load ptr, ptr %11, align 8, !tbaa !5
  %39 = getelementptr inbounds %class.BucketNode, ptr %38, i32 0, i32 2
  store ptr %37, ptr %39, align 8, !tbaa !21
  %40 = load ptr, ptr %10, align 8, !tbaa !5
  %41 = icmp ne ptr %40, null
  br i1 %41, label %42, label %51

42:                                               ; preds = %33
  %43 = load ptr, ptr %10, align 8, !tbaa !5
  %44 = getelementptr inbounds %class.BucketNode, ptr %43, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !18
  %46 = load ptr, ptr %11, align 8, !tbaa !5
  %47 = getelementptr inbounds %class.BucketNode, ptr %46, i32 0, i32 1
  store ptr %45, ptr %47, align 8, !tbaa !18
  %48 = load ptr, ptr %11, align 8, !tbaa !5
  %49 = load ptr, ptr %10, align 8, !tbaa !5
  %50 = getelementptr inbounds %class.BucketNode, ptr %49, i32 0, i32 1
  store ptr %48, ptr %50, align 8, !tbaa !18
  br label %58

51:                                               ; preds = %33
  %52 = getelementptr inbounds %class.BucketHeader, ptr %12, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !13
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  %55 = getelementptr inbounds %class.BucketNode, ptr %54, i32 0, i32 1
  store ptr %53, ptr %55, align 8, !tbaa !18
  %56 = load ptr, ptr %11, align 8, !tbaa !5
  %57 = getelementptr inbounds %class.BucketHeader, ptr %12, i32 0, i32 0
  store ptr %56, ptr %57, align 8, !tbaa !13
  br label %58

58:                                               ; preds = %51, %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %68

59:                                               ; preds = %30
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = getelementptr inbounds %class.BucketNode, ptr %60, i32 0, i32 2
  %62 = load ptr, ptr %61, align 8, !tbaa !21
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = getelementptr inbounds %class.itemid_t, ptr %63, i32 0, i32 3
  store ptr %62, ptr %64, align 8, !tbaa !22
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = load ptr, ptr %9, align 8, !tbaa !5
  %67 = getelementptr inbounds %class.BucketNode, ptr %66, i32 0, i32 2
  store ptr %65, ptr %67, align 8, !tbaa !21
  br label %68

68:                                               ; preds = %59, %58
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN10BucketNode4initEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #3 align 2

attributes #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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 = !{!"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}
!22 = !{!23, !6, i64 16}
!23 = !{!"_ZTS8itemid_t", !24, i64 0, !6, i64 8, !6, i64 16, !15, i64 24}
!24 = !{!"_ZTS9Data_type", !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"

%class.mem_alloc = type { i8 }

@mem_allocator = external global %class.mem_alloc, align 1

declare noundef ptr @_ZN9mem_alloc5allocEm(ptr noundef nonnull align 1 dereferenceable(1), i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN12BucketHeader11insert_itemEmP8itemid_ti(ptr nocapture noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #1 align 2 {
  %.025 = load ptr, ptr %0, align 8, !tbaa !5
  %cond26 = icmp eq ptr %.025, null
  br i1 %cond26, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4, %7
  %.027 = phi ptr [ %.0, %7 ], [ %.025, %4 ]
  %5 = load i64, ptr %.027, align 8, !tbaa !9
  %6 = icmp eq i64 %5, %1
  br i1 %6, label %18, label %7

7:                                                ; preds = %.lr.ph
  %8 = getelementptr inbounds i8, ptr %.027, i64 8
  %.0 = load ptr, ptr %8, align 8, !tbaa !5
  %cond = icmp eq ptr %.0, null
  br i1 %cond, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %7, %4
  %.021.lcssa = phi ptr [ null, %4 ], [ %.027, %7 ]
  %9 = tail call noundef ptr @_ZN9mem_alloc5allocEm(ptr noundef nonnull align 1 dereferenceable(1) @mem_allocator, i64 noundef 24)
  tail call void @_ZN10BucketNode4initEm(ptr noundef nonnull align 8 dereferenceable(24) %9, i64 noundef %1)
  %10 = getelementptr inbounds i8, ptr %9, i64 16
  store ptr %2, ptr %10, align 8, !tbaa !14
  %.not22 = icmp eq ptr %.021.lcssa, null
  br i1 %.not22, label %15, label %11

11:                                               ; preds = %._crit_edge
  %12 = getelementptr inbounds i8, ptr %.021.lcssa, i64 8
  %13 = load ptr, ptr %12, align 8, !tbaa !15
  %14 = getelementptr inbounds i8, ptr %9, i64 8
  store ptr %13, ptr %14, align 8, !tbaa !15
  store ptr %9, ptr %12, align 8, !tbaa !15
  br label %22

15:                                               ; preds = %._crit_edge
  %16 = load ptr, ptr %0, align 8, !tbaa !16
  %17 = getelementptr inbounds i8, ptr %9, i64 8
  store ptr %16, ptr %17, align 8, !tbaa !15
  store ptr %9, ptr %0, align 8, !tbaa !16
  br label %22

18:                                               ; preds = %.lr.ph
  %19 = getelementptr inbounds i8, ptr %.027, i64 16
  %20 = load ptr, ptr %19, align 8, !tbaa !14
  %21 = getelementptr inbounds i8, ptr %2, i64 16
  store ptr %20, ptr %21, align 8, !tbaa !19
  store ptr %2, ptr %19, align 8, !tbaa !14
  br label %22

22:                                               ; preds = %11, %15, %18
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN10BucketNode4initEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #2 align 2

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

!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}
!15 = !{!10, !6, i64 8}
!16 = !{!17, !6, i64 0}
!17 = !{!"_ZTS12BucketHeader", !6, i64 0, !11, i64 8, !18, i64 16}
!18 = !{!"bool", !7, i64 0}
!19 = !{!20, !6, i64 16}
!20 = !{!"_ZTS8itemid_t", !21, i64 0, !6, i64 8, !6, i64 16, !18, i64 24}
!21 = !{!"_ZTS9Data_type", !7, i64 0}


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