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

; Function Attrs: nounwind uwtable
define dso_local void @cplx_ifft_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_e2pimx(ptr noundef %19, double noundef %20)
  %21 = load i32, ptr %8, align 4, !tbaa !5
  %22 = load double, ptr %7, align 8, !tbaa !9
  %23 = load ptr, ptr %6, align 8, !tbaa !11
  call void @cplx_ifft_naive(i32 noundef %21, double noundef %22, ptr noundef %23)
  %24 = load i32, ptr %8, align 4, !tbaa !5
  %25 = load double, ptr %7, align 8, !tbaa !9
  %26 = fadd double %25, 5.000000e-01
  %27 = load ptr, ptr %6, align 8, !tbaa !11
  %28 = load i32, ptr %8, align 4, !tbaa !5
  %29 = zext i32 %28 to i64
  %30 = getelementptr inbounds [2 x double], ptr %27, i64 %29
  call void @cplx_ifft_naive(i32 noundef %24, double noundef %26, ptr noundef %30)
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  store i64 0, ptr %10, align 8, !tbaa !13
  br label %31

31:                                               ; preds = %50, %14
  %32 = load i64, ptr %10, align 8, !tbaa !13
  %33 = load i32, ptr %8, align 4, !tbaa !5
  %34 = zext i32 %33 to i64
  %35 = icmp ult i64 %32, %34
  br i1 %35, label %37, label %36

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

37:                                               ; preds = %31
  %38 = load ptr, ptr %6, align 8, !tbaa !11
  %39 = load i64, ptr %10, align 8, !tbaa !13
  %40 = getelementptr inbounds [2 x double], ptr %38, i64 %39
  %41 = getelementptr inbounds [2 x double], ptr %40, i64 0, i64 0
  %42 = load ptr, ptr %6, align 8, !tbaa !11
  %43 = load i64, ptr %10, align 8, !tbaa !13
  %44 = load i32, ptr %8, align 4, !tbaa !5
  %45 = zext i32 %44 to i64
  %46 = add i64 %43, %45
  %47 = getelementptr inbounds [2 x double], ptr %42, i64 %46
  %48 = getelementptr inbounds [2 x double], ptr %47, i64 0, i64 0
  %49 = getelementptr inbounds [2 x double], ptr %9, i64 0, i64 0
  call void @invctwiddle(ptr noundef %41, ptr noundef %48, ptr noundef %49)
  br label %50

50:                                               ; preds = %37
  %51 = load i64, ptr %10, align 8, !tbaa !13
  %52 = add i64 %51, 1
  store i64 %52, ptr %10, align 8, !tbaa !13
  br label %31, !llvm.loop !15

53:                                               ; preds = %36
  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 = %53, %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 @invctwiddle(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_e2pimx(ptr noundef, double noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @cplx_ifft_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_e2pimx(ptr noundef nonnull %4, double noundef %7)
  call void @cplx_ifft_naive(i32 noundef %8, double noundef %7, ptr noundef %2)
  %9 = fadd double %7, 5.000000e-01
  %10 = zext nneg i32 %8 to i64
  %11 = getelementptr inbounds [2 x double], ptr %2, i64 %10
  call void @cplx_ifft_naive(i32 noundef %8, double noundef %9, ptr noundef %11)
  %.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 %10, i64 1)
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %6
  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 %10
  call void @invctwiddle(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,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass