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

; 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

; 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: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

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

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

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

31:                                               ; preds = %29, %27
  %32 = phi i64 [ %28, %27 ], [ %30, %29 ]
  store i64 %32, ptr %16, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  store i64 0, ptr %17, align 8, !tbaa !9
  br label %33

33:                                               ; preds = %53, %31
  %34 = load i64, ptr %17, align 8, !tbaa !9
  %35 = load i64, ptr %16, align 8, !tbaa !9
  %36 = icmp ult i64 %34, %35
  br i1 %36, label %38, label %37

37:                                               ; preds = %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  br label %56

38:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = load i64, ptr %17, align 8, !tbaa !9
  %41 = load i64, ptr %11, align 8, !tbaa !9
  %42 = mul i64 %40, %41
  %43 = getelementptr inbounds double, ptr %39, i64 %42
  store ptr %43, ptr %18, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #4
  %44 = load ptr, ptr %12, align 8, !tbaa !5
  %45 = load i64, ptr %17, align 8, !tbaa !9
  %46 = load i64, ptr %14, align 8, !tbaa !9
  %47 = mul i64 %45, %46
  %48 = getelementptr inbounds double, ptr %44, i64 %47
  store ptr %48, ptr %19, align 8, !tbaa !5
  %49 = load ptr, ptr %18, align 8, !tbaa !5
  %50 = load ptr, ptr %19, align 8, !tbaa !5
  %51 = load i64, ptr %15, align 8, !tbaa !9
  %52 = mul i64 %51, 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %49, ptr align 8 %50, i64 %52, i1 false)
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  br label %53

53:                                               ; preds = %38
  %54 = load i64, ptr %17, align 8, !tbaa !9
  %55 = add i64 %54, 1
  store i64 %55, ptr %17, align 8, !tbaa !9
  br label %33, !llvm.loop !15

56:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #4
  %57 = load i64, ptr %16, align 8, !tbaa !9
  store i64 %57, ptr %20, align 8, !tbaa !9
  br label %58

58:                                               ; preds = %71, %56
  %59 = load i64, ptr %20, align 8, !tbaa !9
  %60 = load i64, ptr %10, align 8, !tbaa !9
  %61 = icmp ult i64 %59, %60
  br i1 %61, label %63, label %62

62:                                               ; preds = %58
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #4
  br label %74

63:                                               ; preds = %58
  %64 = load ptr, ptr %9, align 8, !tbaa !5
  %65 = load i64, ptr %20, align 8, !tbaa !9
  %66 = load i64, ptr %11, align 8, !tbaa !9
  %67 = mul i64 %65, %66
  %68 = getelementptr inbounds double, ptr %64, i64 %67
  %69 = load i64, ptr %15, align 8, !tbaa !9
  %70 = mul i64 %69, 8
  call void @llvm.memset.p0.i64(ptr align 8 %68, i8 0, i64 %70, i1 false)
  br label %71

71:                                               ; preds = %63
  %72 = load i64, ptr %20, align 8, !tbaa !9
  %73 = add i64 %72, 1
  store i64 %73, ptr %20, align 8, !tbaa !9
  br label %58, !llvm.loop !17

74:                                               ; preds = %62
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { 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 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


; 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: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

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

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

.lr.ph:                                           ; preds = %7
  %10 = shl i64 %8, 3
  %xtraiter = and i64 %9, 1
  %11 = icmp eq i64 %9, 1
  br i1 %11, label %.preheader.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %9, -2
  br label %24

.preheader.loopexit.unr-lcssa:                    ; preds = %24, %.lr.ph
  %.02426.unr = phi i64 [ 0, %.lr.ph ], [ %34, %24 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader, label %.preheader.loopexit.epilog-lcssa

.preheader.loopexit.epilog-lcssa:                 ; preds = %.preheader.loopexit.unr-lcssa
  %12 = mul i64 %.02426.unr, %3
  %13 = getelementptr inbounds double, ptr %1, i64 %12
  %14 = mul i64 %.02426.unr, %6
  %15 = getelementptr inbounds double, ptr %4, i64 %14
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 8 %13, ptr align 8 %15, i64 %10, i1 false)
  br label %.preheader

.preheader:                                       ; preds = %.preheader.loopexit.epilog-lcssa, %.preheader.loopexit.unr-lcssa, %7
  %16 = icmp ult i64 %5, %2
  br i1 %16, label %.lr.ph28, label %._crit_edge

.lr.ph28:                                         ; preds = %.preheader
  %17 = shl i64 %8, 3
  %18 = sub i64 %2, %9
  %xtraiter30 = and i64 %18, 7
  %lcmp.mod31.not = icmp eq i64 %xtraiter30, 0
  br i1 %lcmp.mod31.not, label %.prol.loopexit, label %.prol.preheader

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

.prol.loopexit:                                   ; preds = %.prol.preheader, %.lr.ph28
  %.027.unr = phi i64 [ %9, %.lr.ph28 ], [ %21, %.prol.preheader ]
  %22 = sub i64 %9, %2
  %23 = icmp ugt i64 %22, -8
  br i1 %23, label %._crit_edge, label %.lr.ph28.new

24:                                               ; preds = %24, %.lr.ph.new
  %.02426 = phi i64 [ 0, %.lr.ph.new ], [ %34, %24 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %24 ]
  %25 = mul i64 %.02426, %3
  %26 = getelementptr inbounds double, ptr %1, i64 %25
  %27 = mul i64 %.02426, %6
  %28 = getelementptr inbounds double, ptr %4, i64 %27
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 8 %26, ptr align 8 %28, i64 %10, i1 false)
  %29 = or disjoint i64 %.02426, 1
  %30 = mul i64 %29, %3
  %31 = getelementptr inbounds double, ptr %1, i64 %30
  %32 = mul i64 %29, %6
  %33 = getelementptr inbounds double, ptr %4, i64 %32
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 8 %31, ptr align 8 %33, i64 %10, i1 false)
  %34 = add nuw i64 %.02426, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.preheader.loopexit.unr-lcssa, label %24, !llvm.loop !15

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

.lr.ph28.new:                                     ; preds = %.prol.loopexit, %.lr.ph28.new
  %.027 = phi i64 [ %58, %.lr.ph28.new ], [ %.027.unr, %.prol.loopexit ]
  %35 = mul i64 %.027, %3
  %36 = getelementptr inbounds double, ptr %1, i64 %35
  tail call void @llvm.memset.p0.i64(ptr align 8 %36, i8 0, i64 %17, i1 false)
  %37 = add nuw i64 %.027, 1
  %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 %17, i1 false)
  %40 = add nuw i64 %.027, 2
  %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 %17, i1 false)
  %43 = add nuw i64 %.027, 3
  %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 %17, i1 false)
  %46 = add nuw i64 %.027, 4
  %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 %17, i1 false)
  %49 = add nuw i64 %.027, 5
  %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 %17, i1 false)
  %52 = add nuw i64 %.027, 6
  %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 %17, i1 false)
  %55 = add nuw i64 %.027, 7
  %56 = mul i64 %55, %3
  %57 = getelementptr inbounds double, ptr %1, i64 %56
  tail call void @llvm.memset.p0.i64(ptr align 8 %57, i8 0, i64 %17, i1 false)
  %58 = add nuw i64 %.027, 8
  %exitcond29.not.7 = icmp eq i64 %58, %2
  br i1 %exitcond29.not.7, label %._crit_edge, label %.lr.ph28.new, !llvm.loop !17
}

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

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { nofree norecurse nosync nounwind memory(argmem: readwrite) 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 nosync nounwind speculatable willreturn memory(none) }

!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 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


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