; LLVM IR from hasseily/SuperDuperDisplay :: Ayumi.ll (ZN5AyumiC2Ebdi)

; 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.Ayumi = type <{ i8, [7 x i8], [3 x %"struct.Ayumi::tone_channel"], i32, i32, i32, i32, i32, i32, i32, i32, ptr, double, double, %"struct.Ayumi::interpolator", %"struct.Ayumi::interpolator", [384 x double], [384 x double], i32, [4 x i8], %"struct.Ayumi::dc_filter", %"struct.Ayumi::dc_filter", i32, [4 x i8], double, double, i8, [7 x i8] }>
%"struct.Ayumi::tone_channel" = type { i32, i32, i32, i8, i8, i8, i32, double, double }
%"struct.Ayumi::interpolator" = type { [4 x double], [4 x double] }
%"struct.Ayumi::dc_filter" = type { double, [1024 x double] }

@_ZL12YM_dac_table = external hidden constant [32 x double], align 16
@_ZL12AY_dac_table = external hidden constant [32 x double], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5AyumiC2Ebdi(ptr noundef nonnull align 8 dereferenceable(22889) %0, i1 noundef zeroext %1, double noundef %2, i32 noundef %3) unnamed_addr #0 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca double, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  %10 = zext i1 %1 to i8
  store i8 %10, ptr %6, align 1, !tbaa !9
  store double %2, ptr %7, align 8, !tbaa !11
  store i32 %3, ptr %8, align 4, !tbaa !13
  %11 = load ptr, ptr %5, align 8
  %12 = getelementptr inbounds %class.Ayumi, ptr %11, i32 0, i32 0
  store i8 0, ptr %12, align 8, !tbaa !15
  %13 = getelementptr inbounds %class.Ayumi, ptr %11, i32 0, i32 2
  %14 = getelementptr inbounds [3 x %"struct.Ayumi::tone_channel"], ptr %13, i32 0, i32 0
  %15 = getelementptr inbounds %"struct.Ayumi::tone_channel", ptr %14, i64 3
  br label %16

16:                                               ; preds = %16, %4
  %17 = phi ptr [ %14, %4 ], [ %18, %16 ]
  call void @_ZN5Ayumi12tone_channelC2Ev(ptr noundef nonnull align 8 dereferenceable(40) %17) #4
  %18 = getelementptr inbounds %"struct.Ayumi::tone_channel", ptr %17, i64 1
  %19 = icmp eq ptr %18, %15
  br i1 %19, label %20, label %16

20:                                               ; preds = %16
  %21 = getelementptr inbounds %class.Ayumi, ptr %11, i32 0, i32 3
  store i32 0, ptr %21, align 8, !tbaa !19
  %22 = getelementptr inbounds %class.Ayumi, ptr %11, i32 0, i32 4
  store i32 0, ptr %22, align 4, !tbaa !20
  %23 = getelementptr inbounds %class.Ayumi, ptr %11, i32 0, i32 5
  store i32 0, ptr %23, align 8, !tbaa !21
  %24 = getelementptr inbounds %class.Ayumi, ptr %11, i32 0, i32 6
  store i32 0, ptr %24, align 4, !tbaa !22
  %25 = getelementptr inbounds %class.Ayumi, ptr %11, i32 0, i32 7
  store i32 0, ptr %25, align 8, !tbaa !23
  %26 = getelementptr inbounds %class.Ayumi, ptr %11, i32 0, i32 8
  store i32 0, ptr %26, align 4, !tbaa !24
  %27 = getelementptr inbounds %class.Ayumi, ptr %11, i32 0, i32 9
  store i32 0, ptr %27, align 8, !tbaa !25
  %28 = getelementptr inbounds %class.Ayumi, ptr %11, i32 0, i32 10
  store i32 0, ptr %28, align 4, !tbaa !26
  %29 = getelementptr inbounds %class.Ayumi, ptr %11, i32 0, i32 12
  store double 0.000000e+00, ptr %29, align 8, !tbaa !27
  %30 = getelementptr inbounds %class.Ayumi, ptr %11, i32 0, i32 13
  store double 0.000000e+00, ptr %30, align 8, !tbaa !28
  %31 = getelementptr inbounds %class.Ayumi, ptr %11, i32 0, i32 14
  call void @_ZN5Ayumi12interpolatorC2Ev(ptr noundef nonnull align 8 dereferenceable(64) %31) #4
  %32 = getelementptr inbounds %class.Ayumi, ptr %11, i32 0, i32 15
  call void @_ZN5Ayumi12interpolatorC2Ev(ptr noundef nonnull align 8 dereferenceable(64) %32) #4
  %33 = getelementptr inbounds %class.Ayumi, ptr %11, i32 0, i32 18
  store i32 0, ptr %33, align 8, !tbaa !29
  %34 = getelementptr inbounds %class.Ayumi, ptr %11, i32 0, i32 20
  call void @_ZN5Ayumi9dc_filterC2Ev(ptr noundef nonnull align 8 dereferenceable(8200) %34) #4
  %35 = getelementptr inbounds %class.Ayumi, ptr %11, i32 0, i32 21
  call void @_ZN5Ayumi9dc_filterC2Ev(ptr noundef nonnull align 8 dereferenceable(8200) %35) #4
  %36 = getelementptr inbounds %class.Ayumi, ptr %11, i32 0, i32 22
  store i32 0, ptr %36, align 8, !tbaa !30
  %37 = getelementptr inbounds %class.Ayumi, ptr %11, i32 0, i32 24
  store double 0.000000e+00, ptr %37, align 8, !tbaa !31
  %38 = getelementptr inbounds %class.Ayumi, ptr %11, i32 0, i32 25
  store double 0.000000e+00, ptr %38, align 8, !tbaa !32
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %39 = load double, ptr %7, align 8, !tbaa !11
  %40 = load i32, ptr %8, align 4, !tbaa !13
  %41 = mul nsw i32 %40, 8
  %42 = mul nsw i32 %41, 8
  %43 = sitofp i32 %42 to double
  %44 = fdiv double %39, %43
  %45 = getelementptr inbounds %class.Ayumi, ptr %11, i32 0, i32 12
  store double %44, ptr %45, align 8, !tbaa !27
  %46 = load i8, ptr %6, align 1, !tbaa !9, !range !33, !noundef !34
  %47 = trunc i8 %46 to i1
  br i1 %47, label %48, label %49

48:                                               ; preds = %20
  br label %50

49:                                               ; preds = %20
  br label %50

50:                                               ; preds = %49, %48
  %51 = phi ptr [ @_ZL12YM_dac_table, %48 ], [ @_ZL12AY_dac_table, %49 ]
  %52 = getelementptr inbounds [32 x double], ptr %51, i64 0, i64 0
  %53 = getelementptr inbounds %class.Ayumi, ptr %11, i32 0, i32 11
  store ptr %52, ptr %53, align 8, !tbaa !35
  %54 = getelementptr inbounds %class.Ayumi, ptr %11, i32 0, i32 5
  store i32 1, ptr %54, align 8, !tbaa !21
  call void @_ZN5Ayumi11SetEnvelopeEi(ptr noundef nonnull align 8 dereferenceable(22889) %11, i32 noundef 1)
  store i32 0, ptr %9, align 4, !tbaa !13
  br label %55

55:                                               ; preds = %61, %50
  %56 = load i32, ptr %9, align 4, !tbaa !13
  %57 = icmp slt i32 %56, 3
  br i1 %57, label %58, label %64

58:                                               ; preds = %55
  %59 = load i32, ptr %9, align 4, !tbaa !13
  call void @_ZN5Ayumi7SetToneEii(ptr noundef nonnull align 8 dereferenceable(22889) %11, i32 noundef %59, i32 noundef 1)
  %60 = load i32, ptr %9, align 4, !tbaa !13
  call void @_ZN5Ayumi9SetVolumeEii(ptr noundef nonnull align 8 dereferenceable(22889) %11, i32 noundef %60, i32 noundef 0)
  br label %61

61:                                               ; preds = %58
  %62 = load i32, ptr %9, align 4, !tbaa !13
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %9, align 4, !tbaa !13
  br label %55, !llvm.loop !36

64:                                               ; preds = %55
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN5Ayumi12tone_channelC2Ev(ptr noundef nonnull align 8 dereferenceable(40)) unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN5Ayumi12interpolatorC2Ev(ptr noundef nonnull align 8 dereferenceable(64)) unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN5Ayumi9dc_filterC2Ev(ptr noundef nonnull align 8 dereferenceable(8200)) unnamed_addr #1 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5Ayumi11SetEnvelopeEi(ptr noundef nonnull align 8 dereferenceable(22889), i32 noundef) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5Ayumi7SetToneEii(ptr noundef nonnull align 8 dereferenceable(22889), i32 noundef, i32 noundef) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5Ayumi9SetVolumeEii(ptr noundef nonnull align 8 dereferenceable(22889), i32 noundef, i32 noundef) #3 align 2

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

attributes #0 = { mustprogress 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 = { inlinehint 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 willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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 = !{!"bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !7, i64 0}
!16 = !{!"_ZTS5Ayumi", !7, i64 0, !7, i64 8, !14, i64 128, !14, i64 132, !14, i64 136, !14, i64 140, !14, i64 144, !14, i64 148, !14, i64 152, !14, i64 156, !6, i64 160, !12, i64 168, !12, i64 176, !17, i64 184, !17, i64 248, !7, i64 312, !7, i64 3384, !14, i64 6456, !18, i64 6464, !18, i64 14664, !14, i64 22864, !12, i64 22872, !12, i64 22880, !10, i64 22888}
!17 = !{!"_ZTSN5Ayumi12interpolatorE", !7, i64 0, !7, i64 32}
!18 = !{!"_ZTSN5Ayumi9dc_filterE", !12, i64 0, !7, i64 8}
!19 = !{!16, !14, i64 128}
!20 = !{!16, !14, i64 132}
!21 = !{!16, !14, i64 136}
!22 = !{!16, !14, i64 140}
!23 = !{!16, !14, i64 144}
!24 = !{!16, !14, i64 148}
!25 = !{!16, !14, i64 152}
!26 = !{!16, !14, i64 156}
!27 = !{!16, !12, i64 168}
!28 = !{!16, !12, i64 176}
!29 = !{!16, !14, i64 6456}
!30 = !{!16, !14, i64 22864}
!31 = !{!16, !12, i64 22872}
!32 = !{!16, !12, i64 22880}
!33 = !{i8 0, i8 2}
!34 = !{}
!35 = !{!16, !6, i64 160}
!36 = distinct !{!36, !37}
!37 = !{!"llvm.loop.mustprogress"}


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

@_ZL12YM_dac_table = external hidden constant [32 x double], align 16
@_ZL12AY_dac_table = external hidden constant [32 x double], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN5AyumiC2Ebdi(ptr noundef nonnull align 8 dereferenceable(22889) %0, i1 noundef zeroext %1, double noundef %2, i32 noundef %3) unnamed_addr #0 align 2 {
  store i8 0, ptr %0, align 8, !tbaa !5
  %.ptr = getelementptr inbounds i8, ptr %0, i64 8
  tail call void @_ZN5Ayumi12tone_channelC2Ev(ptr noundef nonnull align 8 dereferenceable(40) %.ptr) #3
  %.ptr.1 = getelementptr inbounds i8, ptr %0, i64 48
  tail call void @_ZN5Ayumi12tone_channelC2Ev(ptr noundef nonnull align 8 dereferenceable(40) %.ptr.1) #3
  %.ptr.2 = getelementptr inbounds i8, ptr %0, i64 88
  tail call void @_ZN5Ayumi12tone_channelC2Ev(ptr noundef nonnull align 8 dereferenceable(40) %.ptr.2) #3
  %5 = getelementptr inbounds i8, ptr %0, i64 128
  %6 = getelementptr inbounds i8, ptr %0, i64 136
  %7 = getelementptr inbounds i8, ptr %0, i64 168
  %8 = getelementptr inbounds i8, ptr %0, i64 184
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %5, i8 0, i64 32, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %7, i8 0, i64 16, i1 false)
  tail call void @_ZN5Ayumi12interpolatorC2Ev(ptr noundef nonnull align 8 dereferenceable(64) %8) #3
  %9 = getelementptr inbounds i8, ptr %0, i64 248
  tail call void @_ZN5Ayumi12interpolatorC2Ev(ptr noundef nonnull align 8 dereferenceable(64) %9) #3
  %10 = getelementptr inbounds i8, ptr %0, i64 6456
  store i32 0, ptr %10, align 8, !tbaa !15
  %11 = getelementptr inbounds i8, ptr %0, i64 6464
  tail call void @_ZN5Ayumi9dc_filterC2Ev(ptr noundef nonnull align 8 dereferenceable(8200) %11) #3
  %12 = getelementptr inbounds i8, ptr %0, i64 14664
  tail call void @_ZN5Ayumi9dc_filterC2Ev(ptr noundef nonnull align 8 dereferenceable(8200) %12) #3
  %13 = getelementptr inbounds i8, ptr %0, i64 22864
  store i32 0, ptr %13, align 8, !tbaa !16
  %14 = getelementptr inbounds i8, ptr %0, i64 22872
  %15 = shl nsw i32 %3, 6
  %16 = sitofp i32 %15 to double
  %17 = fdiv double %2, %16
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %14, i8 0, i64 16, i1 false)
  store double %17, ptr %7, align 8, !tbaa !17
  %_ZL12YM_dac_table._ZL12AY_dac_table = select i1 %1, ptr @_ZL12YM_dac_table, ptr @_ZL12AY_dac_table
  %18 = getelementptr inbounds i8, ptr %0, i64 160
  store ptr %_ZL12YM_dac_table._ZL12AY_dac_table, ptr %18, align 8, !tbaa !18
  store i32 1, ptr %6, align 8, !tbaa !19
  tail call void @_ZN5Ayumi11SetEnvelopeEi(ptr noundef nonnull align 8 dereferenceable(22889) %0, i32 noundef 1)
  tail call void @_ZN5Ayumi7SetToneEii(ptr noundef nonnull align 8 dereferenceable(22889) %0, i32 noundef 0, i32 noundef 1)
  tail call void @_ZN5Ayumi9SetVolumeEii(ptr noundef nonnull align 8 dereferenceable(22889) %0, i32 noundef 0, i32 noundef 0)
  tail call void @_ZN5Ayumi7SetToneEii(ptr noundef nonnull align 8 dereferenceable(22889) %0, i32 noundef 1, i32 noundef 1)
  tail call void @_ZN5Ayumi9SetVolumeEii(ptr noundef nonnull align 8 dereferenceable(22889) %0, i32 noundef 1, i32 noundef 0)
  tail call void @_ZN5Ayumi7SetToneEii(ptr noundef nonnull align 8 dereferenceable(22889) %0, i32 noundef 2, i32 noundef 1)
  tail call void @_ZN5Ayumi9SetVolumeEii(ptr noundef nonnull align 8 dereferenceable(22889) %0, i32 noundef 2, i32 noundef 0)
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN5Ayumi12tone_channelC2Ev(ptr noundef nonnull align 8 dereferenceable(40)) unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN5Ayumi12interpolatorC2Ev(ptr noundef nonnull align 8 dereferenceable(64)) unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN5Ayumi9dc_filterC2Ev(ptr noundef nonnull align 8 dereferenceable(8200)) unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5Ayumi11SetEnvelopeEi(ptr noundef nonnull align 8 dereferenceable(22889), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5Ayumi7SetToneEii(ptr noundef nonnull align 8 dereferenceable(22889), i32 noundef, i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5Ayumi9SetVolumeEii(ptr noundef nonnull align 8 dereferenceable(22889), i32 noundef, i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

attributes #0 = { 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 #1 = { inlinehint 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 nounwind willreturn memory(argmem: write) }
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 = !{!"_ZTS5Ayumi", !7, i64 0, !7, i64 8, !9, i64 128, !9, i64 132, !9, i64 136, !9, i64 140, !9, i64 144, !9, i64 148, !9, i64 152, !9, i64 156, !10, i64 160, !11, i64 168, !11, i64 176, !12, i64 184, !12, i64 248, !7, i64 312, !7, i64 3384, !9, i64 6456, !13, i64 6464, !13, i64 14664, !9, i64 22864, !11, i64 22872, !11, i64 22880, !14, i64 22888}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!"double", !7, i64 0}
!12 = !{!"_ZTSN5Ayumi12interpolatorE", !7, i64 0, !7, i64 32}
!13 = !{!"_ZTSN5Ayumi9dc_filterE", !11, i64 0, !7, i64 8}
!14 = !{!"bool", !7, i64 0}
!15 = !{!6, !9, i64 6456}
!16 = !{!6, !9, i64 22864}
!17 = !{!6, !11, i64 168}
!18 = !{!6, !10, i64 160}
!19 = !{!6, !9, i64 136}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass