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

; 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.flexframesync_s = type { ptr, ptr, %struct.framesyncstats_s, %struct.framedatastats_s, i32, float, ptr, float, float, float, float, ptr, ptr, ptr, i32, i32, i32, ptr, ptr, i32, ptr, i32, ptr, ptr, i32, ptr, i32, i32, ptr, i32, %struct.flexframegenprops_s, i32, ptr, ptr, i32, ptr, ptr, i32, i32, i32, i32, i32, i32, i32, i32, ptr }
%struct.framesyncstats_s = type { float, float, float, ptr, i32, i32, i32, i32, i32, i32 }
%struct.framedatastats_s = type { i32, i32, i32, i64 }
%struct.flexframegenprops_s = type { i32, i32, i32, 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

; Function Attrs: nounwind uwtable
define dso_local i32 @flexframesync_execute_rxpreamble(ptr noundef %0, <2 x float> noundef %1) #1 {
  %3 = alloca { float, float }, align 4
  %4 = alloca ptr, align 8
  %5 = alloca { float, float }, align 4
  %6 = alloca i32, align 4
  %7 = alloca { float, float }, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store <2 x float> %1, ptr %3, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %10 = getelementptr inbounds { float, float }, ptr %5, i32 0, i32 0
  %11 = getelementptr inbounds { float, float }, ptr %5, i32 0, i32 1
  store float 0.000000e+00, ptr %10, align 4
  store float 0.000000e+00, ptr %11, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds { float, float }, ptr %3, i32 0, i32 0
  %14 = load float, ptr %13, align 4
  %15 = getelementptr inbounds { float, float }, ptr %3, i32 0, i32 1
  %16 = load float, ptr %15, align 4
  %17 = getelementptr inbounds { float, float }, ptr %7, i32 0, i32 0
  %18 = getelementptr inbounds { float, float }, ptr %7, i32 0, i32 1
  store float %14, ptr %17, align 4
  store float %16, ptr %18, align 4
  %19 = load <2 x float>, ptr %7, align 4
  %20 = call i32 @flexframesync_step(ptr noundef %12, <2 x float> noundef %19, ptr noundef %5)
  store i32 %20, ptr %6, align 4, !tbaa !9
  %21 = load i32, ptr %6, align 4, !tbaa !9
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %66

23:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.flexframesync_s, ptr %24, i32 0, i32 4
  %26 = load i32, ptr %25, align 8, !tbaa !11
  %27 = mul i32 2, %26
  store i32 %27, ptr %8, align 4, !tbaa !9
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.flexframesync_s, ptr %28, i32 0, i32 39
  %30 = load i32, ptr %29, align 8, !tbaa !18
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = icmp uge i32 %30, %31
  br i1 %32, label %33, label %51

33:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.flexframesync_s, ptr %34, i32 0, i32 39
  %36 = load i32, ptr %35, align 8, !tbaa !18
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = sub i32 %36, %37
  store i32 %38, ptr %9, align 4, !tbaa !9
  %39 = getelementptr inbounds { float, float }, ptr %5, i32 0, i32 0
  %40 = load float, ptr %39, align 4
  %41 = getelementptr inbounds { float, float }, ptr %5, i32 0, i32 1
  %42 = load float, ptr %41, align 4
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.flexframesync_s, ptr %43, i32 0, i32 18
  %45 = load ptr, ptr %44, align 8, !tbaa !19
  %46 = load i32, ptr %9, align 4, !tbaa !9
  %47 = zext i32 %46 to i64
  %48 = getelementptr inbounds { float, float }, ptr %45, i64 %47
  %49 = getelementptr inbounds { float, float }, ptr %48, i32 0, i32 0
  %50 = getelementptr inbounds { float, float }, ptr %48, i32 0, i32 1
  store float %40, ptr %49, align 4
  store float %42, ptr %50, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %51

51:                                               ; preds = %33, %23
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.flexframesync_s, ptr %52, i32 0, i32 39
  %54 = load i32, ptr %53, align 8, !tbaa !18
  %55 = add i32 %54, 1
  store i32 %55, ptr %53, align 8, !tbaa !18
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.flexframesync_s, ptr %56, i32 0, i32 39
  %58 = load i32, ptr %57, align 8, !tbaa !18
  %59 = load i32, ptr %8, align 4, !tbaa !9
  %60 = add i32 64, %59
  %61 = icmp eq i32 %58, %60
  br i1 %61, label %62, label %65

62:                                               ; preds = %51
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.flexframesync_s, ptr %63, i32 0, i32 41
  store i32 2, ptr %64, align 8, !tbaa !20
  br label %65

65:                                               ; preds = %62, %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %66

66:                                               ; preds = %65, %2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret i32 0
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @flexframesync_step(ptr noundef, <2 x float> noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="64" "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 = !{!"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 = !{!12, !10, i64 88}
!12 = !{!"flexframesync_s", !6, i64 0, !6, i64 8, !13, i64 16, !15, i64 64, !10, i64 88, !14, i64 92, !6, i64 96, !14, i64 104, !14, i64 108, !14, i64 112, !14, i64 116, !6, i64 120, !6, i64 128, !6, i64 136, !10, i64 144, !10, i64 148, !10, i64 152, !6, i64 160, !6, i64 168, !10, i64 176, !6, i64 184, !10, i64 192, !6, i64 200, !6, i64 208, !10, i64 216, !6, i64 224, !10, i64 232, !10, i64 236, !6, i64 240, !10, i64 248, !17, i64 252, !10, i64 268, !6, i64 272, !6, i64 280, !10, i64 288, !6, i64 296, !6, i64 304, !10, i64 312, !10, i64 316, !10, i64 320, !10, i64 324, !10, i64 328, !10, i64 332, !10, i64 336, !10, i64 340, !6, i64 344}
!13 = !{!"", !14, i64 0, !14, i64 4, !14, i64 8, !6, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44}
!14 = !{!"float", !7, i64 0}
!15 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !16, i64 16}
!16 = !{!"long", !7, i64 0}
!17 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12}
!18 = !{!12, !10, i64 320}
!19 = !{!12, !6, i64 168}
!20 = !{!12, !10, i64 328}


; 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @flexframesync_execute_rxpreamble(ptr noundef %0, <2 x float> noundef %1) local_unnamed_addr #1 {
  %3 = alloca { float, float }, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #2
  store <2 x float> zeroinitializer, ptr %3, align 8
  %4 = call i32 @flexframesync_step(ptr noundef %0, <2 x float> noundef %1, ptr noundef nonnull %3)
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %25, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 88
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %8 = shl i32 %7, 1
  %9 = getelementptr inbounds i8, ptr %0, i64 320
  %10 = load i32, ptr %9, align 8, !tbaa !16
  %.not15 = icmp ult i32 %10, %8
  br i1 %.not15, label %18, label %11

11:                                               ; preds = %5
  %12 = sub i32 %10, %8
  %13 = getelementptr inbounds i8, ptr %0, i64 168
  %14 = load ptr, ptr %13, align 8, !tbaa !17
  %15 = zext i32 %12 to i64
  %16 = getelementptr inbounds { float, float }, ptr %14, i64 %15
  %17 = load <2 x float>, ptr %3, align 8
  store <2 x float> %17, ptr %16, align 4
  %.pre = load i32, ptr %9, align 8, !tbaa !16
  br label %18

18:                                               ; preds = %11, %5
  %19 = phi i32 [ %.pre, %11 ], [ %10, %5 ]
  %20 = add i32 %19, 1
  store i32 %20, ptr %9, align 8, !tbaa !16
  %21 = add i32 %8, 63
  %22 = icmp eq i32 %19, %21
  br i1 %22, label %23, label %25

23:                                               ; preds = %18
  %24 = getelementptr inbounds i8, ptr %0, i64 328
  store i32 2, ptr %24, align 8, !tbaa !18
  br label %25

25:                                               ; preds = %18, %23, %2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #2
  ret i32 0
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @flexframesync_step(ptr noundef, <2 x float> noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="64" "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, !12, i64 88}
!6 = !{!"flexframesync_s", !7, i64 0, !7, i64 8, !10, i64 16, !13, i64 64, !12, i64 88, !11, i64 92, !7, i64 96, !11, i64 104, !11, i64 108, !11, i64 112, !11, i64 116, !7, i64 120, !7, i64 128, !7, i64 136, !12, i64 144, !12, i64 148, !12, i64 152, !7, i64 160, !7, i64 168, !12, i64 176, !7, i64 184, !12, i64 192, !7, i64 200, !7, i64 208, !12, i64 216, !7, i64 224, !12, i64 232, !12, i64 236, !7, i64 240, !12, i64 248, !15, i64 252, !12, i64 268, !7, i64 272, !7, i64 280, !12, i64 288, !7, i64 296, !7, i64 304, !12, i64 312, !12, i64 316, !12, i64 320, !12, i64 324, !12, i64 328, !12, i64 332, !12, i64 336, !12, i64 340, !7, i64 344}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !7, i64 16, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !12, i64 40, !12, i64 44}
!11 = !{!"float", !8, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !14, i64 16}
!14 = !{!"long", !8, i64 0}
!15 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12}
!16 = !{!6, !12, i64 320}
!17 = !{!6, !7, i64 168}
!18 = !{!6, !12, i64 328}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass