; 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_context = type { %struct.ma_backend_callbacks, i32, ptr, %struct.ma_log, i32, i64, ptr, %struct.ma_allocation_callbacks, %union.pthread_mutex_t, %union.pthread_mutex_t, i32, i32, i32, ptr, %union.anon.41, %union.anon.46 }
%struct.ma_backend_callbacks = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.ma_log = type { [4 x %struct.ma_log_callback], i32, %struct.ma_allocation_callbacks, %union.pthread_mutex_t }
%struct.ma_log_callback = type { ptr, ptr }
%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 }
%union.anon.41 = type { %struct.anon.42 }
%struct.anon.42 = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, %union.pthread_mutex_t, i32 }
%union.anon.46 = type { %struct.anon.47 }
%struct.anon.47 = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.ma_device_info = type { %union.ma_device_id, [256 x i8], i32, i32, [64 x %struct.anon.18] }
%union.ma_device_id = type { %union.anon.17 }
%union.anon.17 = type { ptr, [248 x i8] }
%struct.anon.18 = type { i32, i32, i32, i32 }

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

; Function Attrs: mustprogress uwtable
declare dso_local void @ma_mutex_unlock(ptr noundef) #1

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

16:                                               ; preds = %5
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr null, ptr %17, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %16, %5
  %19 = load ptr, ptr %9, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %23

21:                                               ; preds = %18
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 0, ptr %22, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %21, %18
  %24 = load ptr, ptr %10, align 8, !tbaa !5
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %28

26:                                               ; preds = %23
  %27 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr null, ptr %27, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %26, %23
  %29 = load ptr, ptr %11, align 8, !tbaa !5
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %33

31:                                               ; preds = %28
  %32 = load ptr, ptr %11, align 8, !tbaa !5
  store i32 0, ptr %32, align 4, !tbaa !9
  br label %33

33:                                               ; preds = %31, %28
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = icmp eq ptr %34, null
  br i1 %35, label %36, label %37

36:                                               ; preds = %33
  store i32 -2, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %101

37:                                               ; preds = %33
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.ma_context, ptr %38, i32 0, i32 0
  %40 = getelementptr inbounds %struct.ma_backend_callbacks, ptr %39, i32 0, i32 2
  %41 = load ptr, ptr %40, align 8, !tbaa !11
  %42 = icmp eq ptr %41, null
  br i1 %42, label %43, label %44

43:                                               ; preds = %37
  store i32 -3, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %101

44:                                               ; preds = %37
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.ma_context, ptr %45, i32 0, i32 8
  call void @ma_mutex_lock(ptr noundef %46)
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.ma_context, ptr %47, i32 0, i32 11
  store i32 0, ptr %48, align 4, !tbaa !19
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.ma_context, ptr %49, i32 0, i32 12
  store i32 0, ptr %50, align 8, !tbaa !20
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.ma_context, ptr %51, i32 0, i32 0
  %53 = getelementptr inbounds %struct.ma_backend_callbacks, ptr %52, i32 0, i32 2
  %54 = load ptr, ptr %53, align 8, !tbaa !11
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = call noundef i32 %54(ptr noundef %55, ptr noundef @_ZL37ma_context_get_devices__enum_callbackP10ma_context14ma_device_typePK14ma_device_infoPv, ptr noundef null)
  store i32 %56, ptr %12, align 4, !tbaa !21
  %57 = load i32, ptr %12, align 4, !tbaa !21
  %58 = icmp eq i32 %57, 0
  br i1 %58, label %59, label %97

59:                                               ; preds = %44
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = icmp ne ptr %60, null
  br i1 %61, label %62, label %67

62:                                               ; preds = %59
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.ma_context, ptr %63, i32 0, i32 13
  %65 = load ptr, ptr %64, align 8, !tbaa !23
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %65, ptr %66, align 8, !tbaa !5
  br label %67

67:                                               ; preds = %62, %59
  %68 = load ptr, ptr %9, align 8, !tbaa !5
  %69 = icmp ne ptr %68, null
  br i1 %69, label %70, label %75

70:                                               ; preds = %67
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.ma_context, ptr %71, i32 0, i32 11
  %73 = load i32, ptr %72, align 4, !tbaa !19
  %74 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 %73, ptr %74, align 4, !tbaa !9
  br label %75

75:                                               ; preds = %70, %67
  %76 = load ptr, ptr %10, align 8, !tbaa !5
  %77 = icmp ne ptr %76, null
  br i1 %77, label %78, label %88

78:                                               ; preds = %75
  %79 = load ptr, ptr %7, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.ma_context, ptr %79, i32 0, i32 13
  %81 = load ptr, ptr %80, align 8, !tbaa !23
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.ma_context, ptr %82, i32 0, i32 11
  %84 = load i32, ptr %83, align 4, !tbaa !19
  %85 = zext i32 %84 to i64
  %86 = getelementptr inbounds %struct.ma_device_info, ptr %81, i64 %85
  %87 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %86, ptr %87, align 8, !tbaa !5
  br label %88

88:                                               ; preds = %78, %75
  %89 = load ptr, ptr %11, align 8, !tbaa !5
  %90 = icmp ne ptr %89, null
  br i1 %90, label %91, label %96

91:                                               ; preds = %88
  %92 = load ptr, ptr %7, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.ma_context, ptr %92, i32 0, i32 12
  %94 = load i32, ptr %93, align 8, !tbaa !20
  %95 = load ptr, ptr %11, align 8, !tbaa !5
  store i32 %94, ptr %95, align 4, !tbaa !9
  br label %96

96:                                               ; preds = %91, %88
  br label %97

97:                                               ; preds = %96, %44
  %98 = load ptr, ptr %7, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.ma_context, ptr %98, i32 0, i32 8
  call void @ma_mutex_unlock(ptr noundef %99)
  %100 = load i32, ptr %12, align 4, !tbaa !21
  store i32 %100, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %101

101:                                              ; preds = %97, %43, %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  %102 = load i32, ptr %6, align 4
  ret i32 %102
}

; Function Attrs: mustprogress uwtable
declare hidden noundef i32 @_ZL37ma_context_get_devices__enum_callbackP10ma_context14ma_device_typePK14ma_device_infoPv(ptr noundef, i32 noundef, ptr noundef, ptr noundef) #1

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 = { 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, !6, i64 16}
!12 = !{!"_ZTS10ma_context", !13, i64 0, !14, i64 104, !6, i64 112, !15, i64 120, !17, i64 264, !18, i64 272, !6, i64 280, !16, i64 288, !7, i64 320, !7, i64 360, !10, i64 400, !10, i64 404, !10, i64 408, !6, i64 416, !7, i64 424, !7, i64 1008}
!13 = !{!"_ZTS20ma_backend_callbacks", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96}
!14 = !{!"_ZTS10ma_backend", !7, i64 0}
!15 = !{!"_ZTS6ma_log", !7, i64 0, !10, i64 64, !16, i64 72, !7, i64 104}
!16 = !{!"_ZTS23ma_allocation_callbacks", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!17 = !{!"_ZTS18ma_thread_priority", !7, i64 0}
!18 = !{!"long", !7, i64 0}
!19 = !{!12, !10, i64 404}
!20 = !{!12, !10, i64 408}
!21 = !{!22, !22, i64 0}
!22 = !{!"_ZTS9ma_result", !7, i64 0}
!23 = !{!12, !6, i64 416}


; 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_device_info = type { %union.ma_device_id, [256 x i8], i32, i32, [64 x %struct.anon.18] }
%union.ma_device_id = type { %union.anon.17 }
%union.anon.17 = type { ptr, [248 x i8] }
%struct.anon.18 = type { i32, i32, i32, i32 }

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @ma_context_get_devices(ptr noundef %0, ptr noundef writeonly %1, ptr noundef writeonly %2, ptr noundef writeonly %3, ptr noundef writeonly %4) local_unnamed_addr #0 {
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %7, label %6

6:                                                ; preds = %5
  store ptr null, ptr %1, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %6, %5
  %.not39 = icmp eq ptr %2, null
  br i1 %.not39, label %9, label %8

8:                                                ; preds = %7
  store i32 0, ptr %2, align 4, !tbaa !9
  br label %9

9:                                                ; preds = %8, %7
  %.not40 = icmp eq ptr %3, null
  br i1 %.not40, label %11, label %10

10:                                               ; preds = %9
  store ptr null, ptr %3, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %10, %9
  %.not41 = icmp eq ptr %4, null
  br i1 %.not41, label %13, label %12

12:                                               ; preds = %11
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %12, %11
  %14 = icmp eq ptr %0, null
  br i1 %14, label %44, label %15

15:                                               ; preds = %13
  %16 = getelementptr inbounds i8, ptr %0, i64 16
  %17 = load ptr, ptr %16, align 8, !tbaa !11
  %18 = icmp eq ptr %17, null
  br i1 %18, label %44, label %19

19:                                               ; preds = %15
  %20 = getelementptr inbounds i8, ptr %0, i64 320
  tail call void @ma_mutex_lock(ptr noundef nonnull %20)
  %21 = getelementptr inbounds i8, ptr %0, i64 404
  store i32 0, ptr %21, align 4, !tbaa !19
  %22 = getelementptr inbounds i8, ptr %0, i64 408
  store i32 0, ptr %22, align 8, !tbaa !20
  %23 = load ptr, ptr %16, align 8, !tbaa !11
  %24 = tail call noundef i32 %23(ptr noundef nonnull %0, ptr noundef nonnull @_ZL37ma_context_get_devices__enum_callbackP10ma_context14ma_device_typePK14ma_device_infoPv, ptr noundef null)
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %43

26:                                               ; preds = %19
  br i1 %.not, label %30, label %27

27:                                               ; preds = %26
  %28 = getelementptr inbounds i8, ptr %0, i64 416
  %29 = load ptr, ptr %28, align 8, !tbaa !21
  store ptr %29, ptr %1, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %27, %26
  br i1 %.not39, label %33, label %31

31:                                               ; preds = %30
  %32 = load i32, ptr %21, align 4, !tbaa !19
  store i32 %32, ptr %2, align 4, !tbaa !9
  br label %33

33:                                               ; preds = %31, %30
  br i1 %.not40, label %40, label %34

34:                                               ; preds = %33
  %35 = getelementptr inbounds i8, ptr %0, i64 416
  %36 = load ptr, ptr %35, align 8, !tbaa !21
  %37 = load i32, ptr %21, align 4, !tbaa !19
  %38 = zext i32 %37 to i64
  %39 = getelementptr inbounds %struct.ma_device_info, ptr %36, i64 %38
  store ptr %39, ptr %3, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %34, %33
  br i1 %.not41, label %43, label %41

41:                                               ; preds = %40
  %42 = load i32, ptr %22, align 8, !tbaa !20
  store i32 %42, ptr %4, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %40, %41, %19
  tail call void @ma_mutex_unlock(ptr noundef nonnull %20)
  br label %44

44:                                               ; preds = %15, %13, %43
  %.0 = phi i32 [ %24, %43 ], [ -2, %13 ], [ -3, %15 ]
  ret i32 %.0
}

; Function Attrs: mustprogress uwtable
declare hidden noundef i32 @_ZL37ma_context_get_devices__enum_callbackP10ma_context14ma_device_typePK14ma_device_infoPv(ptr noundef, i32 noundef, ptr noundef, ptr noundef) #0

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

!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, !6, i64 16}
!12 = !{!"_ZTS10ma_context", !13, i64 0, !14, i64 104, !6, i64 112, !15, i64 120, !17, i64 264, !18, i64 272, !6, i64 280, !16, i64 288, !7, i64 320, !7, i64 360, !10, i64 400, !10, i64 404, !10, i64 408, !6, i64 416, !7, i64 424, !7, i64 1008}
!13 = !{!"_ZTS20ma_backend_callbacks", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96}
!14 = !{!"_ZTS10ma_backend", !7, i64 0}
!15 = !{!"_ZTS6ma_log", !7, i64 0, !10, i64 64, !16, i64 72, !7, i64 104}
!16 = !{!"_ZTS23ma_allocation_callbacks", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!17 = !{!"_ZTS18ma_thread_priority", !7, i64 0}
!18 = !{!"long", !7, i64 0}
!19 = !{!12, !10, i64 404}
!20 = !{!12, !10, i64 408}
!21 = !{!12, !6, i64 416}


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