; LLVM IR from jgaeddert/liquid-dsp :: src/framing/src (gmskframegen)

; 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.gmskframegen_s = type { ptr, i32, i32, float, i32, i32, i32, i32, ptr, i32, i32, ptr, ptr, ptr, ptr, i32, i32, i32, i32, i32, ptr, i32, i32, i32, i32, ptr, i32 }

; 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 @msequence_reset(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @gmskframegen_write_preamble(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i8, align 1
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #3
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.gmskframegen_s, ptr %5, i32 0, i32 8
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  %8 = call i32 @msequence_advance(ptr noundef %7)
  %9 = trunc i32 %8 to i8
  store i8 %9, ptr %3, align 1, !tbaa !13
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.gmskframegen_s, ptr %10, i32 0, i32 0
  %12 = load ptr, ptr %11, align 8, !tbaa !14
  %13 = load i8, ptr %3, align 1, !tbaa !13
  %14 = zext i8 %13 to i32
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.gmskframegen_s, ptr %15, i32 0, i32 25
  %17 = load ptr, ptr %16, align 8, !tbaa !15
  %18 = call i32 @gmskmod_modulate(ptr noundef %12, i32 noundef %14, ptr noundef %17)
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.gmskframegen_s, ptr %19, i32 0, i32 24
  %21 = load i32, ptr %20, align 4, !tbaa !16
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.gmskframegen_s, ptr %22, i32 0, i32 2
  %24 = load i32, ptr %23, align 4, !tbaa !17
  %25 = icmp ult i32 %21, %24
  br i1 %25, label %26, label %70

26:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !18
  br label %27

27:                                               ; preds = %66, %26
  %28 = load i32, ptr %4, align 4, !tbaa !18
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.gmskframegen_s, ptr %29, i32 0, i32 1
  %31 = load i32, ptr %30, align 8, !tbaa !19
  %32 = icmp ult i32 %28, %31
  br i1 %32, label %33, label %69

33:                                               ; preds = %27
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.gmskframegen_s, ptr %34, i32 0, i32 24
  %36 = load i32, ptr %35, align 4, !tbaa !16
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.gmskframegen_s, ptr %37, i32 0, i32 1
  %39 = load i32, ptr %38, align 8, !tbaa !19
  %40 = mul i32 %36, %39
  %41 = load i32, ptr %4, align 4, !tbaa !18
  %42 = add i32 %40, %41
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.gmskframegen_s, ptr %43, i32 0, i32 2
  %45 = load i32, ptr %44, align 4, !tbaa !17
  %46 = mul i32 2, %45
  %47 = load ptr, ptr %2, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.gmskframegen_s, ptr %47, i32 0, i32 1
  %49 = load i32, ptr %48, align 8, !tbaa !19
  %50 = mul i32 %46, %49
  %51 = call float @liquid_hamming(i32 noundef %42, i32 noundef %50)
  %52 = load ptr, ptr %2, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.gmskframegen_s, ptr %52, i32 0, i32 25
  %54 = load ptr, ptr %53, align 8, !tbaa !15
  %55 = load i32, ptr %4, align 4, !tbaa !18
  %56 = zext i32 %55 to i64
  %57 = getelementptr inbounds { float, float }, ptr %54, i64 %56
  %58 = getelementptr inbounds { float, float }, ptr %57, i32 0, i32 0
  %59 = load float, ptr %58, align 4
  %60 = getelementptr inbounds { float, float }, ptr %57, i32 0, i32 1
  %61 = load float, ptr %60, align 4
  %62 = fmul float %59, %51
  %63 = fmul float %61, %51
  %64 = getelementptr inbounds { float, float }, ptr %57, i32 0, i32 0
  %65 = getelementptr inbounds { float, float }, ptr %57, i32 0, i32 1
  store float %62, ptr %64, align 4
  store float %63, ptr %65, align 4
  br label %66

66:                                               ; preds = %33
  %67 = load i32, ptr %4, align 4, !tbaa !18
  %68 = add i32 %67, 1
  store i32 %68, ptr %4, align 4, !tbaa !18
  br label %27, !llvm.loop !20

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

70:                                               ; preds = %69, %1
  %71 = load ptr, ptr %2, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.gmskframegen_s, ptr %71, i32 0, i32 24
  %73 = load i32, ptr %72, align 4, !tbaa !16
  %74 = add i32 %73, 1
  store i32 %74, ptr %72, align 4, !tbaa !16
  %75 = load ptr, ptr %2, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.gmskframegen_s, ptr %75, i32 0, i32 24
  %77 = load i32, ptr %76, align 4, !tbaa !16
  %78 = load ptr, ptr %2, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.gmskframegen_s, ptr %78, i32 0, i32 4
  %80 = load i32, ptr %79, align 4, !tbaa !22
  %81 = icmp eq i32 %77, %80
  br i1 %81, label %82, label %91

82:                                               ; preds = %70
  %83 = load ptr, ptr %2, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.gmskframegen_s, ptr %83, i32 0, i32 8
  %85 = load ptr, ptr %84, align 8, !tbaa !9
  %86 = call i32 @msequence_reset(ptr noundef %85)
  %87 = load ptr, ptr %2, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.gmskframegen_s, ptr %87, i32 0, i32 24
  store i32 0, ptr %88, align 4, !tbaa !16
  %89 = load ptr, ptr %2, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.gmskframegen_s, ptr %89, i32 0, i32 21
  store i32 2, ptr %90, align 8, !tbaa !23
  br label %91

91:                                               ; preds = %82, %70
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #3
  ret i32 0
}

declare i32 @msequence_advance(ptr noundef) #1

declare i32 @gmskmod_modulate(ptr noundef, i32 noundef, ptr noundef) #1

declare float @liquid_hamming(i32 noundef, i32 noundef) #1

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, !6, i64 40}
!10 = !{!"gmskframegen_s", !6, i64 0, !11, i64 8, !11, i64 12, !12, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !6, i64 40, !11, i64 48, !11, i64 52, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !11, i64 88, !11, i64 92, !11, i64 96, !11, i64 100, !11, i64 104, !6, i64 112, !11, i64 120, !11, i64 124, !11, i64 128, !11, i64 132, !6, i64 136, !11, i64 144}
!11 = !{!"int", !7, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!10, !6, i64 0}
!15 = !{!10, !6, i64 136}
!16 = !{!10, !11, i64 132}
!17 = !{!10, !11, i64 12}
!18 = !{!11, !11, i64 0}
!19 = !{!10, !11, i64 8}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!10, !11, i64 20}
!23 = !{!10, !11, i64 120}


; 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 @msequence_reset(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @gmskframegen_write_preamble(ptr nocapture noundef %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 40
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = tail call i32 @msequence_advance(ptr noundef %3) #2
  %5 = load ptr, ptr %0, align 8, !tbaa !12
  %6 = and i32 %4, 255
  %7 = getelementptr inbounds i8, ptr %0, i64 136
  %8 = load ptr, ptr %7, align 8, !tbaa !13
  %9 = tail call i32 @gmskmod_modulate(ptr noundef %5, i32 noundef %6, ptr noundef %8) #2
  %10 = getelementptr inbounds i8, ptr %0, i64 132
  %11 = load i32, ptr %10, align 4, !tbaa !14
  %12 = getelementptr inbounds i8, ptr %0, i64 12
  %13 = load i32, ptr %12, align 4, !tbaa !15
  %14 = icmp ult i32 %11, %13
  br i1 %14, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %1
  %15 = getelementptr inbounds i8, ptr %0, i64 8
  %16 = load i32, ptr %15, align 8, !tbaa !16
  %.not = icmp eq i32 %16, 0
  br i1 %.not, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.preheader ]
  %17 = phi i32 [ %32, %.lr.ph ], [ %16, %.preheader ]
  %18 = load i32, ptr %10, align 4, !tbaa !14
  %19 = mul i32 %18, %17
  %20 = trunc nuw i64 %indvars.iv to i32
  %21 = add i32 %19, %20
  %22 = load i32, ptr %12, align 4, !tbaa !15
  %23 = shl i32 %17, 1
  %24 = mul i32 %23, %22
  %25 = tail call float @liquid_hamming(i32 noundef %21, i32 noundef %24) #2
  %26 = load ptr, ptr %7, align 8, !tbaa !13
  %27 = getelementptr inbounds { float, float }, ptr %26, i64 %indvars.iv
  %28 = load <2 x float>, ptr %27, align 4
  %29 = insertelement <2 x float> poison, float %25, i64 0
  %30 = shufflevector <2 x float> %29, <2 x float> poison, <2 x i32> zeroinitializer
  %31 = fmul <2 x float> %30, %28
  store <2 x float> %31, ptr %27, align 4
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %32 = load i32, ptr %15, align 8, !tbaa !16
  %33 = zext i32 %32 to i64
  %34 = icmp ult i64 %indvars.iv.next, %33
  br i1 %34, label %.lr.ph, label %.loopexit.loopexit, !llvm.loop !17

.loopexit.loopexit:                               ; preds = %.lr.ph
  %.pre = load i32, ptr %10, align 4, !tbaa !14
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %.preheader, %1
  %35 = phi i32 [ %.pre, %.loopexit.loopexit ], [ %11, %.preheader ], [ %11, %1 ]
  %36 = add i32 %35, 1
  store i32 %36, ptr %10, align 4, !tbaa !14
  %37 = getelementptr inbounds i8, ptr %0, i64 20
  %38 = load i32, ptr %37, align 4, !tbaa !19
  %39 = icmp eq i32 %36, %38
  br i1 %39, label %40, label %44

40:                                               ; preds = %.loopexit
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  %42 = tail call i32 @msequence_reset(ptr noundef %41) #2
  store i32 0, ptr %10, align 4, !tbaa !14
  %43 = getelementptr inbounds i8, ptr %0, i64 120
  store i32 2, ptr %43, align 8, !tbaa !20
  br label %44

44:                                               ; preds = %40, %.loopexit
  ret i32 0
}

declare i32 @msequence_advance(ptr noundef) local_unnamed_addr #0

declare i32 @gmskmod_modulate(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

declare float @liquid_hamming(i32 noundef, i32 noundef) local_unnamed_addr #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, !7, i64 40}
!6 = !{!"gmskframegen_s", !7, i64 0, !10, i64 8, !10, i64 12, !11, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !7, i64 40, !10, i64 48, !10, i64 52, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !10, i64 88, !10, i64 92, !10, i64 96, !10, i64 100, !10, i64 104, !7, i64 112, !10, i64 120, !10, i64 124, !10, i64 128, !10, i64 132, !7, i64 136, !10, i64 144}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"float", !8, i64 0}
!12 = !{!6, !7, i64 0}
!13 = !{!6, !7, i64 136}
!14 = !{!6, !10, i64 132}
!15 = !{!6, !10, i64 12}
!16 = !{!6, !10, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!6, !10, i64 20}
!20 = !{!6, !10, i64 120}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass