; LLVM IR from ubaldot/defrecs :: stm32f4x/ADC_Readings/Drivers/CMSIS/DSP/Examples/ARM/arm_fir_example (main)

; 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.arm_fir_instance_f32 = type { i16, ptr, ptr }

@firCoeffs32 = external dso_local constant [29 x float], align 16
@blockSize = external dso_local global i32, align 4
@numBlocks = external dso_local global i32, align 4
@testInput_f32_1kHz_15kHz = external global [320 x float], align 16
@testOutput = external hidden global [320 x float], align 16
@firStateF32 = external hidden global [60 x float], align 16
@refOutput = external global [320 x float], align 16
@snr = external dso_local global float, align 4

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca %struct.arm_fir_instance_f32, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 24, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store ptr @testInput_f32_1kHz_15kHz, ptr %5, align 8, !tbaa !5
  store ptr @testOutput, ptr %6, align 8, !tbaa !5
  %7 = load i32, ptr @blockSize, align 4, !tbaa !9
  call void @arm_fir_init_f32(ptr noundef %3, i16 noundef zeroext 29, ptr noundef @firCoeffs32, ptr noundef @firStateF32, i32 noundef %7)
  store i32 0, ptr %2, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %26, %0
  %9 = load i32, ptr %2, align 4, !tbaa !9
  %10 = load i32, ptr @numBlocks, align 4, !tbaa !9
  %11 = icmp ult i32 %9, %10
  br i1 %11, label %12, label %29

12:                                               ; preds = %8
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = load i32, ptr %2, align 4, !tbaa !9
  %15 = load i32, ptr @blockSize, align 4, !tbaa !9
  %16 = mul i32 %14, %15
  %17 = zext i32 %16 to i64
  %18 = getelementptr inbounds float, ptr %13, i64 %17
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = load i32, ptr %2, align 4, !tbaa !9
  %21 = load i32, ptr @blockSize, align 4, !tbaa !9
  %22 = mul i32 %20, %21
  %23 = zext i32 %22 to i64
  %24 = getelementptr inbounds float, ptr %19, i64 %23
  %25 = load i32, ptr @blockSize, align 4, !tbaa !9
  call void @arm_fir_f32(ptr noundef %3, ptr noundef %18, ptr noundef %24, i32 noundef %25)
  br label %26

26:                                               ; preds = %12
  %27 = load i32, ptr %2, align 4, !tbaa !9
  %28 = add i32 %27, 1
  store i32 %28, ptr %2, align 4, !tbaa !9
  br label %8, !llvm.loop !11

29:                                               ; preds = %8
  %30 = call float @arm_snr_f32(ptr noundef @refOutput, ptr noundef @testOutput, i32 noundef 320)
  store float %30, ptr @snr, align 4, !tbaa !13
  %31 = load float, ptr @snr, align 4, !tbaa !13
  %32 = fcmp olt float %31, 7.500000e+01
  %33 = zext i1 %32 to i64
  %34 = select i1 %32, i32 -6, i32 0
  store i32 %34, ptr %4, align 4, !tbaa !9
  %35 = load i32, ptr %4, align 4, !tbaa !9
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %37, label %40

37:                                               ; preds = %29
  br label %38

38:                                               ; preds = %39, %37
  br label %39

39:                                               ; preds = %38
  br label %38

40:                                               ; preds = %29
  br label %41

41:                                               ; preds = %42, %40
  br label %42

42:                                               ; preds = %41
  br label %41
}

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

declare void @arm_fir_init_f32(ptr noundef, i16 noundef zeroext, ptr noundef, ptr noundef, i32 noundef) #2

declare void @arm_fir_f32(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #2

declare float @arm_snr_f32(ptr noundef, ptr noundef, i32 noundef) #2

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !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"

%struct.arm_fir_instance_f32 = type { i16, ptr, ptr }

@firCoeffs32 = external dso_local constant [29 x float], align 16
@blockSize = external dso_local local_unnamed_addr global i32, align 4
@numBlocks = external dso_local local_unnamed_addr global i32, align 4
@testInput_f32_1kHz_15kHz = external global [320 x float], align 16
@testOutput = external hidden global [320 x float], align 16
@firStateF32 = external hidden global [60 x float], align 16
@refOutput = external global [320 x float], align 16
@snr = external dso_local local_unnamed_addr global float, align 4

; Function Attrs: noreturn nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca %struct.arm_fir_instance_f32, align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %1) #3
  %2 = load i32, ptr @blockSize, align 4, !tbaa !5
  call void @arm_fir_init_f32(ptr noundef nonnull %1, i16 noundef zeroext 29, ptr noundef nonnull @firCoeffs32, ptr noundef nonnull @firStateF32, i32 noundef %2) #3
  %3 = load i32, ptr @numBlocks, align 4, !tbaa !5
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %.lr.ph
  %.07 = phi i32 [ %9, %.lr.ph ], [ 0, %0 ]
  %4 = load i32, ptr @blockSize, align 4, !tbaa !5
  %5 = mul i32 %4, %.07
  %6 = zext i32 %5 to i64
  %7 = getelementptr inbounds float, ptr @testInput_f32_1kHz_15kHz, i64 %6
  %8 = getelementptr inbounds float, ptr @testOutput, i64 %6
  call void @arm_fir_f32(ptr noundef nonnull %1, ptr noundef nonnull %7, ptr noundef nonnull %8, i32 noundef %4) #3
  %9 = add nuw i32 %.07, 1
  %10 = load i32, ptr @numBlocks, align 4, !tbaa !5
  %11 = icmp ult i32 %9, %10
  br i1 %11, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %0
  %12 = call float @arm_snr_f32(ptr noundef nonnull @refOutput, ptr noundef nonnull @testOutput, i32 noundef 320) #3
  store float %12, ptr @snr, align 4, !tbaa !11
  %13 = fcmp olt float %12, 7.500000e+01
  br i1 %13, label %.preheader, label %.preheader6

.preheader:                                       ; preds = %._crit_edge, %.preheader
  br label %.preheader

.preheader6:                                      ; preds = %._crit_edge, %.preheader6
  br label %.preheader6
}

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

declare void @arm_fir_init_f32(ptr noundef, i16 noundef zeroext, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

declare void @arm_fir_f32(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

declare float @arm_snr_f32(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

attributes #0 = { noreturn 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass