; LLVM IR from pavlosdais/Abstract-Data-Types :: modules/HashTable/SeparateChaining (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.hash_table = type { ptr, i8, i64, ptr, ptr, ptr }
%struct.node = type { ptr, i32, ptr }

@.str.1 = external hidden unnamed_addr constant [112 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [11 x i8], align 1
@__PRETTY_FUNCTION__.hash_destroy = external hidden unnamed_addr constant [35 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
declare void @free(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @hash_destroy(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  br i1 %8, label %9, label %10

9:                                                ; preds = %1
  br label %11

10:                                               ; preds = %1
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 211, ptr noundef @__PRETTY_FUNCTION__.hash_destroy) #4
  unreachable

11:                                               ; preds = %9
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.hash_table, ptr %12, i32 0, i32 2
  %14 = load i64, ptr %13, align 8, !tbaa !9
  %15 = icmp ne i64 %14, 0
  br i1 %15, label %16, label %64

16:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  store i64 0, ptr %3, align 8, !tbaa !12
  br label %17

17:                                               ; preds = %59, %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.hash_table, ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !13
  %21 = load i64, ptr %3, align 8, !tbaa !12
  %22 = getelementptr inbounds ptr, ptr %20, i64 %21
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  store ptr %23, ptr %4, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %43, %17
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %49

27:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %28, ptr %5, align 8, !tbaa !5
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.node, ptr %29, i32 0, i32 2
  %31 = load ptr, ptr %30, align 8, !tbaa !14
  store ptr %31, ptr %4, align 8, !tbaa !5
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.hash_table, ptr %32, i32 0, i32 5
  %34 = load ptr, ptr %33, align 8, !tbaa !17
  %35 = icmp ne ptr %34, null
  br i1 %35, label %36, label %43

36:                                               ; preds = %27
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.hash_table, ptr %37, i32 0, i32 5
  %39 = load ptr, ptr %38, align 8, !tbaa !17
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.node, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !18
  call void %39(ptr noundef %42)
  br label %43

43:                                               ; preds = %36, %27
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  call void @free(ptr noundef %44) #5
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.hash_table, ptr %45, i32 0, i32 2
  %47 = load i64, ptr %46, align 8, !tbaa !9
  %48 = add i64 %47, -1
  store i64 %48, ptr %46, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  br label %24, !llvm.loop !19

49:                                               ; preds = %24
  %50 = load ptr, ptr %2, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.hash_table, ptr %50, i32 0, i32 2
  %52 = load i64, ptr %51, align 8, !tbaa !9
  %53 = icmp eq i64 %52, 0
  br i1 %53, label %54, label %55

54:                                               ; preds = %49
  store i32 2, ptr %6, align 4
  br label %56

55:                                               ; preds = %49
  store i32 0, ptr %6, align 4
  br label %56

56:                                               ; preds = %55, %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  %57 = load i32, ptr %6, align 4
  switch i32 %57, label %62 [
    i32 0, label %58
  ]

58:                                               ; preds = %56
  br label %59

59:                                               ; preds = %58
  %60 = load i64, ptr %3, align 8, !tbaa !12
  %61 = add i64 %60, 1
  store i64 %61, ptr %3, align 8, !tbaa !12
  br label %17

62:                                               ; preds = %56
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  br label %63

63:                                               ; preds = %62
  br label %64

64:                                               ; preds = %63, %11
  %65 = load ptr, ptr %2, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.hash_table, ptr %65, i32 0, i32 0
  %67 = load ptr, ptr %66, align 8, !tbaa !13
  call void @free(ptr noundef %67) #5
  %68 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %68) #5
  ret void
}

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 "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 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 = { noreturn nounwind }
attributes #5 = { 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, !11, i64 16}
!10 = !{!"hash_table", !6, i64 0, !7, i64 8, !11, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!11 = !{!"long", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !6, i64 0}
!14 = !{!15, !6, i64 16}
!15 = !{!"node", !6, i64 0, !16, i64 8, !6, i64 16}
!16 = !{!"int", !7, i64 0}
!17 = !{!10, !6, i64 40}
!18 = !{!15, !6, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; 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.1 = external hidden unnamed_addr constant [112 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [11 x i8], align 1
@__PRETTY_FUNCTION__.hash_destroy = external hidden unnamed_addr constant [35 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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @hash_destroy(ptr noundef %0) local_unnamed_addr #2 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %2, label %3

2:                                                ; preds = %1
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 211, ptr noundef nonnull @__PRETTY_FUNCTION__.hash_destroy) #3
  unreachable

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %.not20 = icmp eq i64 %5, 0
  br i1 %.not20, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 40
  br label %7

7:                                                ; preds = %._crit_edge, %.preheader
  %8 = phi i64 [ %20, %._crit_edge ], [ %5, %.preheader ]
  %.016 = phi i64 [ %21, %._crit_edge ], [ 0, %.preheader ]
  %9 = load ptr, ptr %0, align 8, !tbaa !11
  %10 = getelementptr inbounds ptr, ptr %9, i64 %.016
  %11 = load ptr, ptr %10, align 8, !tbaa !12
  %.not2124 = icmp eq ptr %11, null
  br i1 %.not2124, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %7, %17
  %.01725 = phi ptr [ %13, %17 ], [ %11, %7 ]
  %12 = getelementptr inbounds i8, ptr %.01725, i64 16
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  %14 = load ptr, ptr %6, align 8, !tbaa !16
  %.not23 = icmp eq ptr %14, null
  br i1 %.not23, label %17, label %15

15:                                               ; preds = %.lr.ph
  %16 = load ptr, ptr %.01725, align 8, !tbaa !17
  tail call void %14(ptr noundef %16) #4
  br label %17

17:                                               ; preds = %15, %.lr.ph
  tail call void @free(ptr noundef nonnull %.01725) #4
  %18 = load i64, ptr %4, align 8, !tbaa !5
  %19 = add i64 %18, -1
  store i64 %19, ptr %4, align 8, !tbaa !5
  %.not21 = icmp eq ptr %13, null
  br i1 %.not21, label %._crit_edge, label %.lr.ph, !llvm.loop !18

._crit_edge:                                      ; preds = %17, %7
  %20 = phi i64 [ %8, %7 ], [ %19, %17 ]
  %.not22 = icmp eq i64 %20, 0
  %21 = add i64 %.016, 1
  br i1 %.not22, label %.loopexit, label %7

.loopexit:                                        ; preds = %._crit_edge, %3
  %22 = load ptr, ptr %0, align 8, !tbaa !11
  tail call void @free(ptr noundef %22) #4
  tail call void @free(ptr noundef nonnull %0) #4
  ret void
}

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 nounwind willreturn allockind("free") memory(argmem: readwrite, 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 #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, !10, i64 16}
!6 = !{!"hash_table", !7, i64 0, !8, i64 8, !10, i64 16, !7, i64 24, !7, i64 32, !7, i64 40}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !7, i64 16}
!14 = !{!"node", !7, i64 0, !15, i64 8, !7, i64 16}
!15 = !{!"int", !8, i64 0}
!16 = !{!6, !7, i64 40}
!17 = !{!14, !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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