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

@stderr = external global ptr, align 8
@.str = external hidden unnamed_addr constant [34 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [64 x i8], align 1
@__func__.hashtable2_itor_prev = external hidden unnamed_addr constant [21 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [17 x i8], align 1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #0

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

; Function Attrs: noreturn nounwind
declare void @abort() #2

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @hashtable2_itor_prev(ptr noundef %0) #3 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.hashtable2_itor, ptr %4, i32 0, i32 1
  %6 = load i32, ptr %5, align 8, !tbaa !9
  %7 = icmp slt i32 %6, 0
  br i1 %7, label %8, label %9

8:                                                ; preds = %1
  store i1 false, ptr %2, align 1
  br label %47

9:                                                ; preds = %1
  br label %10

10:                                               ; preds = %31, %9
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.hashtable2_itor, ptr %11, i32 0, i32 1
  %13 = load i32, ptr %12, align 8, !tbaa !9
  %14 = add nsw i32 %13, -1
  store i32 %14, ptr %12, align 8, !tbaa !9
  %15 = icmp sgt i32 %13, 0
  br i1 %15, label %16, label %32

16:                                               ; preds = %10
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.hashtable2_itor, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !12
  %20 = getelementptr inbounds %struct.hashtable2, ptr %19, i32 0, i32 3
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.hashtable2_itor, ptr %22, i32 0, i32 1
  %24 = load i32, ptr %23, align 8, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds %struct.hash_node, ptr %21, i64 %25
  %27 = getelementptr inbounds %struct.hash_node, ptr %26, i32 0, i32 2
  %28 = load i32, ptr %27, align 8, !tbaa !16
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %30, label %31

30:                                               ; preds = %16
  store i1 true, ptr %2, align 1
  br label %47

31:                                               ; preds = %16
  br label %10, !llvm.loop !18

32:                                               ; preds = %10
  br label %33

33:                                               ; preds = %32
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.hashtable2_itor, ptr %34, i32 0, i32 1
  %36 = load i32, ptr %35, align 8, !tbaa !9
  %37 = icmp eq i32 %36, -1
  %38 = zext i1 %37 to i32
  %39 = sext i32 %38 to i64
  %40 = call i64 @llvm.expect.i64(i64 %39, i64 1)
  %41 = icmp ne i64 %40, 0
  br i1 %41, label %45, label %42

42:                                               ; preds = %33
  %43 = load ptr, ptr @stderr, align 8, !tbaa !5
  %44 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %43, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 487, ptr noundef @__func__.hashtable2_itor_prev, ptr noundef @.str.10) #4
  call void @abort() #5
  unreachable

45:                                               ; preds = %33
  br label %46

46:                                               ; preds = %45
  store i1 false, ptr %2, align 1
  br label %47

47:                                               ; preds = %46, %30, %8
  %48 = load i1, ptr %2, align 1
  ret i1 %48
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #1 = { nounwind "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 = { noreturn nounwind "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 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 #4 = { nounwind }
attributes #5 = { noreturn 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, !11, i64 8}
!10 = !{!"hashtable2_itor", !6, i64 0, !11, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 0}
!13 = !{!14, !6, i64 24}
!14 = !{!"hashtable2", !15, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32}
!15 = !{!"long", !7, i64 0}
!16 = !{!17, !11, i64 16}
!17 = !{!"hash_node", !6, i64 0, !6, i64 8, !11, i64 16}
!18 = distinct !{!18, !19}
!19 = !{!"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_prev(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %4 = icmp slt i32 %3, 0
  br i1 %4, label %14, label %.preheader

.preheader:                                       ; preds = %1
  %.not10 = icmp eq i32 %3, 0
  br i1 %.not10, label %.sink.split, label %thread-pre-split.lr.ph

thread-pre-split.lr.ph:                           ; preds = %.preheader
  %5 = load ptr, ptr %0, align 8, !tbaa !11
  %6 = getelementptr inbounds i8, ptr %5, i64 24
  %7 = load ptr, ptr %6, align 8, !tbaa !12
  br label %thread-pre-split

8:                                                ; preds = %thread-pre-split
  %9 = icmp sgt i32 %.in, 1
  br i1 %9, label %thread-pre-split, label %.sink.split

thread-pre-split:                                 ; preds = %thread-pre-split.lr.ph, %8
  %.in = phi i32 [ %3, %thread-pre-split.lr.ph ], [ %10, %8 ]
  %10 = add nsw i32 %.in, -1
  %11 = zext nneg i32 %10 to i64
  %12 = getelementptr inbounds %struct.hash_node, ptr %7, i64 %11, i32 2
  %13 = load i32, ptr %12, align 8, !tbaa !15
  %.not = icmp ne i32 %13, 0
  br i1 %.not, label %.sink.split, label %8, !llvm.loop !17

.sink.split:                                      ; preds = %thread-pre-split, %8, %.preheader
  %.sink = phi i32 [ -1, %.preheader ], [ -1, %8 ], [ %10, %thread-pre-split ]
  %.0.ph = phi i1 [ false, %.preheader ], [ %.not, %8 ], [ %.not, %thread-pre-split ]
  store i32 %.sink, ptr %2, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %.sink.split, %1
  %.0 = phi i1 [ false, %1 ], [ %.0.ph, %.sink.split ]
  ret i1 %.0
}

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, !10, i64 8}
!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 = !{!6, !7, i64 0}
!12 = !{!13, !7, i64 24}
!13 = !{!"hashtable2", !14, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32}
!14 = !{!"long", !8, i64 0}
!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"}


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