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

; 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.TED = type { i32, i32, i32, i32, i32, i32, i16, i16, i32, [2 x i32], [2 x i32], [2 x i32], [2 x i32], [2 x i32], i32, i32, [256 x i8], [3 x i32], i32 }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3TED13writeSoundRegEjh(ptr noundef nonnull align 4 dereferenceable(352) %0, i32 noundef %1, i8 noundef zeroext %2) #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i8 %2, ptr %6, align 1, !tbaa !11
  %7 = load ptr, ptr %4, align 8
  %8 = load i32, ptr %5, align 4, !tbaa !9
  switch i32 %8, label %118 [
    i32 0, label %9
    i32 1, label %22
    i32 2, label %35
    i32 3, label %49
    i32 4, label %104
  ]

9:                                                ; preds = %3
  %10 = getelementptr inbounds %class.TED, ptr %7, i32 0, i32 6
  %11 = load i16, ptr %10, align 4, !tbaa !12
  %12 = zext i16 %11 to i32
  %13 = and i32 %12, 768
  %14 = load i8, ptr %6, align 1, !tbaa !11
  %15 = zext i8 %14 to i32
  %16 = or i32 %13, %15
  %17 = trunc i32 %16 to i16
  %18 = getelementptr inbounds %class.TED, ptr %7, i32 0, i32 6
  store i16 %17, ptr %18, align 4, !tbaa !12
  %19 = getelementptr inbounds %class.TED, ptr %7, i32 0, i32 6
  %20 = load i16, ptr %19, align 4, !tbaa !12
  %21 = zext i16 %20 to i32
  call void @_ZN3TED7setFreqEji(ptr noundef nonnull align 4 dereferenceable(352) %7, i32 noundef 0, i32 noundef %21)
  br label %118

22:                                               ; preds = %3
  %23 = getelementptr inbounds %class.TED, ptr %7, i32 0, i32 7
  %24 = load i16, ptr %23, align 2, !tbaa !15
  %25 = zext i16 %24 to i32
  %26 = and i32 %25, 768
  %27 = load i8, ptr %6, align 1, !tbaa !11
  %28 = zext i8 %27 to i32
  %29 = or i32 %26, %28
  %30 = trunc i32 %29 to i16
  %31 = getelementptr inbounds %class.TED, ptr %7, i32 0, i32 7
  store i16 %30, ptr %31, align 2, !tbaa !15
  %32 = getelementptr inbounds %class.TED, ptr %7, i32 0, i32 7
  %33 = load i16, ptr %32, align 2, !tbaa !15
  %34 = zext i16 %33 to i32
  call void @_ZN3TED7setFreqEji(ptr noundef nonnull align 4 dereferenceable(352) %7, i32 noundef 1, i32 noundef %34)
  br label %118

35:                                               ; preds = %3
  %36 = getelementptr inbounds %class.TED, ptr %7, i32 0, i32 7
  %37 = load i16, ptr %36, align 2, !tbaa !15
  %38 = zext i16 %37 to i32
  %39 = and i32 %38, 255
  %40 = load i8, ptr %6, align 1, !tbaa !11
  %41 = zext i8 %40 to i32
  %42 = shl i32 %41, 8
  %43 = or i32 %39, %42
  %44 = trunc i32 %43 to i16
  %45 = getelementptr inbounds %class.TED, ptr %7, i32 0, i32 7
  store i16 %44, ptr %45, align 2, !tbaa !15
  %46 = getelementptr inbounds %class.TED, ptr %7, i32 0, i32 7
  %47 = load i16, ptr %46, align 2, !tbaa !15
  %48 = zext i16 %47 to i32
  call void @_ZN3TED7setFreqEji(ptr noundef nonnull align 4 dereferenceable(352) %7, i32 noundef 1, i32 noundef %48)
  br label %118

49:                                               ; preds = %3
  %50 = load i8, ptr %6, align 1, !tbaa !11
  %51 = zext i8 %50 to i32
  %52 = and i32 %51, 128
  %53 = getelementptr inbounds %class.TED, ptr %7, i32 0, i32 5
  store i32 %52, ptr %53, align 4, !tbaa !16
  %54 = getelementptr inbounds %class.TED, ptr %7, i32 0, i32 5
  %55 = load i32, ptr %54, align 4, !tbaa !16
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %57, label %73

57:                                               ; preds = %49
  %58 = getelementptr inbounds %class.TED, ptr %7, i32 0, i32 9
  %59 = getelementptr inbounds [2 x i32], ptr %58, i64 0, i64 0
  store i32 1, ptr %59, align 4, !tbaa !9
  %60 = getelementptr inbounds %class.TED, ptr %7, i32 0, i32 9
  %61 = getelementptr inbounds [2 x i32], ptr %60, i64 0, i64 1
  store i32 1, ptr %61, align 4, !tbaa !9
  %62 = getelementptr inbounds %class.TED, ptr %7, i32 0, i32 12
  %63 = getelementptr inbounds [2 x i32], ptr %62, i64 0, i64 0
  %64 = load i32, ptr %63, align 4, !tbaa !9
  %65 = getelementptr inbounds %class.TED, ptr %7, i32 0, i32 11
  %66 = getelementptr inbounds [2 x i32], ptr %65, i64 0, i64 0
  store i32 %64, ptr %66, align 4, !tbaa !9
  %67 = getelementptr inbounds %class.TED, ptr %7, i32 0, i32 12
  %68 = getelementptr inbounds [2 x i32], ptr %67, i64 0, i64 1
  %69 = load i32, ptr %68, align 4, !tbaa !9
  %70 = getelementptr inbounds %class.TED, ptr %7, i32 0, i32 11
  %71 = getelementptr inbounds [2 x i32], ptr %70, i64 0, i64 1
  store i32 %69, ptr %71, align 4, !tbaa !9
  %72 = getelementptr inbounds %class.TED, ptr %7, i32 0, i32 8
  store i32 255, ptr %72, align 4, !tbaa !17
  br label %73

73:                                               ; preds = %57, %49
  %74 = load i8, ptr %6, align 1, !tbaa !11
  %75 = zext i8 %74 to i32
  %76 = and i32 %75, 15
  %77 = getelementptr inbounds %class.TED, ptr %7, i32 0, i32 1
  store i32 %76, ptr %77, align 4, !tbaa !18
  %78 = getelementptr inbounds %class.TED, ptr %7, i32 0, i32 1
  %79 = load i32, ptr %78, align 4, !tbaa !18
  %80 = icmp sgt i32 %79, 8
  br i1 %80, label %81, label %83

81:                                               ; preds = %73
  %82 = getelementptr inbounds %class.TED, ptr %7, i32 0, i32 1
  store i32 8, ptr %82, align 4, !tbaa !18
  br label %83

83:                                               ; preds = %81, %73
  %84 = getelementptr inbounds %class.TED, ptr %7, i32 0, i32 1
  %85 = load i32, ptr %84, align 4, !tbaa !18
  %86 = shl i32 %85, 8
  %87 = getelementptr inbounds %class.TED, ptr %7, i32 0, i32 0
  %88 = load i32, ptr %87, align 4, !tbaa !19
  %89 = mul i32 %86, %88
  %90 = udiv i32 %89, 10
  %91 = getelementptr inbounds %class.TED, ptr %7, i32 0, i32 1
  store i32 %90, ptr %91, align 4, !tbaa !18
  %92 = load i8, ptr %6, align 1, !tbaa !11
  %93 = zext i8 %92 to i32
  %94 = and i32 %93, 16
  %95 = getelementptr inbounds %class.TED, ptr %7, i32 0, i32 2
  store i32 %94, ptr %95, align 4, !tbaa !20
  %96 = load i8, ptr %6, align 1, !tbaa !11
  %97 = zext i8 %96 to i32
  %98 = and i32 %97, 32
  %99 = getelementptr inbounds %class.TED, ptr %7, i32 0, i32 3
  store i32 %98, ptr %99, align 4, !tbaa !21
  %100 = load i8, ptr %6, align 1, !tbaa !11
  %101 = zext i8 %100 to i32
  %102 = and i32 %101, 64
  %103 = getelementptr inbounds %class.TED, ptr %7, i32 0, i32 4
  store i32 %102, ptr %103, align 4, !tbaa !22
  br label %118

104:                                              ; preds = %3
  %105 = getelementptr inbounds %class.TED, ptr %7, i32 0, i32 6
  %106 = load i16, ptr %105, align 4, !tbaa !12
  %107 = zext i16 %106 to i32
  %108 = and i32 %107, 255
  %109 = load i8, ptr %6, align 1, !tbaa !11
  %110 = zext i8 %109 to i32
  %111 = shl i32 %110, 8
  %112 = or i32 %108, %111
  %113 = trunc i32 %112 to i16
  %114 = getelementptr inbounds %class.TED, ptr %7, i32 0, i32 6
  store i16 %113, ptr %114, align 4, !tbaa !12
  %115 = getelementptr inbounds %class.TED, ptr %7, i32 0, i32 6
  %116 = load i16, ptr %115, align 4, !tbaa !12
  %117 = zext i16 %116 to i32
  call void @_ZN3TED7setFreqEji(ptr noundef nonnull align 4 dereferenceable(352) %7, i32 noundef 0, i32 noundef %117)
  br label %118

118:                                              ; preds = %104, %83, %35, %22, %9, %3
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3TED7setFreqEji(ptr noundef nonnull align 4 dereferenceable(352), i32 noundef, i32 noundef) #1 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 = { 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" }

!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 = !{!7, !7, i64 0}
!12 = !{!13, !14, i64 24}
!13 = !{!"_ZTS3TED", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !14, i64 24, !14, i64 26, !10, i64 28, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !10, i64 72, !10, i64 76, !7, i64 80, !7, i64 336, !10, i64 348}
!14 = !{!"short", !7, i64 0}
!15 = !{!13, !14, i64 26}
!16 = !{!13, !10, i64 20}
!17 = !{!13, !10, i64 28}
!18 = !{!13, !10, i64 4}
!19 = !{!13, !10, i64 0}
!20 = !{!13, !10, i64 8}
!21 = !{!13, !10, i64 12}
!22 = !{!13, !10, i64 16}


; 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 nounwind uwtable
define dso_local void @_ZN3TED13writeSoundRegEjh(ptr noundef nonnull align 4 dereferenceable(352) %0, i32 noundef %1, i8 noundef zeroext %2) local_unnamed_addr #0 align 2 {
  switch i32 %1, label %58 [
    i32 0, label %4
    i32 1, label %11
    i32 2, label %18
    i32 3, label %26
    i32 4, label %50
  ]

4:                                                ; preds = %3
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %6 = load i16, ptr %5, align 4, !tbaa !5
  %7 = and i16 %6, 768
  %8 = zext i8 %2 to i16
  %9 = or disjoint i16 %7, %8
  store i16 %9, ptr %5, align 4, !tbaa !5
  %10 = zext nneg i16 %9 to i32
  tail call void @_ZN3TED7setFreqEji(ptr noundef nonnull align 4 dereferenceable(352) %0, i32 noundef 0, i32 noundef %10)
  br label %58

11:                                               ; preds = %3
  %12 = getelementptr inbounds i8, ptr %0, i64 26
  %13 = load i16, ptr %12, align 2, !tbaa !11
  %14 = and i16 %13, 768
  %15 = zext i8 %2 to i16
  %16 = or disjoint i16 %14, %15
  store i16 %16, ptr %12, align 2, !tbaa !11
  %17 = zext nneg i16 %16 to i32
  tail call void @_ZN3TED7setFreqEji(ptr noundef nonnull align 4 dereferenceable(352) %0, i32 noundef 1, i32 noundef %17)
  br label %58

18:                                               ; preds = %3
  %19 = getelementptr inbounds i8, ptr %0, i64 26
  %20 = load i16, ptr %19, align 2, !tbaa !11
  %21 = and i16 %20, 255
  %22 = zext i8 %2 to i16
  %23 = shl nuw i16 %22, 8
  %24 = or disjoint i16 %21, %23
  store i16 %24, ptr %19, align 2, !tbaa !11
  %25 = zext i16 %24 to i32
  tail call void @_ZN3TED7setFreqEji(ptr noundef nonnull align 4 dereferenceable(352) %0, i32 noundef 1, i32 noundef %25)
  br label %58

26:                                               ; preds = %3
  %27 = zext i8 %2 to i32
  %28 = and i32 %27, 128
  %29 = getelementptr inbounds i8, ptr %0, i64 20
  store i32 %28, ptr %29, align 4, !tbaa !12
  %.not = icmp eq i32 %28, 0
  br i1 %.not, label %37, label %30

30:                                               ; preds = %26
  %31 = getelementptr inbounds i8, ptr %0, i64 32
  store i32 1, ptr %31, align 4, !tbaa !13
  %32 = getelementptr inbounds i8, ptr %0, i64 36
  store i32 1, ptr %32, align 4, !tbaa !13
  %33 = getelementptr inbounds i8, ptr %0, i64 56
  %34 = getelementptr inbounds i8, ptr %0, i64 48
  %35 = load <2 x i32>, ptr %33, align 4, !tbaa !13
  store <2 x i32> %35, ptr %34, align 4, !tbaa !13
  %36 = getelementptr inbounds i8, ptr %0, i64 28
  store i32 255, ptr %36, align 4, !tbaa !14
  br label %37

37:                                               ; preds = %30, %26
  %38 = and i32 %27, 15
  %39 = getelementptr inbounds i8, ptr %0, i64 4
  %spec.select = tail call i32 @llvm.umin.i32(i32 %38, i32 8)
  %40 = shl nuw nsw i32 %spec.select, 8
  %41 = load i32, ptr %0, align 4, !tbaa !15
  %42 = mul i32 %40, %41
  %43 = udiv i32 %42, 10
  store i32 %43, ptr %39, align 4, !tbaa !16
  %44 = and i32 %27, 16
  %45 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %44, ptr %45, align 4, !tbaa !17
  %46 = and i32 %27, 32
  %47 = getelementptr inbounds i8, ptr %0, i64 12
  store i32 %46, ptr %47, align 4, !tbaa !18
  %48 = and i32 %27, 64
  %49 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 %48, ptr %49, align 4, !tbaa !19
  br label %58

50:                                               ; preds = %3
  %51 = getelementptr inbounds i8, ptr %0, i64 24
  %52 = load i16, ptr %51, align 4, !tbaa !5
  %53 = and i16 %52, 255
  %54 = zext i8 %2 to i16
  %55 = shl nuw i16 %54, 8
  %56 = or disjoint i16 %53, %55
  store i16 %56, ptr %51, align 4, !tbaa !5
  %57 = zext i16 %56 to i32
  tail call void @_ZN3TED7setFreqEji(ptr noundef nonnull align 4 dereferenceable(352) %0, i32 noundef 0, i32 noundef %57)
  br label %58

58:                                               ; preds = %50, %37, %18, %11, %4, %3
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3TED7setFreqEji(ptr noundef nonnull align 4 dereferenceable(352), i32 noundef, i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #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 nosync nounwind speculatable willreturn memory(none) }

!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, !10, i64 24}
!6 = !{!"_ZTS3TED", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !10, i64 24, !10, i64 26, !7, i64 28, !8, i64 32, !8, i64 40, !8, i64 48, !8, i64 56, !8, i64 64, !7, i64 72, !7, i64 76, !8, i64 80, !8, i64 336, !7, i64 348}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!6, !10, i64 26}
!12 = !{!6, !7, i64 20}
!13 = !{!7, !7, i64 0}
!14 = !{!6, !7, i64 28}
!15 = !{!6, !7, i64 0}
!16 = !{!6, !7, i64 4}
!17 = !{!6, !7, i64 8}
!18 = !{!6, !7, i64 12}
!19 = !{!6, !7, i64 16}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass