; 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.hash_node = type { ptr, ptr, ptr, ptr, i32 }
%struct.hashtable = type { ptr, ptr, ptr, i64, 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_prev(ptr noundef %0) #1 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.hashtable_itor, ptr %7, i32 0, i32 1
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = icmp ne ptr %9, null
  br i1 %10, label %12, label %11

11:                                               ; preds = %1
  store i1 false, ptr %2, align 1
  br label %69

12:                                               ; preds = %1
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.hashtable_itor, ptr %13, i32 0, i32 1
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = getelementptr inbounds %struct.hash_node, ptr %15, i32 0, i32 3
  %17 = load ptr, ptr %16, align 8, !tbaa !12
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.hashtable_itor, ptr %18, i32 0, i32 1
  store ptr %17, ptr %19, align 8, !tbaa !9
  %20 = icmp ne ptr %17, null
  br i1 %20, label %21, label %22

21:                                               ; preds = %12
  store i1 true, ptr %2, align 1
  br label %69

22:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.hashtable_itor, ptr %23, i32 0, i32 2
  %25 = load i32, ptr %24, align 8, !tbaa !14
  store i32 %25, ptr %4, align 4, !tbaa !15
  br label %26

26:                                               ; preds = %62, %22
  %27 = load i32, ptr %4, align 4, !tbaa !15
  %28 = icmp ugt i32 %27, 0
  br i1 %28, label %29, label %63

29:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.hashtable_itor, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !16
  %33 = getelementptr inbounds %struct.hashtable, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !17
  %35 = load i32, ptr %4, align 4, !tbaa !15
  %36 = add i32 %35, -1
  store i32 %36, ptr %4, align 4, !tbaa !15
  %37 = zext i32 %36 to i64
  %38 = getelementptr inbounds ptr, ptr %34, i64 %37
  %39 = load ptr, ptr %38, align 8, !tbaa !5
  store ptr %39, ptr %5, align 8, !tbaa !5
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = icmp ne ptr %40, null
  br i1 %41, label %42, label %59

42:                                               ; preds = %29
  br label %43

43:                                               ; preds = %48, %42
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.hash_node, ptr %44, i32 0, i32 2
  %46 = load ptr, ptr %45, align 8, !tbaa !20
  %47 = icmp ne ptr %46, null
  br i1 %47, label %48, label %52

48:                                               ; preds = %43
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.hash_node, ptr %49, i32 0, i32 2
  %51 = load ptr, ptr %50, align 8, !tbaa !20
  store ptr %51, ptr %5, align 8, !tbaa !5
  br label %43, !llvm.loop !21

52:                                               ; preds = %43
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.hashtable_itor, ptr %54, i32 0, i32 1
  store ptr %53, ptr %55, align 8, !tbaa !9
  %56 = load i32, ptr %4, align 4, !tbaa !15
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.hashtable_itor, ptr %57, i32 0, i32 2
  store i32 %56, ptr %58, align 8, !tbaa !14
  store i1 true, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %60

59:                                               ; preds = %29
  store i32 0, ptr %6, align 4
  br label %60

60:                                               ; preds = %59, %52
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  %61 = load i32, ptr %6, align 4
  switch i32 %61, label %68 [
    i32 0, label %62
  ]

62:                                               ; preds = %60
  br label %26, !llvm.loop !23

63:                                               ; preds = %26
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.hashtable_itor, ptr %64, i32 0, i32 1
  store ptr null, ptr %65, align 8, !tbaa !9
  %66 = load ptr, ptr %3, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.hashtable_itor, ptr %66, i32 0, i32 2
  store i32 0, ptr %67, align 8, !tbaa !14
  store i1 false, ptr %2, align 1
  store i32 1, ptr %6, align 4
  br label %68

68:                                               ; preds = %63, %60
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %69

69:                                               ; preds = %68, %21, %11
  %70 = load i1, ptr %2, align 1
  ret i1 %70
}

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


; 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_prev(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %20, label %4

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %3, i64 24
  %6 = load ptr, ptr %5, align 8, !tbaa !11
  store ptr %6, ptr %2, align 8, !tbaa !5
  %.not23 = icmp eq ptr %6, null
  br i1 %.not23, label %7, label %20

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  %9 = load i32, ptr %8, align 8, !tbaa !13
  %.not24.not27 = icmp eq i32 %9, 0
  br i1 %.not24.not27, label %.sink.split, label %.lr.ph

.lr.ph:                                           ; preds = %7
  %10 = load ptr, ptr %0, align 8, !tbaa !14
  %11 = load ptr, ptr %10, align 8, !tbaa !15
  %12 = zext i32 %9 to i64
  br label %13

13:                                               ; preds = %.lr.ph, %.critedge.backedge
  %indvars.iv = phi i64 [ %12, %.lr.ph ], [ %14, %.critedge.backedge ]
  %14 = add nsw i64 %indvars.iv, -1
  %15 = getelementptr inbounds ptr, ptr %11, i64 %14
  %16 = load ptr, ptr %15, align 8, !tbaa !18
  %.not25 = icmp eq ptr %16, null
  br i1 %.not25, label %.critedge.backedge, label %.preheader

.preheader:                                       ; preds = %13, %.preheader
  %.017 = phi ptr [ %18, %.preheader ], [ %16, %13 ]
  %17 = getelementptr inbounds i8, ptr %.017, i64 16
  %18 = load ptr, ptr %17, align 8, !tbaa !19
  %.not26 = icmp eq ptr %18, null
  br i1 %.not26, label %.loopexit, label %.preheader, !llvm.loop !20

.loopexit:                                        ; preds = %.preheader
  %19 = trunc i64 %14 to i32
  br label %.sink.split

.critedge.backedge:                               ; preds = %13
  %.not24.not.wide = icmp eq i64 %14, 0
  br i1 %.not24.not.wide, label %.sink.split, label %13, !llvm.loop !22

.sink.split:                                      ; preds = %.critedge.backedge, %7, %.loopexit
  %.017.lcssa.sink = phi ptr [ %.017, %.loopexit ], [ null, %7 ], [ null, %.critedge.backedge ]
  %.sink = phi i32 [ %19, %.loopexit ], [ 0, %7 ], [ 0, %.critedge.backedge ]
  %.3.ph = phi i1 [ true, %.loopexit ], [ false, %7 ], [ false, %.critedge.backedge ]
  store ptr %.017.lcssa.sink, ptr %2, align 8, !tbaa !5
  store i32 %.sink, ptr %8, align 8, !tbaa !13
  br label %20

20:                                               ; preds = %.sink.split, %4, %1
  %.3 = phi i1 [ false, %1 ], [ true, %4 ], [ %.3.ph, %.sink.split ]
  ret i1 %.3
}

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


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