; LLVM IR from DanEngelbrecht/longtail :: lib/lrublockstore (longtail_lrublockstore)

; 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.Longtail_StoredBlock = type { ptr, ptr, ptr, i32 }
%struct.Longtail_BlockIndex = type { ptr, ptr, ptr, ptr, ptr, ptr }
%struct.LRUStoredBlock = type { %struct.Longtail_StoredBlock, ptr, ptr, i32 }
%struct.LRUBlockStoreAPI = type { %struct.Longtail_BlockStoreAPI, ptr, [22 x i64], ptr, ptr, ptr, ptr, ptr, i32 }
%struct.Longtail_BlockStoreAPI = type { %struct.Longtail_API, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.Longtail_API = type { ptr }
%struct.BlockHashToLRUStoredBlock = type { i64, ptr }

; 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
declare dso_local void @LRU_Refresh(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @LRUStoredBlock_Dispose(ptr noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca [1 x i64], align 8
  %13 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store ptr null, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %14, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.Longtail_StoredBlock, ptr %15, i32 0, i32 1
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct.Longtail_BlockIndex, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !12
  %20 = load i64, ptr %19, align 8, !tbaa !14
  store i64 %20, ptr %6, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.LRUStoredBlock, ptr %21, i32 0, i32 3
  %23 = call i32 @Longtail_AtomicAdd32(ptr noundef %22, i32 noundef -1)
  store i32 %23, ptr %7, align 4, !tbaa !16
  %24 = load i32, ptr %7, align 4, !tbaa !16
  %25 = icmp sgt i32 %24, 1
  br i1 %25, label %26, label %27

26:                                               ; preds = %1
  store i32 0, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %109

27:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.LRUStoredBlock, ptr %28, i32 0, i32 2
  %30 = load ptr, ptr %29, align 8, !tbaa !17
  store ptr %30, ptr %9, align 8, !tbaa !5
  %31 = load i32, ptr %7, align 4, !tbaa !16
  %32 = icmp eq i32 %31, 1
  br i1 %32, label %33, label %76

33:                                               ; preds = %27
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.LRUBlockStoreAPI, ptr %34, i32 0, i32 3
  %36 = load ptr, ptr %35, align 8, !tbaa !19
  call void @Longtail_LockSpinLock(ptr noundef %36)
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %37 = load ptr, ptr %9, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.LRUBlockStoreAPI, ptr %37, i32 0, i32 6
  %39 = load ptr, ptr %38, align 8, !tbaa !23
  %40 = icmp ne ptr %39, null
  br i1 %40, label %41, label %51

41:                                               ; preds = %33
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.LRUBlockStoreAPI, ptr %42, i32 0, i32 6
  %44 = load ptr, ptr %43, align 8, !tbaa !23
  %45 = load i64, ptr %6, align 8, !tbaa !14
  store i64 %45, ptr %12, align 8, !tbaa !14
  %46 = getelementptr inbounds [1 x i64], ptr %12, i64 0, i64 0
  %47 = call ptr @stbds_hmget_key_ts(ptr noundef %44, i64 noundef 16, ptr noundef %46, i64 noundef 8, ptr noundef %10, i32 noundef 0)
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.LRUBlockStoreAPI, ptr %48, i32 0, i32 6
  store ptr %47, ptr %49, align 8, !tbaa !23
  %50 = load i64, ptr %10, align 8, !tbaa !14
  br label %52

51:                                               ; preds = %33
  br label %52

52:                                               ; preds = %51, %41
  %53 = phi i64 [ %50, %41 ], [ -1, %51 ]
  store i64 %53, ptr %11, align 8, !tbaa !14
  %54 = load i64, ptr %11, align 8, !tbaa !14
  %55 = icmp eq i64 %54, -1
  br i1 %55, label %56, label %60

56:                                               ; preds = %52
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.LRUBlockStoreAPI, ptr %57, i32 0, i32 3
  %59 = load ptr, ptr %58, align 8, !tbaa !19
  call void @Longtail_UnlockSpinLock(ptr noundef %59)
  store i32 0, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %75

60:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %61 = load ptr, ptr %9, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.LRUBlockStoreAPI, ptr %61, i32 0, i32 6
  %63 = load ptr, ptr %62, align 8, !tbaa !23
  %64 = load i64, ptr %11, align 8, !tbaa !14
  %65 = getelementptr inbounds %struct.BlockHashToLRUStoredBlock, ptr %63, i64 %64
  %66 = getelementptr inbounds %struct.BlockHashToLRUStoredBlock, ptr %65, i32 0, i32 1
  %67 = load ptr, ptr %66, align 8, !tbaa !24
  store ptr %67, ptr %13, align 8, !tbaa !5
  %68 = load ptr, ptr %9, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.LRUBlockStoreAPI, ptr %68, i32 0, i32 5
  %70 = load ptr, ptr %69, align 8, !tbaa !26
  %71 = load ptr, ptr %13, align 8, !tbaa !5
  call void @LRU_Refresh(ptr noundef %70, ptr noundef %71)
  %72 = load ptr, ptr %9, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.LRUBlockStoreAPI, ptr %72, i32 0, i32 3
  %74 = load ptr, ptr %73, align 8, !tbaa !19
  call void @Longtail_UnlockSpinLock(ptr noundef %74)
  store i32 0, ptr %2, align 4
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  br label %75

75:                                               ; preds = %60, %56
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %108

76:                                               ; preds = %27
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.LRUStoredBlock, ptr %77, i32 0, i32 3
  %79 = load volatile i32, ptr %78, align 8, !tbaa !27
  %80 = icmp eq i32 %79, 0
  br i1 %80, label %81, label %106

81:                                               ; preds = %76
  %82 = load ptr, ptr %5, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.LRUStoredBlock, ptr %82, i32 0, i32 1
  %84 = load ptr, ptr %83, align 8, !tbaa !28
  %85 = icmp ne ptr %84, null
  br i1 %85, label %86, label %105

86:                                               ; preds = %81
  %87 = load ptr, ptr %5, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.LRUStoredBlock, ptr %87, i32 0, i32 1
  %89 = load ptr, ptr %88, align 8, !tbaa !28
  %90 = getelementptr inbounds %struct.Longtail_StoredBlock, ptr %89, i32 0, i32 0
  %91 = load ptr, ptr %90, align 8, !tbaa !29
  %92 = icmp ne ptr %91, null
  br i1 %92, label %93, label %105

93:                                               ; preds = %86
  %94 = load ptr, ptr %5, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.LRUStoredBlock, ptr %94, i32 0, i32 1
  %96 = load ptr, ptr %95, align 8, !tbaa !28
  %97 = getelementptr inbounds %struct.Longtail_StoredBlock, ptr %96, i32 0, i32 0
  %98 = load ptr, ptr %97, align 8, !tbaa !29
  %99 = load ptr, ptr %5, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.LRUStoredBlock, ptr %99, i32 0, i32 1
  %101 = load ptr, ptr %100, align 8, !tbaa !28
  %102 = call i32 %98(ptr noundef %101)
  %103 = load ptr, ptr %5, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.LRUStoredBlock, ptr %103, i32 0, i32 1
  store ptr null, ptr %104, align 8, !tbaa !28
  br label %105

105:                                              ; preds = %93, %86, %81
  br label %106

106:                                              ; preds = %105, %76
  %107 = load ptr, ptr %5, align 8, !tbaa !5
  call void @Longtail_Free(ptr noundef %107)
  store i32 0, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %108

108:                                              ; preds = %106, %75
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %109

109:                                              ; preds = %108, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %110 = load i32, ptr %2, align 4
  ret i32 %110
}

declare i32 @Longtail_AtomicAdd32(ptr noundef, i32 noundef) #2

declare void @Longtail_LockSpinLock(ptr noundef) #2

declare ptr @stbds_hmget_key_ts(ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef, i32 noundef) #2

declare void @Longtail_UnlockSpinLock(ptr noundef) #2

declare void @Longtail_Free(ptr noundef) #2

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 = { "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 }

!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 = !{!"Longtail_StoredBlock", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"Longtail_BlockIndex", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!11, !11, i64 0}
!17 = !{!18, !6, i64 40}
!18 = !{!"LRUStoredBlock", !10, i64 0, !6, i64 32, !6, i64 40, !11, i64 48}
!19 = !{!20, !6, i64 248}
!20 = !{!"LRUBlockStoreAPI", !21, i64 0, !6, i64 64, !7, i64 72, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !6, i64 280, !11, i64 288}
!21 = !{!"Longtail_BlockStoreAPI", !22, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!22 = !{!"Longtail_API", !6, i64 0}
!23 = !{!20, !6, i64 272}
!24 = !{!25, !6, i64 8}
!25 = !{!"BlockHashToLRUStoredBlock", !15, i64 0, !6, i64 8}
!26 = !{!20, !6, i64 264}
!27 = !{!18, !11, i64 48}
!28 = !{!18, !6, i64 32}
!29 = !{!10, !6, 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"

%struct.BlockHashToLRUStoredBlock = type { i64, ptr }

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare dso_local void @LRU_Refresh(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @LRUStoredBlock_Dispose(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca i64, align 8
  %3 = alloca [1 x i64], align 8
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %5, align 8, !tbaa !11
  %7 = load i64, ptr %6, align 8, !tbaa !13
  %8 = getelementptr inbounds i8, ptr %0, i64 48
  %9 = tail call i32 @Longtail_AtomicAdd32(ptr noundef nonnull %8, i32 noundef -1) #3
  %10 = icmp sgt i32 %9, 1
  br i1 %10, label %41, label %11

11:                                               ; preds = %1
  %12 = getelementptr inbounds i8, ptr %0, i64 40
  %13 = load ptr, ptr %12, align 8, !tbaa !15
  %14 = icmp eq i32 %9, 1
  br i1 %14, label %15, label %30

15:                                               ; preds = %11
  %16 = getelementptr inbounds i8, ptr %13, i64 248
  %17 = load ptr, ptr %16, align 8, !tbaa !17
  tail call void @Longtail_LockSpinLock(ptr noundef %17) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  %18 = getelementptr inbounds i8, ptr %13, i64 272
  %19 = load ptr, ptr %18, align 8, !tbaa !21
  %.not30 = icmp eq ptr %19, null
  br i1 %.not30, label %.thread, label %20

20:                                               ; preds = %15
  store i64 %7, ptr %3, align 8, !tbaa !13
  %21 = call ptr @stbds_hmget_key_ts(ptr noundef nonnull %19, i64 noundef 16, ptr noundef nonnull %3, i64 noundef 8, ptr noundef nonnull %2, i32 noundef 0) #3
  store ptr %21, ptr %18, align 8, !tbaa !21
  %22 = load i64, ptr %2, align 8, !tbaa !13
  %23 = icmp eq i64 %22, -1
  br i1 %23, label %.thread, label %24

24:                                               ; preds = %20
  %25 = getelementptr inbounds %struct.BlockHashToLRUStoredBlock, ptr %21, i64 %22, i32 1
  %26 = load ptr, ptr %25, align 8, !tbaa !22
  %27 = getelementptr inbounds i8, ptr %13, i64 264
  %28 = load ptr, ptr %27, align 8, !tbaa !24
  call void @LRU_Refresh(ptr noundef %28, ptr noundef %26)
  br label %.thread

.thread:                                          ; preds = %20, %15, %24
  %29 = load ptr, ptr %16, align 8, !tbaa !17
  call void @Longtail_UnlockSpinLock(ptr noundef %29) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  br label %41

30:                                               ; preds = %11
  %31 = load volatile i32, ptr %8, align 8, !tbaa !25
  %32 = icmp eq i32 %31, 0
  br i1 %32, label %33, label %40

33:                                               ; preds = %30
  %34 = getelementptr inbounds i8, ptr %0, i64 32
  %35 = load ptr, ptr %34, align 8, !tbaa !26
  %.not = icmp eq ptr %35, null
  br i1 %.not, label %40, label %36

36:                                               ; preds = %33
  %37 = load ptr, ptr %35, align 8, !tbaa !27
  %.not29 = icmp eq ptr %37, null
  br i1 %.not29, label %40, label %38

38:                                               ; preds = %36
  %39 = tail call i32 %37(ptr noundef nonnull %35) #3
  store ptr null, ptr %34, align 8, !tbaa !26
  br label %40

40:                                               ; preds = %33, %36, %38, %30
  tail call void @Longtail_Free(ptr noundef nonnull %0) #3
  br label %41

41:                                               ; preds = %.thread, %40, %1
  ret i32 0
}

declare i32 @Longtail_AtomicAdd32(ptr noundef, i32 noundef) local_unnamed_addr #2

declare void @Longtail_LockSpinLock(ptr noundef) local_unnamed_addr #2

declare ptr @stbds_hmget_key_ts(ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

declare void @Longtail_UnlockSpinLock(ptr noundef) local_unnamed_addr #2

declare void @Longtail_Free(ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress 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 = { "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 }

!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 = !{!"Longtail_StoredBlock", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24}
!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 0}
!12 = !{!"Longtail_BlockIndex", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !8, i64 0}
!15 = !{!16, !7, i64 40}
!16 = !{!"LRUStoredBlock", !6, i64 0, !7, i64 32, !7, i64 40, !10, i64 48}
!17 = !{!18, !7, i64 248}
!18 = !{!"LRUBlockStoreAPI", !19, i64 0, !7, i64 64, !8, i64 72, !7, i64 248, !7, i64 256, !7, i64 264, !7, i64 272, !7, i64 280, !10, i64 288}
!19 = !{!"Longtail_BlockStoreAPI", !20, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56}
!20 = !{!"Longtail_API", !7, i64 0}
!21 = !{!18, !7, i64 272}
!22 = !{!23, !7, i64 8}
!23 = !{!"BlockHashToLRUStoredBlock", !14, i64 0, !7, i64 8}
!24 = !{!18, !7, i64 264}
!25 = !{!16, !10, i64 48}
!26 = !{!16, !7, i64 32}
!27 = !{!6, !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass