; LLVM IR from chriskiefer/libcccrt :: benchmarks/maximilian.ll (ZN7maxiOsc7sinebufEd)

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

@chandiv = external dso_local global float, align 4
@_ZN12maxiSettings10sampleRateE = external dso_local global i64, align 8
@sineBuffer = external dso_local global [514 x double], align 16

; 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: 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 double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_ZN7maxiOsc7sinebufEd(ptr noundef nonnull align 8 dereferenceable(48) %0, double noundef %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store double %1, ptr %4, align 8, !tbaa !9
  %6 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %7 = load i64, ptr @_ZN12maxiSettings10sampleRateE, align 8, !tbaa !11
  %8 = uitofp i64 %7 to double
  %9 = load double, ptr %4, align 8, !tbaa !9
  %10 = load float, ptr @chandiv, align 4, !tbaa !13
  %11 = fpext float %10 to double
  %12 = fmul double %9, %11
  %13 = fdiv double %8, %12
  %14 = fdiv double 5.120000e+02, %13
  %15 = getelementptr inbounds %class.maxiOsc, ptr %6, i32 0, i32 1
  %16 = load double, ptr %15, align 8, !tbaa !15
  %17 = fadd double %16, %14
  store double %17, ptr %15, align 8, !tbaa !15
  %18 = getelementptr inbounds %class.maxiOsc, ptr %6, i32 0, i32 1
  %19 = load double, ptr %18, align 8, !tbaa !15
  %20 = fcmp oge double %19, 5.110000e+02
  br i1 %20, label %21, label %25

21:                                               ; preds = %2
  %22 = getelementptr inbounds %class.maxiOsc, ptr %6, i32 0, i32 1
  %23 = load double, ptr %22, align 8, !tbaa !15
  %24 = fsub double %23, 5.120000e+02
  store double %24, ptr %22, align 8, !tbaa !15
  br label %25

25:                                               ; preds = %21, %2
  %26 = getelementptr inbounds %class.maxiOsc, ptr %6, i32 0, i32 1
  %27 = load double, ptr %26, align 8, !tbaa !15
  %28 = getelementptr inbounds %class.maxiOsc, ptr %6, i32 0, i32 1
  %29 = load double, ptr %28, align 8, !tbaa !15
  %30 = call double @llvm.floor.f64(double %29)
  %31 = fsub double %27, %30
  store double %31, ptr %5, align 8, !tbaa !9
  %32 = load double, ptr %5, align 8, !tbaa !9
  %33 = fsub double 1.000000e+00, %32
  %34 = getelementptr inbounds %class.maxiOsc, ptr %6, i32 0, i32 1
  %35 = load double, ptr %34, align 8, !tbaa !15
  %36 = fptosi double %35 to i64
  %37 = add nsw i64 1, %36
  %38 = getelementptr inbounds [514 x double], ptr @sineBuffer, i64 0, i64 %37
  %39 = load double, ptr %38, align 8, !tbaa !9
  %40 = load double, ptr %5, align 8, !tbaa !9
  %41 = getelementptr inbounds %class.maxiOsc, ptr %6, i32 0, i32 1
  %42 = load double, ptr %41, align 8, !tbaa !15
  %43 = fptosi double %42 to i64
  %44 = add nsw i64 2, %43
  %45 = getelementptr inbounds [514 x double], ptr @sineBuffer, i64 0, i64 %44
  %46 = load double, ptr %45, align 8, !tbaa !9
  %47 = fmul double %40, %46
  %48 = call double @llvm.fmuladd.f64(double %33, double %39, double %47)
  %49 = getelementptr inbounds %class.maxiOsc, ptr %6, i32 0, i32 4
  store double %48, ptr %49, align 8, !tbaa !17
  %50 = getelementptr inbounds %class.maxiOsc, ptr %6, i32 0, i32 4
  %51 = load double, ptr %50, align 8, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret double %51
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { 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 = { 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 = !{!"long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !7, i64 0}
!15 = !{!16, !10, i64 8}
!16 = !{!"_ZTS7maxiOsc", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40}
!17 = !{!16, !10, i64 32}


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

@chandiv = external dso_local local_unnamed_addr global float, align 4
@_ZN12maxiSettings10sampleRateE = external dso_local local_unnamed_addr global i64, align 8
@sineBuffer = external dso_local local_unnamed_addr global [514 x double], align 16

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

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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local noundef double @_ZN7maxiOsc7sinebufEd(ptr nocapture noundef nonnull align 8 dereferenceable(48) %0, double noundef %1) local_unnamed_addr #1 align 2 {
  %3 = load i64, ptr @_ZN12maxiSettings10sampleRateE, align 8, !tbaa !5
  %4 = uitofp i64 %3 to double
  %5 = load float, ptr @chandiv, align 4, !tbaa !9
  %6 = fpext float %5 to double
  %7 = fmul double %6, %1
  %8 = fdiv double %4, %7
  %9 = fdiv double 5.120000e+02, %8
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %11 = load double, ptr %10, align 8, !tbaa !11
  %12 = fadd double %11, %9
  %13 = fcmp ult double %12, 5.110000e+02
  %14 = fadd double %12, -5.120000e+02
  %storemerge = select i1 %13, double %12, double %14
  store double %storemerge, ptr %10, align 8, !tbaa !11
  %15 = tail call double @llvm.floor.f64(double %storemerge)
  %16 = fsub double %storemerge, %15
  %17 = fsub double 1.000000e+00, %16
  %18 = fptosi double %storemerge to i64
  %19 = add nsw i64 %18, 1
  %20 = getelementptr inbounds [514 x double], ptr @sineBuffer, i64 0, i64 %19
  %21 = load double, ptr %20, align 8, !tbaa !14
  %22 = add nsw i64 %18, 2
  %23 = getelementptr inbounds [514 x double], ptr @sineBuffer, i64 0, i64 %22
  %24 = load double, ptr %23, align 8, !tbaa !14
  %25 = fmul double %24, %16
  %26 = tail call double @llvm.fmuladd.f64(double %17, double %21, double %25)
  %27 = getelementptr inbounds i8, ptr %0, i64 32
  store double %26, ptr %27, align 8, !tbaa !15
  ret double %26
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) 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, !6, i64 0}
!6 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = !{!12, !13, i64 8}
!12 = !{!"_ZTS7maxiOsc", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !13, i64 32, !13, i64 40}
!13 = !{!"double", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!12, !13, i64 32}


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