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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN6SoLoud15OpenmptInstance8getAudioEPfjj(ptr noundef nonnull align 8 dereferenceable(516) %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) unnamed_addr #0 align 2 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  %15 = load ptr, ptr %6, align 8
  %16 = getelementptr inbounds %"class.SoLoud::OpenmptInstance", ptr %15, i32 0, i32 2
  %17 = load ptr, ptr %16, align 8, !tbaa !11
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %20

19:                                               ; preds = %4
  store i32 0, ptr %5, align 4
  br label %76

20:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %21 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %21, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %72, %20
  %23 = load i32, ptr %10, align 4, !tbaa !9
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %29

25:                                               ; preds = %22
  %26 = getelementptr inbounds %"class.SoLoud::OpenmptInstance", ptr %15, i32 0, i32 3
  %27 = load i32, ptr %26, align 8, !tbaa !17
  %28 = icmp ne i32 %27, 0
  br label %29

29:                                               ; preds = %25, %22
  %30 = phi i1 [ false, %22 ], [ %28, %25 ]
  br i1 %30, label %31, label %73

31:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 512, ptr %12, align 4, !tbaa !9
  %32 = load i32, ptr %10, align 4, !tbaa !9
  %33 = load i32, ptr %12, align 4, !tbaa !9
  %34 = icmp slt i32 %32, %33
  br i1 %34, label %35, label %37

35:                                               ; preds = %31
  %36 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %36, ptr %12, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %35, %31
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %38 = getelementptr inbounds %"class.SoLoud::OpenmptInstance", ptr %15, i32 0, i32 2
  %39 = load ptr, ptr %38, align 8, !tbaa !11
  %40 = getelementptr inbounds %"class.SoLoud::AudioSourceInstance", ptr %15, i32 0, i32 9
  %41 = load float, ptr %40, align 4, !tbaa !18
  %42 = call noundef float @_ZSt5floorf(float noundef %41)
  %43 = fptosi float %42 to i32
  %44 = load i32, ptr %12, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = load i32, ptr %11, align 4, !tbaa !9
  %48 = zext i32 %47 to i64
  %49 = getelementptr inbounds float, ptr %46, i64 %48
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = load i32, ptr %11, align 4, !tbaa !9
  %52 = zext i32 %51 to i64
  %53 = getelementptr inbounds float, ptr %50, i64 %52
  %54 = load i32, ptr %9, align 4, !tbaa !9
  %55 = zext i32 %54 to i64
  %56 = getelementptr inbounds float, ptr %53, i64 %55
  %57 = call i32 @openmpt_module_read_float_stereo(ptr noundef %39, i32 noundef %43, i64 noundef %45, ptr noundef %49, ptr noundef %56)
  store i32 %57, ptr %13, align 4, !tbaa !9
  %58 = load i32, ptr %13, align 4, !tbaa !9
  %59 = icmp eq i32 %58, 0
  br i1 %59, label %60, label %63

60:                                               ; preds = %37
  %61 = getelementptr inbounds %"class.SoLoud::OpenmptInstance", ptr %15, i32 0, i32 3
  store i32 0, ptr %61, align 8, !tbaa !17
  %62 = load i32, ptr %11, align 4, !tbaa !9
  store i32 %62, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %70

63:                                               ; preds = %37
  %64 = load i32, ptr %12, align 4, !tbaa !9
  %65 = load i32, ptr %11, align 4, !tbaa !9
  %66 = add i32 %65, %64
  store i32 %66, ptr %11, align 4, !tbaa !9
  %67 = load i32, ptr %12, align 4, !tbaa !9
  %68 = load i32, ptr %10, align 4, !tbaa !9
  %69 = sub nsw i32 %68, %67
  store i32 %69, ptr %10, align 4, !tbaa !9
  store i32 0, ptr %14, align 4
  br label %70

70:                                               ; preds = %63, %60
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  %71 = load i32, ptr %14, align 4
  switch i32 %71, label %75 [
    i32 0, label %72
  ]

72:                                               ; preds = %70
  br label %22, !llvm.loop !19

73:                                               ; preds = %29
  %74 = load i32, ptr %11, align 4, !tbaa !9
  store i32 %74, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %75

75:                                               ; preds = %73, %70
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %76

76:                                               ; preds = %75, %19
  %77 = load i32, ptr %5, align 4
  ret i32 %77
}

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

declare i32 @openmpt_module_read_float_stereo(ptr noundef, i32 noundef, i64 noundef, ptr noundef, ptr noundef) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt5floorf(float noundef) #3

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { inlinehint mustprogress nounwind 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 #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, !6, i64 504}
!12 = !{!"_ZTSN6SoLoud15OpenmptInstanceE", !13, i64 0, !6, i64 496, !6, i64 504, !10, i64 512}
!13 = !{!"_ZTSN6SoLoud19AudioSourceInstanceE", !10, i64 8, !10, i64 12, !10, i64 16, !14, i64 20, !7, i64 24, !14, i64 56, !14, i64 60, !14, i64 64, !14, i64 68, !10, i64 72, !14, i64 76, !14, i64 80, !15, i64 88, !15, i64 96, !16, i64 104, !16, i64 152, !16, i64 200, !16, i64 248, !16, i64 296, !10, i64 344, !7, i64 348, !10, i64 380, !10, i64 384, !7, i64 392, !7, i64 456, !10, i64 472, !10, i64 476, !10, i64 480, !15, i64 488}
!14 = !{!"float", !7, i64 0}
!15 = !{!"double", !7, i64 0}
!16 = !{!"_ZTSN6SoLoud5FaderE", !14, i64 0, !14, i64 4, !14, i64 8, !15, i64 16, !15, i64 24, !15, i64 32, !14, i64 40, !10, i64 44}
!17 = !{!12, !10, i64 512}
!18 = !{!13, !14, i64 68}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN6SoLoud15OpenmptInstance8getAudioEPfjj(ptr nocapture noundef nonnull align 8 dereferenceable(516) %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) unnamed_addr #0 align 2 {
  %5 = getelementptr inbounds i8, ptr %0, i64 504
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  %.not32 = icmp eq i32 %2, 0
  %or.cond = or i1 %7, %.not32
  br i1 %or.cond, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %4
  %8 = getelementptr inbounds i8, ptr %0, i64 512
  %9 = getelementptr inbounds i8, ptr %0, i64 68
  %10 = zext i32 %3 to i64
  br label %11

11:                                               ; preds = %.lr.ph, %23
  %.02234 = phi i32 [ 0, %.lr.ph ], [ %24, %23 ]
  %.02433 = phi i32 [ %2, %.lr.ph ], [ %25, %23 ]
  %12 = load i32, ptr %8, align 8, !tbaa !15
  %.not26 = icmp eq i32 %12, 0
  br i1 %.not26, label %.critedge, label %13

13:                                               ; preds = %11
  %spec.select = tail call i32 @llvm.smin.i32(i32 %.02433, i32 512)
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = load float, ptr %9, align 4, !tbaa !16
  %16 = tail call noundef float @_ZSt5floorf(float noundef %15)
  %17 = fptosi float %16 to i32
  %18 = sext i32 %spec.select to i64
  %19 = zext i32 %.02234 to i64
  %20 = getelementptr inbounds float, ptr %1, i64 %19
  %21 = getelementptr inbounds float, ptr %20, i64 %10
  %22 = tail call i32 @openmpt_module_read_float_stereo(ptr noundef %14, i32 noundef %17, i64 noundef %18, ptr noundef %20, ptr noundef %21)
  %.not27 = icmp eq i32 %22, 0
  br i1 %.not27, label %.thread, label %23

.thread:                                          ; preds = %13
  store i32 0, ptr %8, align 8, !tbaa !15
  br label %.critedge

23:                                               ; preds = %13
  %24 = add i32 %.02234, %spec.select
  %25 = sub nsw i32 %.02433, %spec.select
  %.not = icmp eq i32 %25, 0
  br i1 %.not, label %.critedge, label %11, !llvm.loop !17

.critedge:                                        ; preds = %11, %23, %.thread, %4
  %.3 = phi i32 [ 0, %4 ], [ %.02234, %.thread ], [ %.02234, %11 ], [ %24, %23 ]
  ret i32 %.3
}

declare i32 @openmpt_module_read_float_stereo(ptr noundef, i32 noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt5floorf(float noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #3

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 = { "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 = { inlinehint mustprogress nounwind 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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, !14, i64 504}
!6 = !{!"_ZTSN6SoLoud15OpenmptInstanceE", !7, i64 0, !14, i64 496, !14, i64 504, !8, i64 512}
!7 = !{!"_ZTSN6SoLoud19AudioSourceInstanceE", !8, i64 8, !8, i64 12, !8, i64 16, !11, i64 20, !9, i64 24, !11, i64 56, !11, i64 60, !11, i64 64, !11, i64 68, !8, i64 72, !11, i64 76, !11, i64 80, !12, i64 88, !12, i64 96, !13, i64 104, !13, i64 152, !13, i64 200, !13, i64 248, !13, i64 296, !8, i64 344, !9, i64 348, !8, i64 380, !8, i64 384, !9, i64 392, !9, i64 456, !8, i64 472, !8, i64 476, !8, i64 480, !12, i64 488}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"float", !9, i64 0}
!12 = !{!"double", !9, i64 0}
!13 = !{!"_ZTSN6SoLoud5FaderE", !11, i64 0, !11, i64 4, !11, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !11, i64 40, !8, i64 44}
!14 = !{!"any pointer", !9, i64 0}
!15 = !{!6, !8, i64 512}
!16 = !{!7, !11, i64 68}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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