; 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.dict_remove_result = type { ptr, ptr, i8 }
%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 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: nounwind uwtable
define dso_local void @hashtable_remove(ptr dead_on_unwind noalias writable sret(%struct.dict_remove_result) align 8 %0, ptr noundef %1, ptr noundef %2) #2 {
  %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 %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) #3
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.hashtable, ptr %10, i32 0, i32 2
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = call i32 %12(ptr noundef %13)
  store i32 %14, ptr %6, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %15 = load i32, ptr %6, align 4, !tbaa !13
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.hashtable, ptr %16, i32 0, i32 4
  %18 = load i32, ptr %17, align 8, !tbaa !14
  %19 = urem i32 %15, %18
  store i32 %19, ptr %7, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.hashtable, ptr %20, i32 0, i32 0
  %22 = load ptr, ptr %21, align 8, !tbaa !15
  %23 = load i32, ptr %7, align 4, !tbaa !13
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds ptr, ptr %22, i64 %24
  %26 = load ptr, ptr %25, align 8, !tbaa !5
  store ptr %26, ptr %8, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %67, %3
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = icmp ne ptr %28, null
  br i1 %29, label %30, label %36

30:                                               ; preds = %27
  %31 = load i32, ptr %6, align 4, !tbaa !13
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.hash_node, ptr %32, i32 0, i32 4
  %34 = load i32, ptr %33, align 8, !tbaa !16
  %35 = icmp uge i32 %31, %34
  br label %36

36:                                               ; preds = %30, %27
  %37 = phi i1 [ false, %27 ], [ %35, %30 ]
  br i1 %37, label %38, label %71

38:                                               ; preds = %36
  %39 = load i32, ptr %6, align 4, !tbaa !13
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.hash_node, ptr %40, i32 0, i32 4
  %42 = load i32, ptr %41, align 8, !tbaa !16
  %43 = icmp eq i32 %39, %42
  br i1 %43, label %44, label %67

44:                                               ; preds = %38
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.hashtable, ptr %45, i32 0, i32 1
  %47 = load ptr, ptr %46, align 8, !tbaa !18
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.hash_node, ptr %49, i32 0, i32 0
  %51 = load ptr, ptr %50, align 8, !tbaa !19
  %52 = call i32 %47(ptr noundef %48, ptr noundef %51)
  %53 = icmp eq i32 %52, 0
  br i1 %53, label %54, label %67

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

67:                                               ; preds = %44, %38
  %68 = load ptr, ptr %8, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.hash_node, ptr %68, i32 0, i32 2
  %70 = load ptr, ptr %69, align 8, !tbaa !26
  store ptr %70, ptr %8, align 8, !tbaa !5
  br label %27, !llvm.loop !27

71:                                               ; preds = %36
  call void @llvm.memset.p0.i64(ptr align 8 %0, i8 0, i64 24, i1 false)
  %72 = getelementptr inbounds %struct.dict_remove_result, ptr %0, i32 0, i32 0
  %73 = getelementptr inbounds %struct.dict_remove_result, ptr %0, i32 0, i32 1
  %74 = getelementptr inbounds %struct.dict_remove_result, ptr %0, i32 0, i32 2
  store i32 1, ptr %9, align 4
  br label %75

75:                                               ; preds = %71, %54
  call void @llvm.lifetime.end.p0(i64 8, 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
  ret void
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 16}
!10 = !{!"hashtable", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24, !12, i64 32}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!12, !12, i64 0}
!14 = !{!10, !12, i64 32}
!15 = !{!10, !6, i64 0}
!16 = !{!17, !12, i64 32}
!17 = !{!"hash_node", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !12, i64 32}
!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 = !{!17, !6, i64 16}
!27 = distinct !{!27, !28}
!28 = !{!"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 }

; 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: nounwind uwtable
define dso_local void @hashtable_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 #1 {
  %4 = getelementptr inbounds i8, ptr %1, i64 16
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = tail call i32 %5(ptr noundef %2) #2
  %7 = getelementptr inbounds i8, ptr %1, i64 32
  %8 = load i32, ptr %7, align 8, !tbaa !12
  %9 = urem i32 %6, %8
  %10 = load ptr, ptr %1, align 8, !tbaa !13
  %11 = zext i32 %9 to i64
  %12 = getelementptr inbounds ptr, ptr %10, i64 %11
  %.023 = load ptr, ptr %12, align 8, !tbaa !14
  %.not24 = icmp eq ptr %.023, null
  br i1 %.not24, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %13 = getelementptr inbounds i8, ptr %1, i64 8
  br label %14

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

17:                                               ; preds = %14
  %18 = icmp eq i32 %6, %16
  br i1 %18, label %19, label %27

19:                                               ; preds = %17
  %20 = load ptr, ptr %13, align 8, !tbaa !17
  %21 = load ptr, ptr %.025, align 8, !tbaa !18
  %22 = tail call i32 %20(ptr noundef %2, ptr noundef %21) #2
  %23 = icmp eq i32 %22, 0
  br i1 %23, label %24, label %27

24:                                               ; preds = %19
  %25 = load <2 x ptr>, ptr %.025, align 8, !tbaa !14
  store <2 x ptr> %25, ptr %0, align 8, !tbaa !14
  %26 = getelementptr inbounds i8, ptr %0, i64 16
  store i8 1, ptr %26, align 8, !tbaa !19
  tail call void @remove_node(ptr noundef nonnull %1, ptr noundef nonnull %.025, i32 noundef %9)
  br label %29

27:                                               ; preds = %19, %17
  %28 = getelementptr inbounds i8, ptr %.025, i64 16
  %.0 = load ptr, ptr %28, align 8, !tbaa !14
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %.critedge, label %14, !llvm.loop !22

.critedge:                                        ; preds = %14, %27, %3
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %0, i8 0, i64 24, i1 false)
  br label %29

29:                                               ; preds = %.critedge, %24
  ret void
}

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

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


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