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

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

declare void @reim_from_znx64(ptr noundef, ptr noundef, ptr noundef) #0

declare void @reim_fft(ptr noundef, ptr noundef) #0

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

30:                                               ; preds = %7
  %31 = load i64, ptr %10, align 8, !tbaa !9
  br label %34

32:                                               ; preds = %7
  %33 = load i64, ptr %13, align 8, !tbaa !9
  br label %34

34:                                               ; preds = %32, %30
  %35 = phi i64 [ %31, %30 ], [ %33, %32 ]
  store i64 %35, ptr %18, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #4
  store i64 0, ptr %19, align 8, !tbaa !9
  br label %36

36:                                               ; preds = %70, %34
  %37 = load i64, ptr %19, align 8, !tbaa !9
  %38 = load i64, ptr %18, align 8, !tbaa !9
  %39 = icmp ult i64 %37, %38
  br i1 %39, label %41, label %40

40:                                               ; preds = %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #4
  br label %73

41:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #4
  %42 = load ptr, ptr %12, align 8, !tbaa !5
  %43 = load i64, ptr %19, align 8, !tbaa !9
  %44 = load i64, ptr %14, align 8, !tbaa !9
  %45 = mul i64 %43, %44
  %46 = getelementptr inbounds i64, ptr %42, i64 %45
  store ptr %46, ptr %20, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #4
  %47 = load ptr, ptr %16, align 8, !tbaa !5
  %48 = load i64, ptr %19, align 8, !tbaa !9
  %49 = load i64, ptr %15, align 8, !tbaa !9
  %50 = mul i64 %48, %49
  %51 = getelementptr inbounds double, ptr %47, i64 %50
  store ptr %51, ptr %21, align 8, !tbaa !5
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.module_info_t, ptr %52, i32 0, i32 3
  %54 = getelementptr inbounds %struct.fft64_module_info_t, ptr %53, i32 0, i32 2
  %55 = load ptr, ptr %54, align 8, !tbaa !15
  %56 = load ptr, ptr %21, align 8, !tbaa !5
  %57 = load ptr, ptr %20, align 8, !tbaa !5
  call void @reim_from_znx64(ptr noundef %55, ptr noundef %56, ptr noundef %57)
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.module_info_t, ptr %58, i32 0, i32 3
  %60 = getelementptr inbounds %struct.fft64_module_info_t, ptr %59, i32 0, i32 0
  %61 = load ptr, ptr %60, align 8, !tbaa !15
  %62 = load ptr, ptr %21, align 8, !tbaa !5
  call void @reim_fft(ptr noundef %61, ptr noundef %62)
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.module_info_t, ptr %63, i32 0, i32 3
  %65 = getelementptr inbounds %struct.fft64_module_info_t, ptr %64, i32 0, i32 1
  %66 = load ptr, ptr %65, align 8, !tbaa !15
  %67 = load ptr, ptr %21, align 8, !tbaa !5
  %68 = load ptr, ptr %21, align 8, !tbaa !5
  %69 = load ptr, ptr %17, align 8, !tbaa !5
  call void @reim_fftvec_mul(ptr noundef %66, ptr noundef %67, ptr noundef %68, ptr noundef %69)
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #4
  br label %70

70:                                               ; preds = %41
  %71 = load i64, ptr %19, align 8, !tbaa !9
  %72 = add i64 %71, 1
  store i64 %72, ptr %19, align 8, !tbaa !9
  br label %36, !llvm.loop !16

73:                                               ; preds = %40
  %74 = load ptr, ptr %16, align 8, !tbaa !5
  %75 = load i64, ptr %18, align 8, !tbaa !9
  %76 = load i64, ptr %15, align 8, !tbaa !9
  %77 = mul i64 %75, %76
  %78 = getelementptr inbounds double, ptr %74, i64 %77
  %79 = load i64, ptr %10, align 8, !tbaa !9
  %80 = load i64, ptr %18, align 8, !tbaa !9
  %81 = sub i64 %79, %80
  %82 = load i64, ptr %15, 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 %18) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  ret void
}

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

declare void @reim_fftvec_mul(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #0

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

attributes #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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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"

declare void @reim_from_znx64(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @reim_fft(ptr noundef, ptr noundef) local_unnamed_addr #0

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

.lr.ph:                                           ; preds = %7
  %11 = getelementptr inbounds i8, ptr %0, i64 24
  %12 = getelementptr inbounds i8, ptr %0, i64 40
  %13 = getelementptr inbounds i8, ptr %0, i64 32
  br label %19

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

19:                                               ; preds = %.lr.ph, %19
  %.031 = phi i64 [ 0, %.lr.ph ], [ %27, %19 ]
  %20 = mul i64 %.031, %6
  %21 = getelementptr inbounds i64, ptr %4, i64 %20
  %22 = mul i64 %.031, %9
  %23 = getelementptr inbounds double, ptr %1, i64 %22
  %24 = load ptr, ptr %12, align 8, !tbaa !13
  tail call void @reim_from_znx64(ptr noundef %24, ptr noundef %23, ptr noundef %21) #4
  %25 = load ptr, ptr %11, align 8, !tbaa !13
  tail call void @reim_fft(ptr noundef %25, ptr noundef %23) #4
  %26 = load ptr, ptr %13, align 8, !tbaa !13
  tail call void @reim_fftvec_mul(ptr noundef %26, ptr noundef %23, ptr noundef %23, ptr noundef %3) #4
  %27 = add nuw i64 %.031, 1
  %exitcond.not = icmp eq i64 %27, %10
  br i1 %exitcond.not, label %._crit_edge, label %19, !llvm.loop !14
}

declare void @reim_fftvec_mul(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

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

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

attributes #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 = { 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: write) }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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