; LLVM IR from tfhe/spqlios-arithmetic :: spqlios/cplx (cplx_ifft_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 @cplx_set_e2pimx(ptr noundef, double noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @fill_cplx_ifft_omegas_bfs_16(double noundef, ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @fill_cplx_ifft_omegas_bfs_2(double noundef, ptr noundef, i32 noundef) #1

declare void @cplx_set(ptr noundef, ptr noundef) #2

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

11:                                               ; preds = %3
  br label %54

12:                                               ; preds = %3
  %13 = load i32, ptr %6, align 4, !tbaa !11
  %14 = icmp ule i32 %13, 8
  br i1 %14, label %15, label %19

15:                                               ; preds = %12
  %16 = load double, ptr %4, align 8, !tbaa !5
  %17 = load ptr, ptr %5, align 8, !tbaa !9
  %18 = load i32, ptr %6, align 4, !tbaa !11
  call void @fill_cplx_ifft_omegas_bfs_2(double noundef %16, ptr noundef %17, i32 noundef %18)
  br label %54

19:                                               ; preds = %12
  %20 = load i32, ptr %6, align 4, !tbaa !11
  %21 = icmp ule i32 %20, 2048
  br i1 %21, label %22, label %26

22:                                               ; preds = %19
  %23 = load double, ptr %4, align 8, !tbaa !5
  %24 = load ptr, ptr %5, align 8, !tbaa !9
  %25 = load i32, ptr %6, align 4, !tbaa !11
  call void @fill_cplx_ifft_omegas_bfs_16(double noundef %23, ptr noundef %24, i32 noundef %25)
  br label %54

26:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %27 = load double, ptr %4, align 8, !tbaa !5
  %28 = fdiv double %27, 2.000000e+00
  store double %28, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %29 = load i32, ptr %6, align 4, !tbaa !11
  %30 = udiv i32 %29, 2
  store i32 %30, ptr %8, align 4, !tbaa !11
  %31 = load double, ptr %7, align 8, !tbaa !5
  %32 = load ptr, ptr %5, align 8, !tbaa !9
  %33 = load i32, ptr %8, align 4, !tbaa !11
  call void @fill_cplx_ifft_omegas_rec_16(double noundef %31, ptr noundef %32, i32 noundef %33)
  %34 = load double, ptr %7, align 8, !tbaa !5
  %35 = fadd double %34, 5.000000e-01
  %36 = load ptr, ptr %5, align 8, !tbaa !9
  %37 = load i32, ptr %8, align 4, !tbaa !11
  call void @fill_cplx_ifft_omegas_rec_16(double noundef %35, ptr noundef %36, i32 noundef %37)
  %38 = load ptr, ptr %5, align 8, !tbaa !9
  %39 = load ptr, ptr %38, align 8, !tbaa !9
  %40 = getelementptr inbounds [2 x double], ptr %39, i64 0
  %41 = getelementptr inbounds [2 x double], ptr %40, i64 0, i64 0
  %42 = load double, ptr %7, align 8, !tbaa !5
  call void @cplx_set_e2pimx(ptr noundef %41, double noundef %42)
  %43 = load ptr, ptr %5, align 8, !tbaa !9
  %44 = load ptr, ptr %43, align 8, !tbaa !9
  %45 = getelementptr inbounds [2 x double], ptr %44, i64 1
  %46 = getelementptr inbounds [2 x double], ptr %45, i64 0, i64 0
  %47 = load ptr, ptr %5, align 8, !tbaa !9
  %48 = load ptr, ptr %47, align 8, !tbaa !9
  %49 = getelementptr inbounds [2 x double], ptr %48, i64 0
  %50 = getelementptr inbounds [2 x double], ptr %49, i64 0, i64 0
  call void @cplx_set(ptr noundef %46, ptr noundef %50)
  %51 = load ptr, ptr %5, align 8, !tbaa !9
  %52 = load ptr, ptr %51, align 8, !tbaa !9
  %53 = getelementptr inbounds [2 x double], ptr %52, i64 2
  store ptr %53, ptr %51, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %54

54:                                               ; preds = %26, %22, %15, %11
  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 = { "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 = !{!"double", !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 @cplx_set_e2pimx(ptr noundef, double noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @fill_cplx_ifft_omegas_bfs_16(double noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @fill_cplx_ifft_omegas_bfs_2(double noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

declare void @cplx_set(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @fill_cplx_ifft_omegas_rec_16(double noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq i32 %2, 1
  br i1 %4, label %common.ret21, label %5

5:                                                ; preds = %3
  %6 = icmp ult i32 %2, 9
  br i1 %6, label %7, label %8

7:                                                ; preds = %5
  tail call void @fill_cplx_ifft_omegas_bfs_2(double noundef %0, ptr noundef %1, i32 noundef %2)
  br label %common.ret21

8:                                                ; preds = %5
  %9 = icmp ult i32 %2, 2049
  br i1 %9, label %10, label %11

10:                                               ; preds = %8
  tail call void @fill_cplx_ifft_omegas_bfs_16(double noundef %0, ptr noundef %1, i32 noundef %2)
  br label %common.ret21

common.ret21:                                     ; preds = %3, %10, %7, %11
  ret void

11:                                               ; preds = %8
  %12 = fmul double %0, 5.000000e-01
  %13 = lshr i32 %2, 1
  tail call void @fill_cplx_ifft_omegas_rec_16(double noundef %12, ptr noundef %1, i32 noundef %13)
  %14 = fadd double %12, 5.000000e-01
  tail call void @fill_cplx_ifft_omegas_rec_16(double noundef %14, ptr noundef %1, i32 noundef %13)
  %15 = load ptr, ptr %1, align 8, !tbaa !5
  tail call void @cplx_set_e2pimx(ptr noundef %15, double noundef %12)
  %16 = load ptr, ptr %1, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %16, i64 16
  tail call void @cplx_set(ptr noundef nonnull %17, ptr noundef %16) #2
  %18 = load ptr, ptr %1, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %18, i64 32
  store ptr %19, ptr %1, align 8, !tbaa !5
  br label %common.ret21
}

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


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