; LLVM IR from Seeed-Studio/Seeed_Arduino_edgeimpulse :: src/edge-impulse-sdk/dsp/kissfft (kiss_fft)

; 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.kiss_fft_state = type { i32, i32, [64 x i32], [1 x %struct.kiss_fft_cpx] }
%struct.kiss_fft_cpx = type { float, float }

; Function Attrs: mustprogress uwtable
define dso_local ptr @kiss_fft_alloc(i32 noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #0 {
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  %14 = alloca double, align 8
  %15 = alloca double, align 8
  store i32 %0, ptr %6, align 4, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !9
  store ptr %4, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  store ptr null, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %16 = load i32, ptr %6, align 4, !tbaa !5
  %17 = sub nsw i32 %16, 1
  %18 = sext i32 %17 to i64
  %19 = mul i64 8, %18
  %20 = add i64 272, %19
  store i64 %20, ptr %12, align 8, !tbaa !11
  %21 = load ptr, ptr %9, align 8, !tbaa !9
  %22 = icmp eq ptr %21, null
  br i1 %22, label %23, label %26

23:                                               ; preds = %5
  %24 = load i64, ptr %12, align 8, !tbaa !11
  %25 = call noalias ptr @malloc(i64 noundef %24) #6
  store ptr %25, ptr %11, align 8, !tbaa !9
  br label %39

26:                                               ; preds = %5
  %27 = load ptr, ptr %8, align 8, !tbaa !9
  %28 = icmp ne ptr %27, null
  br i1 %28, label %29, label %36

29:                                               ; preds = %26
  %30 = load ptr, ptr %9, align 8, !tbaa !9
  %31 = load i64, ptr %30, align 8, !tbaa !11
  %32 = load i64, ptr %12, align 8, !tbaa !11
  %33 = icmp uge i64 %31, %32
  br i1 %33, label %34, label %36

34:                                               ; preds = %29
  %35 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %35, ptr %11, align 8, !tbaa !9
  br label %36

36:                                               ; preds = %34, %29, %26
  %37 = load i64, ptr %12, align 8, !tbaa !11
  %38 = load ptr, ptr %9, align 8, !tbaa !9
  store i64 %37, ptr %38, align 8, !tbaa !11
  br label %39

39:                                               ; preds = %36, %23
  %40 = load ptr, ptr %11, align 8, !tbaa !9
  %41 = icmp ne ptr %40, null
  br i1 %41, label %42, label %99

42:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  %43 = load i32, ptr %6, align 4, !tbaa !5
  %44 = load ptr, ptr %11, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct.kiss_fft_state, ptr %44, i32 0, i32 0
  store i32 %43, ptr %45, align 4, !tbaa !13
  %46 = load i32, ptr %7, align 4, !tbaa !5
  %47 = load ptr, ptr %11, align 8, !tbaa !9
  %48 = getelementptr inbounds %struct.kiss_fft_state, ptr %47, i32 0, i32 1
  store i32 %46, ptr %48, align 4, !tbaa !15
  store i32 0, ptr %13, align 4, !tbaa !5
  br label %49

49:                                               ; preds = %91, %42
  %50 = load i32, ptr %13, align 4, !tbaa !5
  %51 = load i32, ptr %6, align 4, !tbaa !5
  %52 = icmp slt i32 %50, %51
  br i1 %52, label %53, label %94

53:                                               ; preds = %49
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  store double 0x400921FB54442D18, ptr %14, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  %54 = load i32, ptr %13, align 4, !tbaa !5
  %55 = sitofp i32 %54 to double
  %56 = fmul double 0xC01921FB54442D18, %55
  %57 = load i32, ptr %6, align 4, !tbaa !5
  %58 = sitofp i32 %57 to double
  %59 = fdiv double %56, %58
  store double %59, ptr %15, align 8, !tbaa !16
  %60 = load ptr, ptr %11, align 8, !tbaa !9
  %61 = getelementptr inbounds %struct.kiss_fft_state, ptr %60, i32 0, i32 1
  %62 = load i32, ptr %61, align 4, !tbaa !15
  %63 = icmp ne i32 %62, 0
  br i1 %63, label %64, label %67

64:                                               ; preds = %53
  %65 = load double, ptr %15, align 8, !tbaa !16
  %66 = fmul double %65, -1.000000e+00
  store double %66, ptr %15, align 8, !tbaa !16
  br label %67

67:                                               ; preds = %64, %53
  br label %68

68:                                               ; preds = %67
  %69 = load double, ptr %15, align 8, !tbaa !16
  %70 = call double @cos(double noundef %69) #5
  %71 = fptrunc double %70 to float
  %72 = load ptr, ptr %11, align 8, !tbaa !9
  %73 = getelementptr inbounds %struct.kiss_fft_state, ptr %72, i32 0, i32 3
  %74 = getelementptr inbounds [1 x %struct.kiss_fft_cpx], ptr %73, i64 0, i64 0
  %75 = load i32, ptr %13, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds %struct.kiss_fft_cpx, ptr %74, i64 %76
  %78 = getelementptr inbounds %struct.kiss_fft_cpx, ptr %77, i32 0, i32 0
  store float %71, ptr %78, align 4, !tbaa !18
  %79 = load double, ptr %15, align 8, !tbaa !16
  %80 = call double @sin(double noundef %79) #5
  %81 = fptrunc double %80 to float
  %82 = load ptr, ptr %11, align 8, !tbaa !9
  %83 = getelementptr inbounds %struct.kiss_fft_state, ptr %82, i32 0, i32 3
  %84 = getelementptr inbounds [1 x %struct.kiss_fft_cpx], ptr %83, i64 0, i64 0
  %85 = load i32, ptr %13, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds %struct.kiss_fft_cpx, ptr %84, i64 %86
  %88 = getelementptr inbounds %struct.kiss_fft_cpx, ptr %87, i32 0, i32 1
  store float %81, ptr %88, align 4, !tbaa !21
  br label %89

89:                                               ; preds = %68
  br label %90

90:                                               ; preds = %89
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  br label %91

91:                                               ; preds = %90
  %92 = load i32, ptr %13, align 4, !tbaa !5
  %93 = add nsw i32 %92, 1
  store i32 %93, ptr %13, align 4, !tbaa !5
  br label %49, !llvm.loop !22

94:                                               ; preds = %49
  %95 = load i32, ptr %6, align 4, !tbaa !5
  %96 = load ptr, ptr %11, align 8, !tbaa !9
  %97 = getelementptr inbounds %struct.kiss_fft_state, ptr %96, i32 0, i32 2
  %98 = getelementptr inbounds [64 x i32], ptr %97, i64 0, i64 0
  call void @_ZL9kf_factoriPi(i32 noundef %95, ptr noundef %98)
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  br label %99

99:                                               ; preds = %94, %39
  %100 = load ptr, ptr %10, align 8, !tbaa !9
  %101 = icmp ne ptr %100, null
  br i1 %101, label %102, label %105

102:                                              ; preds = %99
  %103 = load i64, ptr %12, align 8, !tbaa !11
  %104 = load ptr, ptr %10, align 8, !tbaa !9
  store i64 %103, ptr %104, align 8, !tbaa !11
  br label %105

105:                                              ; preds = %102, %99
  %106 = load ptr, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  ret ptr %106
}

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: nounwind
declare double @cos(double noundef) #3

; Function Attrs: nounwind
declare double @sin(double noundef) #3

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

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZL9kf_factoriPi(i32 noundef, ptr noundef) #4

attributes #0 = { mustprogress 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 = { nounwind allocsize(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 #3 = { nounwind "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 #4 = { mustprogress 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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"_ZTS14kiss_fft_state", !6, i64 0, !6, i64 4, !7, i64 8, !7, i64 264}
!15 = !{!14, !6, i64 4}
!16 = !{!17, !17, i64 0}
!17 = !{!"double", !7, i64 0}
!18 = !{!19, !20, i64 0}
!19 = !{!"_ZTS12kiss_fft_cpx", !20, i64 0, !20, i64 4}
!20 = !{!"float", !7, i64 0}
!21 = !{!19, !20, i64 4}
!22 = distinct !{!22, !23}
!23 = !{!"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"

%struct.kiss_fft_cpx = type { float, float }

; Function Attrs: mustprogress nounwind uwtable
define dso_local ptr @kiss_fft_alloc(i32 noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef writeonly %4) local_unnamed_addr #0 {
  %6 = add nsw i32 %0, -1
  %7 = sext i32 %6 to i64
  %8 = shl nsw i64 %7, 3
  %9 = add nsw i64 %8, 272
  %10 = icmp eq ptr %3, null
  br i1 %10, label %11, label %13

11:                                               ; preds = %5
  %12 = tail call noalias ptr @malloc(i64 noundef %9) #3
  br label %17

13:                                               ; preds = %5
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %16, label %14

14:                                               ; preds = %13
  %15 = load i64, ptr %3, align 8, !tbaa !5
  %.not39 = icmp ult i64 %15, %9
  %spec.select = select i1 %.not39, ptr null, ptr %2
  br label %16

16:                                               ; preds = %14, %13
  %.032 = phi ptr [ null, %13 ], [ %spec.select, %14 ]
  store i64 %9, ptr %3, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %16, %11
  %.1 = phi ptr [ %12, %11 ], [ %.032, %16 ]
  %.not40 = icmp eq ptr %.1, null
  br i1 %.not40, label %37, label %18

18:                                               ; preds = %17
  store i32 %0, ptr %.1, align 4, !tbaa !9
  %19 = getelementptr inbounds i8, ptr %.1, i64 4
  store i32 %1, ptr %19, align 4, !tbaa !12
  %20 = icmp sgt i32 %0, 0
  br i1 %20, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %18
  %21 = uitofp nneg i32 %0 to double
  %22 = getelementptr inbounds i8, ptr %.1, i64 264
  %wide.trip.count = zext nneg i32 %0 to i64
  br label %23

23:                                               ; preds = %.lr.ph, %23
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %23 ]
  %24 = trunc nuw nsw i64 %indvars.iv to i32
  %25 = uitofp nneg i32 %24 to double
  %26 = fmul double %25, 0xC01921FB54442D18
  %27 = fdiv double %26, %21
  %28 = load i32, ptr %19, align 4, !tbaa !12
  %.not42 = icmp eq i32 %28, 0
  %29 = fneg double %27
  %.0 = select i1 %.not42, double %27, double %29
  %30 = tail call double @cos(double noundef %.0) #4
  %31 = fptrunc double %30 to float
  %32 = getelementptr inbounds %struct.kiss_fft_cpx, ptr %22, i64 %indvars.iv
  store float %31, ptr %32, align 4, !tbaa !13
  %33 = tail call double @sin(double noundef %.0) #4
  %34 = fptrunc double %33 to float
  %35 = getelementptr inbounds i8, ptr %32, i64 4
  store float %34, ptr %35, align 4, !tbaa !16
  %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 %23, !llvm.loop !17

._crit_edge:                                      ; preds = %23, %18
  %36 = getelementptr inbounds i8, ptr %.1, i64 8
  tail call void @_ZL9kf_factoriPi(i32 noundef %0, ptr noundef nonnull %36)
  br label %37

37:                                               ; preds = %._crit_edge, %17
  %.not41 = icmp eq ptr %4, null
  br i1 %.not41, label %39, label %38

38:                                               ; preds = %37
  store i64 %9, ptr %4, align 8, !tbaa !5
  br label %39

39:                                               ; preds = %38, %37
  ret ptr %.1
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @cos(double noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sin(double noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZL9kf_factoriPi(i32 noundef, ptr noundef) local_unnamed_addr #0

attributes #0 = { mustprogress 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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress nofree nounwind willreturn memory(write) "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 allocsize(0) }
attributes #4 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTS14kiss_fft_state", !11, i64 0, !11, i64 4, !7, i64 8, !7, i64 264}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 4}
!13 = !{!14, !15, i64 0}
!14 = !{!"_ZTS12kiss_fft_cpx", !15, i64 0, !15, i64 4}
!15 = !{!"float", !7, i64 0}
!16 = !{!14, !15, i64 4}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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