; 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_log_callback = type { ptr, ptr }
%struct.ma_log = type { [4 x %struct.ma_log_callback], i32, %struct.ma_allocation_callbacks, %union.pthread_mutex_t }
%struct.ma_allocation_callbacks = type { ptr, ptr, ptr, ptr }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, 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: mustprogress uwtable
declare hidden void @_ZL11ma_log_lockP6ma_log(ptr noundef) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL13ma_log_unlockP6ma_log(ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local i32 @ma_log_unregister_callback(ptr noundef %0, ptr %1, ptr %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca %struct.ma_log_callback, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = getelementptr inbounds { ptr, ptr }, ptr %5, i32 0, i32 0
  store ptr %1, ptr %9, align 8
  %10 = getelementptr inbounds { ptr, ptr }, ptr %5, i32 0, i32 1
  store ptr %2, ptr %10, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %14

13:                                               ; preds = %3
  store i32 -2, ptr %4, align 4
  br label %68

14:                                               ; preds = %3
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZL11ma_log_lockP6ma_log(ptr noundef %15)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %65, %14
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.ma_log, ptr %18, i32 0, i32 1
  %20 = load i32, ptr %19, align 8, !tbaa !11
  %21 = icmp ult i32 %17, %20
  br i1 %21, label %22, label %66

22:                                               ; preds = %16
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.ma_log, ptr %23, i32 0, i32 0
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds [4 x %struct.ma_log_callback], ptr %24, i64 0, i64 %26
  %28 = getelementptr inbounds %struct.ma_log_callback, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !14
  %30 = getelementptr inbounds %struct.ma_log_callback, ptr %5, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !14
  %32 = icmp eq ptr %29, %31
  br i1 %32, label %33, label %62

33:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %34 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %34, ptr %8, align 4, !tbaa !9
  br label %35

35:                                               ; preds = %54, %33
  %36 = load i32, ptr %8, align 4, !tbaa !9
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.ma_log, ptr %37, i32 0, i32 1
  %39 = load i32, ptr %38, align 8, !tbaa !11
  %40 = sub i32 %39, 1
  %41 = icmp ult i32 %36, %40
  br i1 %41, label %42, label %57

42:                                               ; preds = %35
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.ma_log, ptr %43, i32 0, i32 0
  %45 = load i32, ptr %8, align 4, !tbaa !9
  %46 = add i32 %45, 1
  %47 = zext i32 %46 to i64
  %48 = getelementptr inbounds [4 x %struct.ma_log_callback], ptr %44, i64 0, i64 %47
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.ma_log, ptr %49, i32 0, i32 0
  %51 = load i32, ptr %8, align 4, !tbaa !9
  %52 = zext i32 %51 to i64
  %53 = getelementptr inbounds [4 x %struct.ma_log_callback], ptr %50, i64 0, i64 %52
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %53, ptr align 8 %48, i64 16, i1 false), !tbaa.struct !16
  br label %54

54:                                               ; preds = %42
  %55 = load i32, ptr %8, align 4, !tbaa !9
  %56 = add i32 %55, 1
  store i32 %56, ptr %8, align 4, !tbaa !9
  br label %35, !llvm.loop !17

57:                                               ; preds = %35
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.ma_log, ptr %58, i32 0, i32 1
  %60 = load i32, ptr %59, align 8, !tbaa !11
  %61 = sub i32 %60, 1
  store i32 %61, ptr %59, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %65

62:                                               ; preds = %22
  %63 = load i32, ptr %7, align 4, !tbaa !9
  %64 = add i32 %63, 1
  store i32 %64, ptr %7, align 4, !tbaa !9
  br label %65

65:                                               ; preds = %62, %57
  br label %16, !llvm.loop !19

66:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZL13ma_log_unlockP6ma_log(ptr noundef %67)
  store i32 0, ptr %4, align 4
  br label %68

68:                                               ; preds = %66, %13
  %69 = load i32, ptr %4, align 4
  ret i32 %69
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 64}
!12 = !{!"_ZTS6ma_log", !7, i64 0, !10, i64 64, !13, i64 72, !7, i64 104}
!13 = !{!"_ZTS23ma_allocation_callbacks", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!14 = !{!15, !6, i64 0}
!15 = !{!"_ZTS15ma_log_callback", !6, i64 0, !6, i64 8}
!16 = !{i64 0, i64 8, !5, i64 8, i64 8, !5}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


; 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_log_callback = type { ptr, ptr }

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL11ma_log_lockP6ma_log(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL13ma_log_unlockP6ma_log(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local range(i32 -2, 1) i32 @ma_log_unregister_callback(ptr noundef %0, ptr readnone %1, ptr nocapture readnone %2) local_unnamed_addr #0 {
  %4 = icmp eq ptr %0, null
  br i1 %4, label %26, label %5

5:                                                ; preds = %3
  tail call void @_ZL11ma_log_lockP6ma_log(ptr noundef nonnull %0)
  %6 = getelementptr inbounds i8, ptr %0, i64 64
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %._crit_edge25, label %.lr.ph24

.lr.ph24:                                         ; preds = %5, %23
  %8 = phi i32 [ %24, %23 ], [ %7, %5 ]
  %.01722 = phi i32 [ %.1, %23 ], [ 0, %5 ]
  %9 = zext i32 %.01722 to i64
  %10 = getelementptr inbounds [4 x %struct.ma_log_callback], ptr %0, i64 0, i64 %9
  %11 = load ptr, ptr %10, align 8, !tbaa !12
  %12 = icmp eq ptr %11, %1
  br i1 %12, label %.preheader, label %21

.preheader:                                       ; preds = %.lr.ph24
  %13 = add i32 %8, -1
  %14 = icmp ult i32 %.01722, %13
  br i1 %14, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %9, %.preheader ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %15 = getelementptr inbounds [4 x %struct.ma_log_callback], ptr %0, i64 0, i64 %indvars.iv.next
  %16 = getelementptr inbounds [4 x %struct.ma_log_callback], ptr %0, i64 0, i64 %indvars.iv
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %16, ptr noundef nonnull align 8 dereferenceable(16) %15, i64 16, i1 false), !tbaa.struct !14
  %17 = load i32, ptr %6, align 8, !tbaa !5
  %18 = add i32 %17, -1
  %19 = zext i32 %18 to i64
  %20 = icmp ult i64 %indvars.iv.next, %19
  br i1 %20, label %.lr.ph, label %._crit_edge, !llvm.loop !16

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %.lcssa = phi i32 [ %13, %.preheader ], [ %18, %.lr.ph ]
  store i32 %.lcssa, ptr %6, align 8, !tbaa !5
  br label %23

21:                                               ; preds = %.lr.ph24
  %22 = add nuw i32 %.01722, 1
  br label %23

23:                                               ; preds = %21, %._crit_edge
  %24 = phi i32 [ %.lcssa, %._crit_edge ], [ %8, %21 ]
  %.1 = phi i32 [ %.01722, %._crit_edge ], [ %22, %21 ]
  %25 = icmp ult i32 %.1, %24
  br i1 %25, label %.lr.ph24, label %._crit_edge25, !llvm.loop !18

._crit_edge25:                                    ; preds = %23, %5
  tail call void @_ZL13ma_log_unlockP6ma_log(ptr noundef nonnull %0)
  br label %26

26:                                               ; preds = %3, %._crit_edge25
  %.018 = phi i32 [ 0, %._crit_edge25 ], [ -2, %3 ]
  ret i32 %.018
}

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }

!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, !9, i64 64}
!6 = !{!"_ZTS6ma_log", !7, i64 0, !9, i64 64, !10, i64 72, !7, i64 104}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"_ZTS23ma_allocation_callbacks", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!13, !11, i64 0}
!13 = !{!"_ZTS15ma_log_callback", !11, i64 0, !11, i64 8}
!14 = !{i64 0, i64 8, !15, i64 8, i64 8, !15}
!15 = !{!11, !11, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


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