; 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_last(ptr noundef %0) #1 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.hashtable_itor, ptr %7, i32 0, i32 0
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = getelementptr inbounds %struct.hashtable, ptr %9, i32 0, i32 4
  %11 = load i32, ptr %10, align 8, !tbaa !12
  store i32 %11, ptr %4, align 4, !tbaa !15
  br label %12

12:                                               ; preds = %54, %1
  %13 = load i32, ptr %4, align 4, !tbaa !15
  %14 = icmp ugt i32 %13, 0
  br i1 %14, label %16, label %15

15:                                               ; preds = %12
  store i32 2, ptr %5, align 4
  br label %55

16:                                               ; preds = %12
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.hashtable_itor, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.hashtable, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !16
  %22 = load i32, ptr %4, align 4, !tbaa !15
  %23 = add i32 %22, -1
  store i32 %23, ptr %4, align 4, !tbaa !15
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds ptr, ptr %21, i64 %24
  %26 = load ptr, ptr %25, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %54

28:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.hashtable_itor, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !9
  %32 = getelementptr inbounds %struct.hashtable, ptr %31, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !16
  %34 = load i32, ptr %4, align 4, !tbaa !15
  %35 = zext i32 %34 to i64
  %36 = getelementptr inbounds ptr, ptr %33, i64 %35
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  store ptr %37, ptr %6, align 8, !tbaa !5
  br label %38

38:                                               ; preds = %43, %28
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.hash_node, ptr %39, i32 0, i32 2
  %41 = load ptr, ptr %40, align 8, !tbaa !17
  %42 = icmp ne ptr %41, null
  br i1 %42, label %43, label %47

43:                                               ; preds = %38
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.hash_node, ptr %44, i32 0, i32 2
  %46 = load ptr, ptr %45, align 8, !tbaa !17
  store ptr %46, ptr %6, align 8, !tbaa !5
  br label %38, !llvm.loop !19

47:                                               ; preds = %38
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.hashtable_itor, ptr %49, i32 0, i32 1
  store ptr %48, ptr %50, align 8, !tbaa !21
  %51 = load i32, ptr %4, align 4, !tbaa !15
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.hashtable_itor, ptr %52, i32 0, i32 2
  store i32 %51, ptr %53, align 8, !tbaa !22
  store i1 true, ptr %2, align 1
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %55

54:                                               ; preds = %16
  br label %12, !llvm.loop !23

55:                                               ; preds = %47, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %56 = load i32, ptr %5, align 4
  switch i32 %56, label %64 [
    i32 2, label %57
    i32 1, label %62
  ]

57:                                               ; preds = %55
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.hashtable_itor, ptr %58, i32 0, i32 1
  store ptr null, ptr %59, align 8, !tbaa !21
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.hashtable_itor, ptr %60, i32 0, i32 2
  store i32 0, ptr %61, align 8, !tbaa !22
  store i1 false, ptr %2, align 1
  br label %62

62:                                               ; preds = %57, %55
  %63 = load i1, ptr %2, align 1
  ret i1 %63

64:                                               ; preds = %55
  unreachable
}

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


; 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: nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @hashtable_itor_last(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %2, i64 32
  %4 = load i32, ptr %3, align 8, !tbaa !11
  %5 = zext i32 %4 to i64
  br label %6

6:                                                ; preds = %7, %1
  %indvars.iv = phi i64 [ %9, %7 ], [ %5, %1 ]
  %.not.not = icmp ne i64 %indvars.iv, 0
  br i1 %.not.not, label %7, label %.loopexit

7:                                                ; preds = %6
  %8 = load ptr, ptr %2, align 8, !tbaa !14
  %9 = add nsw i64 %indvars.iv, -1
  %10 = getelementptr inbounds ptr, ptr %8, i64 %9
  %11 = load ptr, ptr %10, align 8, !tbaa !15
  %.not20 = icmp eq ptr %11, null
  br i1 %.not20, label %6, label %.preheader, !llvm.loop !16

.preheader:                                       ; preds = %7, %.preheader
  %.0 = phi ptr [ %13, %.preheader ], [ %11, %7 ]
  %12 = getelementptr inbounds i8, ptr %.0, i64 16
  %13 = load ptr, ptr %12, align 8, !tbaa !18
  %.not21 = icmp eq ptr %13, null
  br i1 %.not21, label %14, label %.preheader, !llvm.loop !20

14:                                               ; preds = %.preheader
  %15 = trunc i64 %9 to i32
  br label %.loopexit

.loopexit:                                        ; preds = %6, %14
  %.0.lcssa.sink = phi ptr [ %.0, %14 ], [ null, %6 ]
  %.sink = phi i32 [ %15, %14 ], [ 0, %6 ]
  %16 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %.0.lcssa.sink, ptr %16, align 8, !tbaa !21
  %17 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 %.sink, ptr %17, align 8, !tbaa !22
  ret i1 %.not.not
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) 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" }

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass