; 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.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_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 = %42, %1
  %7 = load i32, ptr %4, align 4, !tbaa !9
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.hashtable_itor, ptr %8, i32 0, i32 0
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %11 = getelementptr inbounds %struct.hashtable, 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 %45

15:                                               ; preds = %6
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.hashtable_itor, ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %19 = getelementptr inbounds %struct.hashtable, ptr %18, i32 0, i32 0
  %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 ptr, ptr %20, i64 %22
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %41

26:                                               ; preds = %15
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.hashtable_itor, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !11
  %30 = getelementptr inbounds %struct.hashtable, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !16
  %32 = load i32, ptr %4, align 4, !tbaa !9
  %33 = zext i32 %32 to i64
  %34 = getelementptr inbounds ptr, ptr %31, i64 %33
  %35 = load ptr, ptr %34, align 8, !tbaa !5
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.hashtable_itor, ptr %36, i32 0, i32 1
  store ptr %35, ptr %37, align 8, !tbaa !17
  %38 = load i32, ptr %4, align 4, !tbaa !9
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.hashtable_itor, ptr %39, i32 0, i32 2
  store i32 %38, ptr %40, align 8, !tbaa !18
  store i1 true, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %45

41:                                               ; preds = %15
  br label %42

42:                                               ; preds = %41
  %43 = load i32, ptr %4, align 4, !tbaa !9
  %44 = add i32 %43, 1
  store i32 %44, ptr %4, align 4, !tbaa !9
  br label %6, !llvm.loop !19

45:                                               ; preds = %26, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %46 = load i32, ptr %5, align 4
  switch i32 %46, label %54 [
    i32 2, label %47
    i32 1, label %52
  ]

47:                                               ; preds = %45
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.hashtable_itor, ptr %48, i32 0, i32 1
  store ptr null, ptr %49, align 8, !tbaa !17
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.hashtable_itor, ptr %50, i32 0, i32 2
  store i32 0, ptr %51, align 8, !tbaa !18
  store i1 false, ptr %2, align 1
  br label %52

52:                                               ; preds = %47, %45
  %53 = load i1, ptr %2, align 1
  ret i1 %53

54:                                               ; preds = %45
  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 = !{!"hashtable_itor", !6, i64 0, !6, i64 8, !10, i64 16}
!13 = !{!14, !10, i64 32}
!14 = !{!"hashtable", !6, i64 0, !6, i64 8, !6, i64 16, !15, i64 24, !10, i64 32}
!15 = !{!"long", !7, i64 0}
!16 = !{!14, !6, i64 0}
!17 = !{!12, !6, i64 8}
!18 = !{!12, !10, 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"

; Function Attrs: nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local zeroext i1 @hashtable_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
  %.not29 = icmp eq i32 %4, 0
  br i1 %.not29, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %5 = load ptr, ptr %2, align 8, !tbaa !14
  %6 = zext i32 %4 to i64
  %7 = load ptr, ptr %5, align 8, !tbaa !15
  %.not43 = icmp eq ptr %7, null
  br i1 %.not43, label %.lr.ph45, label %._crit_edge

8:                                                ; preds = %.lr.ph45
  %9 = getelementptr inbounds ptr, ptr %5, i64 %indvars.iv.next
  %10 = load ptr, ptr %9, align 8, !tbaa !15
  %.not = icmp eq ptr %10, null
  br i1 %.not, label %.lr.ph45, label %._crit_edge46, !llvm.loop !16

.lr.ph45:                                         ; preds = %.lr.ph, %8
  %indvars.iv44 = phi i64 [ %indvars.iv.next, %8 ], [ 0, %.lr.ph ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv44, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %6
  br i1 %exitcond.not, label %._crit_edge, label %8, !llvm.loop !16

._crit_edge46:                                    ; preds = %8
  %11 = icmp ult i64 %indvars.iv.next, %6
  %12 = trunc nuw i64 %indvars.iv.next to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph45, %.lr.ph, %._crit_edge46, %1
  %.lcssa30.sink = phi ptr [ null, %1 ], [ %10, %._crit_edge46 ], [ %7, %.lr.ph ], [ null, %.lr.ph45 ]
  %.sink = phi i32 [ 0, %1 ], [ %12, %._crit_edge46 ], [ 0, %.lr.ph ], [ 0, %.lr.ph45 ]
  %13 = phi i1 [ false, %1 ], [ %11, %._crit_edge46 ], [ true, %.lr.ph ], [ false, %.lr.ph45 ]
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %.lcssa30.sink, ptr %14, align 8, !tbaa !18
  %15 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 %.sink, ptr %15, align 8, !tbaa !19
  ret i1 %13
}

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


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