; LLVM IR from erwincoumans/tiny-differentiable-simulator :: third_party/tiny_audio (b3ReadWavFile)

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

%struct.b3WavTicker = type <{ %"class.std::vector", i8, [7 x i8], double, double, double, double, double, i32, [4 x i8] }>
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl" }
%"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl" = type { %"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl_data" }
%"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl_data" = type { ptr, ptr, ptr }

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK13b3ReadWavFile11interpolateEP11b3WavTickerR12b3DataSourceddiPdS4_i(ptr noundef nonnull align 8 dereferenceable(53), ptr noundef, ptr noundef nonnull align 8 dereferenceable(8), double noundef, double noundef, i32 noundef, ptr noundef, ptr noundef, i32 noundef) #0 align 2

; 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 speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN13b3ReadWavFile4tickEP11b3WavTickerR12b3DataSourceddiPdS4_i(ptr noundef nonnull align 8 dereferenceable(53) %0, ptr noundef %1, ptr noundef nonnull align 8 dereferenceable(8) %2, double noundef %3, double noundef %4, i32 noundef %5, ptr noundef %6, ptr noundef %7, i32 noundef %8) #0 align 2 {
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca double, align 8
  %14 = alloca double, align 8
  %15 = alloca i32, align 4
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  store ptr %0, ptr %10, align 8, !tbaa !5
  store ptr %1, ptr %11, align 8, !tbaa !5
  store ptr %2, ptr %12, align 8, !tbaa !5
  store double %3, ptr %13, align 8, !tbaa !9
  store double %4, ptr %14, align 8, !tbaa !9
  store i32 %5, ptr %15, align 4, !tbaa !11
  store ptr %6, ptr %16, align 8, !tbaa !5
  store ptr %7, ptr %17, align 8, !tbaa !5
  store i32 %8, ptr %18, align 4, !tbaa !11
  %21 = load ptr, ptr %10, align 8
  %22 = load ptr, ptr %11, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.b3WavTicker, ptr %22, i32 0, i32 1
  %24 = load i8, ptr %23, align 8, !tbaa !13, !range !20, !noundef !21
  %25 = trunc i8 %24 to i1
  br i1 %25, label %26, label %27

26:                                               ; preds = %9
  br label %95

27:                                               ; preds = %9
  %28 = load ptr, ptr %11, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.b3WavTicker, ptr %28, i32 0, i32 3
  %30 = load double, ptr %29, align 8, !tbaa !22
  %31 = load ptr, ptr %11, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.b3WavTicker, ptr %31, i32 0, i32 4
  %33 = load double, ptr %32, align 8, !tbaa !23
  %34 = fcmp olt double %30, %33
  br i1 %34, label %43, label %35

35:                                               ; preds = %27
  %36 = load ptr, ptr %11, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.b3WavTicker, ptr %36, i32 0, i32 3
  %38 = load double, ptr %37, align 8, !tbaa !22
  %39 = load ptr, ptr %11, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.b3WavTicker, ptr %39, i32 0, i32 5
  %41 = load double, ptr %40, align 8, !tbaa !24
  %42 = fcmp ogt double %38, %41
  br i1 %42, label %43, label %46

43:                                               ; preds = %35, %27
  %44 = load ptr, ptr %11, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.b3WavTicker, ptr %44, i32 0, i32 1
  store i8 1, ptr %45, align 8, !tbaa !13
  br label %95

46:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #3
  store i32 0, ptr %19, align 4, !tbaa !11
  br label %47

47:                                               ; preds = %90, %46
  %48 = load i32, ptr %19, align 4, !tbaa !11
  %49 = load i32, ptr %15, align 4, !tbaa !11
  %50 = icmp slt i32 %48, %49
  br i1 %50, label %52, label %51

51:                                               ; preds = %47
  store i32 2, ptr %20, align 4
  br label %93

52:                                               ; preds = %47
  %53 = load ptr, ptr %11, align 8, !tbaa !5
  %54 = load ptr, ptr %12, align 8, !tbaa !5
  %55 = load double, ptr %13, align 8, !tbaa !9
  %56 = load double, ptr %14, align 8, !tbaa !9
  %57 = load i32, ptr %15, align 4, !tbaa !11
  %58 = load ptr, ptr %16, align 8, !tbaa !5
  %59 = load ptr, ptr %17, align 8, !tbaa !5
  %60 = load i32, ptr %19, align 4, !tbaa !11
  %61 = load i32, ptr %18, align 4, !tbaa !11
  %62 = mul nsw i32 %60, %61
  call void @_ZNK13b3ReadWavFile11interpolateEP11b3WavTickerR12b3DataSourceddiPdS4_i(ptr noundef nonnull align 8 dereferenceable(53) %21, ptr noundef %53, ptr noundef nonnull align 8 dereferenceable(8) %54, double noundef %55, double noundef %56, i32 noundef %57, ptr noundef %58, ptr noundef %59, i32 noundef %62)
  %63 = load ptr, ptr %11, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.b3WavTicker, ptr %63, i32 0, i32 6
  %65 = load double, ptr %64, align 8, !tbaa !25
  %66 = load double, ptr %13, align 8, !tbaa !9
  %67 = load ptr, ptr %11, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.b3WavTicker, ptr %67, i32 0, i32 3
  %69 = load double, ptr %68, align 8, !tbaa !22
  %70 = call double @llvm.fmuladd.f64(double %65, double %66, double %69)
  store double %70, ptr %68, align 8, !tbaa !22
  %71 = load ptr, ptr %11, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.b3WavTicker, ptr %71, i32 0, i32 3
  %73 = load double, ptr %72, align 8, !tbaa !22
  %74 = load ptr, ptr %11, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.b3WavTicker, ptr %74, i32 0, i32 4
  %76 = load double, ptr %75, align 8, !tbaa !23
  %77 = fcmp olt double %73, %76
  br i1 %77, label %86, label %78

78:                                               ; preds = %52
  %79 = load ptr, ptr %11, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.b3WavTicker, ptr %79, i32 0, i32 3
  %81 = load double, ptr %80, align 8, !tbaa !22
  %82 = load ptr, ptr %11, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.b3WavTicker, ptr %82, i32 0, i32 5
  %84 = load double, ptr %83, align 8, !tbaa !24
  %85 = fcmp ogt double %81, %84
  br i1 %85, label %86, label %89

86:                                               ; preds = %78, %52
  %87 = load ptr, ptr %11, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.b3WavTicker, ptr %87, i32 0, i32 1
  store i8 1, ptr %88, align 8, !tbaa !13
  store i32 1, ptr %20, align 4
  br label %93

89:                                               ; preds = %78
  br label %90

90:                                               ; preds = %89
  %91 = load i32, ptr %19, align 4, !tbaa !11
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr %19, align 4, !tbaa !11
  br label %47, !llvm.loop !26

93:                                               ; preds = %86, %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #3
  %94 = load i32, ptr %20, align 4
  switch i32 %94, label %96 [
    i32 2, label %95
    i32 1, label %95
  ]

95:                                               ; preds = %93, %93, %43, %26
  ret void

96:                                               ; preds = %93
  unreachable
}

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 = { 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, !19, i64 24}
!14 = !{!"_ZTS11b3WavTicker", !15, i64 0, !19, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !12, i64 72}
!15 = !{!"_ZTSSt6vectorIdSaIdEE", !16, i64 0}
!16 = !{!"_ZTSSt12_Vector_baseIdSaIdEE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE12_Vector_implE", !18, i64 0}
!18 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!19 = !{!"bool", !7, i64 0}
!20 = !{i8 0, i8 2}
!21 = !{}
!22 = !{!14, !10, i64 32}
!23 = !{!14, !10, i64 40}
!24 = !{!14, !10, i64 48}
!25 = !{!14, !10, i64 56}
!26 = distinct !{!26, !27}
!27 = !{!"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
declare dso_local void @_ZNK13b3ReadWavFile11interpolateEP11b3WavTickerR12b3DataSourceddiPdS4_i(ptr noundef nonnull align 8 dereferenceable(53), ptr noundef, ptr noundef nonnull align 8 dereferenceable(8), double noundef, double noundef, i32 noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN13b3ReadWavFile4tickEP11b3WavTickerR12b3DataSourceddiPdS4_i(ptr noundef nonnull align 8 dereferenceable(53) %0, ptr noundef %1, ptr noundef nonnull align 8 dereferenceable(8) %2, double noundef %3, double noundef %4, i32 noundef %5, ptr noundef %6, ptr noundef %7, i32 noundef %8) local_unnamed_addr #0 align 2 {
  %10 = getelementptr inbounds i8, ptr %1, i64 24
  %11 = load i8, ptr %10, align 8, !tbaa !5, !range !17, !noundef !18
  %12 = trunc nuw i8 %11 to i1
  br i1 %12, label %.loopexit, label %13

13:                                               ; preds = %9
  %14 = getelementptr inbounds i8, ptr %1, i64 32
  %15 = load double, ptr %14, align 8, !tbaa !19
  %16 = getelementptr inbounds i8, ptr %1, i64 40
  %17 = load double, ptr %16, align 8, !tbaa !20
  %18 = fcmp olt double %15, %17
  br i1 %18, label %.loopexit.sink.split, label %19

19:                                               ; preds = %13
  %20 = getelementptr inbounds i8, ptr %1, i64 48
  %21 = load double, ptr %20, align 8, !tbaa !21
  %22 = fcmp ogt double %15, %21
  br i1 %22, label %.loopexit.sink.split, label %.preheader

.preheader:                                       ; preds = %19
  %23 = icmp sgt i32 %5, 0
  br i1 %23, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader
  %24 = getelementptr inbounds i8, ptr %1, i64 56
  br label %27

25:                                               ; preds = %34
  %26 = add nuw nsw i32 %.029, 1
  %exitcond.not = icmp eq i32 %26, %5
  br i1 %exitcond.not, label %.loopexit, label %27, !llvm.loop !22

27:                                               ; preds = %.lr.ph, %25
  %.029 = phi i32 [ 0, %.lr.ph ], [ %26, %25 ]
  %28 = mul nsw i32 %.029, %8
  tail call void @_ZNK13b3ReadWavFile11interpolateEP11b3WavTickerR12b3DataSourceddiPdS4_i(ptr noundef nonnull align 8 dereferenceable(53) %0, ptr noundef nonnull %1, ptr noundef nonnull align 8 dereferenceable(8) %2, double noundef %3, double noundef %4, i32 noundef %5, ptr noundef %6, ptr noundef %7, i32 noundef %28)
  %29 = load double, ptr %24, align 8, !tbaa !24
  %30 = load double, ptr %14, align 8, !tbaa !19
  %31 = tail call double @llvm.fmuladd.f64(double %29, double %3, double %30)
  store double %31, ptr %14, align 8, !tbaa !19
  %32 = load double, ptr %16, align 8, !tbaa !20
  %33 = fcmp olt double %31, %32
  br i1 %33, label %.loopexit.sink.split, label %34

34:                                               ; preds = %27
  %35 = load double, ptr %20, align 8, !tbaa !21
  %36 = fcmp ogt double %31, %35
  br i1 %36, label %.loopexit.sink.split, label %25

.loopexit.sink.split:                             ; preds = %27, %34, %13, %19
  store i8 1, ptr %10, align 8, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %25, %.loopexit.sink.split, %.preheader, %9
  ret void
}

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

!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 24}
!6 = !{!"_ZTS11b3WavTicker", !7, i64 0, !14, i64 24, !15, i64 32, !15, i64 40, !15, i64 48, !15, i64 56, !15, i64 64, !16, i64 72}
!7 = !{!"_ZTSSt6vectorIdSaIdEE", !8, i64 0}
!8 = !{!"_ZTSSt12_Vector_baseIdSaIdEE", !9, i64 0}
!9 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE12_Vector_implE", !10, i64 0}
!10 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE17_Vector_impl_dataE", !11, i64 0, !11, i64 8, !11, i64 16}
!11 = !{!"any pointer", !12, i64 0}
!12 = !{!"omnipotent char", !13, i64 0}
!13 = !{!"Simple C++ TBAA"}
!14 = !{!"bool", !12, i64 0}
!15 = !{!"double", !12, i64 0}
!16 = !{!"int", !12, i64 0}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!6, !15, i64 32}
!20 = !{!6, !15, i64 40}
!21 = !{!6, !15, i64 48}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!6, !15, i64 56}


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