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

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

%struct.module_info_t = type { i32, i64, i64, %union.backend_module_info_t, %struct.module_virtual_functions_t }
%union.backend_module_info_t = type { %struct.fft64_module_info_t }
%struct.fft64_module_info_t = type { ptr, ptr, ptr, ptr, ptr, ptr }
%struct.module_virtual_functions_t = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

; 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: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
define dso_local void @fft64_vec_znx_idft(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5) #2 {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  %16 = alloca ptr, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i64 %2, ptr %9, align 8, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i64 %4, ptr %11, align 8, !tbaa !9
  store ptr %5, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.module_info_t, ptr %17, i32 0, i32 1
  %19 = load i64, ptr %18, align 8, !tbaa !11
  store i64 %19, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  %20 = load i64, ptr %9, align 8, !tbaa !9
  %21 = load i64, ptr %11, align 8, !tbaa !9
  %22 = icmp ult i64 %20, %21
  br i1 %22, label %23, label %25

23:                                               ; preds = %6
  %24 = load i64, ptr %9, align 8, !tbaa !9
  br label %27

25:                                               ; preds = %6
  %26 = load i64, ptr %11, align 8, !tbaa !9
  br label %27

27:                                               ; preds = %25, %23
  %28 = phi i64 [ %24, %23 ], [ %26, %25 ]
  store i64 %28, ptr %14, align 8, !tbaa !9
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  %31 = icmp ne ptr %29, %30
  br i1 %31, label %32, label %39

32:                                               ; preds = %27
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = load ptr, ptr %10, align 8, !tbaa !5
  %35 = load i64, ptr %14, align 8, !tbaa !9
  %36 = load i64, ptr %13, align 8, !tbaa !9
  %37 = mul i64 %35, %36
  %38 = mul i64 %37, 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %33, ptr align 1 %34, i64 %38, i1 false)
  br label %39

39:                                               ; preds = %32, %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  store i64 0, ptr %15, align 8, !tbaa !9
  br label %40

40:                                               ; preds = %69, %39
  %41 = load i64, ptr %15, align 8, !tbaa !9
  %42 = load i64, ptr %14, align 8, !tbaa !9
  %43 = icmp ult i64 %41, %42
  br i1 %43, label %45, label %44

44:                                               ; preds = %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  br label %72

45:                                               ; preds = %40
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.module_info_t, ptr %46, i32 0, i32 3
  %48 = getelementptr inbounds %struct.fft64_module_info_t, ptr %47, i32 0, i32 4
  %49 = load ptr, ptr %48, align 8, !tbaa !15
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = load i64, ptr %15, align 8, !tbaa !9
  %52 = load i64, ptr %13, align 8, !tbaa !9
  %53 = mul i64 %51, %52
  %54 = getelementptr inbounds double, ptr %50, i64 %53
  call void @reim_ifft(ptr noundef %49, ptr noundef %54)
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.module_info_t, ptr %55, i32 0, i32 3
  %57 = getelementptr inbounds %struct.fft64_module_info_t, ptr %56, i32 0, i32 3
  %58 = load ptr, ptr %57, align 8, !tbaa !15
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  %60 = load i64, ptr %15, align 8, !tbaa !9
  %61 = load i64, ptr %13, align 8, !tbaa !9
  %62 = mul i64 %60, %61
  %63 = getelementptr inbounds i64, ptr %59, i64 %62
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  %65 = load i64, ptr %15, align 8, !tbaa !9
  %66 = load i64, ptr %13, align 8, !tbaa !9
  %67 = mul i64 %65, %66
  %68 = getelementptr inbounds i64, ptr %64, i64 %67
  call void @reim_to_znx64(ptr noundef %58, ptr noundef %63, ptr noundef %68)
  br label %69

69:                                               ; preds = %45
  %70 = load i64, ptr %15, align 8, !tbaa !9
  %71 = add i64 %70, 1
  store i64 %71, ptr %15, align 8, !tbaa !9
  br label %40, !llvm.loop !16

72:                                               ; preds = %44
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #5
  %73 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %73, ptr %16, align 8, !tbaa !5
  %74 = load ptr, ptr %16, align 8, !tbaa !5
  %75 = load i64, ptr %14, align 8, !tbaa !9
  %76 = load i64, ptr %13, align 8, !tbaa !9
  %77 = mul i64 %75, %76
  %78 = getelementptr inbounds i64, ptr %74, i64 %77
  %79 = load i64, ptr %9, align 8, !tbaa !9
  %80 = load i64, ptr %14, align 8, !tbaa !9
  %81 = sub i64 %79, %80
  %82 = load i64, ptr %13, align 8, !tbaa !9
  %83 = mul i64 %81, %82
  %84 = mul i64 %83, 8
  call void @llvm.memset.p0.i64(ptr align 8 %78, i8 0, i64 %84, i1 false)
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

declare void @reim_ifft(ptr noundef, ptr noundef) #4

declare void @reim_to_znx64(ptr noundef, ptr noundef, ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { "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 #5 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"module_info_t", !13, i64 0, !10, i64 8, !10, i64 16, !7, i64 24, !14, i64 72}
!13 = !{!"int", !7, i64 0}
!14 = !{!"module_virtual_functions_t", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240, !6, i64 248, !6, i64 256, !6, i64 264, !6, i64 272, !6, i64 280, !6, i64 288, !6, i64 296, !6, i64 304, !6, i64 312}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

; Function Attrs: nounwind uwtable
define dso_local void @fft64_vec_znx_idft(ptr nocapture noundef readonly %0, ptr noundef %1, i64 noundef %2, ptr noundef readonly %3, i64 noundef %4, ptr nocapture noundef readnone %5) local_unnamed_addr #1 {
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load i64, ptr %7, align 8, !tbaa !5
  %9 = tail call i64 @llvm.umin.i64(i64 %2, i64 %4)
  %.not = icmp eq ptr %1, %3
  br i1 %.not, label %13, label %10

10:                                               ; preds = %6
  %11 = mul i64 %8, %9
  %12 = shl i64 %11, 3
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %1, ptr align 1 %3, i64 %12, i1 false)
  br label %13

13:                                               ; preds = %10, %6
  %.not35 = icmp eq i64 %9, 0
  br i1 %.not35, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %13
  %14 = getelementptr inbounds i8, ptr %0, i64 56
  %15 = getelementptr inbounds i8, ptr %0, i64 48
  br label %21

._crit_edge:                                      ; preds = %21, %13
  %16 = mul i64 %8, %9
  %17 = getelementptr inbounds i64, ptr %1, i64 %16
  %18 = sub i64 %2, %9
  %19 = shl i64 %18, 3
  %20 = mul i64 %19, %8
  tail call void @llvm.memset.p0.i64(ptr align 8 %17, i8 0, i64 %20, i1 false)
  ret void

21:                                               ; preds = %.lr.ph, %21
  %.034 = phi i64 [ 0, %.lr.ph ], [ %26, %21 ]
  %22 = load ptr, ptr %14, align 8, !tbaa !13
  %23 = mul i64 %.034, %8
  %24 = getelementptr inbounds double, ptr %1, i64 %23
  tail call void @reim_ifft(ptr noundef %22, ptr noundef %24) #5
  %25 = load ptr, ptr %15, align 8, !tbaa !13
  tail call void @reim_to_znx64(ptr noundef %25, ptr noundef %24, ptr noundef %24) #5
  %26 = add nuw i64 %.034, 1
  %exitcond.not = icmp eq i64 %26, %9
  br i1 %exitcond.not, label %._crit_edge, label %21, !llvm.loop !14
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

declare void @reim_ifft(ptr noundef, ptr noundef) local_unnamed_addr #3

declare void @reim_to_znx64(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #4

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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, !10, i64 8}
!6 = !{!"module_info_t", !7, i64 0, !10, i64 8, !10, i64 16, !8, i64 24, !11, i64 72}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"module_virtual_functions_t", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !12, i64 80, !12, i64 88, !12, i64 96, !12, i64 104, !12, i64 112, !12, i64 120, !12, i64 128, !12, i64 136, !12, i64 144, !12, i64 152, !12, i64 160, !12, i64 168, !12, i64 176, !12, i64 184, !12, i64 192, !12, i64 200, !12, i64 208, !12, i64 216, !12, i64 224, !12, i64 232, !12, i64 240, !12, i64 248, !12, i64 256, !12, i64 264, !12, i64 272, !12, i64 280, !12, i64 288, !12, i64 296, !12, i64 304, !12, i64 312}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!8, !8, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass