; LLVM IR from Overload-Technologies/Overload :: Dependencies/soloud/src/audiosource/tedsid/sid.ll (ZN8SIDsoundC2Ejj)

; 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.SIDsound = type <{ ptr, i32, i32, i32, i32, i32, i32, i32, i32, i32, [4 x i8], [3 x %"class.SIDsound::SIDVoice"], i8, [3 x i8], i32, i8, [7 x i8], [2048 x double], i32, i32, i32, i32, i32, i8, [3 x i8], i32, i8, [3 x i8], i32, [4 x i8] }>
%"class.SIDsound::SIDVoice" = type { i32, i32, ptr, ptr, i32, i32, i32, i32, i16, i16, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i8, i32 }

@_ZTV8SIDsound = external dso_local unnamed_addr constant { [4 x ptr] }, align 8

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8SIDsound8setModelEj(ptr noundef nonnull align 8 dereferenceable(16796), i32 noundef) #0 align 2

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8SIDsoundC2Ejj(ptr noundef nonnull align 8 dereferenceable(16796) %0, i32 noundef %1, i32 noundef %2) unnamed_addr #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  %8 = load ptr, ptr %4, align 8
  store ptr getelementptr inbounds inrange(-16, 16) ({ [4 x ptr] }, ptr @_ZTV8SIDsound, i32 0, i32 0, i32 2), ptr %8, align 8, !tbaa !11
  %9 = getelementptr inbounds %class.SIDsound, ptr %8, i32 0, i32 11
  %10 = getelementptr inbounds %class.SIDsound, ptr %8, i32 0, i32 26
  store i8 0, ptr %10, align 4, !tbaa !13
  %11 = getelementptr inbounds %class.SIDsound, ptr %8, i32 0, i32 28
  store i32 0, ptr %11, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %12 = getelementptr inbounds %class.SIDsound, ptr %8, i32 0, i32 9
  store i32 0, ptr %12, align 8, !tbaa !17
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %52, %3
  %14 = load i32, ptr %7, align 4, !tbaa !9
  %15 = icmp ult i32 %14, 3
  br i1 %15, label %16, label %55

16:                                               ; preds = %13
  %17 = getelementptr inbounds %class.SIDsound, ptr %8, i32 0, i32 11
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = add i32 %18, 2
  %20 = urem i32 %19, 3
  %21 = zext i32 %20 to i64
  %22 = getelementptr inbounds [3 x %"class.SIDsound::SIDVoice"], ptr %17, i64 0, i64 %21
  %23 = getelementptr inbounds %class.SIDsound, ptr %8, i32 0, i32 11
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = zext i32 %24 to i64
  %26 = getelementptr inbounds [3 x %"class.SIDsound::SIDVoice"], ptr %23, i64 0, i64 %25
  %27 = getelementptr inbounds %"class.SIDsound::SIDVoice", ptr %26, i32 0, i32 2
  store ptr %22, ptr %27, align 8, !tbaa !18
  %28 = getelementptr inbounds %class.SIDsound, ptr %8, i32 0, i32 11
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = add i32 %29, 1
  %31 = urem i32 %30, 3
  %32 = zext i32 %31 to i64
  %33 = getelementptr inbounds [3 x %"class.SIDsound::SIDVoice"], ptr %28, i64 0, i64 %32
  %34 = getelementptr inbounds %class.SIDsound, ptr %8, i32 0, i32 11
  %35 = load i32, ptr %7, align 4, !tbaa !9
  %36 = zext i32 %35 to i64
  %37 = getelementptr inbounds [3 x %"class.SIDsound::SIDVoice"], ptr %34, i64 0, i64 %36
  %38 = getelementptr inbounds %"class.SIDsound::SIDVoice", ptr %37, i32 0, i32 3
  store ptr %33, ptr %38, align 8, !tbaa !21
  %39 = load i32, ptr %6, align 4, !tbaa !9
  %40 = load i32, ptr %7, align 4, !tbaa !9
  %41 = lshr i32 %39, %40
  %42 = and i32 %41, 1
  %43 = icmp ne i32 %42, 0
  %44 = xor i1 %43, true
  %45 = xor i1 %44, true
  %46 = getelementptr inbounds %class.SIDsound, ptr %8, i32 0, i32 11
  %47 = load i32, ptr %7, align 4, !tbaa !9
  %48 = zext i32 %47 to i64
  %49 = getelementptr inbounds [3 x %"class.SIDsound::SIDVoice"], ptr %46, i64 0, i64 %48
  %50 = getelementptr inbounds %"class.SIDsound::SIDVoice", ptr %49, i32 0, i32 23
  %51 = zext i1 %45 to i8
  store i8 %51, ptr %50, align 8, !tbaa !22
  br label %52

52:                                               ; preds = %16
  %53 = load i32, ptr %7, align 4, !tbaa !9
  %54 = add i32 %53, 1
  store i32 %54, ptr %7, align 4, !tbaa !9
  br label %13, !llvm.loop !23

55:                                               ; preds = %13
  %56 = getelementptr inbounds %class.SIDsound, ptr %8, i32 0, i32 14
  store i32 0, ptr %56, align 4, !tbaa !25
  %57 = load i32, ptr %5, align 4, !tbaa !9
  call void @_ZN8SIDsound8setModelEj(ptr noundef nonnull align 8 dereferenceable(16796) %8, i32 noundef %57)
  call void @_ZN8SIDsound12setFrequencyEj(ptr noundef nonnull align 8 dereferenceable(16796) %8, i32 noundef 0)
  call void @_ZN8SIDsound5resetEv(ptr noundef nonnull align 8 dereferenceable(16796) %8)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8SIDsound5resetEv(ptr noundef nonnull align 8 dereferenceable(16796)) #0 align 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"vtable pointer", !8, i64 0}
!13 = !{!14, !15, i64 16788}
!14 = !{!"_ZTS8SIDsound", !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !7, i64 48, !7, i64 360, !10, i64 364, !7, i64 368, !7, i64 376, !10, i64 16760, !10, i64 16764, !10, i64 16768, !10, i64 16772, !10, i64 16776, !7, i64 16780, !10, i64 16784, !15, i64 16788, !10, i64 16792}
!15 = !{!"bool", !7, i64 0}
!16 = !{!14, !10, i64 16792}
!17 = !{!14, !10, i64 40}
!18 = !{!19, !6, i64 8}
!19 = !{!"_ZTSN8SIDsound8SIDVoiceE", !10, i64 0, !10, i64 4, !6, i64 8, !6, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !20, i64 40, !20, i64 42, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !10, i64 80, !10, i64 84, !10, i64 88, !10, i64 92, !15, i64 96, !10, i64 100}
!20 = !{!"short", !7, i64 0}
!21 = !{!19, !6, i64 16}
!22 = !{!19, !15, i64 96}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = !{!14, !10, i64 364}


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

@_ZTV8SIDsound = external dso_local unnamed_addr constant { [4 x ptr] }, align 8

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8SIDsoundC2Ejj(ptr noundef nonnull align 8 dereferenceable(16796) %0, i32 noundef %1, i32 noundef %2) unnamed_addr #0 align 2 {
  store ptr getelementptr inbounds inrange(-16, 16) (i8, ptr @_ZTV8SIDsound, i64 16), ptr %0, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 16788
  store i8 0, ptr %4, align 4, !tbaa !8
  %5 = getelementptr inbounds i8, ptr %0, i64 16792
  store i32 0, ptr %5, align 8, !tbaa !13
  %6 = getelementptr inbounds i8, ptr %0, i64 40
  store i32 0, ptr %6, align 8, !tbaa !14
  %7 = getelementptr inbounds i8, ptr %0, i64 48
  %8 = getelementptr inbounds i8, ptr %0, i64 256
  %9 = getelementptr inbounds i8, ptr %0, i64 56
  store ptr %8, ptr %9, align 8, !tbaa !15
  %10 = getelementptr inbounds i8, ptr %0, i64 152
  %11 = getelementptr inbounds i8, ptr %0, i64 64
  store ptr %10, ptr %11, align 8, !tbaa !19
  %12 = getelementptr inbounds i8, ptr %0, i64 144
  %13 = trunc i32 %2 to i8
  %14 = and i8 %13, 1
  store i8 %14, ptr %12, align 8, !tbaa !20
  %15 = getelementptr inbounds i8, ptr %0, i64 160
  store ptr %7, ptr %15, align 8, !tbaa !15
  %16 = getelementptr inbounds i8, ptr %0, i64 168
  store ptr %8, ptr %16, align 8, !tbaa !19
  %17 = getelementptr inbounds i8, ptr %0, i64 248
  %18 = trunc i32 %2 to i8
  %19 = lshr i8 %18, 1
  %20 = and i8 %19, 1
  store i8 %20, ptr %17, align 8, !tbaa !20
  %21 = getelementptr inbounds i8, ptr %0, i64 264
  store ptr %10, ptr %21, align 8, !tbaa !15
  %22 = getelementptr inbounds i8, ptr %0, i64 272
  store ptr %7, ptr %22, align 8, !tbaa !19
  %23 = getelementptr inbounds i8, ptr %0, i64 352
  %24 = trunc i32 %2 to i8
  %25 = lshr i8 %24, 2
  %26 = and i8 %25, 1
  store i8 %26, ptr %23, align 8, !tbaa !20
  %27 = getelementptr inbounds i8, ptr %0, i64 364
  store i32 0, ptr %27, align 4, !tbaa !21
  tail call void @_ZN8SIDsound8setModelEj(ptr noundef nonnull align 8 dereferenceable(16796) %0, i32 noundef %1)
  tail call void @_ZN8SIDsound12setFrequencyEj(ptr noundef nonnull align 8 dereferenceable(16796) %0, i32 noundef 0)
  tail call void @_ZN8SIDsound5resetEv(ptr noundef nonnull align 8 dereferenceable(16796) %0)
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8SIDsound5resetEv(ptr noundef nonnull align 8 dereferenceable(16796)) local_unnamed_addr #0 align 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 = { 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" }

!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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !12, i64 16788}
!9 = !{!"_ZTS8SIDsound", !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !11, i64 48, !11, i64 360, !10, i64 364, !11, i64 368, !11, i64 376, !10, i64 16760, !10, i64 16764, !10, i64 16768, !10, i64 16772, !10, i64 16776, !11, i64 16780, !10, i64 16784, !12, i64 16788, !10, i64 16792}
!10 = !{!"int", !11, i64 0}
!11 = !{!"omnipotent char", !7, i64 0}
!12 = !{!"bool", !11, i64 0}
!13 = !{!9, !10, i64 16792}
!14 = !{!9, !10, i64 40}
!15 = !{!16, !17, i64 8}
!16 = !{!"_ZTSN8SIDsound8SIDVoiceE", !10, i64 0, !10, i64 4, !17, i64 8, !17, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !18, i64 40, !18, i64 42, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !10, i64 80, !10, i64 84, !10, i64 88, !10, i64 92, !12, i64 96, !10, i64 100}
!17 = !{!"any pointer", !11, i64 0}
!18 = !{!"short", !11, i64 0}
!19 = !{!16, !17, i64 16}
!20 = !{!16, !12, i64 96}
!21 = !{!9, !10, i64 364}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,SROAPass,SimplifyCFGPass,TailCallElimPass