; 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_itor = type { ptr, ptr, i32 }
%struct.hash_node = type { ptr, ptr, ptr, ptr, i32 }
%struct.hashtable = type { ptr, ptr, ptr, i64, 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 zeroext i1 @hashtable_itor_next(ptr noundef %0) #1 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.hashtable_itor, ptr %6, i32 0, i32 1
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = icmp ne ptr %8, null
  br i1 %9, label %11, label %10

10:                                               ; preds = %1
  store i1 false, ptr %2, align 1
  br label %71

11:                                               ; preds = %1
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.hashtable_itor, ptr %12, i32 0, i32 1
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  %15 = getelementptr inbounds %struct.hash_node, ptr %14, i32 0, i32 2
  %16 = load ptr, ptr %15, align 8, !tbaa !12
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.hashtable_itor, ptr %17, i32 0, i32 1
  store ptr %16, ptr %18, align 8, !tbaa !9
  %19 = icmp ne ptr %16, null
  br i1 %19, label %20, label %21

20:                                               ; preds = %11
  store i1 true, ptr %2, align 1
  br label %71

21:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.hashtable_itor, ptr %22, i32 0, i32 2
  %24 = load i32, ptr %23, align 8, !tbaa !14
  store i32 %24, ptr %4, align 4, !tbaa !15
  br label %25

25:                                               ; preds = %60, %21
  %26 = load i32, ptr %4, align 4, !tbaa !15
  %27 = add i32 %26, 1
  store i32 %27, ptr %4, align 4, !tbaa !15
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.hashtable_itor, ptr %28, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !16
  %31 = getelementptr inbounds %struct.hashtable, ptr %30, i32 0, i32 4
  %32 = load i32, ptr %31, align 8, !tbaa !17
  %33 = icmp ult i32 %27, %32
  br i1 %33, label %34, label %61

34:                                               ; preds = %25
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.hashtable_itor, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !16
  %38 = getelementptr inbounds %struct.hashtable, ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !20
  %40 = load i32, ptr %4, align 4, !tbaa !15
  %41 = zext i32 %40 to i64
  %42 = getelementptr inbounds ptr, ptr %39, i64 %41
  %43 = load ptr, ptr %42, align 8, !tbaa !5
  %44 = icmp ne ptr %43, null
  br i1 %44, label %45, label %60

45:                                               ; preds = %34
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.hashtable_itor, ptr %46, i32 0, i32 0
  %48 = load ptr, ptr %47, align 8, !tbaa !16
  %49 = getelementptr inbounds %struct.hashtable, ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !20
  %51 = load i32, ptr %4, align 4, !tbaa !15
  %52 = zext i32 %51 to i64
  %53 = getelementptr inbounds ptr, ptr %50, i64 %52
  %54 = load ptr, ptr %53, align 8, !tbaa !5
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.hashtable_itor, ptr %55, i32 0, i32 1
  store ptr %54, ptr %56, align 8, !tbaa !9
  %57 = load i32, ptr %4, align 4, !tbaa !15
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.hashtable_itor, ptr %58, i32 0, i32 2
  store i32 %57, ptr %59, align 8, !tbaa !14
  store i1 true, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %70

60:                                               ; preds = %34
  br label %25, !llvm.loop !21

61:                                               ; preds = %25
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.hashtable_itor, ptr %62, i32 0, i32 1
  store ptr null, ptr %63, align 8, !tbaa !9
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.hashtable_itor, ptr %64, i32 0, i32 2
  store i32 0, ptr %65, align 8, !tbaa !14
  %66 = load ptr, ptr %3, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.hashtable_itor, ptr %66, i32 0, i32 1
  %68 = load ptr, ptr %67, align 8, !tbaa !9
  %69 = icmp ne ptr %68, null
  store i1 %69, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %70

70:                                               ; preds = %61, %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %71

71:                                               ; preds = %70, %20, %10
  %72 = load i1, ptr %2, align 1
  ret i1 %72
}

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, !6, i64 8}
!10 = !{!"hashtable_itor", !6, i64 0, !6, i64 8, !11, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 16}
!13 = !{!"hash_node", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32}
!14 = !{!10, !11, i64 16}
!15 = !{!11, !11, i64 0}
!16 = !{!10, !6, i64 0}
!17 = !{!18, !11, i64 32}
!18 = !{!"hashtable", !6, i64 0, !6, i64 8, !6, i64 16, !19, i64 24, !11, i64 32}
!19 = !{!"long", !7, i64 0}
!20 = !{!18, !6, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"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"

; Function Attrs: nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @hashtable_itor_next(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %22, label %4

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %3, i64 16
  %6 = load ptr, ptr %5, align 8, !tbaa !11
  store ptr %6, ptr %2, align 8, !tbaa !5
  %.not20 = icmp eq ptr %6, null
  br i1 %.not20, label %7, label %22

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  %9 = load i32, ptr %8, align 8, !tbaa !13
  %10 = load ptr, ptr %0, align 8, !tbaa !14
  %11 = getelementptr inbounds i8, ptr %10, i64 32
  %12 = load i32, ptr %11, align 8, !tbaa !15
  br label %13

13:                                               ; preds = %16, %7
  %.0 = phi i32 [ %9, %7 ], [ %14, %16 ]
  %14 = add i32 %.0, 1
  %15 = icmp ult i32 %14, %12
  br i1 %15, label %16, label %21

16:                                               ; preds = %13
  %17 = load ptr, ptr %10, align 8, !tbaa !18
  %18 = zext i32 %14 to i64
  %19 = getelementptr inbounds ptr, ptr %17, i64 %18
  %20 = load ptr, ptr %19, align 8, !tbaa !19
  %.not22 = icmp eq ptr %20, null
  br i1 %.not22, label %13, label %21, !llvm.loop !20

21:                                               ; preds = %13, %16
  %storemerge21 = phi ptr [ null, %13 ], [ %20, %16 ]
  %storemerge = phi i32 [ 0, %13 ], [ %14, %16 ]
  store ptr %storemerge21, ptr %2, align 8, !tbaa !5
  store i32 %storemerge, ptr %8, align 8, !tbaa !13
  br label %22

22:                                               ; preds = %4, %1, %21
  %.1 = phi i1 [ %15, %21 ], [ false, %1 ], [ true, %4 ]
  ret i1 %.1
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) 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" }

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass