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

@.str.1 = external hidden unnamed_addr constant [104 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 i32, align 4
  %5 = alloca i8, align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = icmp ne ptr %6, null
  br i1 %7, label %8, label %9

8:                                                ; preds = %1
  br label %10

9:                                                ; preds = %1
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 220, ptr noundef @__PRETTY_FUNCTION__.hash_destroy) #5
  unreachable

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

11:                                               ; preds = %99, %10
  %12 = load i64, ptr %3, align 8, !tbaa !9
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.hash_table, ptr %13, i32 0, i32 1
  %15 = load i64, ptr %14, align 8, !tbaa !11
  %16 = icmp ult i64 %12, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %11
  store i32 2, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #6
  br label %102

18:                                               ; preds = %11
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.hash_table, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  %22 = load i64, ptr %3, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct.node, ptr %21, i64 %22
  %24 = getelementptr inbounds %struct.node, ptr %23, i32 0, i32 2
  %25 = load i8, ptr %24, align 8, !tbaa !14
  %26 = zext i8 %25 to i32
  %27 = icmp ne i32 %26, 4
  br i1 %27, label %28, label %72

28:                                               ; preds = %18
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.hash_table, ptr %29, i32 0, i32 5
  %31 = load ptr, ptr %30, align 8, !tbaa !16
  %32 = icmp ne ptr %31, null
  br i1 %32, label %33, label %72

33:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #6
  store i8 0, ptr %5, align 1, !tbaa !17
  br label %34

34:                                               ; preds = %68, %33
  %35 = load i8, ptr %5, align 1, !tbaa !17
  %36 = zext i8 %35 to i32
  %37 = icmp slt i32 %36, 3
  br i1 %37, label %39, label %38

38:                                               ; preds = %34
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #6
  br label %71

39:                                               ; preds = %34
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.hash_table, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !13
  %43 = load i64, ptr %3, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct.node, ptr %42, i64 %43
  %45 = getelementptr inbounds %struct.node, ptr %44, i32 0, i32 1
  %46 = load ptr, ptr %45, align 8, !tbaa !18
  %47 = load i8, ptr %5, align 1, !tbaa !17
  %48 = zext i8 %47 to i64
  %49 = getelementptr inbounds ptr, ptr %46, i64 %48
  %50 = load ptr, ptr %49, align 8, !tbaa !5
  %51 = icmp ne ptr %50, null
  br i1 %51, label %52, label %67

52:                                               ; preds = %39
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.hash_table, ptr %53, i32 0, i32 5
  %55 = load ptr, ptr %54, align 8, !tbaa !16
  %56 = load ptr, ptr %2, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.hash_table, ptr %56, i32 0, i32 0
  %58 = load ptr, ptr %57, align 8, !tbaa !13
  %59 = load i64, ptr %3, align 8, !tbaa !9
  %60 = getelementptr inbounds %struct.node, ptr %58, i64 %59
  %61 = getelementptr inbounds %struct.node, ptr %60, i32 0, i32 1
  %62 = load ptr, ptr %61, align 8, !tbaa !18
  %63 = load i8, ptr %5, align 1, !tbaa !17
  %64 = zext i8 %63 to i64
  %65 = getelementptr inbounds ptr, ptr %62, i64 %64
  %66 = load ptr, ptr %65, align 8, !tbaa !5
  call void %55(ptr noundef %66)
  br label %67

67:                                               ; preds = %52, %39
  br label %68

68:                                               ; preds = %67
  %69 = load i8, ptr %5, align 1, !tbaa !17
  %70 = add i8 %69, 1
  store i8 %70, ptr %5, align 1, !tbaa !17
  br label %34, !llvm.loop !19

71:                                               ; preds = %38
  br label %72

72:                                               ; preds = %71, %28, %18
  %73 = load ptr, ptr %2, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.hash_table, ptr %73, i32 0, i32 0
  %75 = load ptr, ptr %74, align 8, !tbaa !13
  %76 = load i64, ptr %3, align 8, !tbaa !9
  %77 = getelementptr inbounds %struct.node, ptr %75, i64 %76
  %78 = getelementptr inbounds %struct.node, ptr %77, i32 0, i32 2
  %79 = load i8, ptr %78, align 8, !tbaa !14
  %80 = zext i8 %79 to i32
  %81 = icmp eq i32 %80, 4
  br i1 %81, label %82, label %90

82:                                               ; preds = %72
  %83 = load ptr, ptr %2, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.hash_table, ptr %83, i32 0, i32 0
  %85 = load ptr, ptr %84, align 8, !tbaa !13
  %86 = load i64, ptr %3, align 8, !tbaa !9
  %87 = getelementptr inbounds %struct.node, ptr %85, i64 %86
  %88 = getelementptr inbounds %struct.node, ptr %87, i32 0, i32 0
  %89 = load ptr, ptr %88, align 8, !tbaa !21
  call void @rbt_destroy(ptr noundef %89)
  br label %98

90:                                               ; preds = %72
  %91 = load ptr, ptr %2, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.hash_table, ptr %91, i32 0, i32 0
  %93 = load ptr, ptr %92, align 8, !tbaa !13
  %94 = load i64, ptr %3, align 8, !tbaa !9
  %95 = getelementptr inbounds %struct.node, ptr %93, i64 %94
  %96 = getelementptr inbounds %struct.node, ptr %95, i32 0, i32 1
  %97 = load ptr, ptr %96, align 8, !tbaa !18
  call void @free(ptr noundef %97) #6
  br label %98

98:                                               ; preds = %90, %82
  br label %99

99:                                               ; preds = %98
  %100 = load i64, ptr %3, align 8, !tbaa !9
  %101 = add i64 %100, 1
  store i64 %101, ptr %3, align 8, !tbaa !9
  br label %11, !llvm.loop !22

102:                                              ; preds = %17
  %103 = load ptr, ptr %2, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.hash_table, ptr %103, i32 0, i32 0
  %105 = load ptr, ptr %104, align 8, !tbaa !13
  call void @free(ptr noundef %105) #6
  %106 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %106) #6
  ret void
}

declare void @rbt_destroy(ptr noundef) #4

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


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

%struct.node = type { ptr, ptr, i8 }

@.str.1 = external hidden unnamed_addr constant [104 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 %5, label %.preheader29

.preheader29:                                     ; preds = %1
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %.not32 = icmp eq i64 %3, 0
  br i1 %.not32, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader29
  %4 = getelementptr inbounds i8, ptr %0, i64 40
  br label %7

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

._crit_edge:                                      ; preds = %39, %.preheader29
  %6 = load ptr, ptr %0, align 8, !tbaa !11
  tail call void @free(ptr noundef %6) #5
  tail call void @free(ptr noundef nonnull %0) #5
  ret void

7:                                                ; preds = %.lr.ph, %39
  %.02331 = phi i64 [ 0, %.lr.ph ], [ %40, %39 ]
  %8 = load ptr, ptr %0, align 8, !tbaa !11
  %9 = getelementptr inbounds %struct.node, ptr %8, i64 %.02331, i32 2
  %10 = load i8, ptr %9, align 8, !tbaa !12
  %.not26 = icmp eq i8 %10, 4
  br i1 %.not26, label %.loopexit, label %11

11:                                               ; preds = %7
  %12 = load ptr, ptr %4, align 8, !tbaa !14
  %.not27 = icmp eq ptr %12, null
  br i1 %.not27, label %.loopexit, label %.preheader.preheader

.preheader.preheader:                             ; preds = %11
  %13 = getelementptr inbounds %struct.node, ptr %8, i64 %.02331, i32 1
  %14 = load ptr, ptr %13, align 8, !tbaa !15
  %15 = load ptr, ptr %14, align 8, !tbaa !16
  %.not28 = icmp eq ptr %15, null
  br i1 %.not28, label %.preheader.1, label %16

16:                                               ; preds = %.preheader.preheader
  tail call void %12(ptr noundef nonnull %15) #5
  %.pre = load ptr, ptr %0, align 8, !tbaa !11
  %.phi.trans.insert = getelementptr inbounds %struct.node, ptr %.pre, i64 %.02331, i32 1
  %.pre34 = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !15
  br label %.preheader.1

.preheader.1:                                     ; preds = %.preheader.preheader, %16
  %17 = phi ptr [ %14, %.preheader.preheader ], [ %.pre34, %16 ]
  %18 = phi ptr [ %8, %.preheader.preheader ], [ %.pre, %16 ]
  %19 = getelementptr inbounds i8, ptr %17, i64 8
  %20 = load ptr, ptr %19, align 8, !tbaa !16
  %.not28.1 = icmp eq ptr %20, null
  br i1 %.not28.1, label %.preheader.2, label %21

21:                                               ; preds = %.preheader.1
  %22 = load ptr, ptr %4, align 8, !tbaa !14
  tail call void %22(ptr noundef nonnull %20) #5
  %.pre35 = load ptr, ptr %0, align 8, !tbaa !11
  %.phi.trans.insert36 = getelementptr inbounds %struct.node, ptr %.pre35, i64 %.02331, i32 1
  %.pre37 = load ptr, ptr %.phi.trans.insert36, align 8, !tbaa !15
  br label %.preheader.2

.preheader.2:                                     ; preds = %21, %.preheader.1
  %23 = phi ptr [ %.pre37, %21 ], [ %17, %.preheader.1 ]
  %24 = phi ptr [ %.pre35, %21 ], [ %18, %.preheader.1 ]
  %25 = getelementptr inbounds i8, ptr %23, i64 16
  %26 = load ptr, ptr %25, align 8, !tbaa !16
  %.not28.2 = icmp eq ptr %26, null
  br i1 %.not28.2, label %.loopexit, label %27

27:                                               ; preds = %.preheader.2
  %28 = load ptr, ptr %4, align 8, !tbaa !14
  tail call void %28(ptr noundef nonnull %26) #5
  %.pre38.pre = load ptr, ptr %0, align 8, !tbaa !11
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader.2, %27, %11, %7
  %29 = phi ptr [ %8, %11 ], [ %8, %7 ], [ %.pre38.pre, %27 ], [ %24, %.preheader.2 ]
  %30 = getelementptr inbounds %struct.node, ptr %29, i64 %.02331
  %31 = getelementptr inbounds i8, ptr %30, i64 16
  %32 = load i8, ptr %31, align 8, !tbaa !12
  %33 = icmp eq i8 %32, 4
  br i1 %33, label %34, label %36

34:                                               ; preds = %.loopexit
  %35 = load ptr, ptr %30, align 8, !tbaa !17
  tail call void @rbt_destroy(ptr noundef %35) #5
  br label %39

36:                                               ; preds = %.loopexit
  %37 = getelementptr inbounds i8, ptr %30, i64 8
  %38 = load ptr, ptr %37, align 8, !tbaa !15
  tail call void @free(ptr noundef %38) #5
  br label %39

39:                                               ; preds = %34, %36
  %40 = add nuw i64 %.02331, 1
  %41 = load i64, ptr %2, align 8, !tbaa !5
  %42 = icmp ult i64 %40, %41
  br i1 %42, label %7, label %._crit_edge, !llvm.loop !18
}

declare void @rbt_destroy(ptr noundef) local_unnamed_addr #3

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 = { "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, !10, i64 8}
!6 = !{!"hash_table", !7, i64 0, !10, 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 = !{!13, !8, i64 16}
!13 = !{!"node", !7, i64 0, !7, i64 8, !8, i64 16}
!14 = !{!6, !7, i64 40}
!15 = !{!13, !7, i64 8}
!16 = !{!7, !7, i64 0}
!17 = !{!13, !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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