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

; 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: alwaysinline nounwind uwtable
declare hidden void @accum_mul_q120_bc(ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @accum_to_q120b(ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @q120x2_vec_mat1col_product_bbc_ref(ptr noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #3 {
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca [2 x [16 x i64]], align 16
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  store ptr %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 256, ptr %11) #4
  call void @llvm.memset.p0.i64(ptr align 16 %11, i8 0, i64 256, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %16 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %16, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %17 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %17, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %18, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  store i64 0, ptr %15, align 8, !tbaa !9
  br label %19

19:                                               ; preds = %49, %5
  %20 = load i64, ptr %15, align 8, !tbaa !9
  %21 = load i64, ptr %7, align 8, !tbaa !9
  %22 = icmp ult i64 %20, %21
  br i1 %22, label %24, label %23

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

24:                                               ; preds = %19
  %25 = getelementptr inbounds [2 x [16 x i64]], ptr %11, i64 0, i64 0
  %26 = getelementptr inbounds [16 x i64], ptr %25, i64 0, i64 0
  %27 = load ptr, ptr %12, align 8, !tbaa !5
  %28 = load i64, ptr %15, align 8, !tbaa !9
  %29 = getelementptr inbounds [2 x [8 x i32]], ptr %27, i64 %28
  %30 = getelementptr inbounds [2 x [8 x i32]], ptr %29, i64 0, i64 0
  %31 = getelementptr inbounds [8 x i32], ptr %30, i64 0, i64 0
  %32 = load ptr, ptr %13, align 8, !tbaa !5
  %33 = load i64, ptr %15, align 8, !tbaa !9
  %34 = getelementptr inbounds [2 x [8 x i32]], ptr %32, i64 %33
  %35 = getelementptr inbounds [2 x [8 x i32]], ptr %34, i64 0, i64 0
  %36 = getelementptr inbounds [8 x i32], ptr %35, i64 0, i64 0
  call void @accum_mul_q120_bc(ptr noundef %26, ptr noundef %31, ptr noundef %36)
  %37 = getelementptr inbounds [2 x [16 x i64]], ptr %11, i64 0, i64 1
  %38 = getelementptr inbounds [16 x i64], ptr %37, i64 0, i64 0
  %39 = load ptr, ptr %12, align 8, !tbaa !5
  %40 = load i64, ptr %15, align 8, !tbaa !9
  %41 = getelementptr inbounds [2 x [8 x i32]], ptr %39, i64 %40
  %42 = getelementptr inbounds [2 x [8 x i32]], ptr %41, i64 0, i64 1
  %43 = getelementptr inbounds [8 x i32], ptr %42, i64 0, i64 0
  %44 = load ptr, ptr %13, align 8, !tbaa !5
  %45 = load i64, ptr %15, align 8, !tbaa !9
  %46 = getelementptr inbounds [2 x [8 x i32]], ptr %44, i64 %45
  %47 = getelementptr inbounds [2 x [8 x i32]], ptr %46, i64 0, i64 1
  %48 = getelementptr inbounds [8 x i32], ptr %47, i64 0, i64 0
  call void @accum_mul_q120_bc(ptr noundef %38, ptr noundef %43, ptr noundef %48)
  br label %49

49:                                               ; preds = %24
  %50 = load i64, ptr %15, align 8, !tbaa !9
  %51 = add i64 %50, 1
  store i64 %51, ptr %15, align 8, !tbaa !9
  br label %19, !llvm.loop !11

52:                                               ; preds = %23
  %53 = load ptr, ptr %14, align 8, !tbaa !5
  %54 = getelementptr inbounds [4 x i64], ptr %53, i64 0
  %55 = getelementptr inbounds [4 x i64], ptr %54, i64 0, i64 0
  %56 = getelementptr inbounds [2 x [16 x i64]], ptr %11, i64 0, i64 0
  %57 = getelementptr inbounds [16 x i64], ptr %56, i64 0, i64 0
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  call void @accum_to_q120b(ptr noundef %55, ptr noundef %57, ptr noundef %58)
  %59 = load ptr, ptr %14, align 8, !tbaa !5
  %60 = getelementptr inbounds [4 x i64], ptr %59, i64 1
  %61 = getelementptr inbounds [4 x i64], ptr %60, i64 0, i64 0
  %62 = getelementptr inbounds [2 x [16 x i64]], ptr %11, i64 0, i64 1
  %63 = getelementptr inbounds [16 x i64], ptr %62, i64 0, i64 0
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  call void @accum_to_q120b(ptr noundef %61, ptr noundef %63, ptr noundef %64)
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 256, ptr %11) #4
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { alwaysinline 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 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 = distinct !{!11, !12}
!12 = !{!"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"

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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: alwaysinline nounwind uwtable
declare hidden void @accum_mul_q120_bc(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: alwaysinline nounwind uwtable
declare hidden void @accum_to_q120b(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @q120x2_vec_mat1col_product_bbc_ref(ptr noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #3 {
  %6 = alloca [2 x [16 x i64]], align 16
  call void @llvm.lifetime.start.p0(i64 256, ptr nonnull %6) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(256) %6, i8 0, i64 256, i1 false)
  %.not = icmp eq i64 %1, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5
  %7 = getelementptr inbounds i8, ptr %6, i64 128
  br label %10

._crit_edge:                                      ; preds = %10, %5
  call void @accum_to_q120b(ptr noundef %2, ptr noundef nonnull %6, ptr noundef %0)
  %8 = getelementptr inbounds i8, ptr %2, i64 32
  %9 = getelementptr inbounds i8, ptr %6, i64 128
  call void @accum_to_q120b(ptr noundef nonnull %8, ptr noundef nonnull %9, ptr noundef %0)
  call void @llvm.lifetime.end.p0(i64 256, ptr nonnull %6) #4
  ret void

10:                                               ; preds = %.lr.ph, %10
  %.017 = phi i64 [ 0, %.lr.ph ], [ %15, %10 ]
  %11 = getelementptr inbounds [2 x [8 x i32]], ptr %3, i64 %.017
  %12 = getelementptr inbounds [2 x [8 x i32]], ptr %4, i64 %.017
  call void @accum_mul_q120_bc(ptr noundef nonnull %6, ptr noundef %11, ptr noundef %12)
  %13 = getelementptr inbounds i8, ptr %11, i64 32
  %14 = getelementptr inbounds i8, ptr %12, i64 32
  call void @accum_mul_q120_bc(ptr noundef nonnull %7, ptr noundef nonnull %13, ptr noundef nonnull %14)
  %15 = add nuw i64 %.017, 1
  %exitcond.not = icmp eq i64 %15, %1
  br i1 %exitcond.not, label %._crit_edge, label %10, !llvm.loop !5
}

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


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