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

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

@_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: mustprogress nounwind uwtable
define dso_local noundef double @_ZN7maxiOsc8sinebuf4Ed(ptr noundef nonnull align 8 dereferenceable(48) %0, double noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store double %1, ptr %4, align 8, !tbaa !9
  %13 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %14 = load i64, ptr @_ZN12maxiSettings10sampleRateE, align 8, !tbaa !11
  %15 = uitofp i64 %14 to double
  %16 = load double, ptr %4, align 8, !tbaa !9
  %17 = fdiv double %15, %16
  %18 = fdiv double 5.120000e+02, %17
  %19 = getelementptr inbounds %class.maxiOsc, ptr %13, i32 0, i32 1
  %20 = load double, ptr %19, align 8, !tbaa !13
  %21 = fadd double %20, %18
  store double %21, ptr %19, align 8, !tbaa !13
  %22 = getelementptr inbounds %class.maxiOsc, ptr %13, i32 0, i32 1
  %23 = load double, ptr %22, align 8, !tbaa !13
  %24 = fcmp oge double %23, 5.110000e+02
  br i1 %24, label %25, label %29

25:                                               ; preds = %2
  %26 = getelementptr inbounds %class.maxiOsc, ptr %13, i32 0, i32 1
  %27 = load double, ptr %26, align 8, !tbaa !13
  %28 = fsub double %27, 5.120000e+02
  store double %28, ptr %26, align 8, !tbaa !13
  br label %29

29:                                               ; preds = %25, %2
  %30 = getelementptr inbounds %class.maxiOsc, ptr %13, i32 0, i32 1
  %31 = load double, ptr %30, align 8, !tbaa !13
  %32 = getelementptr inbounds %class.maxiOsc, ptr %13, i32 0, i32 1
  %33 = load double, ptr %32, align 8, !tbaa !13
  %34 = call double @llvm.floor.f64(double %33)
  %35 = fsub double %31, %34
  store double %35, ptr %5, align 8, !tbaa !9
  %36 = getelementptr inbounds %class.maxiOsc, ptr %13, i32 0, i32 1
  %37 = load double, ptr %36, align 8, !tbaa !13
  %38 = fcmp oeq double %37, 0.000000e+00
  br i1 %38, label %39, label %58

39:                                               ; preds = %29
  %40 = load double, ptr getelementptr inbounds ([514 x double], ptr @sineBuffer, i64 0, i64 512), align 16, !tbaa !9
  store double %40, ptr %6, align 8, !tbaa !9
  %41 = getelementptr inbounds %class.maxiOsc, ptr %13, i32 0, i32 1
  %42 = load double, ptr %41, align 8, !tbaa !13
  %43 = fptosi double %42 to i64
  %44 = getelementptr inbounds [514 x double], ptr @sineBuffer, i64 0, i64 %43
  %45 = load double, ptr %44, align 8, !tbaa !9
  store double %45, ptr %7, align 8, !tbaa !9
  %46 = getelementptr inbounds %class.maxiOsc, ptr %13, i32 0, i32 1
  %47 = load double, ptr %46, align 8, !tbaa !13
  %48 = fptosi double %47 to i64
  %49 = add nsw i64 %48, 1
  %50 = getelementptr inbounds [514 x double], ptr @sineBuffer, i64 0, i64 %49
  %51 = load double, ptr %50, align 8, !tbaa !9
  store double %51, ptr %8, align 8, !tbaa !9
  %52 = getelementptr inbounds %class.maxiOsc, ptr %13, i32 0, i32 1
  %53 = load double, ptr %52, align 8, !tbaa !13
  %54 = fptosi double %53 to i64
  %55 = add nsw i64 %54, 2
  %56 = getelementptr inbounds [514 x double], ptr @sineBuffer, i64 0, i64 %55
  %57 = load double, ptr %56, align 8, !tbaa !9
  store double %57, ptr %9, align 8, !tbaa !9
  br label %82

58:                                               ; preds = %29
  %59 = getelementptr inbounds %class.maxiOsc, ptr %13, i32 0, i32 1
  %60 = load double, ptr %59, align 8, !tbaa !13
  %61 = fptosi double %60 to i64
  %62 = sub nsw i64 %61, 1
  %63 = getelementptr inbounds [514 x double], ptr @sineBuffer, i64 0, i64 %62
  %64 = load double, ptr %63, align 8, !tbaa !9
  store double %64, ptr %6, align 8, !tbaa !9
  %65 = getelementptr inbounds %class.maxiOsc, ptr %13, i32 0, i32 1
  %66 = load double, ptr %65, align 8, !tbaa !13
  %67 = fptosi double %66 to i64
  %68 = getelementptr inbounds [514 x double], ptr @sineBuffer, i64 0, i64 %67
  %69 = load double, ptr %68, align 8, !tbaa !9
  store double %69, ptr %7, align 8, !tbaa !9
  %70 = getelementptr inbounds %class.maxiOsc, ptr %13, i32 0, i32 1
  %71 = load double, ptr %70, align 8, !tbaa !13
  %72 = fptosi double %71 to i64
  %73 = add nsw i64 %72, 1
  %74 = getelementptr inbounds [514 x double], ptr @sineBuffer, i64 0, i64 %73
  %75 = load double, ptr %74, align 8, !tbaa !9
  store double %75, ptr %8, align 8, !tbaa !9
  %76 = getelementptr inbounds %class.maxiOsc, ptr %13, i32 0, i32 1
  %77 = load double, ptr %76, align 8, !tbaa !13
  %78 = fptosi double %77 to i64
  %79 = add nsw i64 %78, 2
  %80 = getelementptr inbounds [514 x double], ptr @sineBuffer, i64 0, i64 %79
  %81 = load double, ptr %80, align 8, !tbaa !9
  store double %81, ptr %9, align 8, !tbaa !9
  br label %82

82:                                               ; preds = %58, %39
  %83 = load double, ptr %8, align 8, !tbaa !9
  %84 = load double, ptr %6, align 8, !tbaa !9
  %85 = fsub double %83, %84
  %86 = fmul double 5.000000e-01, %85
  store double %86, ptr %10, align 8, !tbaa !9
  %87 = load double, ptr %6, align 8, !tbaa !9
  %88 = load double, ptr %7, align 8, !tbaa !9
  %89 = call double @llvm.fmuladd.f64(double -2.500000e+00, double %88, double %87)
  %90 = load double, ptr %8, align 8, !tbaa !9
  %91 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %90, double %89)
  %92 = load double, ptr %9, align 8, !tbaa !9
  %93 = call double @llvm.fmuladd.f64(double -5.000000e-01, double %92, double %91)
  store double %93, ptr %11, align 8, !tbaa !9
  %94 = load double, ptr %9, align 8, !tbaa !9
  %95 = load double, ptr %6, align 8, !tbaa !9
  %96 = fsub double %94, %95
  %97 = load double, ptr %7, align 8, !tbaa !9
  %98 = load double, ptr %8, align 8, !tbaa !9
  %99 = fsub double %97, %98
  %100 = fmul double 1.500000e+00, %99
  %101 = call double @llvm.fmuladd.f64(double 5.000000e-01, double %96, double %100)
  store double %101, ptr %12, align 8, !tbaa !9
  %102 = load double, ptr %12, align 8, !tbaa !9
  %103 = load double, ptr %5, align 8, !tbaa !9
  %104 = load double, ptr %11, align 8, !tbaa !9
  %105 = call double @llvm.fmuladd.f64(double %102, double %103, double %104)
  %106 = load double, ptr %5, align 8, !tbaa !9
  %107 = load double, ptr %10, align 8, !tbaa !9
  %108 = call double @llvm.fmuladd.f64(double %105, double %106, double %107)
  %109 = load double, ptr %5, align 8, !tbaa !9
  %110 = load double, ptr %7, align 8, !tbaa !9
  %111 = call double @llvm.fmuladd.f64(double %108, double %109, double %110)
  %112 = getelementptr inbounds %class.maxiOsc, ptr %13, i32 0, i32 4
  store double %111, ptr %112, align 8, !tbaa !15
  %113 = getelementptr inbounds %class.maxiOsc, ptr %13, i32 0, i32 4
  %114 = load double, ptr %113, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret double %114
}

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

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

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

@_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 nofree norecurse nosync nounwind willreturn memory(read, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local noundef double @_ZN7maxiOsc8sinebuf4Ed(ptr nocapture noundef nonnull align 8 dereferenceable(48) %0, double noundef %1) local_unnamed_addr #0 align 2 {
  %3 = load i64, ptr @_ZN12maxiSettings10sampleRateE, align 8, !tbaa !5
  %4 = uitofp i64 %3 to double
  %5 = fdiv double %4, %1
  %6 = fdiv double 5.120000e+02, %5
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load double, ptr %7, align 8, !tbaa !9
  %9 = fadd double %8, %6
  %10 = fcmp ult double %9, 5.110000e+02
  %11 = fadd double %9, -5.120000e+02
  %storemerge = select i1 %10, double %9, double %11
  store double %storemerge, ptr %7, align 8, !tbaa !9
  %12 = fcmp oeq double %storemerge, 0.000000e+00
  br i1 %12, label %22, label %13

13:                                               ; preds = %2
  %14 = fptosi double %storemerge to i64
  %15 = add nsw i64 %14, -1
  %16 = getelementptr inbounds [514 x double], ptr @sineBuffer, i64 0, i64 %15
  %17 = getelementptr inbounds [514 x double], ptr @sineBuffer, i64 0, i64 %14
  %18 = add nsw i64 %14, 1
  %19 = getelementptr inbounds [514 x double], ptr @sineBuffer, i64 0, i64 %18
  %20 = add nsw i64 %14, 2
  %21 = getelementptr inbounds [514 x double], ptr @sineBuffer, i64 0, i64 %20
  br label %22

22:                                               ; preds = %2, %13
  %.021.in = phi ptr [ %21, %13 ], [ getelementptr inbounds (i8, ptr @sineBuffer, i64 16), %2 ]
  %.020.in = phi ptr [ %19, %13 ], [ getelementptr inbounds (i8, ptr @sineBuffer, i64 8), %2 ]
  %.019.in = phi ptr [ %17, %13 ], [ @sineBuffer, %2 ]
  %.0.in = phi ptr [ %16, %13 ], [ getelementptr inbounds (i8, ptr @sineBuffer, i64 4096), %2 ]
  %.0 = load double, ptr %.0.in, align 8, !tbaa !12
  %.019 = load double, ptr %.019.in, align 8, !tbaa !12
  %.020 = load double, ptr %.020.in, align 8, !tbaa !12
  %.021 = load double, ptr %.021.in, align 8, !tbaa !12
  %23 = tail call double @llvm.floor.f64(double %storemerge)
  %24 = fsub double %storemerge, %23
  %25 = fsub double %.020, %.0
  %26 = fmul double %25, 5.000000e-01
  %27 = tail call double @llvm.fmuladd.f64(double %.019, double -2.500000e+00, double %.0)
  %28 = tail call double @llvm.fmuladd.f64(double %.020, double 2.000000e+00, double %27)
  %29 = tail call double @llvm.fmuladd.f64(double %.021, double -5.000000e-01, double %28)
  %30 = fsub double %.021, %.0
  %31 = fsub double %.019, %.020
  %32 = fmul double %31, 1.500000e+00
  %33 = tail call double @llvm.fmuladd.f64(double %30, double 5.000000e-01, double %32)
  %34 = tail call double @llvm.fmuladd.f64(double %33, double %24, double %29)
  %35 = tail call double @llvm.fmuladd.f64(double %34, double %24, double %26)
  %36 = tail call double @llvm.fmuladd.f64(double %35, double %24, double %.019)
  %37 = getelementptr inbounds i8, ptr %0, i64 32
  store double %36, ptr %37, align 8, !tbaa !13
  ret double %36
}

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

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

attributes #0 = { 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" }
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, !6, i64 0}
!6 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 8}
!10 = !{!"_ZTS7maxiOsc", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !11, i64 40}
!11 = !{!"double", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 32}


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