; LLVM IR from dbry/wavpack-stream :: src (common_utils)

; 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.WavpackContext = type { %struct.WavpackStreamConfig, ptr, i32, i32, ptr, i32, ptr, ptr, ptr, ptr, ptr, ptr, i64, i64, i64, i64, i64, i64, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr, ptr, i8, ptr, ptr, i32, i32, ptr, [8 x i8], ptr, [80 x i8] }
%struct.WavpackStreamConfig = type { float, float, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [16 x i8], i8, i32, ptr }

; 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: nounwind uwtable
define dso_local double @WavpackStreamGetAverageBitrate(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca double, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %63

11:                                               ; preds = %2
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.WavpackContext, ptr %12, i32 0, i32 16
  %14 = load i64, ptr %13, align 8, !tbaa !11
  %15 = icmp ne i64 %14, -1
  br i1 %15, label %16, label %63

16:                                               ; preds = %11
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.WavpackContext, ptr %17, i32 0, i32 12
  %19 = load i64, ptr %18, align 8, !tbaa !16
  %20 = icmp ne i64 %19, 0
  br i1 %20, label %21, label %63

21:                                               ; preds = %16
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = call i32 @WavpackStreamGetSampleRate(ptr noundef %22)
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %63

25:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.WavpackContext, ptr %26, i32 0, i32 16
  %28 = load i64, ptr %27, align 8, !tbaa !11
  %29 = sitofp i64 %28 to double
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = call i32 @WavpackStreamGetSampleRate(ptr noundef %30)
  %32 = uitofp i32 %31 to double
  %33 = fdiv double %29, %32
  store double %33, ptr %6, align 8, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.WavpackContext, ptr %34, i32 0, i32 12
  %36 = load i64, ptr %35, align 8, !tbaa !16
  %37 = sitofp i64 %36 to double
  %38 = load i32, ptr %5, align 4, !tbaa !9
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %44

40:                                               ; preds = %25
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.WavpackContext, ptr %41, i32 0, i32 13
  %43 = load i64, ptr %42, align 8, !tbaa !19
  br label %45

44:                                               ; preds = %25
  br label %45

45:                                               ; preds = %44, %40
  %46 = phi i64 [ %43, %40 ], [ 0, %44 ]
  %47 = sitofp i64 %46 to double
  %48 = fadd double %37, %47
  store double %48, ptr %7, align 8, !tbaa !17
  %49 = load double, ptr %6, align 8, !tbaa !17
  %50 = fcmp oge double %49, 1.000000e-01
  br i1 %50, label %51, label %59

51:                                               ; preds = %45
  %52 = load double, ptr %7, align 8, !tbaa !17
  %53 = fcmp oge double %52, 1.000000e+00
  br i1 %53, label %54, label %59

54:                                               ; preds = %51
  %55 = load double, ptr %7, align 8, !tbaa !17
  %56 = fmul double %55, 8.000000e+00
  %57 = load double, ptr %6, align 8, !tbaa !17
  %58 = fdiv double %56, %57
  store double %58, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %60

59:                                               ; preds = %51, %45
  store i32 0, ptr %8, align 4
  br label %60

60:                                               ; preds = %59, %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %61 = load i32, ptr %8, align 4
  switch i32 %61, label %66 [
    i32 0, label %62
    i32 1, label %64
  ]

62:                                               ; preds = %60
  br label %63

63:                                               ; preds = %62, %21, %16, %11, %2
  store double 0.000000e+00, ptr %3, align 8
  br label %64

64:                                               ; preds = %63, %60
  %65 = load double, ptr %3, align 8
  ret double %65

66:                                               ; preds = %60
  unreachable
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @WavpackStreamGetSampleRate(ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !15, i64 200}
!12 = !{!"WavpackContext", !13, i64 0, !6, i64 88, !10, i64 96, !10, i64 100, !6, i64 104, !10, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !15, i64 168, !15, i64 176, !15, i64 184, !15, i64 192, !15, i64 200, !15, i64 208, !10, i64 216, !10, i64 220, !10, i64 224, !10, i64 228, !10, i64 232, !10, i64 236, !10, i64 240, !10, i64 244, !10, i64 248, !10, i64 252, !10, i64 256, !10, i64 260, !10, i64 264, !10, i64 268, !10, i64 272, !10, i64 276, !10, i64 280, !10, i64 284, !6, i64 288, !6, i64 296, !7, i64 304, !6, i64 312, !6, i64 320, !10, i64 328, !10, i64 332, !6, i64 336, !7, i64 344, !6, i64 352, !7, i64 360}
!13 = !{!"", !14, i64 0, !14, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !7, i64 56, !7, i64 72, !10, i64 76, !6, i64 80}
!14 = !{!"float", !7, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!12, !15, i64 168}
!17 = !{!18, !18, i64 0}
!18 = !{!"double", !7, i64 0}
!19 = !{!12, !15, i64 176}


; 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: nounwind uwtable
define dso_local double @WavpackStreamGetAverageBitrate(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %30, label %3

3:                                                ; preds = %2
  %4 = getelementptr inbounds i8, ptr %0, i64 200
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %.not19 = icmp eq i64 %5, -1
  br i1 %.not19, label %30, label %6

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 168
  %8 = load i64, ptr %7, align 8, !tbaa !14
  %.not20 = icmp eq i64 %8, 0
  br i1 %.not20, label %30, label %9

9:                                                ; preds = %6
  %10 = tail call i32 @WavpackStreamGetSampleRate(ptr noundef nonnull %0)
  %.not21 = icmp eq i32 %10, 0
  br i1 %.not21, label %30, label %11

11:                                               ; preds = %9
  %12 = load i64, ptr %4, align 8, !tbaa !5
  %13 = sitofp i64 %12 to double
  %14 = tail call i32 @WavpackStreamGetSampleRate(ptr noundef nonnull %0)
  %15 = uitofp i32 %14 to double
  %16 = fdiv double %13, %15
  %17 = load i64, ptr %7, align 8, !tbaa !14
  %18 = sitofp i64 %17 to double
  %.not22 = icmp eq i32 %1, 0
  br i1 %.not22, label %23, label %19

19:                                               ; preds = %11
  %20 = getelementptr inbounds i8, ptr %0, i64 176
  %21 = load i64, ptr %20, align 8, !tbaa !15
  %22 = sitofp i64 %21 to double
  br label %23

23:                                               ; preds = %11, %19
  %24 = phi double [ %22, %19 ], [ 0.000000e+00, %11 ]
  %25 = fadd double %24, %18
  %26 = fcmp ult double %16, 1.000000e-01
  %27 = fcmp ult double %25, 1.000000e+00
  %or.cond.not = select i1 %26, i1 true, i1 %27
  %28 = fmul double %25, 8.000000e+00
  %29 = fdiv double %28, %16
  br i1 %or.cond.not, label %30, label %31

30:                                               ; preds = %23, %9, %6, %3, %2
  br label %31

31:                                               ; preds = %23, %30
  %.1 = phi double [ %29, %23 ], [ 0.000000e+00, %30 ]
  ret double %.1
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @WavpackStreamGetSampleRate(ptr noundef) local_unnamed_addr #0

attributes #0 = { 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" }

!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, !13, i64 200}
!6 = !{!"WavpackContext", !7, i64 0, !12, i64 88, !11, i64 96, !11, i64 100, !12, i64 104, !11, i64 112, !12, i64 120, !12, i64 128, !12, i64 136, !12, i64 144, !12, i64 152, !12, i64 160, !13, i64 168, !13, i64 176, !13, i64 184, !13, i64 192, !13, i64 200, !13, i64 208, !11, i64 216, !11, i64 220, !11, i64 224, !11, i64 228, !11, i64 232, !11, i64 236, !11, i64 240, !11, i64 244, !11, i64 248, !11, i64 252, !11, i64 256, !11, i64 260, !11, i64 264, !11, i64 268, !11, i64 272, !11, i64 276, !11, i64 280, !11, i64 284, !12, i64 288, !12, i64 296, !9, i64 304, !12, i64 312, !12, i64 320, !11, i64 328, !11, i64 332, !12, i64 336, !9, i64 344, !12, i64 352, !9, i64 360}
!7 = !{!"", !8, i64 0, !8, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44, !11, i64 48, !11, i64 52, !9, i64 56, !9, i64 72, !11, i64 76, !12, i64 80}
!8 = !{!"float", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!"any pointer", !9, i64 0}
!13 = !{!"long", !9, i64 0}
!14 = !{!6, !13, i64 168}
!15 = !{!6, !13, i64 176}


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