; LLVM IR from Overload-Technologies/Overload :: Dependencies/soloud/src/core (soloud_audiosource)

; 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::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: 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 @_ZN6SoLoud19AudioSourceInstance4seekEdPfj(ptr noundef nonnull align 8 dereferenceable(496) %0, double noundef %1, ptr noundef %2, i32 noundef %3) unnamed_addr #1 align 2 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca double, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca double, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store double %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !11
  %14 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %15 = load double, ptr %7, align 8, !tbaa !9
  %16 = getelementptr inbounds %"class.SoLoud::AudioSourceInstance", ptr %14, i32 0, i32 14
  %17 = load double, ptr %16, align 8, !tbaa !13
  %18 = fsub double %15, %17
  store double %18, ptr %10, align 8, !tbaa !9
  %19 = load double, ptr %10, align 8, !tbaa !9
  %20 = fcmp ole double %19, 0.000000e+00
  br i1 %20, label %21, label %30

21:                                               ; preds = %4
  %22 = load ptr, ptr %14, align 8, !tbaa !17
  %23 = getelementptr inbounds ptr, ptr %22, i64 5
  %24 = load ptr, ptr %23, align 8
  %25 = call noundef i32 %24(ptr noundef nonnull align 8 dereferenceable(496) %14)
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %28

27:                                               ; preds = %21
  store i32 6, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %65

28:                                               ; preds = %21
  %29 = load double, ptr %7, align 8, !tbaa !9
  store double %29, ptr %10, align 8, !tbaa !9
  br label %30

30:                                               ; preds = %28, %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %31 = getelementptr inbounds %"class.SoLoud::AudioSourceInstance", ptr %14, i32 0, i32 9
  %32 = load float, ptr %31, align 4, !tbaa !19
  %33 = fpext float %32 to double
  %34 = load double, ptr %10, align 8, !tbaa !9
  %35 = fmul double %33, %34
  %36 = call double @llvm.floor.f64(double %35)
  %37 = fptosi double %36 to i32
  store i32 %37, ptr %12, align 4, !tbaa !11
  br label %38

38:                                               ; preds = %51, %30
  %39 = load i32, ptr %12, align 4, !tbaa !11
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %41, label %62

41:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %42 = load i32, ptr %9, align 4, !tbaa !11
  %43 = getelementptr inbounds %"class.SoLoud::AudioSourceInstance", ptr %14, i32 0, i32 10
  %44 = load i32, ptr %43, align 8, !tbaa !20
  %45 = udiv i32 %42, %44
  store i32 %45, ptr %13, align 4, !tbaa !11
  %46 = load i32, ptr %13, align 4, !tbaa !11
  %47 = load i32, ptr %12, align 4, !tbaa !11
  %48 = icmp sgt i32 %46, %47
  br i1 %48, label %49, label %51

49:                                               ; preds = %41
  %50 = load i32, ptr %12, align 4, !tbaa !11
  store i32 %50, ptr %13, align 4, !tbaa !11
  br label %51

51:                                               ; preds = %49, %41
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = load i32, ptr %13, align 4, !tbaa !11
  %54 = load i32, ptr %13, align 4, !tbaa !11
  %55 = load ptr, ptr %14, align 8, !tbaa !17
  %56 = getelementptr inbounds ptr, ptr %55, i64 2
  %57 = load ptr, ptr %56, align 8
  %58 = call noundef i32 %57(ptr noundef nonnull align 8 dereferenceable(496) %14, ptr noundef %52, i32 noundef %53, i32 noundef %54)
  %59 = load i32, ptr %13, align 4, !tbaa !11
  %60 = load i32, ptr %12, align 4, !tbaa !11
  %61 = sub nsw i32 %60, %59
  store i32 %61, ptr %12, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %38, !llvm.loop !21

62:                                               ; preds = %38
  %63 = load double, ptr %7, align 8, !tbaa !9
  %64 = getelementptr inbounds %"class.SoLoud::AudioSourceInstance", ptr %14, i32 0, i32 14
  store double %63, ptr %64, align 8, !tbaa !13
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %65

65:                                               ; preds = %62, %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %66 = load i32, ptr %5, align 4
  ret i32 %66
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.floor.f64(double) #2

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !10, i64 96}
!14 = !{!"_ZTSN6SoLoud19AudioSourceInstanceE", !12, i64 8, !12, i64 12, !12, i64 16, !15, i64 20, !7, i64 24, !15, i64 56, !15, i64 60, !15, i64 64, !15, i64 68, !12, i64 72, !15, i64 76, !15, i64 80, !10, i64 88, !10, i64 96, !16, i64 104, !16, i64 152, !16, i64 200, !16, i64 248, !16, i64 296, !12, i64 344, !7, i64 348, !12, i64 380, !12, i64 384, !7, i64 392, !7, i64 456, !12, i64 472, !12, i64 476, !12, i64 480, !10, i64 488}
!15 = !{!"float", !7, i64 0}
!16 = !{!"_ZTSN6SoLoud5FaderE", !15, i64 0, !15, i64 4, !15, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !15, i64 40, !12, i64 44}
!17 = !{!18, !18, i64 0}
!18 = !{!"vtable pointer", !8, i64 0}
!19 = !{!14, !15, i64 68}
!20 = !{!14, !12, i64 72}
!21 = distinct !{!21, !22}
!22 = !{!"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 range(i32 0, 7) i32 @_ZN6SoLoud19AudioSourceInstance4seekEdPfj(ptr noundef nonnull align 8 dereferenceable(496) %0, double noundef %1, ptr noundef %2, i32 noundef %3) unnamed_addr #0 align 2 {
  %5 = getelementptr inbounds i8, ptr %0, i64 96
  %6 = load double, ptr %5, align 8, !tbaa !5
  %7 = fsub double %1, %6
  %8 = fcmp ugt double %7, 0.000000e+00
  br i1 %8, label %14, label %9

9:                                                ; preds = %4
  %10 = load ptr, ptr %0, align 8, !tbaa !13
  %11 = getelementptr inbounds i8, ptr %10, i64 40
  %12 = load ptr, ptr %11, align 8
  %13 = tail call noundef i32 %12(ptr noundef nonnull align 8 dereferenceable(496) %0)
  %.not = icmp eq i32 %13, 0
  br i1 %.not, label %14, label %30

14:                                               ; preds = %9, %4
  %.017 = phi double [ %7, %4 ], [ %1, %9 ]
  %15 = getelementptr inbounds i8, ptr %0, i64 68
  %16 = load float, ptr %15, align 4, !tbaa !15
  %17 = fpext float %16 to double
  %18 = fmul double %.017, %17
  %19 = tail call double @llvm.floor.f64(double %18)
  %20 = fptosi double %19 to i32
  %.not2122 = icmp eq i32 %20, 0
  br i1 %.not2122, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %14
  %21 = getelementptr inbounds i8, ptr %0, i64 72
  br label %22

22:                                               ; preds = %.lr.ph, %22
  %.01623 = phi i32 [ %20, %.lr.ph ], [ %29, %22 ]
  %23 = load i32, ptr %21, align 8, !tbaa !16
  %24 = udiv i32 %3, %23
  %spec.select = tail call i32 @llvm.smin.i32(i32 %24, i32 %.01623)
  %25 = load ptr, ptr %0, align 8, !tbaa !13
  %26 = getelementptr inbounds i8, ptr %25, i64 16
  %27 = load ptr, ptr %26, align 8
  %28 = tail call noundef i32 %27(ptr noundef nonnull align 8 dereferenceable(496) %0, ptr noundef %2, i32 noundef %spec.select, i32 noundef %spec.select)
  %29 = sub nsw i32 %.01623, %spec.select
  %.not21 = icmp eq i32 %29, 0
  br i1 %.not21, label %._crit_edge, label %22, !llvm.loop !17

._crit_edge:                                      ; preds = %22, %14
  store double %1, ptr %5, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %9, %._crit_edge
  %.018 = phi i32 [ 0, %._crit_edge ], [ 6, %9 ]
  ret i32 %.018
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.floor.f64(double) #1

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

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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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, !11, i64 96}
!6 = !{!"_ZTSN6SoLoud19AudioSourceInstanceE", !7, i64 8, !7, i64 12, !7, i64 16, !10, i64 20, !8, i64 24, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68, !7, i64 72, !10, i64 76, !10, i64 80, !11, i64 88, !11, i64 96, !12, i64 104, !12, i64 152, !12, i64 200, !12, i64 248, !12, i64 296, !7, i64 344, !8, i64 348, !7, i64 380, !7, i64 384, !8, i64 392, !8, i64 456, !7, i64 472, !7, i64 476, !7, i64 480, !11, i64 488}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"float", !8, i64 0}
!11 = !{!"double", !8, i64 0}
!12 = !{!"_ZTSN6SoLoud5FaderE", !10, i64 0, !10, i64 4, !10, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !10, i64 40, !7, i64 44}
!13 = !{!14, !14, i64 0}
!14 = !{!"vtable pointer", !9, i64 0}
!15 = !{!6, !10, i64 68}
!16 = !{!6, !7, i64 72}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass