; 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 }
%struct.q120_module_info_t = type { 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: 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

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

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

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

28:                                               ; preds = %26, %24
  %29 = phi i64 [ %25, %24 ], [ %27, %26 ]
  store i64 %29, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %30, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #5
  %31 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %31, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #5
  store i64 0, ptr %17, align 8, !tbaa !9
  br label %32

32:                                               ; preds = %60, %28
  %33 = load i64, ptr %17, align 8, !tbaa !9
  %34 = load i64, ptr %14, align 8, !tbaa !9
  %35 = icmp ult i64 %33, %34
  br i1 %35, label %37, label %36

36:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #5
  br label %63

37:                                               ; preds = %32
  %38 = load ptr, ptr %12, align 8, !tbaa !5
  %39 = load ptr, ptr %16, align 8, !tbaa !5
  %40 = load i64, ptr %17, align 8, !tbaa !9
  %41 = load i64, ptr %13, align 8, !tbaa !9
  %42 = mul i64 %40, %41
  %43 = mul i64 %42, 4
  %44 = getelementptr inbounds i64, ptr %39, i64 %43
  %45 = load i64, ptr %13, align 8, !tbaa !9
  %46 = mul i64 %45, 4
  %47 = mul i64 %46, 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %38, ptr align 8 %44, i64 %47, i1 false)
  %48 = load ptr, ptr %7, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.module_info_t, ptr %48, i32 0, i32 3
  %50 = getelementptr inbounds %struct.q120_module_info_t, ptr %49, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !15
  %52 = load ptr, ptr %12, align 8, !tbaa !5
  call void @q120_intt_bb_avx2(ptr noundef %51, ptr noundef %52)
  %53 = load i64, ptr %13, align 8, !tbaa !9
  %54 = load ptr, ptr %15, align 8, !tbaa !5
  %55 = load i64, ptr %17, align 8, !tbaa !9
  %56 = load i64, ptr %13, align 8, !tbaa !9
  %57 = mul i64 %55, %56
  %58 = getelementptr inbounds i128, ptr %54, i64 %57
  %59 = load ptr, ptr %12, align 8, !tbaa !5
  call void @q120_b_to_znx128_simple(i64 noundef %53, ptr noundef %58, ptr noundef %59)
  br label %60

60:                                               ; preds = %37
  %61 = load i64, ptr %17, align 8, !tbaa !9
  %62 = add i64 %61, 1
  store i64 %62, ptr %17, align 8, !tbaa !9
  br label %32, !llvm.loop !16

63:                                               ; preds = %36
  %64 = load ptr, ptr %15, align 8, !tbaa !5
  %65 = load i64, ptr %14, align 8, !tbaa !9
  %66 = load i64, ptr %13, align 8, !tbaa !9
  %67 = mul i64 %65, %66
  %68 = getelementptr inbounds i128, ptr %64, i64 %67
  %69 = load i64, ptr %9, align 8, !tbaa !9
  %70 = load i64, ptr %14, align 8, !tbaa !9
  %71 = sub i64 %69, %70
  %72 = load i64, ptr %13, align 8, !tbaa !9
  %73 = mul i64 %71, %72
  %74 = mul i64 %73, 16
  call void @llvm.memset.p0.i64(ptr align 16 %68, i8 0, i64 %74, i1 false)
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #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
}

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

declare void @q120_b_to_znx128_simple(i64 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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: 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) #1

; Function Attrs: nounwind uwtable
define dso_local void @ntt120_vec_znx_idft_avx(ptr nocapture noundef readonly %0, ptr noundef %1, i64 noundef %2, ptr nocapture noundef readonly %3, i64 noundef %4, ptr noundef %5) local_unnamed_addr #2 {
  %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 i64 %9, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %6
  %10 = shl i64 %8, 5
  %11 = getelementptr inbounds i8, ptr %0, i64 32
  br label %17

._crit_edge:                                      ; preds = %17, %6
  %12 = mul i64 %8, %9
  %13 = getelementptr inbounds i128, ptr %1, i64 %12
  %14 = sub i64 %2, %9
  %15 = shl i64 %14, 4
  %16 = mul i64 %15, %8
  tail call void @llvm.memset.p0.i64(ptr align 16 %13, i8 0, i64 %16, i1 false)
  ret void

17:                                               ; preds = %.lr.ph, %17
  %.028 = phi i64 [ 0, %.lr.ph ], [ %22, %17 ]
  %18 = mul i64 %.028, %8
  %.idx = shl i64 %18, 5
  %19 = getelementptr inbounds i8, ptr %3, i64 %.idx
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %5, ptr align 8 %19, i64 %10, i1 false)
  %20 = load ptr, ptr %11, align 8, !tbaa !13
  tail call void @q120_intt_bb_avx2(ptr noundef %20, ptr noundef %5) #5
  %21 = getelementptr inbounds i128, ptr %1, i64 %18
  tail call void @q120_b_to_znx128_simple(i64 noundef %8, ptr noundef %21, ptr noundef %5) #5
  %22 = add nuw i64 %.028, 1
  %exitcond.not = icmp eq i64 %22, %9
  br i1 %exitcond.not, label %._crit_edge, label %17, !llvm.loop !14
}

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

declare void @q120_b_to_znx128_simple(i64 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { "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,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass