; LLVM IR from tfhe/spqlios-arithmetic :: spqlios/reim (reim_fft_ref)

; 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
declare dso_local void @reim_twiddle_fft_ref(i64 noundef, ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @reim_fft_bfs_16_ref(i64 noundef, ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @reim_fft_rec_16_ref(i64 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store i64 %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !9
  %10 = load i64, ptr %5, align 8, !tbaa !5
  %11 = icmp ule i64 %10, 2048
  br i1 %11, label %12, label %17

12:                                               ; preds = %4
  %13 = load i64, ptr %5, align 8, !tbaa !5
  %14 = load ptr, ptr %6, align 8, !tbaa !9
  %15 = load ptr, ptr %7, align 8, !tbaa !9
  %16 = load ptr, ptr %8, align 8, !tbaa !9
  call void @reim_fft_bfs_16_ref(i64 noundef %13, ptr noundef %14, ptr noundef %15, ptr noundef %16)
  br label %46

17:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %18 = load i64, ptr %5, align 8, !tbaa !5
  %19 = udiv i64 %18, 2
  %20 = trunc i64 %19 to i32
  store i32 %20, ptr %9, align 4, !tbaa !11
  %21 = load i32, ptr %9, align 4, !tbaa !11
  %22 = zext i32 %21 to i64
  %23 = load ptr, ptr %6, align 8, !tbaa !9
  %24 = load ptr, ptr %7, align 8, !tbaa !9
  %25 = load ptr, ptr %8, align 8, !tbaa !9
  %26 = load ptr, ptr %25, align 8, !tbaa !9
  call void @reim_twiddle_fft_ref(i64 noundef %22, ptr noundef %23, ptr noundef %24, ptr noundef %26)
  %27 = load ptr, ptr %8, align 8, !tbaa !9
  %28 = load ptr, ptr %27, align 8, !tbaa !9
  %29 = getelementptr inbounds double, ptr %28, i64 2
  store ptr %29, ptr %27, align 8, !tbaa !9
  %30 = load i32, ptr %9, align 4, !tbaa !11
  %31 = zext i32 %30 to i64
  %32 = load ptr, ptr %6, align 8, !tbaa !9
  %33 = load ptr, ptr %7, align 8, !tbaa !9
  %34 = load ptr, ptr %8, align 8, !tbaa !9
  call void @reim_fft_rec_16_ref(i64 noundef %31, ptr noundef %32, ptr noundef %33, ptr noundef %34)
  %35 = load i32, ptr %9, align 4, !tbaa !11
  %36 = zext i32 %35 to i64
  %37 = load ptr, ptr %6, align 8, !tbaa !9
  %38 = load i32, ptr %9, align 4, !tbaa !11
  %39 = zext i32 %38 to i64
  %40 = getelementptr inbounds double, ptr %37, i64 %39
  %41 = load ptr, ptr %7, align 8, !tbaa !9
  %42 = load i32, ptr %9, align 4, !tbaa !11
  %43 = zext i32 %42 to i64
  %44 = getelementptr inbounds double, ptr %41, i64 %43
  %45 = load ptr, ptr %8, align 8, !tbaa !9
  call void @reim_fft_rec_16_ref(i64 noundef %36, ptr noundef %40, ptr noundef %44, ptr noundef %45)
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %46

46:                                               ; preds = %17, %12
  ret void
}

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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !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"

; Function Attrs: nounwind uwtable
declare dso_local void @reim_twiddle_fft_ref(i64 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @reim_fft_bfs_16_ref(i64 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @reim_fft_rec_16_ref(i64 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = icmp ult i64 %0, 2049
  br i1 %5, label %tailrecurse._crit_edge, label %tailrecurse

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %4
  %.tr.lcssa = phi i64 [ %0, %4 ], [ %7, %tailrecurse ]
  %.tr20.lcssa = phi ptr [ %1, %4 ], [ %11, %tailrecurse ]
  %.tr21.lcssa = phi ptr [ %2, %4 ], [ %12, %tailrecurse ]
  tail call void @reim_fft_bfs_16_ref(i64 noundef %.tr.lcssa, ptr noundef %.tr20.lcssa, ptr noundef %.tr21.lcssa, ptr noundef %3)
  ret void

tailrecurse:                                      ; preds = %4, %tailrecurse
  %.tr2125 = phi ptr [ %12, %tailrecurse ], [ %2, %4 ]
  %.tr2024 = phi ptr [ %11, %tailrecurse ], [ %1, %4 ]
  %.tr23 = phi i64 [ %7, %tailrecurse ], [ %0, %4 ]
  %6 = lshr i64 %.tr23, 1
  %7 = and i64 %6, 4294967295
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  tail call void @reim_twiddle_fft_ref(i64 noundef %7, ptr noundef %.tr2024, ptr noundef %.tr2125, ptr noundef %8)
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %9, i64 16
  store ptr %10, ptr %3, align 8, !tbaa !5
  tail call void @reim_fft_rec_16_ref(i64 noundef %7, ptr noundef %.tr2024, ptr noundef %.tr2125, ptr noundef nonnull %3)
  %11 = getelementptr inbounds double, ptr %.tr2024, i64 %7
  %12 = getelementptr inbounds double, ptr %.tr2125, i64 %7
  %13 = icmp ult i64 %7, 2049
  br i1 %13, label %tailrecurse._crit_edge, label %tailrecurse
}

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

!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"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass