; LLVM IR from pmwkaa/monotone :: monotone/runtime/lib (compression_mgr)

; 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.CompressionIf = type { i32, ptr, ptr, ptr, ptr }
%struct.CompressionMgr = type { %struct.Cache, %struct.Cache }
%struct.Cache = type { %struct.Spinlock, %struct.List, i32 }
%struct.Spinlock = type { i32 }
%struct.List = type { ptr, ptr }

@compression_zstd = external global %struct.CompressionIf, align 8
@compression_lz4 = external global %struct.CompressionIf, align 8

; 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 ptr @compression_mgr_pop(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = icmp eq i32 %9, 1
  br i1 %10, label %11, label %29

11:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.CompressionMgr, ptr %12, i32 0, i32 0
  %14 = call ptr @cache_pop(ptr noundef %13)
  store ptr %14, ptr %6, align 8, !tbaa !5
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  %17 = xor i1 %16, true
  %18 = xor i1 %17, true
  %19 = zext i1 %18 to i32
  %20 = sext i32 %19 to i64
  %21 = call i64 @llvm.expect.i64(i64 %20, i64 1)
  %22 = icmp ne i64 %21, 0
  br i1 %22, label %23, label %26

23:                                               ; preds = %11
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = call ptr @compression_of(ptr noundef %24)
  store ptr %25, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %28

26:                                               ; preds = %11
  %27 = call ptr @compression_create(ptr noundef @compression_zstd)
  store ptr %27, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %28

28:                                               ; preds = %26, %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %51

29:                                               ; preds = %2
  %30 = load i32, ptr %5, align 4, !tbaa !9
  %31 = icmp eq i32 %30, 2
  br i1 %31, label %32, label %50

32:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.CompressionMgr, ptr %33, i32 0, i32 1
  %35 = call ptr @cache_pop(ptr noundef %34)
  store ptr %35, ptr %8, align 8, !tbaa !5
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = icmp ne ptr %36, null
  %38 = xor i1 %37, true
  %39 = xor i1 %38, true
  %40 = zext i1 %39 to i32
  %41 = sext i32 %40 to i64
  %42 = call i64 @llvm.expect.i64(i64 %41, i64 1)
  %43 = icmp ne i64 %42, 0
  br i1 %43, label %44, label %47

44:                                               ; preds = %32
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = call ptr @compression_of(ptr noundef %45)
  store ptr %46, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %49

47:                                               ; preds = %32
  %48 = call ptr @compression_create(ptr noundef @compression_lz4)
  store ptr %48, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %49

49:                                               ; preds = %47, %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %51

50:                                               ; preds = %29
  store ptr null, ptr %3, align 8
  br label %51

51:                                               ; preds = %50, %49, %28
  %52 = load ptr, ptr %3, align 8
  ret ptr %52
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @cache_pop(ptr noundef) #2

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @compression_of(ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @compression_create(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 = { inlinehint 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 #3 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #4 = { 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}


; 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.CompressionIf = type { i32, ptr, ptr, ptr, ptr }

@compression_zstd = external global %struct.CompressionIf, align 8
@compression_lz4 = external global %struct.CompressionIf, align 8

; Function Attrs: nounwind uwtable
define dso_local ptr @compression_mgr_pop(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  switch i32 %1, label %16 [
    i32 1, label %3
    i32 2, label %9
  ]

3:                                                ; preds = %2
  %4 = tail call ptr @cache_pop(ptr noundef %0)
  %.not11 = icmp eq ptr %4, null
  br i1 %.not11, label %7, label %5, !prof !5

5:                                                ; preds = %3
  %6 = tail call ptr @compression_of(ptr noundef nonnull %4)
  br label %16

7:                                                ; preds = %3
  %8 = tail call ptr @compression_create(ptr noundef nonnull @compression_zstd)
  br label %16

9:                                                ; preds = %2
  %10 = getelementptr inbounds i8, ptr %0, i64 32
  %11 = tail call ptr @cache_pop(ptr noundef nonnull %10)
  %.not = icmp eq ptr %11, null
  br i1 %.not, label %14, label %12, !prof !5

12:                                               ; preds = %9
  %13 = tail call ptr @compression_of(ptr noundef nonnull %11)
  br label %16

14:                                               ; preds = %9
  %15 = tail call ptr @compression_create(ptr noundef nonnull @compression_lz4)
  br label %16

16:                                               ; preds = %2, %12, %14, %5, %7
  %.2 = phi ptr [ %6, %5 ], [ %8, %7 ], [ %13, %12 ], [ %15, %14 ], [ null, %2 ]
  ret ptr %.2
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @cache_pop(ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @compression_of(ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @compression_create(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 = { inlinehint 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" }

!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 = !{!"branch_weights", !"expected", i32 1, i32 2000}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,LowerExpectIntrinsicPass,SROAPass,SimplifyCFGPass,TailCallElimPass