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

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

29:                                               ; preds = %8
  %30 = load i64, ptr %12, align 8, !tbaa !9
  br label %33

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

33:                                               ; preds = %31, %29
  %34 = phi i64 [ %30, %29 ], [ %32, %31 ]
  store i64 %34, 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 %35

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

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

40:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #4
  %41 = load ptr, ptr %11, align 8, !tbaa !5
  %42 = load i64, ptr %19, align 8, !tbaa !9
  %43 = load i64, ptr %13, align 8, !tbaa !9
  %44 = mul i64 %42, %43
  %45 = getelementptr inbounds double, ptr %41, i64 %44
  store ptr %45, ptr %20, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #4
  %46 = load ptr, ptr %14, align 8, !tbaa !5
  %47 = load i64, ptr %19, align 8, !tbaa !9
  %48 = load i64, ptr %16, align 8, !tbaa !9
  %49 = mul i64 %47, %48
  %50 = getelementptr inbounds double, ptr %46, i64 %49
  store ptr %50, ptr %21, align 8, !tbaa !5
  %51 = load ptr, ptr %20, align 8, !tbaa !5
  %52 = load ptr, ptr %21, align 8, !tbaa !5
  %53 = icmp eq ptr %51, %52
  br i1 %53, label %54, label %58

54:                                               ; preds = %40
  %55 = load i64, ptr %17, align 8, !tbaa !9
  %56 = load i64, ptr %10, align 8, !tbaa !9
  %57 = load ptr, ptr %20, align 8, !tbaa !5
  call void @rnx_automorphism_inplace_f64(i64 noundef %55, i64 noundef %56, ptr noundef %57)
  br label %63

58:                                               ; preds = %40
  %59 = load i64, ptr %17, align 8, !tbaa !9
  %60 = load i64, ptr %10, align 8, !tbaa !9
  %61 = load ptr, ptr %20, align 8, !tbaa !5
  %62 = load ptr, ptr %21, align 8, !tbaa !5
  call void @rnx_automorphism_f64(i64 noundef %59, i64 noundef %60, ptr noundef %61, ptr noundef %62)
  br label %63

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

64:                                               ; preds = %63
  %65 = load i64, ptr %19, align 8, !tbaa !9
  %66 = add i64 %65, 1
  store i64 %66, ptr %19, align 8, !tbaa !9
  br label %35, !llvm.loop !15

67:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #4
  %68 = load i64, ptr %18, align 8, !tbaa !9
  store i64 %68, ptr %22, align 8, !tbaa !9
  br label %69

69:                                               ; preds = %82, %67
  %70 = load i64, ptr %22, align 8, !tbaa !9
  %71 = load i64, ptr %12, align 8, !tbaa !9
  %72 = icmp ult i64 %70, %71
  br i1 %72, label %74, label %73

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

74:                                               ; preds = %69
  %75 = load ptr, ptr %11, align 8, !tbaa !5
  %76 = load i64, ptr %22, align 8, !tbaa !9
  %77 = load i64, ptr %13, align 8, !tbaa !9
  %78 = mul i64 %76, %77
  %79 = getelementptr inbounds double, ptr %75, i64 %78
  %80 = load i64, ptr %17, align 8, !tbaa !9
  %81 = mul i64 %80, 8
  call void @llvm.memset.p0.i64(ptr align 8 %79, i8 0, i64 %81, i1 false)
  br label %82

82:                                               ; preds = %74
  %83 = load i64, ptr %22, align 8, !tbaa !9
  %84 = add i64 %83, 1
  store i64 %84, ptr %22, align 8, !tbaa !9
  br label %69, !llvm.loop !17

85:                                               ; preds = %73
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  ret void
}

declare void @rnx_automorphism_inplace_f64(i64 noundef, i64 noundef, ptr noundef) #3

declare void @rnx_automorphism_f64(i64 noundef, i64 noundef, ptr noundef, ptr noundef) #3

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 = { "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: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

; Function Attrs: nounwind uwtable
define dso_local void @vec_rnx_automorphism_ref(ptr nocapture noundef readonly %0, i64 noundef %1, ptr noundef %2, i64 noundef %3, i64 noundef %4, ptr noundef %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 %3, i64 %6)
  %.not = icmp eq i64 %10, 0
  br i1 %.not, label %.preheader, label %.lr.ph

.preheader:                                       ; preds = %26, %8
  %11 = icmp ult i64 %6, %3
  br i1 %11, label %.lr.ph36, label %._crit_edge

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

.prol.preheader:                                  ; preds = %.lr.ph36, %.prol.preheader
  %.035.prol = phi i64 [ %16, %.prol.preheader ], [ %10, %.lr.ph36 ]
  %prol.iter = phi i64 [ %prol.iter.next, %.prol.preheader ], [ 0, %.lr.ph36 ]
  %14 = mul i64 %.035.prol, %4
  %15 = getelementptr inbounds double, ptr %2, i64 %14
  tail call void @llvm.memset.p0.i64(ptr align 8 %15, i8 0, i64 %12, i1 false)
  %16 = add nuw i64 %.035.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.ph36
  %.035.unr = phi i64 [ %10, %.lr.ph36 ], [ %16, %.prol.preheader ]
  %17 = sub i64 %10, %3
  %18 = icmp ugt i64 %17, -8
  br i1 %18, label %._crit_edge, label %.lr.ph36.new

.lr.ph:                                           ; preds = %8, %26
  %.03034 = phi i64 [ %27, %26 ], [ 0, %8 ]
  %19 = mul i64 %.03034, %4
  %20 = getelementptr inbounds double, ptr %2, i64 %19
  %21 = mul i64 %.03034, %7
  %22 = getelementptr inbounds double, ptr %5, i64 %21
  %23 = icmp eq ptr %20, %22
  br i1 %23, label %24, label %25

24:                                               ; preds = %.lr.ph
  tail call void @rnx_automorphism_inplace_f64(i64 noundef %9, i64 noundef %1, ptr noundef %20) #4
  br label %26

25:                                               ; preds = %.lr.ph
  tail call void @rnx_automorphism_f64(i64 noundef %9, i64 noundef %1, ptr noundef %20, ptr noundef %22) #4
  br label %26

26:                                               ; preds = %25, %24
  %27 = add nuw i64 %.03034, 1
  %exitcond.not = icmp eq i64 %27, %10
  br i1 %exitcond.not, label %.preheader, label %.lr.ph, !llvm.loop !15

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

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

declare void @rnx_automorphism_inplace_f64(i64 noundef, i64 noundef, ptr noundef) local_unnamed_addr #2

declare void @rnx_automorphism_f64(i64 noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; 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: 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 = { "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) }
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, !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