; LLVM IR from jgaeddert/liquid-dsp :: src/modem/src (modemcf)

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

%struct.modemcf_s = type { i32, i32, i32, [8 x float], ptr, i32, { float, float }, { float, float }, %union.anon, ptr, ptr, ptr, i32 }
%union.anon = type { %struct.anon.3 }
%struct.anon.3 = type { i32, [8 x i32], [8 x float], [8 x float], [8 x float], ptr }
%struct.anon.2 = type { i32, i32, i32, i32, float }

; 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

declare i32 @gray_decode(i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @modemcf_modulate_qam(ptr noundef %0, i32 noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.modemcf_s, ptr %10, i32 0, i32 8
  %12 = getelementptr inbounds %struct.anon.2, ptr %11, i32 0, i32 1
  %13 = load i32, ptr %12, align 4, !tbaa !11
  %14 = lshr i32 %9, %13
  store i32 %14, ptr %7, align 4, !tbaa !9
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.modemcf_s, ptr %16, i32 0, i32 8
  %18 = getelementptr inbounds %struct.anon.2, ptr %17, i32 0, i32 1
  %19 = load i32, ptr %18, align 4, !tbaa !11
  %20 = shl i32 1, %19
  %21 = sub nsw i32 %20, 1
  %22 = and i32 %15, %21
  store i32 %22, ptr %8, align 4, !tbaa !9
  %23 = load i32, ptr %7, align 4, !tbaa !9
  %24 = call i32 @gray_decode(i32 noundef %23)
  store i32 %24, ptr %7, align 4, !tbaa !9
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = call i32 @gray_decode(i32 noundef %25)
  store i32 %26, ptr %8, align 4, !tbaa !9
  %27 = load i32, ptr %7, align 4, !tbaa !9
  %28 = mul nsw i32 2, %27
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.modemcf_s, ptr %29, i32 0, i32 8
  %31 = getelementptr inbounds %struct.anon.2, ptr %30, i32 0, i32 2
  %32 = load i32, ptr %31, align 8, !tbaa !11
  %33 = sub nsw i32 %28, %32
  %34 = add nsw i32 %33, 1
  %35 = sitofp i32 %34 to float
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.modemcf_s, ptr %36, i32 0, i32 8
  %38 = getelementptr inbounds %struct.anon.2, ptr %37, i32 0, i32 4
  %39 = load float, ptr %38, align 8, !tbaa !11
  %40 = fmul float %35, %39
  %41 = load i32, ptr %8, align 4, !tbaa !9
  %42 = mul nsw i32 2, %41
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.modemcf_s, ptr %43, i32 0, i32 8
  %45 = getelementptr inbounds %struct.anon.2, ptr %44, i32 0, i32 3
  %46 = load i32, ptr %45, align 4, !tbaa !11
  %47 = sub nsw i32 %42, %46
  %48 = add nsw i32 %47, 1
  %49 = sitofp i32 %48 to float
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.modemcf_s, ptr %50, i32 0, i32 8
  %52 = getelementptr inbounds %struct.anon.2, ptr %51, i32 0, i32 4
  %53 = load float, ptr %52, align 8, !tbaa !11
  %54 = fmul float %49, %53
  %55 = fmul float %54, 0.000000e+00
  %56 = fmul float %54, 1.000000e+00
  %57 = fadd float %40, %55
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = getelementptr inbounds { float, float }, ptr %58, i32 0, i32 0
  %60 = getelementptr inbounds { float, float }, ptr %58, i32 0, i32 1
  store float %57, ptr %59, align 4
  store float %56, ptr %60, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret i32 0
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}


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

declare i32 @gray_decode(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @modemcf_modulate_qam(ptr nocapture noundef readonly %0, i32 noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %0, i64 84
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = lshr i32 %1, %5
  %notmask = shl nsw i32 -1, %5
  %7 = xor i32 %notmask, -1
  %8 = and i32 %7, %1
  %9 = tail call i32 @gray_decode(i32 noundef %6) #2
  %10 = tail call i32 @gray_decode(i32 noundef %8) #2
  %11 = shl nsw i32 %9, 1
  %12 = getelementptr inbounds i8, ptr %0, i64 88
  %13 = load i32, ptr %12, align 8, !tbaa !5
  %14 = or disjoint i32 %11, 1
  %15 = sub i32 %14, %13
  %16 = sitofp i32 %15 to float
  %17 = getelementptr inbounds i8, ptr %0, i64 96
  %18 = load float, ptr %17, align 8, !tbaa !5
  %19 = fmul float %18, %16
  %20 = shl nsw i32 %10, 1
  %21 = getelementptr inbounds i8, ptr %0, i64 92
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = or disjoint i32 %20, 1
  %24 = sub i32 %23, %22
  %25 = sitofp i32 %24 to float
  %26 = fmul float %18, %25
  %27 = fmul float %26, 0.000000e+00
  %28 = fadd float %19, %27
  %29 = getelementptr inbounds i8, ptr %2, i64 4
  store float %28, ptr %2, align 4
  store float %26, ptr %29, align 4
  ret i32 0
}

attributes #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 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,TailCallElimPass