; LLVM IR from Overload-Technologies/Overload :: Dependencies/soloud/src/audiosource/ay/soloud_ay.ll (ZN6SoLoud2Ay7loadMemEPKhjbb)

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

declare i32 @__gxx_personality_v0(...)

; 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
define dso_local noundef i32 @_ZN6SoLoud2Ay7loadMemEPKhjbb(ptr noundef nonnull align 8 dereferenceable(184) %0, ptr noundef %1, i32 noundef %2, i1 noundef zeroext %3, i1 noundef zeroext %4) #1 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 i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = 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
  %17 = zext i1 %3 to i8
  store i8 %17, ptr %10, align 1, !tbaa !11
  %18 = zext i1 %4 to i8
  store i8 %18, ptr %11, align 1, !tbaa !11
  %19 = load ptr, ptr %7, align 8
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %25

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

25:                                               ; preds = %22, %5
  store i32 1, ptr %6, align 4
  br label %48

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

34:                                               ; preds = %26
  store i32 %33, ptr %13, align 4, !tbaa !9
  %35 = load i32, ptr %13, align 4, !tbaa !9
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %37, label %43

37:                                               ; preds = %34
  %38 = load i32, ptr %13, align 4, !tbaa !9
  store i32 %38, ptr %6, align 4
  store i32 1, ptr %16, align 4
  br label %47

39:                                               ; preds = %43, %26
  %40 = landingpad { ptr, i32 }
          cleanup
  %41 = extractvalue { ptr, i32 } %40, 0
  store ptr %41, ptr %14, align 8
  %42 = extractvalue { ptr, i32 } %40, 1
  store i32 %42, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #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 %50

43:                                               ; preds = %34
  %44 = invoke noundef i32 @_ZN6SoLoud2Ay8loadFileEPNS_4FileE(ptr noundef nonnull align 8 dereferenceable(184) %19, ptr noundef %12)
          to label %45 unwind label %39

45:                                               ; preds = %43
  store i32 %44, ptr %13, align 4, !tbaa !9
  %46 = load i32, ptr %13, align 4, !tbaa !9
  store i32 %46, ptr %6, align 4
  store i32 1, ptr %16, align 4
  br label %47

47:                                               ; preds = %45, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #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 %48

48:                                               ; preds = %47, %25
  %49 = load i32, ptr %6, align 4
  ret i32 %49

50:                                               ; preds = %39
  %51 = load ptr, ptr %14, align 8
  %52 = load i32, ptr %15, align 4
  %53 = insertvalue { ptr, i32 } poison, ptr %51, 0
  %54 = insertvalue { ptr, i32 } %53, i32 %52, 1
  resume { ptr, i32 } %54
}

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

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

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

; 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 = { 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 = { "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 }

declare i32 @__gxx_personality_v0(...)

; 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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN6SoLoud2Ay7loadMemEPKhjbb(ptr noundef nonnull align 8 dereferenceable(184) %0, ptr noundef %1, i32 noundef %2, i1 noundef zeroext %3, i1 noundef zeroext %4) local_unnamed_addr #1 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 %17, label %9

9:                                                ; preds = %5
  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 %12

11:                                               ; preds = %9
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %14, label %16

12:                                               ; preds = %14, %9
  %13 = 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 } %13

14:                                               ; preds = %11
  %15 = invoke noundef i32 @_ZN6SoLoud2Ay8loadFileEPNS_4FileE(ptr noundef nonnull align 8 dereferenceable(184) %0, ptr noundef nonnull %6)
          to label %16 unwind label %12

16:                                               ; preds = %14, %11
  %.0 = phi i32 [ %10, %11 ], [ %15, %14 ]
  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 %17

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

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

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

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

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