; LLVM IR from ubaldot/defrecs :: stm32f4x/ADC_Readings/Drivers/CMSIS/DSP/Examples/ARM/arm_fft_bin_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_cfft_instance_f32 = type { i16, ptr, ptr, i16 }

@fftSize = external dso_local global i32, align 4
@ifftFlag = external dso_local global i32, align 4
@doBitReverse = external dso_local global i32, align 4
@refIndex = external dso_local global i32, align 4
@testIndex = external dso_local global i32, align 4
@varInstCfftF32 = external dso_local global %struct.arm_cfft_instance_f32, align 8
@testInput_f32_10khz = external global [2048 x float], align 16
@testOutput = external hidden global [1024 x float], align 16

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca float, align 4
  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 4, ptr %3) #3
  store i32 0, ptr %2, align 4, !tbaa !5
  %4 = load i32, ptr @fftSize, align 4, !tbaa !5
  %5 = trunc i32 %4 to i16
  %6 = call i32 @arm_cfft_init_f32(ptr noundef @varInstCfftF32, i16 noundef zeroext %5)
  store i32 %6, ptr %2, align 4, !tbaa !5
  %7 = load i32, ptr @ifftFlag, align 4, !tbaa !5
  %8 = trunc i32 %7 to i8
  %9 = load i32, ptr @doBitReverse, align 4, !tbaa !5
  %10 = trunc i32 %9 to i8
  call void @arm_cfft_f32(ptr noundef @varInstCfftF32, ptr noundef @testInput_f32_10khz, i8 noundef zeroext %8, i8 noundef zeroext %10)
  %11 = load i32, ptr @fftSize, align 4, !tbaa !5
  call void @arm_cmplx_mag_f32(ptr noundef @testInput_f32_10khz, ptr noundef @testOutput, i32 noundef %11)
  %12 = load i32, ptr @fftSize, align 4, !tbaa !5
  call void @arm_max_f32(ptr noundef @testOutput, i32 noundef %12, ptr noundef %3, ptr noundef @testIndex)
  %13 = load i32, ptr @testIndex, align 4, !tbaa !5
  %14 = load i32, ptr @refIndex, align 4, !tbaa !5
  %15 = icmp ne i32 %13, %14
  %16 = zext i1 %15 to i64
  %17 = select i1 %15, i32 -6, i32 0
  store i32 %17, ptr %2, align 4, !tbaa !5
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %23

20:                                               ; preds = %0
  br label %21

21:                                               ; preds = %22, %20
  br label %22

22:                                               ; preds = %21
  br label %21

23:                                               ; preds = %0
  br label %24

24:                                               ; preds = %25, %23
  br label %25

25:                                               ; preds = %24
  br label %24
}

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

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

declare void @arm_cfft_f32(ptr noundef, ptr noundef, i8 noundef zeroext, i8 noundef zeroext) #2

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

declare void @arm_max_f32(ptr noundef, i32 noundef, ptr noundef, ptr 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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

@fftSize = external dso_local local_unnamed_addr global i32, align 4
@ifftFlag = external dso_local local_unnamed_addr global i32, align 4
@doBitReverse = external dso_local local_unnamed_addr global i32, align 4
@refIndex = external dso_local local_unnamed_addr global i32, align 4
@testIndex = external dso_local global i32, align 4
@varInstCfftF32 = external dso_local global %struct.arm_cfft_instance_f32, align 8
@testInput_f32_10khz = external global [2048 x float], align 16
@testOutput = external hidden global [1024 x float], align 16

; Function Attrs: noreturn nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca float, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  %2 = load i32, ptr @fftSize, align 4, !tbaa !5
  %3 = trunc i32 %2 to i16
  %4 = tail call i32 @arm_cfft_init_f32(ptr noundef nonnull @varInstCfftF32, i16 noundef zeroext %3) #3
  %5 = load i32, ptr @ifftFlag, align 4, !tbaa !5
  %6 = trunc i32 %5 to i8
  %7 = load i32, ptr @doBitReverse, align 4, !tbaa !5
  %8 = trunc i32 %7 to i8
  tail call void @arm_cfft_f32(ptr noundef nonnull @varInstCfftF32, ptr noundef nonnull @testInput_f32_10khz, i8 noundef zeroext %6, i8 noundef zeroext %8) #3
  %9 = load i32, ptr @fftSize, align 4, !tbaa !5
  tail call void @arm_cmplx_mag_f32(ptr noundef nonnull @testInput_f32_10khz, ptr noundef nonnull @testOutput, i32 noundef %9) #3
  %10 = load i32, ptr @fftSize, align 4, !tbaa !5
  call void @arm_max_f32(ptr noundef nonnull @testOutput, i32 noundef %10, ptr noundef nonnull %1, ptr noundef nonnull @testIndex) #3
  %11 = load i32, ptr @testIndex, align 4, !tbaa !5
  %12 = load i32, ptr @refIndex, align 4, !tbaa !5
  %.not = icmp eq i32 %11, %12
  br i1 %.not, label %.preheader, label %.preheader1

.preheader1:                                      ; preds = %0, %.preheader1
  br label %.preheader1

.preheader:                                       ; preds = %0, %.preheader
  br label %.preheader
}

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

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

declare void @arm_cfft_f32(ptr noundef, ptr noundef, i8 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #2

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

declare void @arm_max_f32(ptr noundef, i32 noundef, ptr noundef, ptr 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"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass