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

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

; 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

declare void @znx_zero_i64_ref(i64 noundef, ptr noundef) #1

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

30:                                               ; preds = %45, %9
  %31 = load i64, ptr %22, align 8, !tbaa !9
  %32 = load i64, ptr %13, align 8, !tbaa !9
  %33 = icmp uge i64 %31, %32
  br i1 %33, label %34, label %48

34:                                               ; preds = %30
  %35 = load i64, ptr %19, align 8, !tbaa !9
  %36 = load i64, ptr %11, align 8, !tbaa !9
  %37 = load ptr, ptr %20, align 8, !tbaa !5
  %38 = load ptr, ptr %15, align 8, !tbaa !5
  %39 = load i64, ptr %22, align 8, !tbaa !9
  %40 = load i64, ptr %17, align 8, !tbaa !9
  %41 = mul i64 %39, %40
  %42 = getelementptr inbounds i64, ptr %38, i64 %41
  %43 = load ptr, ptr %21, align 8, !tbaa !5
  call void @znx_normalize(i64 noundef %35, i64 noundef %36, ptr noundef null, ptr noundef %37, ptr noundef %42, ptr noundef %43)
  %44 = load ptr, ptr %20, align 8, !tbaa !5
  store ptr %44, ptr %21, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %34
  %46 = load i64, ptr %22, align 8, !tbaa !9
  %47 = add nsw i64 %46, -1
  store i64 %47, ptr %22, align 8, !tbaa !9
  br label %30, !llvm.loop !15

48:                                               ; preds = %30
  br label %49

49:                                               ; preds = %68, %48
  %50 = load i64, ptr %22, align 8, !tbaa !9
  %51 = icmp sge i64 %50, 1
  br i1 %51, label %52, label %71

52:                                               ; preds = %49
  %53 = load i64, ptr %19, align 8, !tbaa !9
  %54 = load i64, ptr %11, align 8, !tbaa !9
  %55 = load ptr, ptr %12, align 8, !tbaa !5
  %56 = load i64, ptr %22, align 8, !tbaa !9
  %57 = load i64, ptr %14, align 8, !tbaa !9
  %58 = mul i64 %56, %57
  %59 = getelementptr inbounds i64, ptr %55, i64 %58
  %60 = load ptr, ptr %20, align 8, !tbaa !5
  %61 = load ptr, ptr %15, align 8, !tbaa !5
  %62 = load i64, ptr %22, align 8, !tbaa !9
  %63 = load i64, ptr %17, align 8, !tbaa !9
  %64 = mul i64 %62, %63
  %65 = getelementptr inbounds i64, ptr %61, i64 %64
  %66 = load ptr, ptr %21, align 8, !tbaa !5
  call void @znx_normalize(i64 noundef %53, i64 noundef %54, ptr noundef %59, ptr noundef %60, ptr noundef %65, ptr noundef %66)
  %67 = load ptr, ptr %20, align 8, !tbaa !5
  store ptr %67, ptr %21, align 8, !tbaa !5
  br label %68

68:                                               ; preds = %52
  %69 = load i64, ptr %22, align 8, !tbaa !9
  %70 = add nsw i64 %69, -1
  store i64 %70, ptr %22, align 8, !tbaa !9
  br label %49, !llvm.loop !17

71:                                               ; preds = %49
  %72 = load i64, ptr %19, align 8, !tbaa !9
  %73 = load i64, ptr %11, align 8, !tbaa !9
  %74 = load ptr, ptr %12, align 8, !tbaa !5
  %75 = load ptr, ptr %15, align 8, !tbaa !5
  %76 = load ptr, ptr %21, align 8, !tbaa !5
  call void @znx_normalize(i64 noundef %72, i64 noundef %73, ptr noundef %74, ptr noundef null, ptr noundef %75, ptr noundef %76)
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #3
  %77 = load i64, ptr %16, align 8, !tbaa !9
  store i64 %77, ptr %23, align 8, !tbaa !9
  br label %78

78:                                               ; preds = %90, %71
  %79 = load i64, ptr %23, align 8, !tbaa !9
  %80 = load i64, ptr %13, align 8, !tbaa !9
  %81 = icmp ult i64 %79, %80
  br i1 %81, label %83, label %82

82:                                               ; preds = %78
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #3
  br label %93

83:                                               ; preds = %78
  %84 = load i64, ptr %19, align 8, !tbaa !9
  %85 = load ptr, ptr %12, align 8, !tbaa !5
  %86 = load i64, ptr %23, align 8, !tbaa !9
  %87 = load i64, ptr %14, align 8, !tbaa !9
  %88 = mul i64 %86, %87
  %89 = getelementptr inbounds i64, ptr %85, i64 %88
  call void @znx_zero_i64_ref(i64 noundef %84, ptr noundef %89)
  br label %90

90:                                               ; preds = %83
  %91 = load i64, ptr %23, align 8, !tbaa !9
  %92 = add i64 %91, 1
  store i64 %92, ptr %23, align 8, !tbaa !9
  br label %78, !llvm.loop !18

93:                                               ; preds = %82
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #3
  ret void
}

declare void @znx_normalize(i64 noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #1

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

declare void @znx_zero_i64_ref(i64 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @vec_znx_normalize_base2k_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, ptr noundef %8) local_unnamed_addr #1 {
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %11 = load i64, ptr %10, align 8, !tbaa !5
  %.03942 = add i64 %6, -1
  %.not43 = icmp ult i64 %.03942, %3
  br i1 %.not43, label %.preheader, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %9
  %12 = mul i64 %.03942, %7
  %13 = getelementptr inbounds i64, ptr %5, i64 %12
  tail call void @znx_normalize(i64 noundef %11, i64 noundef %1, ptr noundef null, ptr noundef %8, ptr noundef %13, ptr noundef null) #2
  %.039.peel = add i64 %6, -2
  %.not.peel = icmp ult i64 %.039.peel, %3
  br i1 %.not.peel, label %.preheader, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph, %.lr.ph.preheader, %9
  %.040.lcssa = phi ptr [ null, %9 ], [ %8, %.lr.ph.preheader ], [ %8, %.lr.ph ]
  %.039.lcssa = phi i64 [ %.03942, %9 ], [ %.039.peel, %.lr.ph.preheader ], [ %.039, %.lr.ph ]
  %14 = icmp sgt i64 %.039.lcssa, 0
  br i1 %14, label %.lr.ph49.preheader, label %._crit_edge

.lr.ph49.preheader:                               ; preds = %.preheader
  %15 = mul i64 %.039.lcssa, %4
  %16 = getelementptr inbounds i64, ptr %2, i64 %15
  %17 = mul i64 %.039.lcssa, %7
  %18 = getelementptr inbounds i64, ptr %5, i64 %17
  tail call void @znx_normalize(i64 noundef %11, i64 noundef %1, ptr noundef %16, ptr noundef %8, ptr noundef %18, ptr noundef %.040.lcssa) #2
  %.not58 = icmp eq i64 %.039.lcssa, 1
  br i1 %.not58, label %._crit_edge, label %.lr.ph49

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.03945 = phi i64 [ %.039, %.lr.ph ], [ %.039.peel, %.lr.ph.preheader ]
  %19 = mul i64 %.03945, %7
  %20 = getelementptr inbounds i64, ptr %5, i64 %19
  tail call void @znx_normalize(i64 noundef %11, i64 noundef %1, ptr noundef null, ptr noundef %8, ptr noundef %20, ptr noundef %8) #2
  %.039 = add i64 %.03945, -1
  %.not = icmp ult i64 %.039, %3
  br i1 %.not, label %.preheader, label %.lr.ph, !llvm.loop !13

.lr.ph49:                                         ; preds = %.lr.ph49.preheader, %.lr.ph49
  %.148.in = phi i64 [ %.148, %.lr.ph49 ], [ %.039.lcssa, %.lr.ph49.preheader ]
  %.148 = add nsw i64 %.148.in, -1
  %21 = mul i64 %.148, %4
  %22 = getelementptr inbounds i64, ptr %2, i64 %21
  %23 = mul i64 %.148, %7
  %24 = getelementptr inbounds i64, ptr %5, i64 %23
  tail call void @znx_normalize(i64 noundef %11, i64 noundef %1, ptr noundef %22, ptr noundef %8, ptr noundef %24, ptr noundef %8) #2
  %25 = icmp ugt i64 %.148.in, 2
  br i1 %25, label %.lr.ph49, label %._crit_edge, !llvm.loop !16

._crit_edge:                                      ; preds = %.lr.ph49, %.lr.ph49.preheader, %.preheader
  %.141.lcssa = phi ptr [ %.040.lcssa, %.preheader ], [ %8, %.lr.ph49.preheader ], [ %8, %.lr.ph49 ]
  tail call void @znx_normalize(i64 noundef %11, i64 noundef %1, ptr noundef %2, ptr noundef null, ptr noundef %5, ptr noundef %.141.lcssa) #2
  %26 = icmp ult i64 %6, %3
  br i1 %26, label %.lr.ph53, label %._crit_edge54

._crit_edge54:                                    ; preds = %.lr.ph53, %._crit_edge
  ret void

.lr.ph53:                                         ; preds = %._crit_edge, %.lr.ph53
  %.051 = phi i64 [ %29, %.lr.ph53 ], [ %6, %._crit_edge ]
  %27 = mul i64 %.051, %4
  %28 = getelementptr inbounds i64, ptr %2, i64 %27
  tail call void @znx_zero_i64_ref(i64 noundef %11, ptr noundef %28) #2
  %29 = add i64 %.051, 1
  %exitcond.not = icmp eq i64 %29, %3
  br i1 %exitcond.not, label %._crit_edge54, label %.lr.ph53, !llvm.loop !17
}

declare void @znx_normalize(i64 noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

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 = { 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 = distinct !{!13, !14, !15}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!"llvm.loop.peeled.count", i32 1}
!16 = distinct !{!16, !14, !15}
!17 = distinct !{!17, !14}


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