; LLVM IR from SelfishOlex/MiniAudioO3DE :: MiniAudio/Code/Source/Clients (MiniAudioImplementation)

; 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.ma_slot_allocator = type { ptr, ptr, i32, i32, i32, ptr }
%struct.ma_slot_allocator_group = type { i32 }

@.str.6 = external hidden unnamed_addr constant [104 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [10 x i8], align 1
@__PRETTY_FUNCTION__.ma_slot_allocator_free = external hidden unnamed_addr constant [65 x i8], align 1

; 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: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL32ma_slot_allocator_group_capacityPK17ma_slot_allocator(ptr noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local i32 @ma_slot_allocator_free(ptr noundef %0, i64 noundef %1) #3 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = icmp eq ptr %15, null
  br i1 %16, label %17, label %18

17:                                               ; preds = %2
  store i32 -2, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %84

18:                                               ; preds = %2
  %19 = load i64, ptr %5, align 8, !tbaa !9
  %20 = and i64 %19, 4294967295
  %21 = lshr i64 %20, 5
  %22 = trunc i64 %21 to i32
  store i32 %22, ptr %6, align 4, !tbaa !11
  %23 = load i64, ptr %5, align 8, !tbaa !9
  %24 = and i64 %23, 4294967295
  %25 = and i64 %24, 31
  %26 = trunc i64 %25 to i32
  store i32 %26, ptr %7, align 4, !tbaa !11
  %27 = load i32, ptr %6, align 4, !tbaa !11
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = call noundef i32 @_ZL32ma_slot_allocator_group_capacityPK17ma_slot_allocator(ptr noundef %28)
  %30 = icmp uge i32 %27, %29
  br i1 %30, label %31, label %32

31:                                               ; preds = %18
  store i32 -2, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %84

32:                                               ; preds = %18
  %33 = load i32, ptr %7, align 4, !tbaa !11
  %34 = icmp ult i32 %33, 32
  br i1 %34, label %35, label %36

35:                                               ; preds = %32
  br label %38

36:                                               ; preds = %32
  call void @__assert_fail(ptr noundef @.str.8, ptr noundef @.str.6, i32 noundef 16529, ptr noundef @__PRETTY_FUNCTION__.ma_slot_allocator_free) #5
  unreachable

37:                                               ; No predecessors!
  br label %38

38:                                               ; preds = %37, %35
  br label %39

39:                                               ; preds = %82, %38
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.ma_slot_allocator, ptr %40, i32 0, i32 2
  %42 = load atomic i32, ptr %41 seq_cst, align 8
  store i32 %42, ptr %9, align 4
  %43 = load i32, ptr %9, align 4, !tbaa !11
  %44 = icmp ugt i32 %43, 0
  br i1 %44, label %45, label %83

45:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.ma_slot_allocator, ptr %46, i32 0, i32 0
  %48 = load ptr, ptr %47, align 8, !tbaa !13
  %49 = load i32, ptr %6, align 4, !tbaa !11
  %50 = zext i32 %49 to i64
  %51 = getelementptr inbounds %struct.ma_slot_allocator_group, ptr %48, i64 %50
  %52 = getelementptr inbounds %struct.ma_slot_allocator_group, ptr %51, i32 0, i32 0
  %53 = load atomic i32, ptr %52 seq_cst, align 4
  store i32 %53, ptr %12, align 4
  %54 = load i32, ptr %12, align 4, !tbaa !11
  store i32 %54, ptr %10, align 4, !tbaa !11
  %55 = load i32, ptr %10, align 4, !tbaa !11
  %56 = load i32, ptr %7, align 4, !tbaa !11
  %57 = shl i32 1, %56
  %58 = xor i32 %57, -1
  %59 = and i32 %55, %58
  store i32 %59, ptr %11, align 4, !tbaa !11
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.ma_slot_allocator, ptr %60, i32 0, i32 0
  %62 = load ptr, ptr %61, align 8, !tbaa !13
  %63 = load i32, ptr %6, align 4, !tbaa !11
  %64 = zext i32 %63 to i64
  %65 = getelementptr inbounds %struct.ma_slot_allocator_group, ptr %62, i64 %64
  %66 = getelementptr inbounds %struct.ma_slot_allocator_group, ptr %65, i32 0, i32 0
  %67 = load i32, ptr %10, align 4, !tbaa !11
  %68 = load i32, ptr %11, align 4, !tbaa !11
  %69 = cmpxchg ptr %66, i32 %67, i32 %68 seq_cst seq_cst, align 4
  %70 = extractvalue { i32, i1 } %69, 0
  %71 = load i32, ptr %10, align 4, !tbaa !11
  %72 = icmp eq i32 %70, %71
  br i1 %72, label %73, label %79

73:                                               ; preds = %45
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.ma_slot_allocator, ptr %74, i32 0, i32 2
  store i32 1, ptr %13, align 4, !tbaa !11
  %76 = load i32, ptr %13, align 4
  %77 = atomicrmw sub ptr %75, i32 %76 seq_cst, align 8
  store i32 %77, ptr %14, align 4
  %78 = load i32, ptr %14, align 4, !tbaa !11
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %80

79:                                               ; preds = %45
  store i32 0, ptr %8, align 4
  br label %80

80:                                               ; preds = %79, %73
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  %81 = load i32, ptr %8, align 4
  switch i32 %81, label %84 [
    i32 0, label %82
  ]

82:                                               ; preds = %80
  br label %39, !llvm.loop !15

83:                                               ; preds = %39
  store i32 -3, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %84

84:                                               ; preds = %83, %80, %31, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %85 = load i32, ptr %3, align 4
  ret i32 %85
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { alwaysinline mustprogress 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 = { mustprogress 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"_ZTS17ma_slot_allocator", !6, i64 0, !6, i64 8, !12, i64 16, !12, i64 20, !12, i64 24, !6, i64 32}
!15 = distinct !{!15, !16}
!16 = !{!"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.ma_slot_allocator_group = type { i32 }

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL32ma_slot_allocator_group_capacityPK17ma_slot_allocator(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @ma_slot_allocator_free(ptr noundef %0, i64 noundef %1) local_unnamed_addr #1 {
  %3 = icmp eq ptr %0, null
  br i1 %3, label %.loopexit, label %4

4:                                                ; preds = %2
  %5 = trunc i64 %1 to i32
  %6 = lshr i32 %5, 5
  %7 = tail call noundef i32 @_ZL32ma_slot_allocator_group_capacityPK17ma_slot_allocator(ptr noundef nonnull %0)
  %.not = icmp ult i32 %6, %7
  br i1 %.not, label %.critedge.preheader, label %.loopexit

.critedge.preheader:                              ; preds = %4
  %8 = and i32 %5, 31
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = zext nneg i32 %6 to i64
  %11 = shl nuw i32 1, %8
  %12 = xor i32 %11, -1
  br label %.critedge

.critedge:                                        ; preds = %.critedge.preheader, %14
  %13 = load atomic i32, ptr %9 seq_cst, align 8
  %.not25 = icmp eq i32 %13, 0
  br i1 %.not25, label %.loopexit, label %14

14:                                               ; preds = %.critedge
  %15 = load ptr, ptr %0, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.ma_slot_allocator_group, ptr %15, i64 %10
  %17 = load atomic i32, ptr %16 seq_cst, align 4
  %18 = and i32 %17, %12
  %19 = load ptr, ptr %0, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.ma_slot_allocator_group, ptr %19, i64 %10
  %21 = cmpxchg ptr %20, i32 %17, i32 %18 seq_cst seq_cst, align 4
  %22 = extractvalue { i32, i1 } %21, 1
  br i1 %22, label %23, label %.critedge

23:                                               ; preds = %14
  %24 = atomicrmw sub ptr %9, i32 1 seq_cst, align 8
  br label %.loopexit, !llvm.loop !11

.loopexit:                                        ; preds = %.critedge, %23, %4, %2
  %.2 = phi i32 [ 0, %23 ], [ -2, %2 ], [ -2, %4 ], [ -3, %.critedge ]
  ret i32 %.2
}

attributes #0 = { alwaysinline mustprogress 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 = { mustprogress 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 = !{!6, !7, i64 0}
!6 = !{!"_ZTS17ma_slot_allocator", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !7, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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