; LLVM IR from tfhe/spqlios-arithmetic :: spqlios/arithmetic (vec_rnx_svp_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"

%struct.rnx_module_info_t = type { i64, i64, i32, %struct.rnx_module_vtable_t, %union.rnx_module_precomp_t, ptr, ptr }
%struct.rnx_module_vtable_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 }
%union.rnx_module_precomp_t = type { %struct.fft64_rnx_module_precomp_t }
%struct.fft64_rnx_module_precomp_t = type { 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

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

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

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

31:                                               ; preds = %8
  %32 = load i64, ptr %11, align 8, !tbaa !9
  br label %35

33:                                               ; preds = %8
  %34 = load i64, ptr %15, align 8, !tbaa !9
  br label %35

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

37:                                               ; preds = %74, %35
  %38 = load i64, ptr %20, align 8, !tbaa !9
  %39 = load i64, ptr %19, align 8, !tbaa !9
  %40 = icmp ult i64 %38, %39
  br i1 %40, label %42, label %41

41:                                               ; preds = %37
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #5
  br label %77

42:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #5
  %43 = load ptr, ptr %14, align 8, !tbaa !5
  %44 = load i64, ptr %20, align 8, !tbaa !9
  %45 = load i64, ptr %16, align 8, !tbaa !9
  %46 = mul i64 %44, %45
  %47 = getelementptr inbounds double, ptr %43, i64 %46
  store ptr %47, ptr %21, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #5
  %48 = load ptr, ptr %10, align 8, !tbaa !5
  %49 = load i64, ptr %20, align 8, !tbaa !9
  %50 = load i64, ptr %12, align 8, !tbaa !9
  %51 = mul i64 %49, %50
  %52 = getelementptr inbounds double, ptr %48, i64 %51
  store ptr %52, ptr %22, align 8, !tbaa !5
  %53 = load ptr, ptr %22, align 8, !tbaa !5
  %54 = load ptr, ptr %21, align 8, !tbaa !5
  %55 = load i64, ptr %17, align 8, !tbaa !9
  %56 = mul i64 %55, 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %53, ptr align 8 %54, i64 %56, i1 false)
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.rnx_module_info_t, ptr %57, i32 0, i32 4
  %59 = getelementptr inbounds %struct.fft64_rnx_module_precomp_t, ptr %58, i32 0, i32 0
  %60 = load ptr, ptr %59, align 8, !tbaa !15
  %61 = load ptr, ptr %22, align 8, !tbaa !5
  call void @reim_fft(ptr noundef %60, ptr noundef %61)
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.rnx_module_info_t, ptr %62, i32 0, i32 4
  %64 = getelementptr inbounds %struct.fft64_rnx_module_precomp_t, ptr %63, i32 0, i32 2
  %65 = load ptr, ptr %64, align 8, !tbaa !15
  %66 = load ptr, ptr %22, align 8, !tbaa !5
  %67 = load ptr, ptr %22, align 8, !tbaa !5
  %68 = load ptr, ptr %18, align 8, !tbaa !5
  call void @reim_fftvec_mul(ptr noundef %65, ptr noundef %66, ptr noundef %67, ptr noundef %68)
  %69 = load ptr, ptr %9, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.rnx_module_info_t, ptr %69, i32 0, i32 4
  %71 = getelementptr inbounds %struct.fft64_rnx_module_precomp_t, ptr %70, i32 0, i32 1
  %72 = load ptr, ptr %71, align 8, !tbaa !15
  %73 = load ptr, ptr %22, align 8, !tbaa !5
  call void @reim_ifft(ptr noundef %72, ptr noundef %73)
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #5
  br label %74

74:                                               ; preds = %42
  %75 = load i64, ptr %20, align 8, !tbaa !9
  %76 = add i64 %75, 1
  store i64 %76, ptr %20, align 8, !tbaa !9
  br label %37, !llvm.loop !16

77:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #5
  %78 = load i64, ptr %19, align 8, !tbaa !9
  store i64 %78, ptr %23, align 8, !tbaa !9
  br label %79

79:                                               ; preds = %92, %77
  %80 = load i64, ptr %23, align 8, !tbaa !9
  %81 = load i64, ptr %11, align 8, !tbaa !9
  %82 = icmp ult i64 %80, %81
  br i1 %82, label %84, label %83

83:                                               ; preds = %79
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #5
  br label %95

84:                                               ; preds = %79
  %85 = load ptr, ptr %10, align 8, !tbaa !5
  %86 = load i64, ptr %23, align 8, !tbaa !9
  %87 = load i64, ptr %12, align 8, !tbaa !9
  %88 = mul i64 %86, %87
  %89 = getelementptr inbounds double, ptr %85, i64 %88
  %90 = load i64, ptr %17, align 8, !tbaa !9
  %91 = mul i64 %90, 8
  call void @llvm.memset.p0.i64(ptr align 8 %89, i8 0, i64 %91, i1 false)
  br label %92

92:                                               ; preds = %84
  %93 = load i64, ptr %23, align 8, !tbaa !9
  %94 = add i64 %93, 1
  store i64 %94, ptr %23, align 8, !tbaa !9
  br label %79, !llvm.loop !18

95:                                               ; preds = %83
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #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_fftvec_mul(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #1

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 0}
!12 = !{!"rnx_module_info_t", !10, i64 0, !10, i64 8, !13, i64 16, !14, i64 24, !7, i64 328, !6, i64 360, !6, i64 368}
!13 = !{!"int", !7, i64 0}
!14 = !{!"rnx_module_vtable_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}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


; 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_fft(ptr noundef, ptr noundef) local_unnamed_addr #0

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

.lr.ph:                                           ; preds = %8
  %11 = shl i64 %9, 3
  %12 = getelementptr inbounds i8, ptr %0, i64 328
  %13 = getelementptr inbounds i8, ptr %0, i64 344
  %14 = getelementptr inbounds i8, ptr %0, i64 336
  br label %23

.preheader:                                       ; preds = %23, %8
  %15 = icmp ult i64 %6, %2
  br i1 %15, label %.lr.ph37, label %._crit_edge

.lr.ph37:                                         ; preds = %.preheader
  %16 = shl i64 %9, 3
  %17 = sub i64 %2, %10
  %xtraiter = and i64 %17, 7
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.prol.loopexit, label %.prol.preheader

.prol.preheader:                                  ; preds = %.lr.ph37, %.prol.preheader
  %.036.prol = phi i64 [ %20, %.prol.preheader ], [ %10, %.lr.ph37 ]
  %prol.iter = phi i64 [ %prol.iter.next, %.prol.preheader ], [ 0, %.lr.ph37 ]
  %18 = mul i64 %.036.prol, %3
  %19 = getelementptr inbounds double, ptr %1, i64 %18
  tail call void @llvm.memset.p0.i64(ptr align 8 %19, i8 0, i64 %16, i1 false)
  %20 = add nuw i64 %.036.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.prol.loopexit, label %.prol.preheader, !llvm.loop !13

.prol.loopexit:                                   ; preds = %.prol.preheader, %.lr.ph37
  %.036.unr = phi i64 [ %10, %.lr.ph37 ], [ %20, %.prol.preheader ]
  %21 = sub i64 %10, %2
  %22 = icmp ugt i64 %21, -8
  br i1 %22, label %._crit_edge, label %.lr.ph37.new

23:                                               ; preds = %.lr.ph, %23
  %.03335 = phi i64 [ 0, %.lr.ph ], [ %31, %23 ]
  %24 = mul i64 %.03335, %7
  %25 = getelementptr inbounds double, ptr %5, i64 %24
  %26 = mul i64 %.03335, %3
  %27 = getelementptr inbounds double, ptr %1, i64 %26
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 8 %27, ptr align 8 %25, i64 %11, i1 false)
  %28 = load ptr, ptr %12, align 8, !tbaa !15
  tail call void @reim_fft(ptr noundef %28, ptr noundef %27) #5
  %29 = load ptr, ptr %13, align 8, !tbaa !15
  tail call void @reim_fftvec_mul(ptr noundef %29, ptr noundef %27, ptr noundef %27, ptr noundef %4) #5
  %30 = load ptr, ptr %14, align 8, !tbaa !15
  tail call void @reim_ifft(ptr noundef %30, ptr noundef %27) #5
  %31 = add nuw i64 %.03335, 1
  %exitcond.not = icmp eq i64 %31, %10
  br i1 %exitcond.not, label %.preheader, label %23, !llvm.loop !16

._crit_edge:                                      ; preds = %.prol.loopexit, %.lr.ph37.new, %.preheader
  ret void

.lr.ph37.new:                                     ; preds = %.prol.loopexit, %.lr.ph37.new
  %.036 = phi i64 [ %55, %.lr.ph37.new ], [ %.036.unr, %.prol.loopexit ]
  %32 = mul i64 %.036, %3
  %33 = getelementptr inbounds double, ptr %1, i64 %32
  tail call void @llvm.memset.p0.i64(ptr align 8 %33, i8 0, i64 %16, i1 false)
  %34 = add nuw i64 %.036, 1
  %35 = mul i64 %34, %3
  %36 = getelementptr inbounds double, ptr %1, i64 %35
  tail call void @llvm.memset.p0.i64(ptr align 8 %36, i8 0, i64 %16, i1 false)
  %37 = add nuw i64 %.036, 2
  %38 = mul i64 %37, %3
  %39 = getelementptr inbounds double, ptr %1, i64 %38
  tail call void @llvm.memset.p0.i64(ptr align 8 %39, i8 0, i64 %16, i1 false)
  %40 = add nuw i64 %.036, 3
  %41 = mul i64 %40, %3
  %42 = getelementptr inbounds double, ptr %1, i64 %41
  tail call void @llvm.memset.p0.i64(ptr align 8 %42, i8 0, i64 %16, i1 false)
  %43 = add nuw i64 %.036, 4
  %44 = mul i64 %43, %3
  %45 = getelementptr inbounds double, ptr %1, i64 %44
  tail call void @llvm.memset.p0.i64(ptr align 8 %45, i8 0, i64 %16, i1 false)
  %46 = add nuw i64 %.036, 5
  %47 = mul i64 %46, %3
  %48 = getelementptr inbounds double, ptr %1, i64 %47
  tail call void @llvm.memset.p0.i64(ptr align 8 %48, i8 0, i64 %16, i1 false)
  %49 = add nuw i64 %.036, 6
  %50 = mul i64 %49, %3
  %51 = getelementptr inbounds double, ptr %1, i64 %50
  tail call void @llvm.memset.p0.i64(ptr align 8 %51, i8 0, i64 %16, i1 false)
  %52 = add nuw i64 %.036, 7
  %53 = mul i64 %52, %3
  %54 = getelementptr inbounds double, ptr %1, i64 %53
  tail call void @llvm.memset.p0.i64(ptr align 8 %54, i8 0, i64 %16, i1 false)
  %55 = add nuw i64 %.036, 8
  %exitcond38.not.7 = icmp eq i64 %55, %2
  br i1 %exitcond38.not.7, label %._crit_edge, label %.lr.ph37.new, !llvm.loop !18
}

; 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_fftvec_mul(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @reim_ifft(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) #3

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

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: readwrite) }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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, !7, i64 0}
!6 = !{!"rnx_module_info_t", !7, i64 0, !7, i64 8, !10, i64 16, !11, i64 24, !8, i64 328, !12, i64 360, !12, i64 368}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"rnx_module_vtable_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 = !{!"any pointer", !8, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.unroll.disable"}
!15 = !{!8, !8, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


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