; LLVM IR from Overload-Technologies/Overload :: Dependencies/soloud/src/audiosource/openmpt (soloud_openmpt)

; 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::Openmpt" = type <{ %"class.SoLoud::AudioSource", ptr, i32, [4 x i8] }>
%"class.SoLoud::AudioSource" = type { ptr, i32, float, float, i32, i32, float, float, float, i32, float, [8 x ptr], ptr, ptr, ptr, i32, double }

declare ptr @openmpt_module_create_from_memory(ptr noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef) #0

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

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

declare void @openmpt_module_destroy(ptr noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN6SoLoud7Openmpt8loadFileEPNS_4FileE(ptr noundef nonnull align 8 dereferenceable(164) %0, ptr noundef %1) #2 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8
  %9 = getelementptr inbounds %"class.SoLoud::Openmpt", ptr %8, i32 0, i32 1
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = icmp eq ptr %10, null
  br i1 %11, label %13, label %12

12:                                               ; preds = %2
  call void @_ZdaPv(ptr noundef %10) #5
  br label %13

13:                                               ; preds = %12, %2
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = load ptr, ptr %14, align 8, !tbaa !15
  %16 = getelementptr inbounds ptr, ptr %15, i64 4
  %17 = load ptr, ptr %16, align 8
  %18 = call noundef i32 %17(ptr noundef nonnull align 8 dereferenceable(8) %14)
  %19 = getelementptr inbounds %"class.SoLoud::Openmpt", ptr %8, i32 0, i32 2
  store i32 %18, ptr %19, align 8, !tbaa !17
  %20 = getelementptr inbounds %"class.SoLoud::Openmpt", ptr %8, i32 0, i32 2
  %21 = load i32, ptr %20, align 8, !tbaa !17
  %22 = zext i32 %21 to i64
  %23 = call noalias noundef nonnull ptr @_Znam(i64 noundef %22) #6
  %24 = getelementptr inbounds %"class.SoLoud::Openmpt", ptr %8, i32 0, i32 1
  store ptr %23, ptr %24, align 8, !tbaa !9
  %25 = getelementptr inbounds %"class.SoLoud::Openmpt", ptr %8, i32 0, i32 1
  %26 = load ptr, ptr %25, align 8, !tbaa !9
  %27 = icmp ne ptr %26, null
  br i1 %27, label %31, label %28

28:                                               ; preds = %13
  %29 = getelementptr inbounds %"class.SoLoud::Openmpt", ptr %8, i32 0, i32 1
  store ptr null, ptr %29, align 8, !tbaa !9
  %30 = getelementptr inbounds %"class.SoLoud::Openmpt", ptr %8, i32 0, i32 2
  store i32 0, ptr %30, align 8, !tbaa !17
  store i32 5, ptr %3, align 4
  br label %60

31:                                               ; preds = %13
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %"class.SoLoud::Openmpt", ptr %8, i32 0, i32 1
  %34 = load ptr, ptr %33, align 8, !tbaa !9
  %35 = getelementptr inbounds %"class.SoLoud::Openmpt", ptr %8, i32 0, i32 2
  %36 = load i32, ptr %35, align 8, !tbaa !17
  %37 = load ptr, ptr %32, align 8, !tbaa !15
  %38 = getelementptr inbounds ptr, ptr %37, i64 3
  %39 = load ptr, ptr %38, align 8
  %40 = call noundef i32 %39(ptr noundef nonnull align 8 dereferenceable(8) %32, ptr noundef %34, i32 noundef %36)
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #7
  %41 = getelementptr inbounds %"class.SoLoud::Openmpt", ptr %8, i32 0, i32 1
  %42 = load ptr, ptr %41, align 8, !tbaa !9
  %43 = getelementptr inbounds %"class.SoLoud::Openmpt", ptr %8, i32 0, i32 2
  %44 = load i32, ptr %43, align 8, !tbaa !17
  %45 = zext i32 %44 to i64
  %46 = call ptr @openmpt_module_create_from_memory(ptr noundef %42, i64 noundef %45, ptr noundef null, ptr noundef null, ptr noundef null)
  store ptr %46, ptr %6, align 8, !tbaa !5
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = icmp ne ptr %47, null
  br i1 %48, label %57, label %49

49:                                               ; preds = %31
  %50 = getelementptr inbounds %"class.SoLoud::Openmpt", ptr %8, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !9
  %52 = icmp eq ptr %51, null
  br i1 %52, label %54, label %53

53:                                               ; preds = %49
  call void @_ZdaPv(ptr noundef %51) #5
  br label %54

54:                                               ; preds = %53, %49
  %55 = getelementptr inbounds %"class.SoLoud::Openmpt", ptr %8, i32 0, i32 1
  store ptr null, ptr %55, align 8, !tbaa !9
  %56 = getelementptr inbounds %"class.SoLoud::Openmpt", ptr %8, i32 0, i32 2
  store i32 0, ptr %56, align 8, !tbaa !17
  store i32 3, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %59

57:                                               ; preds = %31
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  call void @openmpt_module_destroy(ptr noundef %58)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %59

59:                                               ; preds = %57, %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #7
  br label %60

60:                                               ; preds = %59, %28
  %61 = load i32, ptr %3, align 4
  ret i32 %61
}

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) #3

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #4

attributes #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nobuiltin 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 = { nobuiltin allocsize(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 #5 = { builtin nounwind }
attributes #6 = { builtin allocsize(0) }
attributes #7 = { 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, !6, i64 152}
!10 = !{!"_ZTSN6SoLoud7OpenmptE", !11, i64 0, !6, i64 152, !12, i64 160}
!11 = !{!"_ZTSN6SoLoud11AudioSourceE", !12, i64 8, !13, i64 12, !13, i64 16, !12, i64 20, !12, i64 24, !13, i64 28, !13, i64 32, !13, i64 36, !12, i64 40, !13, i64 44, !7, i64 48, !6, i64 112, !6, i64 120, !6, i64 128, !12, i64 136, !14, i64 144}
!12 = !{!"int", !7, i64 0}
!13 = !{!"float", !7, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"vtable pointer", !8, i64 0}
!17 = !{!10, !12, i64 160}


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

declare ptr @openmpt_module_create_from_memory(ptr noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @openmpt_module_destroy(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 4) i32 @_ZN6SoLoud7Openmpt8loadFileEPNS_4FileE(ptr nocapture noundef nonnull align 8 dereferenceable(164) %0, ptr noundef %1) local_unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 152
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = icmp eq ptr %4, null
  br i1 %5, label %7, label %6

6:                                                ; preds = %2
  tail call void @_ZdaPv(ptr noundef nonnull %4) #4
  br label %7

7:                                                ; preds = %6, %2
  %8 = load ptr, ptr %1, align 8, !tbaa !14
  %9 = getelementptr inbounds i8, ptr %8, i64 32
  %10 = load ptr, ptr %9, align 8
  %11 = tail call noundef i32 %10(ptr noundef nonnull align 8 dereferenceable(8) %1)
  %12 = getelementptr inbounds i8, ptr %0, i64 160
  store i32 %11, ptr %12, align 8, !tbaa !16
  %13 = zext i32 %11 to i64
  %14 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %13) #5
  store ptr %14, ptr %3, align 8, !tbaa !5
  %15 = load ptr, ptr %1, align 8, !tbaa !14
  %16 = getelementptr inbounds i8, ptr %15, i64 24
  %17 = load ptr, ptr %16, align 8
  %18 = tail call noundef i32 %17(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull %14, i32 noundef %11)
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = load i32, ptr %12, align 8, !tbaa !16
  %21 = zext i32 %20 to i64
  %22 = tail call ptr @openmpt_module_create_from_memory(ptr noundef %19, i64 noundef %21, ptr noundef null, ptr noundef null, ptr noundef null)
  %.not = icmp eq ptr %22, null
  br i1 %.not, label %23, label %28

23:                                               ; preds = %7
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = icmp eq ptr %24, null
  br i1 %25, label %27, label %26

26:                                               ; preds = %23
  tail call void @_ZdaPv(ptr noundef nonnull %24) #4
  br label %27

27:                                               ; preds = %26, %23
  store ptr null, ptr %3, align 8, !tbaa !5
  store i32 0, ptr %12, align 8, !tbaa !16
  br label %29

28:                                               ; preds = %7
  tail call void @openmpt_module_destroy(ptr noundef nonnull %22)
  br label %29

29:                                               ; preds = %27, %28
  %.0 = phi i32 [ 0, %28 ], [ 3, %27 ]
  ret i32 %.0
}

; Function Attrs: nobuiltin nounwind
declare void @_ZdaPv(ptr noundef) local_unnamed_addr #2

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #3

attributes #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 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 = { nobuiltin 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 #3 = { nobuiltin allocsize(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 = { builtin nounwind }
attributes #5 = { builtin allocsize(0) }

!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, !12, i64 152}
!6 = !{!"_ZTSN6SoLoud7OpenmptE", !7, i64 0, !12, i64 152, !8, i64 160}
!7 = !{!"_ZTSN6SoLoud11AudioSourceE", !8, i64 8, !11, i64 12, !11, i64 16, !8, i64 20, !8, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !8, i64 40, !11, i64 44, !9, i64 48, !12, i64 112, !12, i64 120, !12, i64 128, !8, i64 136, !13, i64 144}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"float", !9, i64 0}
!12 = !{!"any pointer", !9, i64 0}
!13 = !{!"double", !9, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"vtable pointer", !10, i64 0}
!16 = !{!6, !8, i64 160}


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