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

; 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
@transition = external dso_local global [1001 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 @_ZN7maxiOsc4sawnEd(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
  %6 = alloca double, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store double %1, ptr %4, align 8, !tbaa !9
  %7 = load ptr, ptr %3, align 8
  %8 = getelementptr inbounds %class.maxiOsc, ptr %7, i32 0, i32 1
  %9 = load double, ptr %8, align 8, !tbaa !11
  %10 = fcmp oge double %9, 5.000000e-01
  br i1 %10, label %11, label %15

11:                                               ; preds = %2
  %12 = getelementptr inbounds %class.maxiOsc, ptr %7, i32 0, i32 1
  %13 = load double, ptr %12, align 8, !tbaa !11
  %14 = fsub double %13, 1.000000e+00
  store double %14, ptr %12, align 8, !tbaa !11
  br label %15

15:                                               ; preds = %11, %2
  %16 = load i64, ptr @_ZN12maxiSettings10sampleRateE, align 8, !tbaa !13
  %17 = uitofp i64 %16 to double
  %18 = load double, ptr %4, align 8, !tbaa !9
  %19 = fdiv double %17, %18
  %20 = fdiv double 1.000000e+00, %19
  %21 = getelementptr inbounds %class.maxiOsc, ptr %7, i32 0, i32 1
  %22 = load double, ptr %21, align 8, !tbaa !11
  %23 = fadd double %22, %20
  store double %23, ptr %21, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %24 = load double, ptr %4, align 8, !tbaa !9
  %25 = fdiv double 0x40C13A1C28F5C28F, %24
  %26 = getelementptr inbounds %class.maxiOsc, ptr %7, i32 0, i32 1
  %27 = load double, ptr %26, align 8, !tbaa !11
  %28 = fmul double %25, %27
  store double %28, ptr %5, align 8, !tbaa !9
  %29 = load double, ptr %5, align 8, !tbaa !9
  %30 = fcmp olt double %29, -5.000000e-01
  br i1 %30, label %31, label %32

31:                                               ; preds = %15
  store double -5.000000e-01, ptr %5, align 8, !tbaa !9
  br label %32

32:                                               ; preds = %31, %15
  %33 = load double, ptr %5, align 8, !tbaa !9
  %34 = fcmp ogt double %33, 5.000000e-01
  br i1 %34, label %35, label %36

35:                                               ; preds = %32
  store double 5.000000e-01, ptr %5, align 8, !tbaa !9
  br label %36

36:                                               ; preds = %35, %32
  %37 = load double, ptr %5, align 8, !tbaa !9
  %38 = fmul double %37, 1.000000e+03
  store double %38, ptr %5, align 8, !tbaa !9
  %39 = load double, ptr %5, align 8, !tbaa !9
  %40 = fadd double %39, 5.000000e+02
  store double %40, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %41 = load double, ptr %5, align 8, !tbaa !9
  %42 = load double, ptr %5, align 8, !tbaa !9
  %43 = call double @llvm.floor.f64(double %42)
  %44 = fsub double %41, %43
  store double %44, ptr %6, align 8, !tbaa !9
  %45 = load double, ptr %6, align 8, !tbaa !9
  %46 = fsub double 1.000000e+00, %45
  %47 = load double, ptr %5, align 8, !tbaa !9
  %48 = fptosi double %47 to i64
  %49 = getelementptr inbounds [1001 x double], ptr @transition, i64 0, i64 %48
  %50 = load double, ptr %49, align 8, !tbaa !9
  %51 = load double, ptr %6, align 8, !tbaa !9
  %52 = load double, ptr %5, align 8, !tbaa !9
  %53 = fptosi double %52 to i64
  %54 = add nsw i64 1, %53
  %55 = getelementptr inbounds [1001 x double], ptr @transition, i64 0, i64 %54
  %56 = load double, ptr %55, align 8, !tbaa !9
  %57 = fmul double %51, %56
  %58 = call double @llvm.fmuladd.f64(double %46, double %50, double %57)
  %59 = getelementptr inbounds %class.maxiOsc, ptr %7, i32 0, i32 1
  %60 = load double, ptr %59, align 8, !tbaa !11
  %61 = fsub double %58, %60
  %62 = getelementptr inbounds %class.maxiOsc, ptr %7, i32 0, i32 4
  store double %61, ptr %62, align 8, !tbaa !15
  %63 = getelementptr inbounds %class.maxiOsc, ptr %7, i32 0, i32 4
  %64 = load double, ptr %63, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret double %64
}

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, !10, i64 8}
!12 = !{!"_ZTS7maxiOsc", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!12, !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
@transition = external dso_local local_unnamed_addr global [1001 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 @_ZN7maxiOsc4sawnEd(ptr nocapture noundef nonnull align 8 dereferenceable(48) %0, double noundef %1) local_unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load double, ptr %3, align 8, !tbaa !5
  %5 = fcmp ult double %4, 5.000000e-01
  %6 = fadd double %4, -1.000000e+00
  %7 = select i1 %5, double %4, double %6
  %8 = load i64, ptr @_ZN12maxiSettings10sampleRateE, align 8, !tbaa !10
  %9 = uitofp i64 %8 to double
  %10 = fdiv double %9, %1
  %11 = fdiv double 1.000000e+00, %10
  %12 = fadd double %7, %11
  store double %12, ptr %3, align 8, !tbaa !5
  %13 = fdiv double 0x40C13A1C28F5C28F, %1
  %14 = fmul double %13, %12
  %15 = fcmp olt double %14, -5.000000e-01
  %.0 = select i1 %15, double -5.000000e-01, double %14
  %16 = fcmp ogt double %.0, 5.000000e-01
  %.1 = select i1 %16, double 5.000000e-01, double %.0
  %17 = fmul double %.1, 1.000000e+03
  %18 = fadd double %17, 5.000000e+02
  %19 = tail call double @llvm.floor.f64(double %18)
  %20 = fsub double %18, %19
  %21 = fsub double 1.000000e+00, %20
  %22 = fptosi double %18 to i64
  %23 = getelementptr inbounds [1001 x double], ptr @transition, i64 0, i64 %22
  %24 = load double, ptr %23, align 8, !tbaa !12
  %25 = add nsw i64 %22, 1
  %26 = getelementptr inbounds [1001 x double], ptr @transition, i64 0, i64 %25
  %27 = load double, ptr %26, align 8, !tbaa !12
  %28 = fmul double %27, %20
  %29 = tail call double @llvm.fmuladd.f64(double %21, double %24, double %28)
  %30 = fsub double %29, %12
  %31 = getelementptr inbounds i8, ptr %0, i64 32
  store double %30, ptr %31, align 8, !tbaa !13
  ret double %30
}

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


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