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

; 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.hashtable2 = type { i64, ptr, ptr, ptr, i32 }
%struct.hash_node = type { 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 @hashtable2_traverse(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store i64 0, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.hashtable2, ptr %11, i32 0, i32 3
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  store ptr %13, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.hashtable2, ptr %14, i32 0, i32 3
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.hashtable2, ptr %17, i32 0, i32 4
  %19 = load i32, ptr %18, align 8, !tbaa !14
  %20 = zext i32 %19 to i64
  %21 = getelementptr inbounds %struct.hash_node, ptr %16, i64 %20
  store ptr %21, ptr %9, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %47, %3
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  %25 = icmp ne ptr %23, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %22
  store i32 2, ptr %10, align 4
  br label %50

27:                                               ; preds = %22
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.hash_node, ptr %28, i32 0, i32 2
  %30 = load i32, ptr %29, align 8, !tbaa !15
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %46

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

44:                                               ; preds = %32
  store i32 2, ptr %10, align 4
  br label %50

45:                                               ; preds = %32
  br label %46

46:                                               ; preds = %45, %27
  br label %47

47:                                               ; preds = %46
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.hash_node, ptr %48, i32 1
  store ptr %49, ptr %8, align 8, !tbaa !5
  br label %22, !llvm.loop !19

50:                                               ; preds = %44, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  br label %51

51:                                               ; preds = %50
  %52 = load i64, ptr %7, align 8, !tbaa !9
  store i32 1, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret i64 %52
}

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, !6, i64 24}
!12 = !{!"hashtable2", !10, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !13, i64 32}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !13, i64 32}
!15 = !{!16, !13, i64 16}
!16 = !{!"hash_node", !6, i64 0, !6, i64 8, !13, i64 16}
!17 = !{!16, !6, i64 0}
!18 = !{!16, !6, i64 8}
!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"

%struct.hash_node = type { ptr, ptr, i32 }

; Function Attrs: nounwind uwtable
define dso_local i64 @hashtable2_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 24
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 32
  %7 = load i32, ptr %6, align 8, !tbaa !12
  %8 = zext i32 %7 to i64
  %9 = getelementptr inbounds %struct.hash_node, ptr %5, i64 %8
  %.not14 = icmp eq i32 %7, 0
  br i1 %.not14, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3, %18
  %.016 = phi i64 [ %.1, %18 ], [ 0, %3 ]
  %.01215 = phi ptr [ %19, %18 ], [ %5, %3 ]
  %10 = getelementptr inbounds i8, ptr %.01215, i64 16
  %11 = load i32, ptr %10, align 8, !tbaa !13
  %.not13 = icmp eq i32 %11, 0
  br i1 %.not13, label %18, label %12

12:                                               ; preds = %.lr.ph
  %13 = add i64 %.016, 1
  %14 = load ptr, ptr %.01215, align 8, !tbaa !15
  %15 = getelementptr inbounds i8, ptr %.01215, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !16
  %17 = tail call zeroext i1 %1(ptr noundef %14, ptr noundef %16, ptr noundef %2) #1
  br i1 %17, label %18, label %._crit_edge

18:                                               ; preds = %.lr.ph, %12
  %.1 = phi i64 [ %13, %12 ], [ %.016, %.lr.ph ]
  %19 = getelementptr inbounds i8, ptr %.01215, i64 24
  %.not = icmp eq ptr %19, %9
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !17

._crit_edge:                                      ; preds = %18, %12, %3
  %.2 = phi i64 [ 0, %3 ], [ %13, %12 ], [ %.1, %18 ]
  ret i64 %.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 = { 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 24}
!6 = !{!"hashtable2", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !11, i64 32}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !11, i64 32}
!13 = !{!14, !11, i64 16}
!14 = !{!"hash_node", !10, i64 0, !10, i64 8, !11, i64 16}
!15 = !{!14, !10, i64 0}
!16 = !{!14, !10, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass