; LLVM IR from maksimandrianov/cdcontainers :: src (hash-table)

; 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.cdc_hash_table_entry = type { ptr, ptr, ptr, i64 }
%struct.cdc_hash_table_iter = type { ptr, ptr }

@.str = external hidden unnamed_addr constant [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [79 x i8], align 1
@__PRETTY_FUNCTION__.cdc_hash_table_insert_or_assign = external hidden unnamed_addr constant [108 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr 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: nounwind uwtable
declare hidden ptr @find_entry(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @make_and_insert_unique(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @cdc_hash_table_insert_or_assign(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #2 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i8, align 1
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %19

18:                                               ; preds = %5
  br label %20

19:                                               ; preds = %5
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 453, ptr noundef @__PRETTY_FUNCTION__.cdc_hash_table_insert_or_assign) #3
  unreachable

20:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = call ptr @find_entry(ptr noundef %21, ptr noundef %22)
  store ptr %23, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #4
  %24 = load ptr, ptr %12, align 8, !tbaa !5
  %25 = icmp ne ptr %24, null
  %26 = zext i1 %25 to i8
  store i8 %26, ptr %13, align 1, !tbaa !9
  %27 = load i8, ptr %13, align 1, !tbaa !9, !range !11, !noundef !12
  %28 = trunc i8 %27 to i1
  br i1 %28, label %42, label %29

29:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  %33 = call i32 @make_and_insert_unique(ptr noundef %30, ptr noundef %31, ptr noundef %32, ptr noundef %12)
  store i32 %33, ptr %14, align 4, !tbaa !13
  %34 = load i32, ptr %14, align 4, !tbaa !13
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %38

36:                                               ; preds = %29
  %37 = load i32, ptr %14, align 4, !tbaa !13
  store i32 %37, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %39

38:                                               ; preds = %29
  store i32 0, ptr %15, align 4
  br label %39

39:                                               ; preds = %38, %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  %40 = load i32, ptr %15, align 4
  switch i32 %40, label %70 [
    i32 0, label %41
  ]

41:                                               ; preds = %39
  br label %48

42:                                               ; preds = %20
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = load ptr, ptr %12, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.cdc_hash_table_entry, ptr %44, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8, !tbaa !15
  %47 = getelementptr inbounds %struct.cdc_hash_table_entry, ptr %46, i32 0, i32 2
  store ptr %43, ptr %47, align 8, !tbaa !18
  br label %48

48:                                               ; preds = %42, %41
  %49 = load ptr, ptr %10, align 8, !tbaa !5
  %50 = icmp ne ptr %49, null
  br i1 %50, label %51, label %60

51:                                               ; preds = %48
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = load ptr, ptr %10, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.cdc_hash_table_iter, ptr %53, i32 0, i32 0
  store ptr %52, ptr %54, align 8, !tbaa !19
  %55 = load ptr, ptr %12, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.cdc_hash_table_entry, ptr %55, i32 0, i32 0
  %57 = load ptr, ptr %56, align 8, !tbaa !15
  %58 = load ptr, ptr %10, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.cdc_hash_table_iter, ptr %58, i32 0, i32 1
  store ptr %57, ptr %59, align 8, !tbaa !21
  br label %60

60:                                               ; preds = %51, %48
  %61 = load ptr, ptr %11, align 8, !tbaa !5
  %62 = icmp ne ptr %61, null
  br i1 %62, label %63, label %69

63:                                               ; preds = %60
  %64 = load i8, ptr %13, align 1, !tbaa !9, !range !11, !noundef !12
  %65 = trunc i8 %64 to i1
  %66 = xor i1 %65, true
  %67 = load ptr, ptr %11, align 8, !tbaa !5
  %68 = zext i1 %66 to i8
  store i8 %68, ptr %67, align 1, !tbaa !9
  br label %69

69:                                               ; preds = %63, %60
  store i32 0, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %70

70:                                               ; preds = %69, %39
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  %71 = load i32, ptr %6, align 4
  ret i32 %71
}

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { noreturn nounwind }
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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_Bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !6, i64 0}
!16 = !{!"cdc_hash_table_entry", !6, i64 0, !6, i64 8, !6, i64 16, !17, i64 24}
!17 = !{!"long", !7, i64 0}
!18 = !{!16, !6, i64 16}
!19 = !{!20, !6, i64 0}
!20 = !{!"cdc_hash_table_iter", !6, i64 0, !6, i64 8}
!21 = !{!20, !6, i64 8}


; 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 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [79 x i8], align 1
@__PRETTY_FUNCTION__.cdc_hash_table_insert_or_assign = external hidden unnamed_addr constant [108 x i8], align 1

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

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

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

; Function Attrs: nounwind uwtable
declare hidden ptr @find_entry(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden i32 @make_and_insert_unique(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i32 @cdc_hash_table_insert_or_assign(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef writeonly %3, ptr noundef writeonly %4) local_unnamed_addr #2 {
  %6 = alloca ptr, align 8
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %7, label %8

7:                                                ; preds = %5
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 453, ptr noundef nonnull @__PRETTY_FUNCTION__.cdc_hash_table_insert_or_assign) #3
  unreachable

8:                                                ; preds = %5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #4
  %9 = tail call ptr @find_entry(ptr noundef nonnull %0, ptr noundef %1)
  store ptr %9, ptr %6, align 8, !tbaa !5
  %.not23 = icmp eq ptr %9, null
  br i1 %.not23, label %10, label %12

10:                                               ; preds = %8
  %11 = call i32 @make_and_insert_unique(ptr noundef nonnull %0, ptr noundef %1, ptr noundef %2, ptr noundef nonnull %6)
  %.not24 = icmp eq i32 %11, 0
  br i1 %.not24, label %15, label %23

12:                                               ; preds = %8
  %13 = load ptr, ptr %9, align 8, !tbaa !9
  %14 = getelementptr inbounds i8, ptr %13, i64 16
  store ptr %2, ptr %14, align 8, !tbaa !12
  br label %15

15:                                               ; preds = %10, %12
  %.not25 = icmp eq ptr %3, null
  br i1 %.not25, label %20, label %16

16:                                               ; preds = %15
  store ptr %0, ptr %3, align 8, !tbaa !13
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr %18, ptr %19, align 8, !tbaa !15
  br label %20

20:                                               ; preds = %16, %15
  %.not26 = icmp eq ptr %4, null
  br i1 %.not26, label %23, label %21

21:                                               ; preds = %20
  %22 = zext i1 %.not23 to i8
  store i8 %22, ptr %4, align 1, !tbaa !16
  br label %23

23:                                               ; preds = %20, %21, %10
  %.1 = phi i32 [ %11, %10 ], [ 0, %21 ], [ 0, %20 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #4
  ret i32 %.1
}

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { noreturn nounwind }
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/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"cdc_hash_table_entry", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !6, i64 16}
!13 = !{!14, !6, i64 0}
!14 = !{!"cdc_hash_table_iter", !6, i64 0, !6, i64 8}
!15 = !{!14, !6, i64 8}
!16 = !{!17, !17, i64 0}
!17 = !{!"_Bool", !7, i64 0}


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