; LLVM IR from dpt/Containers :: libraries/datastruct/hash (insert)

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

%struct.hash = type { ptr, i32, i32, ptr, ptr, ptr, ptr, ptr }
%struct.hash__node = type { ptr, %struct.item }
%struct.item = type { ptr, i64, ptr }

; Function Attrs: nounwind uwtable
define dso_local i64 @hash_insert(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3) #0 {
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = call ptr @hash_lookup_node(ptr noundef %13, ptr noundef %14)
  store ptr %15, ptr %10, align 8, !tbaa !5
  %16 = load ptr, ptr %10, align 8, !tbaa !5
  %17 = load ptr, ptr %16, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %37

19:                                               ; preds = %4
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.hash, ptr %20, i32 0, i32 7
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  %23 = load ptr, ptr %10, align 8, !tbaa !5
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.hash__node, ptr %24, i32 0, i32 1
  %26 = getelementptr inbounds %struct.item, ptr %25, i32 0, i32 2
  %27 = load ptr, ptr %26, align 8, !tbaa !14
  call void %22(ptr noundef %27)
  %28 = load ptr, ptr %9, align 8, !tbaa !5
  %29 = load ptr, ptr %10, align 8, !tbaa !5
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.hash__node, ptr %30, i32 0, i32 1
  %32 = getelementptr inbounds %struct.item, ptr %31, i32 0, i32 2
  store ptr %28, ptr %32, align 8, !tbaa !14
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.hash, ptr %33, i32 0, i32 6
  %35 = load ptr, ptr %34, align 8, !tbaa !17
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  call void %35(ptr noundef %36)
  br label %66

37:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %38 = call noalias ptr @malloc(i64 noundef 32) #5
  store ptr %38, ptr %11, align 8, !tbaa !5
  %39 = load ptr, ptr %11, align 8, !tbaa !5
  %40 = icmp eq ptr %39, null
  br i1 %40, label %41, label %42

41:                                               ; preds = %37
  store i64 1, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %63

42:                                               ; preds = %37
  %43 = load ptr, ptr %11, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.hash__node, ptr %43, i32 0, i32 0
  store ptr null, ptr %44, align 8, !tbaa !18
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = load ptr, ptr %11, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.hash__node, ptr %46, i32 0, i32 1
  %48 = getelementptr inbounds %struct.item, ptr %47, i32 0, i32 0
  store ptr %45, ptr %48, align 8, !tbaa !19
  %49 = load i64, ptr %8, align 8, !tbaa !9
  %50 = load ptr, ptr %11, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.hash__node, ptr %50, i32 0, i32 1
  %52 = getelementptr inbounds %struct.item, ptr %51, i32 0, i32 1
  store i64 %49, ptr %52, align 8, !tbaa !20
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.hash__node, ptr %54, i32 0, i32 1
  %56 = getelementptr inbounds %struct.item, ptr %55, i32 0, i32 2
  store ptr %53, ptr %56, align 8, !tbaa !14
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.hash, ptr %57, i32 0, i32 2
  %59 = load i32, ptr %58, align 4, !tbaa !21
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %58, align 4, !tbaa !21
  %61 = load ptr, ptr %11, align 8, !tbaa !5
  %62 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %61, ptr %62, align 8, !tbaa !5
  store i32 0, ptr %12, align 4
  br label %63

63:                                               ; preds = %42, %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  %64 = load i32, ptr %12, align 4
  switch i32 %64, label %67 [
    i32 0, label %65
  ]

65:                                               ; preds = %63
  br label %66

66:                                               ; preds = %65, %19
  store i64 0, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %67

67:                                               ; preds = %66, %63
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %68 = load i64, ptr %5, align 8
  ret i64 %68
}

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

declare ptr @hash_lookup_node(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 allocsize(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 }
attributes #5 = { nounwind allocsize(0) }

!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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 48}
!12 = !{!"hash", !6, i64 0, !13, i64 8, !13, i64 12, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !6, i64 24}
!15 = !{!"hash__node", !6, i64 0, !16, i64 8}
!16 = !{!"item", !6, i64 0, !10, i64 8, !6, i64 16}
!17 = !{!12, !6, i64 40}
!18 = !{!15, !6, i64 0}
!19 = !{!15, !6, i64 8}
!20 = !{!15, !10, i64 16}
!21 = !{!12, !13, i64 12}


; 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: nounwind uwtable
define dso_local range(i64 0, 2) i64 @hash_insert(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = tail call ptr @hash_lookup_node(ptr noundef %0, ptr noundef %1) #3
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %16, label %7

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %0, i64 48
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = getelementptr inbounds i8, ptr %6, i64 24
  %11 = load ptr, ptr %10, align 8, !tbaa !12
  tail call void %9(ptr noundef %11) #3
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %12, i64 24
  store ptr %3, ptr %13, align 8, !tbaa !12
  %14 = getelementptr inbounds i8, ptr %0, i64 40
  %15 = load ptr, ptr %14, align 8, !tbaa !16
  tail call void %15(ptr noundef %1) #3
  br label %.critedge

16:                                               ; preds = %4
  %17 = tail call noalias dereferenceable_or_null(32) ptr @malloc(i64 noundef 32) #4
  %.not24 = icmp eq ptr %17, null
  br i1 %.not24, label %.critedge, label %18

18:                                               ; preds = %16
  store ptr null, ptr %17, align 8, !tbaa !17
  %19 = getelementptr inbounds i8, ptr %17, i64 8
  store ptr %1, ptr %19, align 8, !tbaa !18
  %20 = getelementptr inbounds i8, ptr %17, i64 16
  store i64 %2, ptr %20, align 8, !tbaa !19
  %21 = getelementptr inbounds i8, ptr %17, i64 24
  store ptr %3, ptr %21, align 8, !tbaa !12
  %22 = getelementptr inbounds i8, ptr %0, i64 12
  %23 = load i32, ptr %22, align 4, !tbaa !20
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %22, align 4, !tbaa !20
  store ptr %17, ptr %5, align 8, !tbaa !5
  br label %.critedge

.critedge:                                        ; preds = %7, %18, %16
  %.1 = phi i64 [ 1, %16 ], [ 0, %18 ], [ 0, %7 ]
  ret i64 %.1
}

declare ptr @hash_lookup_node(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

attributes #0 = { 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 #1 = { "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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 }
attributes #4 = { nounwind allocsize(0) }

!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/C++ TBAA"}
!9 = !{!10, !6, i64 48}
!10 = !{!"hash", !6, i64 0, !11, i64 8, !11, i64 12, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 24}
!13 = !{!"hash__node", !6, i64 0, !14, i64 8}
!14 = !{!"item", !6, i64 0, !15, i64 8, !6, i64 16}
!15 = !{!"long", !7, i64 0}
!16 = !{!10, !6, i64 40}
!17 = !{!13, !6, i64 0}
!18 = !{!13, !6, i64 8}
!19 = !{!13, !15, i64 16}
!20 = !{!10, !11, i64 12}


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