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

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

14:                                               ; preds = %11
  store i32 2, ptr %5, align 4
  br label %33

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

28:                                               ; preds = %15
  %29 = load i32, ptr %4, align 4, !tbaa !15
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.hashtable2_itor, ptr %30, i32 0, i32 1
  store i32 %29, ptr %31, align 8, !tbaa !19
  store i1 true, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %33

32:                                               ; preds = %15
  br label %11, !llvm.loop !20

33:                                               ; preds = %28, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %34 = load i32, ptr %5, align 4
  switch i32 %34, label %40 [
    i32 2, label %35
    i32 1, label %38
  ]

35:                                               ; preds = %33
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.hashtable2_itor, ptr %36, i32 0, i32 1
  store i32 -1, ptr %37, align 8, !tbaa !19
  store i1 false, ptr %2, align 1
  br label %38

38:                                               ; preds = %35, %33
  %39 = load i1, ptr %2, align 1
  ret i1 %39

40:                                               ; preds = %33
  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 = !{!"hashtable2_itor", !6, i64 0, !11, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 32}
!13 = !{!"hashtable2", !14, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32}
!14 = !{!"long", !7, i64 0}
!15 = !{!11, !11, i64 0}
!16 = !{!13, !6, i64 24}
!17 = !{!18, !11, i64 16}
!18 = !{!"hash_node", !6, i64 0, !6, i64 8, !11, i64 16}
!19 = !{!10, !11, i64 8}
!20 = distinct !{!20, !21}
!21 = !{!"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.hash_node = type { ptr, ptr, i32 }

; Function Attrs: nofree norecurse nosync nounwind memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @hashtable2_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 = getelementptr inbounds i8, ptr %2, i64 24
  %6 = zext i32 %4 to i64
  br label %7

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

8:                                                ; preds = %7
  %9 = load ptr, ptr %5, align 8, !tbaa !14
  %10 = add nsw i64 %indvars.iv, -1
  %11 = getelementptr inbounds %struct.hash_node, ptr %9, i64 %10, i32 2
  %12 = load i32, ptr %11, align 8, !tbaa !15
  %.not10 = icmp eq i32 %12, 0
  br i1 %.not10, label %7, label %13, !llvm.loop !17

13:                                               ; preds = %8
  %14 = trunc i64 %10 to i32
  br label %.loopexit

.loopexit:                                        ; preds = %7, %13
  %.sink = phi i32 [ %14, %13 ], [ -1, %7 ]
  %15 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %.sink, ptr %15, align 8, !tbaa !19
  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 = !{!"hashtable2_itor", !7, i64 0, !10, i64 8}
!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 = !{!"hashtable2", !13, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32}
!13 = !{!"long", !8, i64 0}
!14 = !{!12, !7, i64 24}
!15 = !{!16, !10, i64 16}
!16 = !{!"hash_node", !7, i64 0, !7, i64 8, !10, i64 16}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!6, !10, i64 8}


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