; 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: 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 @hashtable2_itor_first(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
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %6

6:                                                ; preds = %32, %1
  %7 = load i32, ptr %4, align 4, !tbaa !9
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.hashtable2_itor, ptr %8, i32 0, i32 0
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %11 = getelementptr inbounds %struct.hashtable2, ptr %10, i32 0, i32 4
  %12 = load i32, ptr %11, align 8, !tbaa !13
  %13 = icmp ult i32 %7, %12
  br i1 %13, label %15, label %14

14:                                               ; preds = %6
  store i32 2, ptr %5, align 4
  br label %35

15:                                               ; preds = %6
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.hashtable2_itor, ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = getelementptr inbounds %struct.hashtable2, ptr %18, i32 0, i32 3
  %20 = load ptr, ptr %19, align 8, !tbaa !16
  %21 = load i32, ptr %4, align 4, !tbaa !9
  %22 = zext i32 %21 to i64
  %23 = getelementptr inbounds %struct.hash_node, ptr %20, i64 %22
  %24 = getelementptr inbounds %struct.hash_node, ptr %23, i32 0, i32 2
  %25 = load i32, ptr %24, align 8, !tbaa !17
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %31

27:                                               ; preds = %15
  %28 = load i32, ptr %4, align 4, !tbaa !9
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.hashtable2_itor, ptr %29, i32 0, i32 1
  store i32 %28, ptr %30, align 8, !tbaa !19
  store i1 true, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %35

31:                                               ; preds = %15
  br label %32

32:                                               ; preds = %31
  %33 = load i32, ptr %4, align 4, !tbaa !9
  %34 = add i32 %33, 1
  store i32 %34, ptr %4, align 4, !tbaa !9
  br label %6, !llvm.loop !20

35:                                               ; preds = %27, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %36 = load i32, ptr %5, align 4
  switch i32 %36, label %42 [
    i32 2, label %37
    i32 1, label %40
  ]

37:                                               ; preds = %35
  %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 !19
  store i1 false, ptr %2, align 1
  br label %40

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

42:                                               ; preds = %35
  unreachable
}

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 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"hashtable2_itor", !6, i64 0, !10, i64 8}
!13 = !{!14, !10, i64 32}
!14 = !{!"hashtable2", !15, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !10, i64 32}
!15 = !{!"long", !7, i64 0}
!16 = !{!14, !6, i64 24}
!17 = !{!18, !10, i64 16}
!18 = !{!"hash_node", !6, i64 0, !6, i64 8, !10, i64 16}
!19 = !{!12, !10, i64 8}
!20 = distinct !{!20, !21}
!21 = !{!"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 zeroext i1 @hashtable2_itor_first(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %2, i64 32
  %4 = load i32, ptr %3, align 8, !tbaa !11
  %.not21 = icmp eq i32 %4, 0
  br i1 %.not21, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %5 = getelementptr inbounds i8, ptr %2, i64 24
  %6 = load ptr, ptr %5, align 8, !tbaa !14
  %7 = zext i32 %4 to i64
  %8 = getelementptr inbounds i8, ptr %6, i64 16
  %9 = load i32, ptr %8, align 8, !tbaa !15
  %.not30 = icmp eq i32 %9, 0
  br i1 %.not30, label %.lr.ph32, label %._crit_edge

10:                                               ; preds = %.lr.ph32
  %11 = getelementptr inbounds %struct.hash_node, ptr %6, i64 %indvars.iv.next, i32 2
  %12 = load i32, ptr %11, align 8, !tbaa !15
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %.lr.ph32, label %._crit_edge33, !llvm.loop !17

.lr.ph32:                                         ; preds = %.lr.ph, %10
  %indvars.iv31 = phi i64 [ %indvars.iv.next, %10 ], [ 0, %.lr.ph ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv31, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %7
  br i1 %exitcond.not, label %._crit_edge, label %10, !llvm.loop !17

._crit_edge33:                                    ; preds = %10
  %13 = icmp ult i64 %indvars.iv.next, %7
  %14 = trunc nuw i64 %indvars.iv.next to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph32, %.lr.ph, %._crit_edge33, %1
  %.sink = phi i32 [ -1, %1 ], [ %14, %._crit_edge33 ], [ 0, %.lr.ph ], [ -1, %.lr.ph32 ]
  %15 = phi i1 [ false, %1 ], [ %13, %._crit_edge33 ], [ true, %.lr.ph ], [ false, %.lr.ph32 ]
  %16 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %.sink, ptr %16, align 8, !tbaa !19
  ret i1 %15
}

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 0}
!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 = !{!12, !10, i64 32}
!12 = !{!"hashtable2", !13, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32}
!13 = !{!"long", !8, i64 0}
!14 = !{!12, !7, i64 24}
!15 = !{!16, !10, i64 16}
!16 = !{!"hash_node", !7, i64 0, !7, i64 8, !10, i64 16}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!6, !10, i64 8}


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