; LLVM IR from Overload-Technologies/Overload :: Dependencies/soloud/src/audiosource/wav/soloud_wav.ll (ZN6SoLoud3Wav7loadMemEPKhjbb)

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

%"class.SoLoud::MemoryFile" = type <{ %"class.SoLoud::File", ptr, i32, i32, i8, [7 x i8] }>
%"class.SoLoud::File" = type { 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

declare void @_ZN6SoLoud11AudioSource4stopEv(ptr noundef nonnull align 8 dereferenceable(152)) #1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN6SoLoud3Wav15testAndLoadFileEPNS_10MemoryFileE(ptr noundef nonnull align 8 dereferenceable(164), ptr noundef) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN6SoLoud3Wav7loadMemEPKhjbb(ptr noundef nonnull align 8 dereferenceable(164) %0, ptr noundef %1, i32 noundef %2, i1 noundef zeroext %3, i1 noundef zeroext %4) #2 align 2 personality ptr @__gxx_personality_v0 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i8, align 1
  %11 = alloca i8, align 1
  %12 = alloca %"class.SoLoud::MemoryFile", align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !9
  %15 = zext i1 %3 to i8
  store i8 %15, ptr %10, align 1, !tbaa !11
  %16 = zext i1 %4 to i8
  store i8 %16, ptr %11, align 1, !tbaa !11
  %17 = load ptr, ptr %7, align 8
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = icmp eq ptr %18, null
  br i1 %19, label %23, label %20

20:                                               ; preds = %5
  %21 = load i32, ptr %9, align 4, !tbaa !9
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %23, label %24

23:                                               ; preds = %20, %5
  store i32 1, ptr %6, align 4
  br label %39

24:                                               ; preds = %20
  call void @_ZN6SoLoud11AudioSource4stopEv(ptr noundef nonnull align 8 dereferenceable(152) %17)
  call void @llvm.lifetime.start.p0(i64 32, ptr %12) #4
  call void @_ZN6SoLoud10MemoryFileC1Ev(ptr noundef nonnull align 8 dereferenceable(25) %12)
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = load i32, ptr %9, align 4, !tbaa !9
  %27 = load i8, ptr %10, align 1, !tbaa !11, !range !13, !noundef !14
  %28 = trunc i8 %27 to i1
  %29 = load i8, ptr %11, align 1, !tbaa !11, !range !13, !noundef !14
  %30 = trunc i8 %29 to i1
  %31 = invoke noundef i32 @_ZN6SoLoud10MemoryFile7openMemEPKhjbb(ptr noundef nonnull align 8 dereferenceable(25) %12, ptr noundef %25, i32 noundef %26, i1 noundef zeroext %28, i1 noundef zeroext %30)
          to label %32 unwind label %35

32:                                               ; preds = %24
  %33 = invoke noundef i32 @_ZN6SoLoud3Wav15testAndLoadFileEPNS_10MemoryFileE(ptr noundef nonnull align 8 dereferenceable(164) %17, ptr noundef %12)
          to label %34 unwind label %35

34:                                               ; preds = %32
  store i32 %33, ptr %6, align 4
  call void @_ZN6SoLoud10MemoryFileD1Ev(ptr noundef nonnull align 8 dereferenceable(25) %12) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %12) #4
  br label %39

35:                                               ; preds = %32, %24
  %36 = landingpad { ptr, i32 }
          cleanup
  %37 = extractvalue { ptr, i32 } %36, 0
  store ptr %37, ptr %13, align 8
  %38 = extractvalue { ptr, i32 } %36, 1
  store i32 %38, ptr %14, align 4
  call void @_ZN6SoLoud10MemoryFileD1Ev(ptr noundef nonnull align 8 dereferenceable(25) %12) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %12) #4
  br label %41

39:                                               ; preds = %34, %23
  %40 = load i32, ptr %6, align 4
  ret i32 %40

41:                                               ; preds = %35
  %42 = load ptr, ptr %13, align 8
  %43 = load i32, ptr %14, align 4
  %44 = insertvalue { ptr, i32 } poison, ptr %42, 0
  %45 = insertvalue { ptr, i32 } %44, i32 %43, 1
  resume { ptr, i32 } %45
}

declare void @_ZN6SoLoud10MemoryFileC1Ev(ptr noundef nonnull align 8 dereferenceable(25)) unnamed_addr #1

declare noundef i32 @_ZN6SoLoud10MemoryFile7openMemEPKhjbb(ptr noundef nonnull align 8 dereferenceable(25), ptr noundef, i32 noundef, i1 noundef zeroext, i1 noundef zeroext) #1

; Function Attrs: nounwind
declare void @_ZN6SoLoud10MemoryFileD1Ev(ptr noundef nonnull align 8 dereferenceable(25)) unnamed_addr #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #3 = { 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}


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

%"class.SoLoud::MemoryFile" = type <{ %"class.SoLoud::File", ptr, i32, i32, i8, [7 x i8] }>
%"class.SoLoud::File" = type { ptr }

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

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

declare void @_ZN6SoLoud11AudioSource4stopEv(ptr noundef nonnull align 8 dereferenceable(152)) local_unnamed_addr #1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN6SoLoud3Wav15testAndLoadFileEPNS_10MemoryFileE(ptr noundef nonnull align 8 dereferenceable(164), ptr noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN6SoLoud3Wav7loadMemEPKhjbb(ptr noundef nonnull align 8 dereferenceable(164) %0, ptr noundef %1, i32 noundef %2, i1 noundef zeroext %3, i1 noundef zeroext %4) local_unnamed_addr #2 align 2 personality ptr @__gxx_personality_v0 {
  %6 = alloca %"class.SoLoud::MemoryFile", align 8
  %7 = icmp eq ptr %1, null
  %8 = icmp eq i32 %2, 0
  %or.cond = or i1 %7, %8
  br i1 %or.cond, label %16, label %9

9:                                                ; preds = %5
  tail call void @_ZN6SoLoud11AudioSource4stopEv(ptr noundef nonnull align 8 dereferenceable(152) %0)
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %6) #4
  call void @_ZN6SoLoud10MemoryFileC1Ev(ptr noundef nonnull align 8 dereferenceable(25) %6)
  %10 = invoke noundef i32 @_ZN6SoLoud10MemoryFile7openMemEPKhjbb(ptr noundef nonnull align 8 dereferenceable(25) %6, ptr noundef nonnull %1, i32 noundef %2, i1 noundef zeroext %3, i1 noundef zeroext %4)
          to label %11 unwind label %14

11:                                               ; preds = %9
  %12 = invoke noundef i32 @_ZN6SoLoud3Wav15testAndLoadFileEPNS_10MemoryFileE(ptr noundef nonnull align 8 dereferenceable(164) %0, ptr noundef nonnull %6)
          to label %13 unwind label %14

13:                                               ; preds = %11
  call void @_ZN6SoLoud10MemoryFileD1Ev(ptr noundef nonnull align 8 dereferenceable(25) %6) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %6) #4
  br label %16

14:                                               ; preds = %11, %9
  %15 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN6SoLoud10MemoryFileD1Ev(ptr noundef nonnull align 8 dereferenceable(25) %6) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %6) #4
  resume { ptr, i32 } %15

16:                                               ; preds = %5, %13
  %.0 = phi i32 [ %12, %13 ], [ 1, %5 ]
  ret i32 %.0
}

declare void @_ZN6SoLoud10MemoryFileC1Ev(ptr noundef nonnull align 8 dereferenceable(25)) unnamed_addr #1

declare noundef i32 @_ZN6SoLoud10MemoryFile7openMemEPKhjbb(ptr noundef nonnull align 8 dereferenceable(25), ptr noundef, i32 noundef, i1 noundef zeroext, i1 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nounwind
declare void @_ZN6SoLoud10MemoryFileD1Ev(ptr noundef nonnull align 8 dereferenceable(25)) unnamed_addr #3

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


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