; LLVM IR from jgaeddert/liquid-dsp :: src/fft/src (fftf)

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

; 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 @fft_shift(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca { float, float }, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %8 = load i32, ptr %4, align 4, !tbaa !9
  %9 = urem i32 %8, 2
  %10 = icmp ne i32 %9, 0
  br i1 %10, label %11, label %15

11:                                               ; preds = %2
  %12 = load i32, ptr %4, align 4, !tbaa !9
  %13 = sub i32 %12, 1
  %14 = udiv i32 %13, 2
  store i32 %14, ptr %6, align 4, !tbaa !9
  br label %18

15:                                               ; preds = %2
  %16 = load i32, ptr %4, align 4, !tbaa !9
  %17 = udiv i32 %16, 2
  store i32 %17, ptr %6, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %15, %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %62, %18
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = load i32, ptr %6, align 4, !tbaa !9
  %22 = icmp ult i32 %20, %21
  br i1 %22, label %23, label %65

23:                                               ; preds = %19
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = load i32, ptr %5, align 4, !tbaa !9
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds { float, float }, ptr %24, i64 %26
  %28 = getelementptr inbounds { float, float }, ptr %27, i32 0, i32 0
  %29 = load float, ptr %28, align 4
  %30 = getelementptr inbounds { float, float }, ptr %27, i32 0, i32 1
  %31 = load float, ptr %30, align 4
  %32 = getelementptr inbounds { float, float }, ptr %7, i32 0, i32 0
  %33 = getelementptr inbounds { float, float }, ptr %7, i32 0, i32 1
  store float %29, ptr %32, align 4
  store float %31, ptr %33, align 4
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = load i32, ptr %5, align 4, !tbaa !9
  %36 = load i32, ptr %6, align 4, !tbaa !9
  %37 = add i32 %35, %36
  %38 = zext i32 %37 to i64
  %39 = getelementptr inbounds { float, float }, ptr %34, i64 %38
  %40 = getelementptr inbounds { float, float }, ptr %39, i32 0, i32 0
  %41 = load float, ptr %40, align 4
  %42 = getelementptr inbounds { float, float }, ptr %39, i32 0, i32 1
  %43 = load float, ptr %42, align 4
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = load i32, ptr %5, align 4, !tbaa !9
  %46 = zext i32 %45 to i64
  %47 = getelementptr inbounds { float, float }, ptr %44, i64 %46
  %48 = getelementptr inbounds { float, float }, ptr %47, i32 0, i32 0
  %49 = getelementptr inbounds { float, float }, ptr %47, i32 0, i32 1
  store float %41, ptr %48, align 4
  store float %43, ptr %49, align 4
  %50 = getelementptr inbounds { float, float }, ptr %7, i32 0, i32 0
  %51 = load float, ptr %50, align 4
  %52 = getelementptr inbounds { float, float }, ptr %7, i32 0, i32 1
  %53 = load float, ptr %52, align 4
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = load i32, ptr %5, align 4, !tbaa !9
  %56 = load i32, ptr %6, align 4, !tbaa !9
  %57 = add i32 %55, %56
  %58 = zext i32 %57 to i64
  %59 = getelementptr inbounds { float, float }, ptr %54, i64 %58
  %60 = getelementptr inbounds { float, float }, ptr %59, i32 0, i32 0
  %61 = getelementptr inbounds { float, float }, ptr %59, i32 0, i32 1
  store float %51, ptr %60, align 4
  store float %53, ptr %61, align 4
  br label %62

62:                                               ; preds = %23
  %63 = load i32, ptr %5, align 4, !tbaa !9
  %64 = add i32 %63, 1
  store i32 %64, ptr %5, align 4, !tbaa !9
  br label %19, !llvm.loop !11

65:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i32 0
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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, !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"}


; 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: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local noundef i32 @fft_shift(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %.not = icmp ult i32 %1, 2
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %2
  %.015 = lshr i32 %1, 1
  %3 = zext nneg i32 %.015 to i64
  %invariant.gep = getelementptr inbounds { float, float }, ptr %0, i64 %3
  %min.iters.check = icmp ult i32 %1, 4
  br i1 %min.iters.check, label %.lr.ph.preheader23, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %3, 2147483646
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %4 = getelementptr inbounds { float, float }, ptr %0, i64 %index
  %wide.vec = load <4 x float>, ptr %4, align 4
  %5 = getelementptr inbounds { float, float }, ptr %invariant.gep, i64 %index
  %wide.vec19 = load <4 x float>, ptr %5, align 4
  store <4 x float> %wide.vec19, ptr %4, align 4
  store <4 x float> %wide.vec, ptr %5, align 4
  %index.next = add nuw i64 %index, 2
  %6 = icmp eq i64 %index.next, %n.vec
  br i1 %6, label %middle.block, label %vector.body, !llvm.loop !5

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %3
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader23

.lr.ph.preheader23:                               ; preds = %middle.block, %.lr.ph.preheader
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader23, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader23 ]
  %7 = getelementptr inbounds { float, float }, ptr %0, i64 %indvars.iv
  %gep = getelementptr inbounds { float, float }, ptr %invariant.gep, i64 %indvars.iv
  %8 = load <2 x float>, ptr %7, align 4
  %9 = load <2 x float>, ptr %gep, align 4
  store <2 x float> %9, ptr %7, align 4
  store <2 x float> %8, ptr %gep, align 4
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %3
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %middle.block, %2
  ret i32 0
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: readwrite) 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" }

!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 = distinct !{!5, !6, !7, !8}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!"llvm.loop.isvectorized", i32 1}
!8 = !{!"llvm.loop.unroll.runtime.disable"}
!9 = distinct !{!9, !6, !8, !7}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SCCPPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass