; 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 }
%struct.hash_node = type { ptr, ptr, 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 @hashtable_itor_search(ptr noundef %0, ptr noundef %1) #1 {
  %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 ptr, align 8
  %9 = 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) #2
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.hashtable_itor, ptr %10, i32 0, i32 0
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = getelementptr inbounds %struct.hashtable, ptr %12, i32 0, i32 2
  %14 = load ptr, ptr %13, align 8, !tbaa !12
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = call i32 %14(ptr noundef %15)
  store i32 %16, ptr %6, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %17 = load i32, ptr %6, align 4, !tbaa !15
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.hashtable_itor, ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct.hashtable, ptr %20, i32 0, i32 4
  %22 = load i32, ptr %21, align 8, !tbaa !16
  %23 = urem i32 %17, %22
  store i32 %23, ptr %7, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.hashtable_itor, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !9
  %27 = getelementptr inbounds %struct.hashtable, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !17
  %29 = load i32, ptr %7, align 4, !tbaa !15
  %30 = zext i32 %29 to i64
  %31 = getelementptr inbounds ptr, ptr %28, i64 %30
  %32 = load ptr, ptr %31, align 8, !tbaa !5
  store ptr %32, ptr %8, align 8, !tbaa !5
  br label %33

33:                                               ; preds = %69, %2
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = icmp ne ptr %34, null
  br i1 %35, label %36, label %42

36:                                               ; preds = %33
  %37 = load i32, ptr %6, align 4, !tbaa !15
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.hash_node, ptr %38, i32 0, i32 4
  %40 = load i32, ptr %39, align 8, !tbaa !18
  %41 = icmp uge i32 %37, %40
  br label %42

42:                                               ; preds = %36, %33
  %43 = phi i1 [ false, %33 ], [ %41, %36 ]
  br i1 %43, label %44, label %73

44:                                               ; preds = %42
  %45 = load i32, ptr %6, align 4, !tbaa !15
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.hash_node, ptr %46, i32 0, i32 4
  %48 = load i32, ptr %47, align 8, !tbaa !18
  %49 = icmp eq i32 %45, %48
  br i1 %49, label %50, label %69

50:                                               ; preds = %44
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.hashtable_itor, ptr %51, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !9
  %54 = getelementptr inbounds %struct.hashtable, ptr %53, i32 0, i32 1
  %55 = load ptr, ptr %54, align 8, !tbaa !20
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.hash_node, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !21
  %60 = call i32 %55(ptr noundef %56, ptr noundef %59)
  %61 = icmp eq i32 %60, 0
  br i1 %61, label %62, label %69

62:                                               ; preds = %50
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.hashtable_itor, ptr %64, i32 0, i32 1
  store ptr %63, ptr %65, align 8, !tbaa !22
  %66 = load i32, ptr %7, align 4, !tbaa !15
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.hashtable_itor, ptr %67, i32 0, i32 2
  store i32 %66, ptr %68, align 8, !tbaa !23
  store i1 true, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %78

69:                                               ; preds = %50, %44
  %70 = load ptr, ptr %8, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.hash_node, ptr %70, i32 0, i32 2
  %72 = load ptr, ptr %71, align 8, !tbaa !24
  store ptr %72, ptr %8, align 8, !tbaa !5
  br label %33, !llvm.loop !25

73:                                               ; preds = %42
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.hashtable_itor, ptr %74, i32 0, i32 1
  store ptr null, ptr %75, align 8, !tbaa !22
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.hashtable_itor, ptr %76, i32 0, i32 2
  store i32 0, ptr %77, align 8, !tbaa !23
  store i1 false, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %78

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

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 0}
!10 = !{!"hashtable_itor", !6, i64 0, !6, i64 8, !11, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 16}
!13 = !{!"hashtable", !6, i64 0, !6, i64 8, !6, i64 16, !14, i64 24, !11, i64 32}
!14 = !{!"long", !7, i64 0}
!15 = !{!11, !11, i64 0}
!16 = !{!13, !11, i64 32}
!17 = !{!13, !6, i64 0}
!18 = !{!19, !11, i64 32}
!19 = !{!"hash_node", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32}
!20 = !{!13, !6, i64 8}
!21 = !{!19, !6, i64 0}
!22 = !{!10, !6, i64 8}
!23 = !{!10, !11, i64 16}
!24 = !{!19, !6, i64 16}
!25 = distinct !{!25, !26}
!26 = !{!"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: nounwind uwtable
define dso_local noundef zeroext i1 @hashtable_itor_search(ptr nocapture noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %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 %5(ptr noundef %1) #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
  %11 = load ptr, ptr %7, align 8, !tbaa !15
  %12 = zext i32 %10 to i64
  %13 = getelementptr inbounds ptr, ptr %11, i64 %12
  %.026 = load ptr, ptr %13, align 8, !tbaa !16
  %.not27 = icmp eq ptr %.026, null
  br i1 %.not27, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %25
  %.028 = phi ptr [ %.0, %25 ], [ %.026, %2 ]
  %14 = getelementptr inbounds i8, ptr %.028, i64 32
  %15 = load i32, ptr %14, align 8, !tbaa !17
  %.not24 = icmp ult i32 %6, %15
  br i1 %.not24, label %.critedge, label %16

16:                                               ; preds = %.lr.ph
  %17 = icmp eq i32 %6, %15
  br i1 %17, label %18, label %25

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

25:                                               ; preds = %18, %16
  %26 = getelementptr inbounds i8, ptr %.028, i64 16
  %.0 = load ptr, ptr %26, align 8, !tbaa !16
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %.critedge, label %.lr.ph, !llvm.loop !21

.critedge:                                        ; preds = %25, %.lr.ph, %18, %2
  %.sink33 = phi ptr [ null, %2 ], [ %.028, %18 ], [ null, %.lr.ph ], [ null, %25 ]
  %.sink = phi i32 [ 0, %2 ], [ %10, %18 ], [ 0, %.lr.ph ], [ 0, %25 ]
  %.021 = phi i1 [ false, %2 ], [ true, %18 ], [ false, %.lr.ph ], [ false, %25 ]
  %27 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %.sink33, ptr %27, align 8, !tbaa !23
  %28 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 %.sink, ptr %28, align 8, !tbaa !24
  ret i1 %.021
}

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


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