; LLVM IR from fmela/libdict :: src (hashtable)

; 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.hashtable = type { ptr, ptr, ptr, i64, i32 }
%struct.hash_node = type { ptr, ptr, ptr, ptr, i32 }

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @hashtable_traverse(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  store i64 0, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 0, ptr %9, align 4, !tbaa !11
  br label %12

12:                                               ; preds = %53, %3
  %13 = load i32, ptr %9, align 4, !tbaa !11
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.hashtable, ptr %14, i32 0, i32 4
  %16 = load i32, ptr %15, align 8, !tbaa !13
  %17 = icmp ult i32 %13, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %12
  store i32 2, ptr %10, align 4
  br label %56

19:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.hashtable, ptr %20, i32 0, i32 0
  %22 = load ptr, ptr %21, align 8, !tbaa !15
  %23 = load i32, ptr %9, align 4, !tbaa !11
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds ptr, ptr %22, i64 %24
  %26 = load ptr, ptr %25, align 8, !tbaa !5
  store ptr %26, ptr %11, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %46, %19
  %28 = load ptr, ptr %11, align 8, !tbaa !5
  %29 = icmp ne ptr %28, null
  br i1 %29, label %31, label %30

30:                                               ; preds = %27
  store i32 5, ptr %10, align 4
  br label %50

31:                                               ; preds = %27
  %32 = load i64, ptr %8, align 8, !tbaa !9
  %33 = add i64 %32, 1
  store i64 %33, ptr %8, align 8, !tbaa !9
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = load ptr, ptr %11, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.hash_node, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !16
  %38 = load ptr, ptr %11, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.hash_node, ptr %38, i32 0, i32 1
  %40 = load ptr, ptr %39, align 8, !tbaa !18
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = call zeroext i1 %34(ptr noundef %37, ptr noundef %40, ptr noundef %41)
  br i1 %42, label %45, label %43

43:                                               ; preds = %31
  %44 = load i64, ptr %8, align 8, !tbaa !9
  store i64 %44, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %50

45:                                               ; preds = %31
  br label %46

46:                                               ; preds = %45
  %47 = load ptr, ptr %11, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.hash_node, ptr %47, i32 0, i32 2
  %49 = load ptr, ptr %48, align 8, !tbaa !19
  store ptr %49, ptr %11, align 8, !tbaa !5
  br label %27, !llvm.loop !20

50:                                               ; preds = %43, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  %51 = load i32, ptr %10, align 4
  switch i32 %51, label %56 [
    i32 5, label %52
  ]

52:                                               ; preds = %50
  br label %53

53:                                               ; preds = %52
  %54 = load i32, ptr %9, align 4, !tbaa !11
  %55 = add i32 %54, 1
  store i32 %55, ptr %9, align 4, !tbaa !11
  br label %12, !llvm.loop !22

56:                                               ; preds = %50, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  %57 = load i32, ptr %10, align 4
  switch i32 %57, label %60 [
    i32 2, label %58
  ]

58:                                               ; preds = %56
  %59 = load i64, ptr %8, align 8, !tbaa !9
  store i64 %59, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %60

60:                                               ; preds = %58, %56
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %61 = load i64, ptr %4, align 8
  ret i64 %61
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 32}
!14 = !{!"hashtable", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24, !12, i64 32}
!15 = !{!14, !6, i64 0}
!16 = !{!17, !6, i64 0}
!17 = !{!"hash_node", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !12, i64 32}
!18 = !{!17, !6, i64 8}
!19 = !{!17, !6, i64 16}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = distinct !{!22, !21}


; 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 i64 @hashtable_traverse(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 32
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %.not2537.not = icmp eq i32 %5, 0
  br i1 %.not2537.not, label %.loopexit, label %.lr.ph41

.lr.ph41:                                         ; preds = %3, %._crit_edge
  %6 = phi i32 [ %16, %._crit_edge ], [ %5, %3 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %._crit_edge ], [ 0, %3 ]
  %.01938 = phi i64 [ %.120.lcssa, %._crit_edge ], [ 0, %3 ]
  %7 = load ptr, ptr %0, align 8, !tbaa !12
  %8 = getelementptr inbounds ptr, ptr %7, i64 %indvars.iv
  %.033 = load ptr, ptr %8, align 8, !tbaa !13
  %.not34 = icmp eq ptr %.033, null
  br i1 %.not34, label %._crit_edge, label %.lr.ph

9:                                                ; preds = %.lr.ph
  %10 = getelementptr inbounds i8, ptr %.036, i64 16
  %.0 = load ptr, ptr %10, align 8, !tbaa !13
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !14

.lr.ph:                                           ; preds = %.lr.ph41, %9
  %.036 = phi ptr [ %.0, %9 ], [ %.033, %.lr.ph41 ]
  %.12035 = phi i64 [ %11, %9 ], [ %.01938, %.lr.ph41 ]
  %11 = add i64 %.12035, 1
  %12 = load ptr, ptr %.036, align 8, !tbaa !16
  %13 = getelementptr inbounds i8, ptr %.036, i64 8
  %14 = load ptr, ptr %13, align 8, !tbaa !18
  %15 = tail call zeroext i1 %1(ptr noundef %12, ptr noundef %14, ptr noundef %2) #1
  br i1 %15, label %9, label %.loopexit

._crit_edge.loopexit:                             ; preds = %9
  %.pre = load i32, ptr %4, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.lr.ph41
  %16 = phi i32 [ %6, %.lr.ph41 ], [ %.pre, %._crit_edge.loopexit ]
  %.120.lcssa = phi i64 [ %.01938, %.lr.ph41 ], [ %11, %._crit_edge.loopexit ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %17 = zext i32 %16 to i64
  %.not25 = icmp ult i64 %indvars.iv.next, %17
  br i1 %.not25, label %.lr.ph41, label %.loopexit, !llvm.loop !19

.loopexit:                                        ; preds = %._crit_edge, %.lr.ph, %3
  %spec.select = phi i64 [ 0, %3 ], [ %11, %.lr.ph ], [ %.120.lcssa, %._crit_edge ]
  ret i64 %spec.select
}

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 = { 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, !11, i64 32}
!6 = !{!"hashtable", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !11, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !7, i64 0}
!17 = !{!"hash_node", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !11, i64 32}
!18 = !{!17, !7, i64 8}
!19 = distinct !{!19, !15}


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