; 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: nounwind uwtable
declare dso_local void @ctwiddle(ptr noundef, ptr noundef, ptr noundef) #0

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

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

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

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

13:                                               ; preds = %3
  br label %54

14:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %15 = load double, ptr %5, align 8, !tbaa !9
  %16 = fdiv double %15, 2.000000e+00
  store double %16, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = udiv i32 %17, 2
  store i32 %18, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #2
  %19 = getelementptr inbounds [2 x double], ptr %9, i64 0, i64 0
  %20 = load double, ptr %7, align 8, !tbaa !9
  call void @cplx_set_e2pix(ptr noundef %19, double noundef %20)
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  store i64 0, ptr %10, align 8, !tbaa !13
  br label %21

21:                                               ; preds = %40, %14
  %22 = load i64, ptr %10, align 8, !tbaa !13
  %23 = load i32, ptr %8, align 4, !tbaa !5
  %24 = zext i32 %23 to i64
  %25 = icmp ult i64 %22, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  br label %43

27:                                               ; preds = %21
  %28 = load ptr, ptr %6, align 8, !tbaa !11
  %29 = load i64, ptr %10, align 8, !tbaa !13
  %30 = getelementptr inbounds [2 x double], ptr %28, i64 %29
  %31 = getelementptr inbounds [2 x double], ptr %30, i64 0, i64 0
  %32 = load ptr, ptr %6, align 8, !tbaa !11
  %33 = load i64, ptr %10, align 8, !tbaa !13
  %34 = load i32, ptr %8, align 4, !tbaa !5
  %35 = zext i32 %34 to i64
  %36 = add i64 %33, %35
  %37 = getelementptr inbounds [2 x double], ptr %32, i64 %36
  %38 = getelementptr inbounds [2 x double], ptr %37, i64 0, i64 0
  %39 = getelementptr inbounds [2 x double], ptr %9, i64 0, i64 0
  call void @ctwiddle(ptr noundef %31, ptr noundef %38, ptr noundef %39)
  br label %40

40:                                               ; preds = %27
  %41 = load i64, ptr %10, align 8, !tbaa !13
  %42 = add i64 %41, 1
  store i64 %42, ptr %10, align 8, !tbaa !13
  br label %21, !llvm.loop !15

43:                                               ; preds = %26
  %44 = load i32, ptr %8, align 4, !tbaa !5
  %45 = load double, ptr %7, align 8, !tbaa !9
  %46 = load ptr, ptr %6, align 8, !tbaa !11
  call void @cplx_fft_naive(i32 noundef %44, double noundef %45, ptr noundef %46)
  %47 = load i32, ptr %8, align 4, !tbaa !5
  %48 = load double, ptr %7, align 8, !tbaa !9
  %49 = fadd double %48, 5.000000e-01
  %50 = load ptr, ptr %6, align 8, !tbaa !11
  %51 = load i32, ptr %8, align 4, !tbaa !5
  %52 = zext i32 %51 to i64
  %53 = getelementptr inbounds [2 x double], ptr %50, i64 %52
  call void @cplx_fft_naive(i32 noundef %47, double noundef %49, ptr noundef %53)
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  br label %54

54:                                               ; preds = %43, %13
  ret void
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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: nounwind uwtable
declare dso_local void @ctwiddle(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @cplx_fft_naive(i32 noundef %0, double noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = alloca [2 x double], align 16
  %5 = icmp eq i32 %0, 1
  br i1 %5, label %15, label %6

6:                                                ; preds = %3
  %7 = fmul double %1, 5.000000e-01
  %8 = lshr i32 %0, 1
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #3
  call void @cplx_set_e2pix(ptr noundef nonnull %4, double noundef %7)
  %9 = zext nneg i32 %8 to i64
  %.not = icmp eq i32 %0, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %6
  %umax = call i64 @llvm.umax.i64(i64 %9, i64 1)
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %6
  call void @cplx_fft_naive(i32 noundef %8, double noundef %7, ptr noundef %2)
  %10 = fadd double %7, 5.000000e-01
  %11 = getelementptr inbounds [2 x double], ptr %2, i64 %9
  call void @cplx_fft_naive(i32 noundef %8, double noundef %10, ptr noundef %11)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #3
  br label %15

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.020 = phi i64 [ %14, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %12 = getelementptr inbounds [2 x double], ptr %2, i64 %.020
  %13 = getelementptr inbounds [2 x double], ptr %12, i64 %9
  call void @ctwiddle(ptr noundef %12, ptr noundef nonnull %13, ptr noundef nonnull %4)
  %14 = add nuw nsw i64 %.020, 1
  %exitcond.not = icmp eq i64 %14, %umax
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5

15:                                               ; preds = %3, %._crit_edge
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SROAPass,SimplifyCFGPass