; LLVM IR from Overload-Technologies/Overload :: Dependencies/soloud/src/audiosource/tedsid (soloud_tedsid)

; 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.SoLoud::TedSidInstance" = type { %"class.SoLoud::AudioSourceInstance", ptr, ptr, ptr, i32, i32, [128 x i32] }
%"class.SoLoud::AudioSourceInstance" = type { ptr, i32, i32, i32, float, [8 x float], float, float, float, float, i32, float, float, double, double, %"class.SoLoud::Fader", %"class.SoLoud::Fader", %"class.SoLoud::Fader", %"class.SoLoud::Fader", %"class.SoLoud::Fader", i32, [8 x float], i32, i32, [8 x ptr], [2 x ptr], i32, i32, i32, double }
%"class.SoLoud::Fader" = type { float, float, float, double, double, double, float, i32 }
%"class.SoLoud::TedSid" = type <{ %"class.SoLoud::AudioSource", i32, i32, ptr, i32, [4 x i8] }>
%"class.SoLoud::AudioSource" = type { ptr, i32, float, float, i32, i32, float, float, float, i32, float, [8 x ptr], ptr, ptr, ptr, i32, 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 uwtable
define dso_local void @_ZN6SoLoud14TedSidInstance4tickEv(ptr noundef nonnull align 8 dereferenceable(1040) %0) unnamed_addr #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i16, align 2
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8
  %7 = getelementptr inbounds %"class.SoLoud::TedSidInstance", ptr %6, i32 0, i32 1
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = getelementptr inbounds %"class.SoLoud::TedSid", ptr %8, i32 0, i32 3
  %10 = load ptr, ptr %9, align 8, !tbaa !16
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %13

12:                                               ; preds = %1
  br label %89

13:                                               ; preds = %1
  br label %14

14:                                               ; preds = %88, %13
  %15 = getelementptr inbounds %"class.SoLoud::TedSidInstance", ptr %6, i32 0, i32 5
  %16 = load i32, ptr %15, align 4, !tbaa !19
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %18, label %89

18:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 2, ptr %3) #3
  %19 = getelementptr inbounds %"class.SoLoud::TedSidInstance", ptr %6, i32 0, i32 1
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  %21 = getelementptr inbounds %"class.SoLoud::TedSid", ptr %20, i32 0, i32 3
  %22 = load ptr, ptr %21, align 8, !tbaa !16
  %23 = getelementptr inbounds %"class.SoLoud::TedSidInstance", ptr %6, i32 0, i32 4
  %24 = load i32, ptr %23, align 8, !tbaa !20
  %25 = sdiv i32 %24, 2
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds i16, ptr %22, i64 %26
  %28 = load i16, ptr %27, align 2, !tbaa !21
  store i16 %28, ptr %3, align 2, !tbaa !21
  %29 = getelementptr inbounds %"class.SoLoud::TedSidInstance", ptr %6, i32 0, i32 4
  %30 = load i32, ptr %29, align 8, !tbaa !20
  %31 = add nsw i32 %30, 2
  store i32 %31, ptr %29, align 8, !tbaa !20
  %32 = getelementptr inbounds %"class.SoLoud::TedSidInstance", ptr %6, i32 0, i32 4
  %33 = load i32, ptr %32, align 8, !tbaa !20
  %34 = getelementptr inbounds %"class.SoLoud::TedSidInstance", ptr %6, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !9
  %36 = getelementptr inbounds %"class.SoLoud::TedSid", ptr %35, i32 0, i32 2
  %37 = load i32, ptr %36, align 4, !tbaa !23
  %38 = icmp sge i32 %33, %37
  br i1 %38, label %39, label %45

39:                                               ; preds = %18
  %40 = getelementptr inbounds %"class.SoLoud::TedSidInstance", ptr %6, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !9
  %42 = getelementptr inbounds %"class.SoLoud::TedSid", ptr %41, i32 0, i32 1
  %43 = load i32, ptr %42, align 8, !tbaa !24
  %44 = getelementptr inbounds %"class.SoLoud::TedSidInstance", ptr %6, i32 0, i32 4
  store i32 %43, ptr %44, align 8, !tbaa !20
  br label %45

45:                                               ; preds = %39, %18
  %46 = load i16, ptr %3, align 2, !tbaa !21
  %47 = zext i16 %46 to i32
  %48 = and i32 %47, 32768
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %50, label %55

50:                                               ; preds = %45
  %51 = load i16, ptr %3, align 2, !tbaa !21
  %52 = zext i16 %51 to i32
  %53 = and i32 %52, 32767
  %54 = getelementptr inbounds %"class.SoLoud::TedSidInstance", ptr %6, i32 0, i32 5
  store i32 %53, ptr %54, align 4, !tbaa !19
  br label %88

55:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %56 = load i16, ptr %3, align 2, !tbaa !21
  %57 = zext i16 %56 to i32
  %58 = ashr i32 %57, 8
  %59 = and i32 %58, 255
  store i32 %59, ptr %4, align 4, !tbaa !25
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %60 = load i16, ptr %3, align 2, !tbaa !21
  %61 = zext i16 %60 to i32
  %62 = and i32 %61, 255
  store i32 %62, ptr %5, align 4, !tbaa !25
  %63 = load i32, ptr %5, align 4, !tbaa !25
  %64 = getelementptr inbounds %"class.SoLoud::TedSidInstance", ptr %6, i32 0, i32 6
  %65 = load i32, ptr %4, align 4, !tbaa !25
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [128 x i32], ptr %64, i64 0, i64 %66
  store i32 %63, ptr %67, align 4, !tbaa !25
  %68 = load i32, ptr %4, align 4, !tbaa !25
  %69 = icmp slt i32 %68, 64
  br i1 %69, label %70, label %76

70:                                               ; preds = %55
  %71 = getelementptr inbounds %"class.SoLoud::TedSidInstance", ptr %6, i32 0, i32 2
  %72 = load ptr, ptr %71, align 8, !tbaa !26
  %73 = load i32, ptr %4, align 4, !tbaa !25
  %74 = load i32, ptr %5, align 4, !tbaa !25
  %75 = trunc i32 %74 to i8
  call void @_ZN8SIDsound5writeEjh(ptr noundef nonnull align 8 dereferenceable(16796) %72, i32 noundef %73, i8 noundef zeroext %75)
  br label %87

76:                                               ; preds = %55
  %77 = load i32, ptr %4, align 4, !tbaa !25
  %78 = icmp slt i32 %77, 69
  br i1 %78, label %79, label %86

79:                                               ; preds = %76
  %80 = getelementptr inbounds %"class.SoLoud::TedSidInstance", ptr %6, i32 0, i32 3
  %81 = load ptr, ptr %80, align 8, !tbaa !27
  %82 = load i32, ptr %4, align 4, !tbaa !25
  %83 = sub nsw i32 %82, 64
  %84 = load i32, ptr %5, align 4, !tbaa !25
  %85 = trunc i32 %84 to i8
  call void @_ZN3TED13writeSoundRegEjh(ptr noundef nonnull align 4 dereferenceable(352) %81, i32 noundef %83, i8 noundef zeroext %85)
  br label %86

86:                                               ; preds = %79, %76
  br label %87

87:                                               ; preds = %86, %70
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %88

88:                                               ; preds = %87, %50
  call void @llvm.lifetime.end.p0(i64 2, ptr %3) #3
  br label %14, !llvm.loop !28

89:                                               ; preds = %14, %12
  ret void
}

declare void @_ZN8SIDsound5writeEjh(ptr noundef nonnull align 8 dereferenceable(16796), i32 noundef, i8 noundef zeroext) #2

declare void @_ZN3TED13writeSoundRegEjh(ptr noundef nonnull align 4 dereferenceable(352), i32 noundef, i8 noundef zeroext) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { "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, !6, i64 496}
!10 = !{!"_ZTSN6SoLoud14TedSidInstanceE", !11, i64 0, !6, i64 496, !6, i64 504, !6, i64 512, !12, i64 520, !12, i64 524, !7, i64 528}
!11 = !{!"_ZTSN6SoLoud19AudioSourceInstanceE", !12, i64 8, !12, i64 12, !12, i64 16, !13, i64 20, !7, i64 24, !13, i64 56, !13, i64 60, !13, i64 64, !13, i64 68, !12, i64 72, !13, i64 76, !13, i64 80, !14, i64 88, !14, i64 96, !15, i64 104, !15, i64 152, !15, i64 200, !15, i64 248, !15, i64 296, !12, i64 344, !7, i64 348, !12, i64 380, !12, i64 384, !7, i64 392, !7, i64 456, !12, i64 472, !12, i64 476, !12, i64 480, !14, i64 488}
!12 = !{!"int", !7, i64 0}
!13 = !{!"float", !7, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = !{!"_ZTSN6SoLoud5FaderE", !13, i64 0, !13, i64 4, !13, i64 8, !14, i64 16, !14, i64 24, !14, i64 32, !13, i64 40, !12, i64 44}
!16 = !{!17, !6, i64 160}
!17 = !{!"_ZTSN6SoLoud6TedSidE", !18, i64 0, !12, i64 152, !12, i64 156, !6, i64 160, !12, i64 168}
!18 = !{!"_ZTSN6SoLoud11AudioSourceE", !12, i64 8, !13, i64 12, !13, i64 16, !12, i64 20, !12, i64 24, !13, i64 28, !13, i64 32, !13, i64 36, !12, i64 40, !13, i64 44, !7, i64 48, !6, i64 112, !6, i64 120, !6, i64 128, !12, i64 136, !14, i64 144}
!19 = !{!10, !12, i64 524}
!20 = !{!10, !12, i64 520}
!21 = !{!22, !22, i64 0}
!22 = !{!"short", !7, i64 0}
!23 = !{!17, !12, i64 156}
!24 = !{!17, !12, i64 152}
!25 = !{!12, !12, i64 0}
!26 = !{!10, !6, i64 504}
!27 = !{!10, !6, i64 512}
!28 = distinct !{!28, !29}
!29 = !{!"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"

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6SoLoud14TedSidInstance4tickEv(ptr nocapture noundef nonnull align 8 dereferenceable(1040) %0) unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 496
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 160
  %5 = load ptr, ptr %4, align 8, !tbaa !15
  %6 = icmp eq ptr %5, null
  br i1 %6, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %1
  %7 = getelementptr inbounds i8, ptr %0, i64 524
  %8 = load i32, ptr %7, align 4, !tbaa !18
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader
  %10 = getelementptr inbounds i8, ptr %0, i64 520
  %11 = getelementptr inbounds i8, ptr %0, i64 528
  %12 = getelementptr inbounds i8, ptr %0, i64 512
  %13 = getelementptr inbounds i8, ptr %0, i64 504
  br label %14

14:                                               ; preds = %.lr.ph, %48
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %15, i64 160
  %17 = load ptr, ptr %16, align 8, !tbaa !15
  %18 = load i32, ptr %10, align 8, !tbaa !19
  %19 = sdiv i32 %18, 2
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds i16, ptr %17, i64 %20
  %22 = load i16, ptr %21, align 2, !tbaa !20
  %23 = add nsw i32 %18, 2
  store i32 %23, ptr %10, align 8, !tbaa !19
  %24 = getelementptr inbounds i8, ptr %15, i64 156
  %25 = load i32, ptr %24, align 4, !tbaa !22
  %.not = icmp slt i32 %23, %25
  br i1 %.not, label %29, label %26

26:                                               ; preds = %14
  %27 = getelementptr inbounds i8, ptr %15, i64 152
  %28 = load i32, ptr %27, align 8, !tbaa !23
  store i32 %28, ptr %10, align 8, !tbaa !19
  br label %29

29:                                               ; preds = %26, %14
  %30 = zext i16 %22 to i32
  %.not12 = icmp sgt i16 %22, -1
  br i1 %.not12, label %33, label %31

31:                                               ; preds = %29
  %32 = and i32 %30, 32767
  store i32 %32, ptr %7, align 4, !tbaa !18
  br label %48

33:                                               ; preds = %29
  %34 = lshr i32 %30, 8
  %35 = and i32 %30, 255
  %36 = zext nneg i32 %34 to i64
  %37 = getelementptr inbounds [128 x i32], ptr %11, i64 0, i64 %36
  store i32 %35, ptr %37, align 4, !tbaa !24
  %38 = icmp ult i16 %22, 16384
  br i1 %38, label %39, label %42

39:                                               ; preds = %33
  %40 = load ptr, ptr %13, align 8, !tbaa !25
  %41 = trunc i16 %22 to i8
  tail call void @_ZN8SIDsound5writeEjh(ptr noundef nonnull align 8 dereferenceable(16796) %40, i32 noundef %34, i8 noundef zeroext %41)
  br label %thread-pre-split

42:                                               ; preds = %33
  %43 = icmp ult i16 %22, 17664
  br i1 %43, label %44, label %thread-pre-split

44:                                               ; preds = %42
  %45 = load ptr, ptr %12, align 8, !tbaa !26
  %46 = add nsw i32 %34, -64
  %47 = trunc i16 %22 to i8
  tail call void @_ZN3TED13writeSoundRegEjh(ptr noundef nonnull align 4 dereferenceable(352) %45, i32 noundef %46, i8 noundef zeroext %47)
  br label %thread-pre-split

thread-pre-split:                                 ; preds = %42, %44, %39
  %.pr = load i32, ptr %7, align 4, !tbaa !18
  br label %48

48:                                               ; preds = %thread-pre-split, %31
  %49 = phi i32 [ %.pr, %thread-pre-split ], [ %32, %31 ]
  %50 = icmp eq i32 %49, 0
  br i1 %50, label %14, label %.loopexit, !llvm.loop !27

.loopexit:                                        ; preds = %48, %.preheader, %1
  ret void
}

declare void @_ZN8SIDsound5writeEjh(ptr noundef nonnull align 8 dereferenceable(16796), i32 noundef, i8 noundef zeroext) local_unnamed_addr #1

declare void @_ZN3TED13writeSoundRegEjh(ptr noundef nonnull align 4 dereferenceable(352), i32 noundef, i8 noundef zeroext) local_unnamed_addr #1

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 = { "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, !14, i64 496}
!6 = !{!"_ZTSN6SoLoud14TedSidInstanceE", !7, i64 0, !14, i64 496, !14, i64 504, !14, i64 512, !8, i64 520, !8, i64 524, !9, i64 528}
!7 = !{!"_ZTSN6SoLoud19AudioSourceInstanceE", !8, i64 8, !8, i64 12, !8, i64 16, !11, i64 20, !9, i64 24, !11, i64 56, !11, i64 60, !11, i64 64, !11, i64 68, !8, i64 72, !11, i64 76, !11, i64 80, !12, i64 88, !12, i64 96, !13, i64 104, !13, i64 152, !13, i64 200, !13, i64 248, !13, i64 296, !8, i64 344, !9, i64 348, !8, i64 380, !8, i64 384, !9, i64 392, !9, i64 456, !8, i64 472, !8, i64 476, !8, i64 480, !12, i64 488}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"float", !9, i64 0}
!12 = !{!"double", !9, i64 0}
!13 = !{!"_ZTSN6SoLoud5FaderE", !11, i64 0, !11, i64 4, !11, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !11, i64 40, !8, i64 44}
!14 = !{!"any pointer", !9, i64 0}
!15 = !{!16, !14, i64 160}
!16 = !{!"_ZTSN6SoLoud6TedSidE", !17, i64 0, !8, i64 152, !8, i64 156, !14, i64 160, !8, i64 168}
!17 = !{!"_ZTSN6SoLoud11AudioSourceE", !8, i64 8, !11, i64 12, !11, i64 16, !8, i64 20, !8, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !8, i64 40, !11, i64 44, !9, i64 48, !14, i64 112, !14, i64 120, !14, i64 128, !8, i64 136, !12, i64 144}
!18 = !{!6, !8, i64 524}
!19 = !{!6, !8, i64 520}
!20 = !{!21, !21, i64 0}
!21 = !{!"short", !9, i64 0}
!22 = !{!16, !8, i64 156}
!23 = !{!16, !8, i64 152}
!24 = !{!8, !8, i64 0}
!25 = !{!6, !14, i64 504}
!26 = !{!6, !14, i64 512}
!27 = distinct !{!27, !28}
!28 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass