; 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 = type { ptr, ptr, ptr, i64, i32 }
%struct.hash_node = type { ptr, ptr, ptr, ptr, i32 }

@dict_free_func = external global ptr, align 8

; 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 i64 @hashtable_clear(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %9

9:                                                ; preds = %52, %2
  %10 = load i32, ptr %5, align 4, !tbaa !9
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.hashtable, ptr %11, i32 0, i32 4
  %13 = load i32, ptr %12, align 8, !tbaa !11
  %14 = icmp ult i32 %10, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %55

16:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.hashtable, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !14
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = zext i32 %20 to i64
  %22 = getelementptr inbounds ptr, ptr %19, i64 %21
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  store ptr %23, ptr %6, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %41, %16
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %45

27:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.hash_node, ptr %28, i32 0, i32 2
  %30 = load ptr, ptr %29, align 8, !tbaa !15
  store ptr %30, ptr %7, align 8, !tbaa !5
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = icmp ne ptr %31, null
  br i1 %32, label %33, label %41

33:                                               ; preds = %27
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.hash_node, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !17
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.hash_node, ptr %38, i32 0, i32 1
  %40 = load ptr, ptr %39, align 8, !tbaa !18
  call void %34(ptr noundef %37, ptr noundef %40)
  br label %41

41:                                               ; preds = %33, %27
  %42 = load ptr, ptr @dict_free_func, align 8, !tbaa !5
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  call void %42(ptr noundef %43)
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %44, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  br label %24, !llvm.loop !19

45:                                               ; preds = %24
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.hashtable, ptr %46, i32 0, i32 0
  %48 = load ptr, ptr %47, align 8, !tbaa !14
  %49 = load i32, ptr %5, align 4, !tbaa !9
  %50 = zext i32 %49 to i64
  %51 = getelementptr inbounds ptr, ptr %48, i64 %50
  store ptr null, ptr %51, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %52

52:                                               ; preds = %45
  %53 = load i32, ptr %5, align 4, !tbaa !9
  %54 = add i32 %53, 1
  store i32 %54, ptr %5, align 4, !tbaa !9
  br label %9, !llvm.loop !21

55:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.hashtable, ptr %56, i32 0, i32 3
  %58 = load i64, ptr %57, align 8, !tbaa !22
  store i64 %58, ptr %8, align 8, !tbaa !23
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.hashtable, ptr %59, i32 0, i32 3
  store i64 0, ptr %60, align 8, !tbaa !22
  %61 = load i64, ptr %8, align 8, !tbaa !23
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  ret i64 %61
}

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


; 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"

@dict_free_func = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local i64 @hashtable_clear(ptr nocapture noundef %0, ptr noundef readonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 32
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %.not26 = icmp eq i32 %4, 0
  br i1 %.not26, label %._crit_edge25, label %.lr.ph24

.lr.ph24:                                         ; preds = %2
  %.not19 = icmp eq ptr %1, null
  br i1 %.not19, label %.lr.ph24.split.us, label %.lr.ph24.split

.lr.ph24.split.us:                                ; preds = %.lr.ph24, %._crit_edge.split.us.us
  %5 = phi i32 [ %9, %._crit_edge.split.us.us ], [ %4, %.lr.ph24 ]
  %indvars.iv29 = phi i64 [ %indvars.iv.next30, %._crit_edge.split.us.us ], [ 0, %.lr.ph24 ]
  %6 = load ptr, ptr %0, align 8, !tbaa !12
  %7 = getelementptr inbounds ptr, ptr %6, i64 %indvars.iv29
  %8 = load ptr, ptr %7, align 8, !tbaa !13
  %.not20.us = icmp eq ptr %8, null
  br i1 %.not20.us, label %._crit_edge.split.us.us, label %.lr.ph.us

._crit_edge.split.us.us.loopexit:                 ; preds = %.lr.ph.us
  %.pre33 = load ptr, ptr %0, align 8, !tbaa !12
  %.pre34 = load i32, ptr %3, align 8, !tbaa !5
  br label %._crit_edge.split.us.us

._crit_edge.split.us.us:                          ; preds = %._crit_edge.split.us.us.loopexit, %.lr.ph24.split.us
  %9 = phi i32 [ %.pre34, %._crit_edge.split.us.us.loopexit ], [ %5, %.lr.ph24.split.us ]
  %10 = phi ptr [ %.pre33, %._crit_edge.split.us.us.loopexit ], [ %6, %.lr.ph24.split.us ]
  %11 = getelementptr inbounds ptr, ptr %10, i64 %indvars.iv29
  store ptr null, ptr %11, align 8, !tbaa !13
  %indvars.iv.next30 = add nuw nsw i64 %indvars.iv29, 1
  %12 = zext i32 %9 to i64
  %13 = icmp ult i64 %indvars.iv.next30, %12
  br i1 %13, label %.lr.ph24.split.us, label %._crit_edge25, !llvm.loop !14

.lr.ph.us:                                        ; preds = %.lr.ph24.split.us, %.lr.ph.us
  %.01721.us.us = phi ptr [ %15, %.lr.ph.us ], [ %8, %.lr.ph24.split.us ]
  %14 = getelementptr inbounds i8, ptr %.01721.us.us, i64 16
  %15 = load ptr, ptr %14, align 8, !tbaa !16
  %16 = load ptr, ptr @dict_free_func, align 8, !tbaa !13
  tail call void %16(ptr noundef nonnull %.01721.us.us) #1
  %.not.us.us = icmp eq ptr %15, null
  br i1 %.not.us.us, label %._crit_edge.split.us.us.loopexit, label %.lr.ph.us, !llvm.loop !18

._crit_edge25:                                    ; preds = %._crit_edge.split, %._crit_edge.split.us.us, %2
  %17 = getelementptr inbounds i8, ptr %0, i64 24
  %18 = load i64, ptr %17, align 8, !tbaa !19
  store i64 0, ptr %17, align 8, !tbaa !19
  ret i64 %18

.lr.ph24.split:                                   ; preds = %.lr.ph24, %._crit_edge.split
  %19 = phi i32 [ %29, %._crit_edge.split ], [ %4, %.lr.ph24 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %._crit_edge.split ], [ 0, %.lr.ph24 ]
  %20 = load ptr, ptr %0, align 8, !tbaa !12
  %21 = getelementptr inbounds ptr, ptr %20, i64 %indvars.iv
  %22 = load ptr, ptr %21, align 8, !tbaa !13
  %.not20 = icmp eq ptr %22, null
  br i1 %.not20, label %._crit_edge.split, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph24.split, %.lr.ph
  %.01721 = phi ptr [ %24, %.lr.ph ], [ %22, %.lr.ph24.split ]
  %23 = getelementptr inbounds i8, ptr %.01721, i64 16
  %24 = load ptr, ptr %23, align 8, !tbaa !16
  %25 = load ptr, ptr %.01721, align 8, !tbaa !20
  %26 = getelementptr inbounds i8, ptr %.01721, i64 8
  %27 = load ptr, ptr %26, align 8, !tbaa !21
  tail call void %1(ptr noundef %25, ptr noundef %27) #1
  %28 = load ptr, ptr @dict_free_func, align 8, !tbaa !13
  tail call void %28(ptr noundef nonnull %.01721) #1
  %.not = icmp eq ptr %24, null
  br i1 %.not, label %._crit_edge.split.loopexit, label %.lr.ph, !llvm.loop !18

._crit_edge.split.loopexit:                       ; preds = %.lr.ph
  %.pre = load ptr, ptr %0, align 8, !tbaa !12
  %.pre32 = load i32, ptr %3, align 8, !tbaa !5
  br label %._crit_edge.split

._crit_edge.split:                                ; preds = %._crit_edge.split.loopexit, %.lr.ph24.split
  %29 = phi i32 [ %.pre32, %._crit_edge.split.loopexit ], [ %19, %.lr.ph24.split ]
  %30 = phi ptr [ %.pre, %._crit_edge.split.loopexit ], [ %20, %.lr.ph24.split ]
  %31 = getelementptr inbounds ptr, ptr %30, i64 %indvars.iv
  store ptr null, ptr %31, align 8, !tbaa !13
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %32 = zext i32 %29 to i64
  %33 = icmp ult i64 %indvars.iv.next, %32
  br i1 %33, label %.lr.ph24.split, label %._crit_edge25, !llvm.loop !14
}

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


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