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

@.str.1 = external hidden unnamed_addr constant [86 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [60 x i8], align 1

; 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 @liquid_error_fl(i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @flexframesync_execute(ptr noundef %0, ptr noundef %1, i32 noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca { float, float }, align 4
  %10 = alloca { float, float }, align 4
  %11 = alloca { float, float }, align 4
  %12 = alloca { float, float }, align 4
  %13 = alloca { float, float }, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %108, %3
  %16 = load i32, ptr %8, align 4, !tbaa !9
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = icmp ult i32 %16, %17
  br i1 %18, label %19, label %111

19:                                               ; preds = %15
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.flexframesync_s, ptr %20, i32 0, i32 42
  %22 = load i32, ptr %21, align 4, !tbaa !11
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %45

24:                                               ; preds = %19
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.flexframesync_s, ptr %25, i32 0, i32 44
  %27 = load i32, ptr %26, align 4, !tbaa !18
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %45, label %29

29:                                               ; preds = %24
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.flexframesync_s, ptr %30, i32 0, i32 45
  %32 = load ptr, ptr %31, align 8, !tbaa !19
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = load i32, ptr %8, align 4, !tbaa !9
  %35 = zext i32 %34 to i64
  %36 = getelementptr inbounds { float, float }, ptr %33, i64 %35
  %37 = getelementptr inbounds { float, float }, ptr %36, i32 0, i32 0
  %38 = load float, ptr %37, align 4
  %39 = getelementptr inbounds { float, float }, ptr %36, i32 0, i32 1
  %40 = load float, ptr %39, align 4
  %41 = getelementptr inbounds { float, float }, ptr %9, i32 0, i32 0
  %42 = getelementptr inbounds { float, float }, ptr %9, i32 0, i32 1
  store float %38, ptr %41, align 4
  store float %40, ptr %42, align 4
  %43 = load <2 x float>, ptr %9, align 4
  %44 = call i32 @windowcf_push(ptr noundef %32, <2 x float> noundef %43)
  br label %45

45:                                               ; preds = %29, %24, %19
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.flexframesync_s, ptr %46, i32 0, i32 41
  %48 = load i32, ptr %47, align 8, !tbaa !20
  switch i32 %48, label %105 [
    i32 0, label %49
    i32 1, label %63
    i32 2, label %77
    i32 3, label %91
  ]

49:                                               ; preds = %45
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = load i32, ptr %8, align 4, !tbaa !9
  %53 = zext i32 %52 to i64
  %54 = getelementptr inbounds { float, float }, ptr %51, i64 %53
  %55 = getelementptr inbounds { float, float }, ptr %54, i32 0, i32 0
  %56 = load float, ptr %55, align 4
  %57 = getelementptr inbounds { float, float }, ptr %54, i32 0, i32 1
  %58 = load float, ptr %57, align 4
  %59 = getelementptr inbounds { float, float }, ptr %10, i32 0, i32 0
  %60 = getelementptr inbounds { float, float }, ptr %10, i32 0, i32 1
  store float %56, ptr %59, align 4
  store float %58, ptr %60, align 4
  %61 = load <2 x float>, ptr %10, align 4
  %62 = call i32 @flexframesync_execute_seekpn(ptr noundef %50, <2 x float> noundef %61)
  br label %107

63:                                               ; preds = %45
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = load i32, ptr %8, align 4, !tbaa !9
  %67 = zext i32 %66 to i64
  %68 = getelementptr inbounds { float, float }, ptr %65, i64 %67
  %69 = getelementptr inbounds { float, float }, ptr %68, i32 0, i32 0
  %70 = load float, ptr %69, align 4
  %71 = getelementptr inbounds { float, float }, ptr %68, i32 0, i32 1
  %72 = load float, ptr %71, align 4
  %73 = getelementptr inbounds { float, float }, ptr %11, i32 0, i32 0
  %74 = getelementptr inbounds { float, float }, ptr %11, i32 0, i32 1
  store float %70, ptr %73, align 4
  store float %72, ptr %74, align 4
  %75 = load <2 x float>, ptr %11, align 4
  %76 = call i32 @flexframesync_execute_rxpreamble(ptr noundef %64, <2 x float> noundef %75)
  br label %107

77:                                               ; preds = %45
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = load i32, ptr %8, align 4, !tbaa !9
  %81 = zext i32 %80 to i64
  %82 = getelementptr inbounds { float, float }, ptr %79, i64 %81
  %83 = getelementptr inbounds { float, float }, ptr %82, i32 0, i32 0
  %84 = load float, ptr %83, align 4
  %85 = getelementptr inbounds { float, float }, ptr %82, i32 0, i32 1
  %86 = load float, ptr %85, align 4
  %87 = getelementptr inbounds { float, float }, ptr %12, i32 0, i32 0
  %88 = getelementptr inbounds { float, float }, ptr %12, i32 0, i32 1
  store float %84, ptr %87, align 4
  store float %86, ptr %88, align 4
  %89 = load <2 x float>, ptr %12, align 4
  %90 = call i32 @flexframesync_execute_rxheader(ptr noundef %78, <2 x float> noundef %89)
  br label %107

91:                                               ; preds = %45
  %92 = load ptr, ptr %5, align 8, !tbaa !5
  %93 = load ptr, ptr %6, align 8, !tbaa !5
  %94 = load i32, ptr %8, align 4, !tbaa !9
  %95 = zext i32 %94 to i64
  %96 = getelementptr inbounds { float, float }, ptr %93, i64 %95
  %97 = getelementptr inbounds { float, float }, ptr %96, i32 0, i32 0
  %98 = load float, ptr %97, align 4
  %99 = getelementptr inbounds { float, float }, ptr %96, i32 0, i32 1
  %100 = load float, ptr %99, align 4
  %101 = getelementptr inbounds { float, float }, ptr %13, i32 0, i32 0
  %102 = getelementptr inbounds { float, float }, ptr %13, i32 0, i32 1
  store float %98, ptr %101, align 4
  store float %100, ptr %102, align 4
  %103 = load <2 x float>, ptr %13, align 4
  %104 = call i32 @flexframesync_execute_rxpayload(ptr noundef %92, <2 x float> noundef %103)
  br label %107

105:                                              ; preds = %45
  %106 = call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 1, ptr noundef @.str.1, i32 noundef 414, ptr noundef @.str.5)
  store i32 %106, ptr %4, align 4
  store i32 1, ptr %14, align 4
  br label %112

107:                                              ; preds = %91, %77, %63, %49
  br label %108

108:                                              ; preds = %107
  %109 = load i32, ptr %8, align 4, !tbaa !9
  %110 = add i32 %109, 1
  store i32 %110, ptr %8, align 4, !tbaa !9
  br label %15, !llvm.loop !21

111:                                              ; preds = %15
  store i32 0, ptr %4, align 4
  store i32 1, ptr %14, align 4
  br label %112

112:                                              ; preds = %111, %105
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %113 = load i32, ptr %4, align 4
  ret i32 %113
}

declare i32 @windowcf_push(ptr noundef, <2 x float> noundef) #1

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

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

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

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

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"="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 #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 = !{!12, !10, i64 332}
!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 340}
!19 = !{!12, !6, i64 344}
!20 = !{!12, !10, i64 328}
!21 = distinct !{!21, !22}
!22 = !{!"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"

@.str.1 = external hidden unnamed_addr constant [86 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [60 x i8], align 1

declare i32 @liquid_error_fl(i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @flexframesync_execute(ptr noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #1 {
  %.not38 = icmp eq i32 %2, 0
  br i1 %.not38, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %4 = getelementptr inbounds i8, ptr %0, i64 332
  %5 = getelementptr inbounds i8, ptr %0, i64 340
  %6 = getelementptr inbounds i8, ptr %0, i64 344
  %7 = getelementptr inbounds i8, ptr %0, i64 328
  %wide.trip.count = zext i32 %2 to i64
  br label %8

8:                                                ; preds = %.lr.ph, %37
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %37 ]
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %17, label %10

10:                                               ; preds = %8
  %11 = load i32, ptr %5, align 4, !tbaa !16
  %.not31 = icmp eq i32 %11, 0
  br i1 %.not31, label %12, label %17

12:                                               ; preds = %10
  %13 = load ptr, ptr %6, align 8, !tbaa !17
  %14 = getelementptr inbounds { float, float }, ptr %1, i64 %indvars.iv
  %15 = load <2 x float>, ptr %14, align 4
  %16 = tail call i32 @windowcf_push(ptr noundef %13, <2 x float> noundef %15) #2
  br label %17

17:                                               ; preds = %12, %10, %8
  %18 = load i32, ptr %7, align 8, !tbaa !18
  switch i32 %18, label %35 [
    i32 0, label %19
    i32 1, label %23
    i32 2, label %27
    i32 3, label %31
  ]

19:                                               ; preds = %17
  %20 = getelementptr inbounds { float, float }, ptr %1, i64 %indvars.iv
  %21 = load <2 x float>, ptr %20, align 4
  %22 = tail call i32 @flexframesync_execute_seekpn(ptr noundef nonnull %0, <2 x float> noundef %21)
  br label %37

23:                                               ; preds = %17
  %24 = getelementptr inbounds { float, float }, ptr %1, i64 %indvars.iv
  %25 = load <2 x float>, ptr %24, align 4
  %26 = tail call i32 @flexframesync_execute_rxpreamble(ptr noundef nonnull %0, <2 x float> noundef %25)
  br label %37

27:                                               ; preds = %17
  %28 = getelementptr inbounds { float, float }, ptr %1, i64 %indvars.iv
  %29 = load <2 x float>, ptr %28, align 4
  %30 = tail call i32 @flexframesync_execute_rxheader(ptr noundef nonnull %0, <2 x float> noundef %29)
  br label %37

31:                                               ; preds = %17
  %32 = getelementptr inbounds { float, float }, ptr %1, i64 %indvars.iv
  %33 = load <2 x float>, ptr %32, align 4
  %34 = tail call i32 @flexframesync_execute_rxpayload(ptr noundef nonnull %0, <2 x float> noundef %33)
  br label %37

35:                                               ; preds = %17
  %36 = tail call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 1, ptr noundef nonnull @.str.1, i32 noundef 414, ptr noundef nonnull @.str.5) #2
  br label %.loopexit

37:                                               ; preds = %19, %23, %27, %31
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %8, !llvm.loop !19

.loopexit:                                        ; preds = %37, %3, %35
  %.030 = phi i32 [ %36, %35 ], [ 0, %3 ], [ 0, %37 ]
  ret i32 %.030
}

declare i32 @windowcf_push(ptr noundef, <2 x float> noundef) local_unnamed_addr #0

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

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

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

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

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"="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 332}
!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 340}
!17 = !{!6, !7, i64 344}
!18 = !{!6, !12, i64 328}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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