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

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

; Function Attrs: nounwind willreturn memory(read)
declare i32 @memcmp(ptr noundef, ptr noundef, i64 noundef) #2

; Function Attrs: noreturn nounwind
declare void @abort() #3

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

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

10:                                               ; preds = %3
  br label %57

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

14:                                               ; preds = %11
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = load i32, ptr %6, align 4, !tbaa !9
  call void @cplx_fft_ref_bfs_2(ptr noundef %15, ptr noundef %16, i32 noundef %17)
  br label %57

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

21:                                               ; preds = %18
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = load i32, ptr %6, align 4, !tbaa !9
  call void @cplx_fft_ref_bfs_16(ptr noundef %22, ptr noundef %23, i32 noundef %24)
  br label %57

25:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %26 = load i32, ptr %6, align 4, !tbaa !9
  %27 = udiv i32 %26, 2
  store i32 %27, ptr %7, align 4, !tbaa !9
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  %30 = getelementptr inbounds [2 x double], ptr %29, i64 0
  %31 = getelementptr inbounds [2 x double], ptr %30, i64 0, i64 0
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = load ptr, ptr %32, align 8, !tbaa !5
  %34 = getelementptr inbounds [2 x double], ptr %33, i64 1
  %35 = getelementptr inbounds [2 x double], ptr %34, i64 0, i64 0
  %36 = call i32 @memcmp(ptr noundef %31, ptr noundef %35, i64 noundef 8) #5
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %39

38:                                               ; preds = %25
  call void @abort() #6
  unreachable

39:                                               ; preds = %25
  %40 = load i32, ptr %7, align 4, !tbaa !9
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = load ptr, ptr %42, align 8, !tbaa !5
  %44 = getelementptr inbounds [2 x double], ptr %43, i64 0, i64 0
  call void @cplx_twiddle_fft_ref(i32 noundef %40, ptr noundef %41, ptr noundef %44)
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = load ptr, ptr %45, align 8, !tbaa !5
  %47 = getelementptr inbounds [2 x double], ptr %46, i64 2
  store ptr %47, ptr %45, align 8, !tbaa !5
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = load i32, ptr %7, align 4, !tbaa !9
  call void @cplx_fft_ref_rec_16(ptr noundef %48, ptr noundef %49, i32 noundef %50)
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = load i32, ptr %7, align 4, !tbaa !9
  %53 = zext i32 %52 to i64
  %54 = getelementptr inbounds [2 x double], ptr %51, i64 %53
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = load i32, ptr %7, align 4, !tbaa !9
  call void @cplx_fft_ref_rec_16(ptr noundef %54, ptr noundef %55, i32 noundef %56)
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %57

57:                                               ; preds = %39, %21, %14, %10
  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 willreturn memory(read) "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 = { noreturn 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 = { nounwind }
attributes #5 = { nounwind willreturn memory(read) }
attributes #6 = { noreturn 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}


; 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_twiddle_fft_ref(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: noreturn nounwind
declare void @abort() local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local void @cplx_fft_ref_rec_16(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq i32 %2, 1
  br i1 %4, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %5 = icmp ult i32 %2, 9
  br i1 %5, label %6, label %.lr.ph50

6:                                                ; preds = %.lr.ph.preheader
  tail call void @cplx_fft_ref_bfs_2(ptr noundef %0, ptr noundef %1, i32 noundef %2)
  br label %.loopexit

.lr.ph50:                                         ; preds = %.lr.ph.preheader, %tailrecurse
  %.tr3049 = phi ptr [ %17, %tailrecurse ], [ %0, %.lr.ph.preheader ]
  %.tr233148 = phi i32 [ %13, %tailrecurse ], [ %2, %.lr.ph.preheader ]
  %7 = icmp ult i32 %.tr233148, 2049
  br i1 %7, label %8, label %9

8:                                                ; preds = %.lr.ph50
  tail call void @cplx_fft_ref_bfs_16(ptr noundef %.tr3049, ptr noundef %1, i32 noundef %.tr233148)
  br label %.loopexit

9:                                                ; preds = %.lr.ph50
  %10 = load ptr, ptr %1, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %10, i64 16
  %bcmp = tail call i32 @bcmp(ptr noundef nonnull dereferenceable(8) %10, ptr noundef nonnull dereferenceable(8) %11, i64 8)
  %.not = icmp eq i32 %bcmp, 0
  br i1 %.not, label %tailrecurse, label %12

12:                                               ; preds = %9
  tail call void @abort() #3
  unreachable

tailrecurse:                                      ; preds = %9
  %13 = lshr i32 %.tr233148, 1
  tail call void @cplx_twiddle_fft_ref(i32 noundef %13, ptr noundef %.tr3049, ptr noundef %10)
  %14 = load ptr, ptr %1, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i64 32
  store ptr %15, ptr %1, align 8, !tbaa !5
  tail call void @cplx_fft_ref_rec_16(ptr noundef %.tr3049, ptr noundef nonnull %1, i32 noundef %13)
  %16 = zext nneg i32 %13 to i64
  %17 = getelementptr inbounds [2 x double], ptr %.tr3049, i64 %16
  br label %.lr.ph50

.loopexit:                                        ; preds = %3, %8, %6
  ret void
}

; Function Attrs: nofree nounwind willreturn memory(argmem: read)
declare i32 @bcmp(ptr nocapture, ptr nocapture, i64) local_unnamed_addr #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 = { noreturn 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 #2 = { nofree nounwind willreturn memory(argmem: read) }
attributes #3 = { noreturn 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: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass