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

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

; 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 i32 @_ZN5Ayumi10UpdateToneEi(ptr noundef nonnull align 8 dereferenceable(22889) %0, i32 noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %6 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %7 = getelementptr inbounds %class.Ayumi, ptr %6, i32 0, i32 2
  %8 = load i32, ptr %4, align 4, !tbaa !9
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [3 x %"struct.Ayumi::tone_channel"], ptr %7, i64 0, i64 %9
  store ptr %10, ptr %5, align 8, !tbaa !5
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %"struct.Ayumi::tone_channel", ptr %11, i32 0, i32 1
  %13 = load i32, ptr %12, align 4, !tbaa !11
  %14 = add nsw i32 %13, 1
  store i32 %14, ptr %12, align 4, !tbaa !11
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %"struct.Ayumi::tone_channel", ptr %15, i32 0, i32 1
  %17 = load i32, ptr %16, align 4, !tbaa !11
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %"struct.Ayumi::tone_channel", ptr %18, i32 0, i32 0
  %20 = load i32, ptr %19, align 8, !tbaa !15
  %21 = icmp sge i32 %17, %20
  br i1 %21, label %22, label %29

22:                                               ; preds = %2
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %"struct.Ayumi::tone_channel", ptr %23, i32 0, i32 1
  store i32 0, ptr %24, align 4, !tbaa !11
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %"struct.Ayumi::tone_channel", ptr %25, i32 0, i32 2
  %27 = load i32, ptr %26, align 8, !tbaa !16
  %28 = xor i32 %27, 1
  store i32 %28, ptr %26, align 8, !tbaa !16
  br label %29

29:                                               ; preds = %22, %2
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %"struct.Ayumi::tone_channel", ptr %30, i32 0, i32 2
  %32 = load i32, ptr %31, align 8, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret i32 %32
}

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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 4}
!12 = !{!"_ZTSN5Ayumi12tone_channelE", !10, i64 0, !10, i64 4, !10, i64 8, !13, i64 12, !13, i64 13, !13, i64 14, !10, i64 16, !14, i64 24, !14, i64 32}
!13 = !{!"bool", !7, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = !{!12, !10, i64 0}
!16 = !{!12, !10, i64 8}


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

%"struct.Ayumi::tone_channel" = type { i32, i32, i32, i8, i8, i8, i32, double, double }

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local noundef i32 @_ZN5Ayumi10UpdateToneEi(ptr nocapture noundef nonnull align 8 dereferenceable(22889) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = sext i32 %1 to i64
  %5 = getelementptr inbounds [3 x %"struct.Ayumi::tone_channel"], ptr %3, i64 0, i64 %4
  %6 = getelementptr inbounds i8, ptr %5, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = add nsw i32 %7, 1
  store i32 %8, ptr %6, align 4, !tbaa !5
  %9 = load i32, ptr %5, align 8, !tbaa !12
  %.not = icmp slt i32 %8, %9
  br i1 %.not, label %._crit_edge, label %10

._crit_edge:                                      ; preds = %2
  %.phi.trans.insert = getelementptr inbounds i8, ptr %5, i64 8
  %.pre = load i32, ptr %.phi.trans.insert, align 8, !tbaa !13
  br label %14

10:                                               ; preds = %2
  store i32 0, ptr %6, align 4, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %5, i64 8
  %12 = load i32, ptr %11, align 8, !tbaa !13
  %13 = xor i32 %12, 1
  store i32 %13, ptr %11, align 8, !tbaa !13
  br label %14

14:                                               ; preds = %._crit_edge, %10
  %15 = phi i32 [ %.pre, %._crit_edge ], [ %13, %10 ]
  ret i32 %15
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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 4}
!6 = !{!"_ZTSN5Ayumi12tone_channelE", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 12, !10, i64 13, !10, i64 14, !7, i64 16, !11, i64 24, !11, i64 32}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"bool", !8, i64 0}
!11 = !{!"double", !8, i64 0}
!12 = !{!6, !7, i64 0}
!13 = !{!6, !7, i64 8}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass