; LLVM IR from DanEngelbrecht/longtail :: lib/shareblockstore (longtail_shareblockstore)

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

; Function Attrs: nounwind uwtable
define dso_local i32 @SharedStoredBlock_Dispose(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca [1 x i64], align 8
  %11 = 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
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %12, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.SharedStoredBlock, ptr %13, i32 0, i32 3
  %15 = call i32 @Longtail_AtomicAdd32(ptr noundef %14, i32 noundef -1)
  store i32 %15, ptr %6, align 4, !tbaa !9
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = icmp sgt i32 %16, 0
  br i1 %17, label %18, label %19

18:                                               ; preds = %1
  store i32 0, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %96

19:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.SharedStoredBlock, ptr %20, i32 0, i32 2
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  store ptr %22, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.Longtail_StoredBlock, ptr %23, i32 0, i32 1
  %25 = load ptr, ptr %24, align 8, !tbaa !14
  %26 = getelementptr inbounds %struct.Longtail_BlockIndex, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !15
  %28 = load i64, ptr %27, align 8, !tbaa !17
  store i64 %28, ptr %9, align 8, !tbaa !17
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.ShareBlockStoreAPI, ptr %29, i32 0, i32 2
  %31 = load ptr, ptr %30, align 8, !tbaa !19
  call void @Longtail_LockSpinLock(ptr noundef %31)
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.SharedStoredBlock, ptr %32, i32 0, i32 3
  %34 = load volatile i32, ptr %33, align 8, !tbaa !23
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %40

36:                                               ; preds = %19
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.ShareBlockStoreAPI, ptr %37, i32 0, i32 2
  %39 = load ptr, ptr %38, align 8, !tbaa !19
  call void @Longtail_UnlockSpinLock(ptr noundef %39)
  store i32 0, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %95

40:                                               ; preds = %19
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.ShareBlockStoreAPI, ptr %41, i32 0, i32 3
  %43 = load ptr, ptr %42, align 8, !tbaa !24
  %44 = load i64, ptr %9, align 8, !tbaa !17
  store i64 %44, ptr %10, align 8, !tbaa !17
  %45 = getelementptr inbounds [1 x i64], ptr %10, i64 0, i64 0
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.ShareBlockStoreAPI, ptr %46, i32 0, i32 3
  %48 = load ptr, ptr %47, align 8, !tbaa !24
  %49 = getelementptr inbounds %struct.BlockHashToSharedStoredBlock, ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.ShareBlockStoreAPI, ptr %50, i32 0, i32 3
  %52 = load ptr, ptr %51, align 8, !tbaa !24
  %53 = ptrtoint ptr %49 to i64
  %54 = ptrtoint ptr %52 to i64
  %55 = sub i64 %53, %54
  %56 = call ptr @stbds_hmdel_key(ptr noundef %43, i64 noundef 16, ptr noundef %45, i64 noundef 8, i64 noundef %55, i32 noundef 0)
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.ShareBlockStoreAPI, ptr %57, i32 0, i32 3
  store ptr %56, ptr %58, align 8, !tbaa !24
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.ShareBlockStoreAPI, ptr %59, i32 0, i32 3
  %61 = load ptr, ptr %60, align 8, !tbaa !24
  %62 = icmp ne ptr %61, null
  br i1 %62, label %63, label %71

63:                                               ; preds = %40
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.ShareBlockStoreAPI, ptr %64, i32 0, i32 3
  %66 = load ptr, ptr %65, align 8, !tbaa !24
  %67 = getelementptr inbounds %struct.BlockHashToSharedStoredBlock, ptr %66, i64 -1
  %68 = getelementptr inbounds %struct.stbds_array_header, ptr %67, i64 -1
  %69 = getelementptr inbounds %struct.stbds_array_header, ptr %68, i32 0, i32 3
  %70 = load i64, ptr %69, align 8, !tbaa !25
  br label %72

71:                                               ; preds = %40
  br label %72

72:                                               ; preds = %71, %63
  %73 = phi i64 [ %70, %63 ], [ 0, %71 ]
  %74 = load ptr, ptr %8, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.ShareBlockStoreAPI, ptr %74, i32 0, i32 2
  %76 = load ptr, ptr %75, align 8, !tbaa !19
  call void @Longtail_UnlockSpinLock(ptr noundef %76)
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.SharedStoredBlock, ptr %77, i32 0, i32 1
  %79 = load ptr, ptr %78, align 8, !tbaa !27
  store ptr %79, ptr %11, align 8, !tbaa !5
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  call void @Longtail_Free(ptr noundef %80)
  %81 = load ptr, ptr %11, align 8, !tbaa !5
  %82 = icmp ne ptr %81, null
  br i1 %82, label %83, label %94

83:                                               ; preds = %72
  %84 = load ptr, ptr %11, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.Longtail_StoredBlock, ptr %84, i32 0, i32 0
  %86 = load ptr, ptr %85, align 8, !tbaa !28
  %87 = icmp ne ptr %86, null
  br i1 %87, label %88, label %94

88:                                               ; preds = %83
  %89 = load ptr, ptr %11, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.Longtail_StoredBlock, ptr %89, i32 0, i32 0
  %91 = load ptr, ptr %90, align 8, !tbaa !28
  %92 = load ptr, ptr %11, align 8, !tbaa !5
  %93 = call i32 %91(ptr noundef %92)
  store ptr null, ptr %11, align 8, !tbaa !5
  br label %94

94:                                               ; preds = %88, %83, %72
  store i32 0, ptr %2, align 4
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  br label %95

95:                                               ; preds = %94, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %96

96:                                               ; preds = %95, %18
  call void @llvm.lifetime.end.p0(i64 4, 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
  %97 = load i32, ptr %2, align 4
  ret i32 %97
}

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

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

declare void @Longtail_LockSpinLock(ptr noundef) #2

declare void @Longtail_UnlockSpinLock(ptr noundef) #2

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

declare void @Longtail_Free(ptr noundef) #2

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 40}
!12 = !{!"SharedStoredBlock", !13, i64 0, !6, i64 32, !6, i64 40, !10, i64 48}
!13 = !{!"Longtail_StoredBlock", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24}
!14 = !{!13, !6, i64 8}
!15 = !{!16, !6, i64 0}
!16 = !{!"Longtail_BlockIndex", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40}
!17 = !{!18, !18, i64 0}
!18 = !{!"long", !7, i64 0}
!19 = !{!20, !6, i64 72}
!20 = !{!"ShareBlockStoreAPI", !21, i64 0, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !7, i64 104, !10, i64 280}
!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 = !{!12, !10, i64 48}
!24 = !{!20, !6, i64 80}
!25 = !{!26, !18, i64 24}
!26 = !{!"", !18, i64 0, !18, i64 8, !6, i64 16, !18, i64 24}
!27 = !{!12, !6, i64 32}
!28 = !{!13, !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"

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

6:                                                ; preds = %1
  %7 = getelementptr inbounds i8, ptr %0, i64 40
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !12
  %11 = load ptr, ptr %10, align 8, !tbaa !13
  %12 = load i64, ptr %11, align 8, !tbaa !15
  %13 = getelementptr inbounds i8, ptr %8, i64 72
  %14 = load ptr, ptr %13, align 8, !tbaa !17
  tail call void @Longtail_LockSpinLock(ptr noundef %14) #2
  %15 = load volatile i32, ptr %3, align 8, !tbaa !21
  %.not = icmp eq i32 %15, 0
  br i1 %.not, label %18, label %16

16:                                               ; preds = %6
  %17 = load ptr, ptr %13, align 8, !tbaa !17
  tail call void @Longtail_UnlockSpinLock(ptr noundef %17) #2
  br label %29

18:                                               ; preds = %6
  %19 = getelementptr inbounds i8, ptr %8, i64 80
  %20 = load ptr, ptr %19, align 8, !tbaa !22
  store i64 %12, ptr %2, align 8, !tbaa !15
  %21 = call ptr @stbds_hmdel_key(ptr noundef %20, i64 noundef 16, ptr noundef nonnull %2, i64 noundef 8, i64 noundef 0, i32 noundef 0) #2
  store ptr %21, ptr %19, align 8, !tbaa !22
  %22 = load ptr, ptr %13, align 8, !tbaa !17
  call void @Longtail_UnlockSpinLock(ptr noundef %22) #2
  %23 = getelementptr inbounds i8, ptr %0, i64 32
  %24 = load ptr, ptr %23, align 8, !tbaa !23
  call void @Longtail_Free(ptr noundef nonnull %0) #2
  %.not25 = icmp eq ptr %24, null
  br i1 %.not25, label %29, label %25

25:                                               ; preds = %18
  %26 = load ptr, ptr %24, align 8, !tbaa !24
  %.not26 = icmp eq ptr %26, null
  br i1 %.not26, label %29, label %27

27:                                               ; preds = %25
  %28 = call i32 %26(ptr noundef nonnull %24) #2
  br label %29

29:                                               ; preds = %16, %27, %25, %18, %1
  ret i32 0
}

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

declare void @Longtail_LockSpinLock(ptr noundef) local_unnamed_addr #1

declare void @Longtail_UnlockSpinLock(ptr noundef) local_unnamed_addr #1

declare ptr @stbds_hmdel_key(ptr noundef, i64 noundef, ptr noundef, i64 noundef, i64 noundef, i32 noundef) local_unnamed_addr #1

declare void @Longtail_Free(ptr noundef) local_unnamed_addr #1

attributes #0 = { 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 #1 = { "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, !8, i64 40}
!6 = !{!"SharedStoredBlock", !7, i64 0, !8, i64 32, !8, i64 40, !11, i64 48}
!7 = !{!"Longtail_StoredBlock", !8, i64 0, !8, i64 8, !8, i64 16, !11, i64 24}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!7, !8, i64 8}
!13 = !{!14, !8, i64 0}
!14 = !{!"Longtail_BlockIndex", !8, i64 0, !8, i64 8, !8, i64 16, !8, i64 24, !8, i64 32, !8, i64 40}
!15 = !{!16, !16, i64 0}
!16 = !{!"long", !9, i64 0}
!17 = !{!18, !8, i64 72}
!18 = !{!"ShareBlockStoreAPI", !19, i64 0, !8, i64 64, !8, i64 72, !8, i64 80, !8, i64 88, !8, i64 96, !9, i64 104, !11, i64 280}
!19 = !{!"Longtail_BlockStoreAPI", !20, i64 0, !8, i64 8, !8, i64 16, !8, i64 24, !8, i64 32, !8, i64 40, !8, i64 48, !8, i64 56}
!20 = !{!"Longtail_API", !8, i64 0}
!21 = !{!6, !11, i64 48}
!22 = !{!18, !8, i64 80}
!23 = !{!6, !8, i64 32}
!24 = !{!7, !8, i64 0}


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