; 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.dict_remove_result = type { ptr, ptr, i8 }
%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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; 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) #2

; Function Attrs: nounwind uwtable
define dso_local void @hashtable2_remove(ptr dead_on_unwind noalias writable sret(%struct.dict_remove_result) align 8 %0, ptr noundef %1, ptr noundef %2) #3 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %1, ptr %4, align 8, !tbaa !5
  store ptr %2, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.hashtable2, ptr %11, i32 0, i32 2
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = call i32 @nonzero_hash(ptr noundef %13, ptr noundef %14)
  store i32 %15, ptr %6, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.hashtable2, ptr %16, i32 0, i32 3
  %18 = load ptr, ptr %17, align 8, !tbaa !14
  %19 = load i32, ptr %6, align 4, !tbaa !13
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.hashtable2, ptr %20, i32 0, i32 4
  %22 = load i32, ptr %21, align 8, !tbaa !15
  %23 = urem i32 %19, %22
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds %struct.hash_node, ptr %18, i64 %24
  store ptr %25, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.hashtable2, ptr %26, i32 0, i32 3
  %28 = load ptr, ptr %27, align 8, !tbaa !14
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.hashtable2, ptr %29, i32 0, i32 4
  %31 = load i32, ptr %30, align 8, !tbaa !15
  %32 = zext i32 %31 to i64
  %33 = getelementptr inbounds %struct.hash_node, ptr %28, i64 %32
  store ptr %33, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %34, ptr %9, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %80, %3
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.hash_node, ptr %36, i32 0, i32 2
  %38 = load i32, ptr %37, align 8, !tbaa !16
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %41, label %40

40:                                               ; preds = %35
  br label %84

41:                                               ; preds = %35
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.hash_node, ptr %42, i32 0, i32 2
  %44 = load i32, ptr %43, align 8, !tbaa !16
  %45 = load i32, ptr %6, align 4, !tbaa !13
  %46 = icmp eq i32 %44, %45
  br i1 %46, label %47, label %70

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

57:                                               ; preds = %47
  %58 = getelementptr inbounds %struct.dict_remove_result, ptr %0, i32 0, i32 0
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.hash_node, ptr %59, i32 0, i32 0
  %61 = load ptr, ptr %60, align 8, !tbaa !19
  store ptr %61, ptr %58, align 8, !tbaa !20
  %62 = getelementptr inbounds %struct.dict_remove_result, ptr %0, i32 0, i32 1
  %63 = load ptr, ptr %9, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.hash_node, ptr %63, i32 0, i32 1
  %65 = load ptr, ptr %64, align 8, !tbaa !23
  store ptr %65, ptr %62, align 8, !tbaa !24
  %66 = getelementptr inbounds %struct.dict_remove_result, ptr %0, i32 0, i32 2
  store i8 1, ptr %66, align 8, !tbaa !25
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = load ptr, ptr %9, align 8, !tbaa !5
  call void @remove_node(ptr noundef %67, ptr noundef %68, ptr noundef %69)
  store i32 1, ptr %10, align 4
  br label %88

70:                                               ; preds = %47, %41
  %71 = load ptr, ptr %9, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.hash_node, ptr %71, i32 1
  store ptr %72, ptr %9, align 8, !tbaa !5
  %73 = load ptr, ptr %8, align 8, !tbaa !5
  %74 = icmp eq ptr %72, %73
  br i1 %74, label %75, label %79

75:                                               ; preds = %70
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.hashtable2, ptr %76, i32 0, i32 3
  %78 = load ptr, ptr %77, align 8, !tbaa !14
  store ptr %78, ptr %9, align 8, !tbaa !5
  br label %79

79:                                               ; preds = %75, %70
  br label %80

80:                                               ; preds = %79
  %81 = load ptr, ptr %9, align 8, !tbaa !5
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  %83 = icmp ne ptr %81, %82
  br i1 %83, label %35, label %84, !llvm.loop !26

84:                                               ; preds = %80, %40
  call void @llvm.memset.p0.i64(ptr align 8 %0, i8 0, i64 24, i1 false)
  %85 = getelementptr inbounds %struct.dict_remove_result, ptr %0, i32 0, i32 0
  %86 = getelementptr inbounds %struct.dict_remove_result, ptr %0, i32 0, i32 1
  %87 = getelementptr inbounds %struct.dict_remove_result, ptr %0, i32 0, i32 2
  store i32 1, ptr %10, align 4
  br label %88

88:                                               ; preds = %84, %57
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @remove_node(ptr noundef, ptr noundef, ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { 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 #3 = { 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 #4 = { 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 16}
!10 = !{!"hashtable2", !11, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !12, i64 32}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!12, !12, i64 0}
!14 = !{!10, !6, i64 24}
!15 = !{!10, !12, i64 32}
!16 = !{!17, !12, i64 16}
!17 = !{!"hash_node", !6, i64 0, !6, i64 8, !12, i64 16}
!18 = !{!10, !6, i64 8}
!19 = !{!17, !6, i64 0}
!20 = !{!21, !6, i64 0}
!21 = !{!"", !6, i64 0, !6, i64 8, !22, i64 16}
!22 = !{!"_Bool", !7, i64 0}
!23 = !{!17, !6, i64 8}
!24 = !{!21, !6, i64 8}
!25 = !{!21, !22, i64 16}
!26 = distinct !{!26, !27}
!27 = !{!"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.dict_remove_result = type { ptr, ptr, i8 }
%struct.hash_node = type { ptr, ptr, i32 }

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @nonzero_hash(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @hashtable2_remove(ptr dead_on_unwind noalias nocapture writable writeonly sret(%struct.dict_remove_result) align 8 %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #2 {
  %4 = getelementptr inbounds i8, ptr %1, i64 16
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = tail call i32 @nonzero_hash(ptr noundef %5, ptr noundef %2)
  %7 = getelementptr inbounds i8, ptr %1, i64 24
  %8 = load ptr, ptr %7, align 8, !tbaa !12
  %9 = getelementptr inbounds i8, ptr %1, i64 32
  %10 = load i32, ptr %9, align 8, !tbaa !13
  %11 = urem i32 %6, %10
  %12 = zext i32 %11 to i64
  %13 = getelementptr inbounds %struct.hash_node, ptr %8, i64 %12
  %14 = zext i32 %10 to i64
  %15 = getelementptr inbounds %struct.hash_node, ptr %8, i64 %14
  %16 = getelementptr inbounds i8, ptr %1, i64 8
  br label %17

17:                                               ; preds = %35, %3
  %.0 = phi ptr [ %13, %3 ], [ %.1, %35 ]
  %18 = getelementptr inbounds i8, ptr %.0, i64 16
  %19 = load i32, ptr %18, align 8, !tbaa !14
  %.not = icmp eq i32 %19, 0
  br i1 %.not, label %36, label %20

20:                                               ; preds = %17
  %21 = icmp eq i32 %19, %6
  br i1 %21, label %22, label %30

22:                                               ; preds = %20
  %23 = load ptr, ptr %16, align 8, !tbaa !16
  %24 = load ptr, ptr %.0, align 8, !tbaa !17
  %25 = tail call i32 %23(ptr noundef %2, ptr noundef %24) #3
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %27, label %30

27:                                               ; preds = %22
  %28 = load <2 x ptr>, ptr %.0, align 8, !tbaa !18
  store <2 x ptr> %28, ptr %0, align 8, !tbaa !18
  %29 = getelementptr inbounds i8, ptr %0, i64 16
  store i8 1, ptr %29, align 8, !tbaa !19
  tail call void @remove_node(ptr noundef nonnull %1, ptr noundef %13, ptr noundef nonnull %.0)
  br label %37

30:                                               ; preds = %22, %20
  %31 = getelementptr inbounds i8, ptr %.0, i64 24
  %32 = icmp eq ptr %31, %15
  br i1 %32, label %33, label %35

33:                                               ; preds = %30
  %34 = load ptr, ptr %7, align 8, !tbaa !12
  br label %35

35:                                               ; preds = %30, %33
  %.1 = phi ptr [ %34, %33 ], [ %31, %30 ]
  %.not25 = icmp eq ptr %.1, %13
  br i1 %.not25, label %36, label %17, !llvm.loop !22

36:                                               ; preds = %17, %35
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %0, i8 0, i64 24, i1 false)
  br label %37

37:                                               ; preds = %36, %27
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @remove_node(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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, !10, i64 16}
!6 = !{!"hashtable2", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !11, i64 32}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !10, i64 24}
!13 = !{!6, !11, i64 32}
!14 = !{!15, !11, i64 16}
!15 = !{!"hash_node", !10, i64 0, !10, i64 8, !11, i64 16}
!16 = !{!6, !10, i64 8}
!17 = !{!15, !10, i64 0}
!18 = !{!10, !10, i64 0}
!19 = !{!20, !21, i64 16}
!20 = !{!"", !10, i64 0, !10, i64 8, !21, i64 16}
!21 = !{!"_Bool", !8, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass