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

; 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.flexframegen_s = type { i32, i32, float, ptr, [2 x { float, float }], %struct.flexframegenprops_s, %struct.flexframegenprops_s, ptr, ptr, i32, i32, ptr, i32, ptr, ptr, i32, ptr, i32, ptr, i32, ptr, i32, i32, i32, i32, i32 }
%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 @flexframegen_write_samples(ptr noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca { float, float }, align 4
  %9 = alloca { float, float }, align 4
  %10 = alloca { float, float }, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %71, %3
  %12 = load i32, ptr %7, align 4, !tbaa !9
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = icmp ult i32 %12, %13
  br i1 %14, label %15, label %74

15:                                               ; preds = %11
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.flexframegen_s, ptr %16, i32 0, i32 22
  %18 = load i32, ptr %17, align 4, !tbaa !11
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %20, label %43

20:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = call <2 x float> @flexframegen_generate_symbol(ptr noundef %21)
  store <2 x float> %22, ptr %9, align 4
  %23 = getelementptr inbounds { float, float }, ptr %9, i32 0, i32 0
  %24 = load float, ptr %23, align 4
  %25 = getelementptr inbounds { float, float }, ptr %9, i32 0, i32 1
  %26 = load float, ptr %25, align 4
  %27 = getelementptr inbounds { float, float }, ptr %8, i32 0, i32 0
  %28 = getelementptr inbounds { float, float }, ptr %8, i32 0, i32 1
  store float %24, ptr %27, align 4
  store float %26, ptr %28, align 4
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.flexframegen_s, ptr %29, i32 0, i32 3
  %31 = load ptr, ptr %30, align 8, !tbaa !15
  %32 = getelementptr inbounds { float, float }, ptr %8, i32 0, i32 0
  %33 = load float, ptr %32, align 4
  %34 = getelementptr inbounds { float, float }, ptr %8, i32 0, i32 1
  %35 = load float, ptr %34, align 4
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.flexframegen_s, ptr %36, i32 0, i32 4
  %38 = getelementptr inbounds [2 x { float, float }], ptr %37, i64 0, i64 0
  %39 = getelementptr inbounds { float, float }, ptr %10, i32 0, i32 0
  %40 = getelementptr inbounds { float, float }, ptr %10, i32 0, i32 1
  store float %33, ptr %39, align 4
  store float %35, ptr %40, align 4
  %41 = load <2 x float>, ptr %10, align 4
  %42 = call i32 @firinterp_crcf_execute(ptr noundef %31, <2 x float> noundef %41, ptr noundef %38)
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %43

43:                                               ; preds = %20, %15
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.flexframegen_s, ptr %44, i32 0, i32 4
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.flexframegen_s, ptr %46, i32 0, i32 22
  %48 = load i32, ptr %47, align 4, !tbaa !11
  %49 = zext i32 %48 to i64
  %50 = getelementptr inbounds [2 x { float, float }], ptr %45, i64 0, i64 %49
  %51 = getelementptr inbounds { float, float }, ptr %50, i32 0, i32 0
  %52 = load float, ptr %51, align 8
  %53 = getelementptr inbounds { float, float }, ptr %50, i32 0, i32 1
  %54 = load float, ptr %53, align 4
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = load i32, ptr %7, align 4, !tbaa !9
  %57 = zext i32 %56 to i64
  %58 = getelementptr inbounds { float, float }, ptr %55, i64 %57
  %59 = getelementptr inbounds { float, float }, ptr %58, i32 0, i32 0
  %60 = getelementptr inbounds { float, float }, ptr %58, i32 0, i32 1
  store float %52, ptr %59, align 4
  store float %54, ptr %60, align 4
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.flexframegen_s, ptr %61, i32 0, i32 22
  %63 = load i32, ptr %62, align 4, !tbaa !11
  %64 = add i32 %63, 1
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.flexframegen_s, ptr %65, i32 0, i32 0
  %67 = load i32, ptr %66, align 8, !tbaa !16
  %68 = urem i32 %64, %67
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.flexframegen_s, ptr %69, i32 0, i32 22
  store i32 %68, ptr %70, align 4, !tbaa !11
  br label %71

71:                                               ; preds = %43
  %72 = load i32, ptr %7, align 4, !tbaa !9
  %73 = add i32 %72, 1
  store i32 %73, ptr %7, align 4, !tbaa !9
  br label %11, !llvm.loop !17

74:                                               ; preds = %11
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.flexframegen_s, ptr %75, i32 0, i32 24
  %77 = load i32, ptr %76, align 4, !tbaa !19
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret i32 %77
}

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

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

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 = { "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 180}
!12 = !{!"flexframegen_s", !10, i64 0, !10, i64 4, !13, i64 8, !6, i64 16, !7, i64 24, !14, i64 40, !14, i64 56, !6, i64 72, !6, i64 80, !10, i64 88, !10, i64 92, !6, i64 96, !10, i64 104, !6, i64 112, !6, i64 120, !10, i64 128, !6, i64 136, !10, i64 144, !6, i64 152, !10, i64 160, !6, i64 168, !10, i64 176, !10, i64 180, !10, i64 184, !10, i64 188, !10, i64 192}
!13 = !{!"float", !7, i64 0}
!14 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12}
!15 = !{!12, !6, i64 16}
!16 = !{!12, !10, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!12, !10, i64 188}


; 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: nounwind uwtable
define dso_local i32 @flexframegen_write_samples(ptr noundef %0, ptr nocapture noundef writeonly %1, i32 noundef %2) local_unnamed_addr #0 {
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %4 = getelementptr inbounds i8, ptr %0, i64 180
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %wide.trip.count = zext i32 %2 to i64
  %.pre = load i32, ptr %4, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %.lr.ph, %14
  %8 = phi i32 [ %.pre, %.lr.ph ], [ %23, %14 ]
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %14 ]
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %10, label %14

10:                                               ; preds = %7
  %11 = tail call <2 x float> @flexframegen_generate_symbol(ptr noundef nonnull %0)
  %12 = load ptr, ptr %5, align 8, !tbaa !13
  %13 = tail call i32 @firinterp_crcf_execute(ptr noundef %12, <2 x float> noundef %11, ptr noundef nonnull %6) #2
  %.pre19 = load i32, ptr %4, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %10, %7
  %15 = phi i32 [ %.pre19, %10 ], [ %8, %7 ]
  %16 = zext i32 %15 to i64
  %17 = getelementptr inbounds [2 x { float, float }], ptr %6, i64 0, i64 %16
  %18 = getelementptr inbounds { float, float }, ptr %1, i64 %indvars.iv
  %19 = load <2 x float>, ptr %17, align 8
  store <2 x float> %19, ptr %18, align 4
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = add i32 %20, 1
  %22 = load i32, ptr %0, align 8, !tbaa !14
  %23 = urem i32 %21, %22
  store i32 %23, ptr %4, align 4, !tbaa !5
  %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 %._crit_edge, label %7, !llvm.loop !15

._crit_edge:                                      ; preds = %14, %3
  %24 = getelementptr inbounds i8, ptr %0, i64 188
  %25 = load i32, ptr %24, align 4, !tbaa !17
  ret i32 %25
}

; Function Attrs: nounwind uwtable
declare dso_local <2 x float> @flexframegen_generate_symbol(ptr noundef) local_unnamed_addr #0

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

attributes #0 = { 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 #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 }

!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 180}
!6 = !{!"flexframegen_s", !7, i64 0, !7, i64 4, !10, i64 8, !11, i64 16, !8, i64 24, !12, i64 40, !12, i64 56, !11, i64 72, !11, i64 80, !7, i64 88, !7, i64 92, !11, i64 96, !7, i64 104, !11, i64 112, !11, i64 120, !7, i64 128, !11, i64 136, !7, i64 144, !11, i64 152, !7, i64 160, !11, i64 168, !7, i64 176, !7, i64 180, !7, i64 184, !7, i64 188, !7, i64 192}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"float", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12}
!13 = !{!6, !11, i64 16}
!14 = !{!6, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!6, !7, i64 188}


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