; LLVM IR from TobiasKozel/VAE :: external/portaudio/src/common (pa_cpuload)

; 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.PaUtilCpuLoadMeasurer = type { double, double, double }

@.str.1 = external hidden unnamed_addr constant [92 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [20 x i8], align 1
@__PRETTY_FUNCTION__.PaUtil_EndCpuLoadMeasurement = external hidden unnamed_addr constant [74 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

declare double @PaUtil_GetTime() #1

; Function Attrs: nounwind uwtable
define dso_local void @PaUtil_EndCpuLoadMeasurement(ptr noundef %0, i64 noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %8 = load i64, ptr %4, align 8, !tbaa !9
  %9 = icmp ugt i64 %8, 0
  br i1 %9, label %10, label %38

10:                                               ; preds = %2
  %11 = call double @PaUtil_GetTime()
  store double %11, ptr %5, align 8, !tbaa !11
  %12 = load i64, ptr %4, align 8, !tbaa !9
  %13 = icmp ugt i64 %12, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %10
  br label %16

15:                                               ; preds = %10
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 86, ptr noundef @__PRETTY_FUNCTION__.PaUtil_EndCpuLoadMeasurement) #6
  unreachable

16:                                               ; preds = %14
  %17 = load i64, ptr %4, align 8, !tbaa !9
  %18 = uitofp i64 %17 to double
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.PaUtilCpuLoadMeasurer, ptr %19, i32 0, i32 0
  %21 = load double, ptr %20, align 8, !tbaa !13
  %22 = fmul double %18, %21
  store double %22, ptr %6, align 8, !tbaa !11
  %23 = load double, ptr %5, align 8, !tbaa !11
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.PaUtilCpuLoadMeasurer, ptr %24, i32 0, i32 1
  %26 = load double, ptr %25, align 8, !tbaa !15
  %27 = fsub double %23, %26
  %28 = load double, ptr %6, align 8, !tbaa !11
  %29 = fdiv double %27, %28
  store double %29, ptr %7, align 8, !tbaa !11
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.PaUtilCpuLoadMeasurer, ptr %30, i32 0, i32 2
  %32 = load double, ptr %31, align 8, !tbaa !16
  %33 = load double, ptr %7, align 8, !tbaa !11
  %34 = fmul double 0x3FB998F1D3ED5280, %33
  %35 = call double @llvm.fmuladd.f64(double 9.000000e-01, double %32, double %34)
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.PaUtilCpuLoadMeasurer, ptr %36, i32 0, i32 2
  store double %35, ptr %37, align 8, !tbaa !16
  br label %38

38:                                               ; preds = %16, %2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret void
}

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

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

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

attributes #0 = { noreturn 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 #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 = { 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 willreturn memory(argmem: readwrite) }
attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nounwind }
attributes #6 = { noreturn 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"", !12, i64 0, !12, i64 8, !12, i64 16}
!15 = !{!14, !12, i64 8}
!16 = !{!14, !12, i64 16}


; 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 double @PaUtil_GetTime() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @PaUtil_EndCpuLoadMeasurement(ptr nocapture noundef %0, i64 noundef %1) local_unnamed_addr #1 {
  %.not = icmp eq i64 %1, 0
  br i1 %.not, label %16, label %3

3:                                                ; preds = %2
  %4 = tail call double @PaUtil_GetTime() #3
  %5 = uitofp i64 %1 to double
  %6 = load double, ptr %0, align 8, !tbaa !5
  %7 = fmul double %6, %5
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load double, ptr %8, align 8, !tbaa !10
  %10 = fsub double %4, %9
  %11 = fdiv double %10, %7
  %12 = getelementptr inbounds i8, ptr %0, i64 16
  %13 = load double, ptr %12, align 8, !tbaa !11
  %14 = fmul double %11, 0x3FB998F1D3ED5280
  %15 = tail call double @llvm.fmuladd.f64(double %13, double 9.000000e-01, double %14)
  store double %15, ptr %12, align 8, !tbaa !11
  br label %16

16:                                               ; preds = %3, %2
  ret void
}

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

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 = { 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 = { mustprogress 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = !{!6, !7, i64 16}


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