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

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @hashtable2_itor_next(ptr noundef %0) #0 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.hashtable2_itor, ptr %4, i32 0, i32 1
  %6 = load i32, ptr %5, align 8, !tbaa !9
  %7 = icmp slt i32 %6, 0
  br i1 %7, label %8, label %9

8:                                                ; preds = %1
  store i1 false, ptr %2, align 1
  br label %40

9:                                                ; preds = %1
  br label %10

10:                                               ; preds = %36, %9
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.hashtable2_itor, ptr %11, i32 0, i32 1
  %13 = load i32, ptr %12, align 8, !tbaa !9
  %14 = add nsw i32 %13, 1
  store i32 %14, ptr %12, align 8, !tbaa !9
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.hashtable2_itor, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !12
  %18 = getelementptr inbounds %struct.hashtable2, ptr %17, i32 0, i32 4
  %19 = load i32, ptr %18, align 8, !tbaa !13
  %20 = icmp slt i32 %14, %19
  br i1 %20, label %21, label %37

21:                                               ; preds = %10
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.hashtable2_itor, ptr %22, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !12
  %25 = getelementptr inbounds %struct.hashtable2, ptr %24, i32 0, i32 3
  %26 = load ptr, ptr %25, align 8, !tbaa !16
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.hashtable2_itor, ptr %27, i32 0, i32 1
  %29 = load i32, ptr %28, align 8, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds %struct.hash_node, ptr %26, i64 %30
  %32 = getelementptr inbounds %struct.hash_node, ptr %31, i32 0, i32 2
  %33 = load i32, ptr %32, align 8, !tbaa !17
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %36

35:                                               ; preds = %21
  store i1 true, ptr %2, align 1
  br label %40

36:                                               ; preds = %21
  br label %10, !llvm.loop !19

37:                                               ; preds = %10
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.hashtable2_itor, ptr %38, i32 0, i32 1
  store i32 -1, ptr %39, align 8, !tbaa !9
  store i1 false, ptr %2, align 1
  br label %40

40:                                               ; preds = %37, %35, %8
  %41 = load i1, ptr %2, align 1
  ret i1 %41
}

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

!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 8}
!10 = !{!"hashtable2_itor", !6, i64 0, !11, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 0}
!13 = !{!14, !11, i64 32}
!14 = !{!"hashtable2", !15, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32}
!15 = !{!"long", !7, i64 0}
!16 = !{!14, !6, i64 24}
!17 = !{!18, !11, i64 16}
!18 = !{!"hash_node", !6, i64 0, !6, i64 8, !11, i64 16}
!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: nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @hashtable2_itor_next(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %4 = icmp slt i32 %3, 0
  br i1 %4, label %18, label %.preheader

.preheader:                                       ; preds = %1
  %5 = load ptr, ptr %0, align 8, !tbaa !11
  %6 = getelementptr inbounds i8, ptr %5, i64 32
  %7 = load i32, ptr %6, align 8, !tbaa !12
  %8 = getelementptr inbounds i8, ptr %5, i64 24
  %9 = zext nneg i32 %3 to i64
  %10 = sext i32 %7 to i64
  br label %11

11:                                               ; preds = %.preheader, %13
  %indvars.iv = phi i64 [ %9, %.preheader ], [ %indvars.iv.next, %13 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %12 = icmp slt i64 %indvars.iv.next, %10
  br i1 %12, label %13, label %.sink.split

13:                                               ; preds = %11
  %14 = load ptr, ptr %8, align 8, !tbaa !15
  %15 = getelementptr inbounds %struct.hash_node, ptr %14, i64 %indvars.iv.next, i32 2
  %16 = load i32, ptr %15, align 8, !tbaa !16
  %.not = icmp eq i32 %16, 0
  br i1 %.not, label %11, label %.loopexit, !llvm.loop !18

.loopexit:                                        ; preds = %13
  %17 = trunc nsw i64 %indvars.iv.next to i32
  br label %.sink.split

.sink.split:                                      ; preds = %11, %.loopexit
  %.sink = phi i32 [ %17, %.loopexit ], [ -1, %11 ]
  store i32 %.sink, ptr %2, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %.sink.split, %1
  %.0 = phi i1 [ false, %1 ], [ %12, %.sink.split ]
  ret i1 %.0
}

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


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