; 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: inlinehint nounwind uwtable
declare hidden i32 @nonzero_hash(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @hashtable2_itor_search(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %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
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.hashtable2_itor, ptr %11, i32 0, i32 0
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  %14 = getelementptr inbounds %struct.hashtable2, ptr %13, i32 0, i32 2
  %15 = load ptr, ptr %14, align 8, !tbaa !12
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = call i32 @nonzero_hash(ptr noundef %15, ptr noundef %16)
  store i32 %17, ptr %6, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %18 = load i32, ptr %6, align 4, !tbaa !15
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.hashtable2_itor, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.hashtable2, ptr %21, i32 0, i32 4
  %23 = load i32, ptr %22, align 8, !tbaa !16
  %24 = urem i32 %18, %23
  store i32 %24, ptr %7, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %25 = load i32, ptr %7, align 4, !tbaa !15
  store i32 %25, ptr %8, align 4, !tbaa !15
  br label %26

26:                                               ; preds = %76, %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.hashtable2_itor, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !9
  %30 = getelementptr inbounds %struct.hashtable2, ptr %29, i32 0, i32 3
  %31 = load ptr, ptr %30, align 8, !tbaa !17
  %32 = load i32, ptr %8, align 4, !tbaa !15
  %33 = zext i32 %32 to i64
  %34 = getelementptr inbounds %struct.hash_node, ptr %31, i64 %33
  store ptr %34, ptr %9, align 8, !tbaa !5
  %35 = load ptr, ptr %9, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.hash_node, ptr %35, i32 0, i32 2
  %37 = load i32, ptr %36, align 8, !tbaa !18
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %40, label %39

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

40:                                               ; preds = %26
  %41 = load ptr, ptr %9, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.hash_node, ptr %41, i32 0, i32 2
  %43 = load i32, ptr %42, align 8, !tbaa !18
  %44 = load i32, ptr %6, align 4, !tbaa !15
  %45 = icmp eq i32 %43, %44
  br i1 %45, label %46, label %62

46:                                               ; preds = %40
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.hashtable2_itor, ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !9
  %50 = getelementptr inbounds %struct.hashtable2, ptr %49, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !20
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.hash_node, ptr %53, i32 0, i32 0
  %55 = load ptr, ptr %54, align 8, !tbaa !21
  %56 = call i32 %51(ptr noundef %52, ptr noundef %55)
  %57 = icmp eq i32 %56, 0
  br i1 %57, label %58, label %62

58:                                               ; preds = %46
  %59 = load i32, ptr %8, align 4, !tbaa !15
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.hashtable2_itor, ptr %60, i32 0, i32 1
  store i32 %59, ptr %61, align 8, !tbaa !22
  store i1 true, ptr %3, align 1
  store i32 1, ptr %10, align 4
  br label %73

62:                                               ; preds = %46, %40
  %63 = load i32, ptr %8, align 4, !tbaa !15
  %64 = add i32 %63, 1
  store i32 %64, ptr %8, align 4, !tbaa !15
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.hashtable2_itor, ptr %65, i32 0, i32 0
  %67 = load ptr, ptr %66, align 8, !tbaa !9
  %68 = getelementptr inbounds %struct.hashtable2, ptr %67, i32 0, i32 4
  %69 = load i32, ptr %68, align 8, !tbaa !16
  %70 = icmp eq i32 %64, %69
  br i1 %70, label %71, label %72

71:                                               ; preds = %62
  store i32 0, ptr %8, align 4, !tbaa !15
  br label %72

72:                                               ; preds = %71, %62
  store i32 0, ptr %10, align 4
  br label %73

73:                                               ; preds = %72, %58, %39
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  %74 = load i32, ptr %10, align 4
  switch i32 %74, label %83 [
    i32 0, label %75
    i32 2, label %80
  ]

75:                                               ; preds = %73
  br label %76

76:                                               ; preds = %75
  %77 = load i32, ptr %8, align 4, !tbaa !15
  %78 = load i32, ptr %7, align 4, !tbaa !15
  %79 = icmp ne i32 %77, %78
  br i1 %79, label %26, label %80, !llvm.loop !23

80:                                               ; preds = %76, %73
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.hashtable2_itor, ptr %81, i32 0, i32 1
  store i32 -1, ptr %82, align 8, !tbaa !22
  store i1 false, ptr %3, align 1
  store i32 1, ptr %10, align 4
  br label %83

83:                                               ; preds = %80, %73
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %84 = load i1, ptr %3, align 1
  ret i1 %84
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 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 #3 = { 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 0}
!10 = !{!"hashtable2_itor", !6, i64 0, !11, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 16}
!13 = !{!"hashtable2", !14, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32}
!14 = !{!"long", !7, i64 0}
!15 = !{!11, !11, i64 0}
!16 = !{!13, !11, i64 32}
!17 = !{!13, !6, i64 24}
!18 = !{!19, !11, i64 16}
!19 = !{!"hash_node", !6, i64 0, !6, i64 8, !11, i64 16}
!20 = !{!13, !6, i64 8}
!21 = !{!19, !6, i64 0}
!22 = !{!10, !11, i64 8}
!23 = distinct !{!23, !24}
!24 = !{!"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: inlinehint nounwind uwtable
declare hidden i32 @nonzero_hash(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @hashtable2_itor_search(ptr nocapture noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 16
  %5 = load ptr, ptr %4, align 8, !tbaa !11
  %6 = tail call i32 @nonzero_hash(ptr noundef %5, ptr noundef %1)
  %7 = load ptr, ptr %0, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %7, i64 32
  %9 = load i32, ptr %8, align 8, !tbaa !14
  %10 = urem i32 %6, %9
  br label %11

11:                                               ; preds = %27, %2
  %12 = phi ptr [ %7, %2 ], [ %28, %27 ]
  %.022 = phi i32 [ %10, %2 ], [ %spec.store.select, %27 ]
  %13 = getelementptr inbounds i8, ptr %12, i64 24
  %14 = load ptr, ptr %13, align 8, !tbaa !15
  %15 = zext i32 %.022 to i64
  %16 = getelementptr inbounds %struct.hash_node, ptr %14, i64 %15
  %17 = getelementptr inbounds i8, ptr %16, i64 16
  %18 = load i32, ptr %17, align 8, !tbaa !16
  %.not = icmp eq i32 %18, 0
  br i1 %.not, label %.thread, label %19

19:                                               ; preds = %11
  %20 = icmp eq i32 %18, %6
  br i1 %20, label %21, label %27

21:                                               ; preds = %19
  %22 = getelementptr inbounds i8, ptr %12, i64 8
  %23 = load ptr, ptr %22, align 8, !tbaa !18
  %24 = load ptr, ptr %16, align 8, !tbaa !19
  %25 = tail call i32 %23(ptr noundef %1, ptr noundef %24) #2
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %.thread, label %._crit_edge

._crit_edge:                                      ; preds = %21
  %.pre = load ptr, ptr %0, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %._crit_edge, %19
  %28 = phi ptr [ %.pre, %._crit_edge ], [ %12, %19 ]
  %29 = add i32 %.022, 1
  %30 = getelementptr inbounds i8, ptr %28, i64 32
  %31 = load i32, ptr %30, align 8, !tbaa !14
  %32 = icmp eq i32 %29, %31
  %spec.store.select = select i1 %32, i32 0, i32 %29
  %.not25 = icmp eq i32 %spec.store.select, %10
  br i1 %.not25, label %.thread, label %11, !llvm.loop !20

.thread:                                          ; preds = %27, %11, %21
  %.022.lcssa34.sink = phi i32 [ %.022, %21 ], [ -1, %11 ], [ -1, %27 ]
  %.2 = phi i1 [ true, %21 ], [ false, %11 ], [ false, %27 ]
  %33 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %.022.lcssa34.sink, ptr %33, align 8, !tbaa !22
  ret i1 %.2
}

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass