; 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_mat2cols_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 [4 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 512, ptr %11) #4
  call void @llvm.memset.p0.i64(ptr align 16 %11, i8 0, i64 512, 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 = %73, %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 %76

24:                                               ; preds = %19
  %25 = getelementptr inbounds [4 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 [4 x [8 x i32]], ptr %32, i64 %33
  %35 = getelementptr inbounds [4 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 [4 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 [4 x [8 x i32]], ptr %44, i64 %45
  %47 = getelementptr inbounds [4 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)
  %49 = getelementptr inbounds [4 x [16 x i64]], ptr %11, i64 0, i64 2
  %50 = getelementptr inbounds [16 x i64], ptr %49, i64 0, i64 0
  %51 = load ptr, ptr %12, align 8, !tbaa !5
  %52 = load i64, ptr %15, align 8, !tbaa !9
  %53 = getelementptr inbounds [2 x [8 x i32]], ptr %51, i64 %52
  %54 = getelementptr inbounds [2 x [8 x i32]], ptr %53, i64 0, i64 0
  %55 = getelementptr inbounds [8 x i32], ptr %54, i64 0, i64 0
  %56 = load ptr, ptr %13, align 8, !tbaa !5
  %57 = load i64, ptr %15, align 8, !tbaa !9
  %58 = getelementptr inbounds [4 x [8 x i32]], ptr %56, i64 %57
  %59 = getelementptr inbounds [4 x [8 x i32]], ptr %58, i64 0, i64 2
  %60 = getelementptr inbounds [8 x i32], ptr %59, i64 0, i64 0
  call void @accum_mul_q120_bc(ptr noundef %50, ptr noundef %55, ptr noundef %60)
  %61 = getelementptr inbounds [4 x [16 x i64]], ptr %11, i64 0, i64 3
  %62 = getelementptr inbounds [16 x i64], ptr %61, i64 0, i64 0
  %63 = load ptr, ptr %12, align 8, !tbaa !5
  %64 = load i64, ptr %15, align 8, !tbaa !9
  %65 = getelementptr inbounds [2 x [8 x i32]], ptr %63, i64 %64
  %66 = getelementptr inbounds [2 x [8 x i32]], ptr %65, i64 0, i64 1
  %67 = getelementptr inbounds [8 x i32], ptr %66, i64 0, i64 0
  %68 = load ptr, ptr %13, align 8, !tbaa !5
  %69 = load i64, ptr %15, align 8, !tbaa !9
  %70 = getelementptr inbounds [4 x [8 x i32]], ptr %68, i64 %69
  %71 = getelementptr inbounds [4 x [8 x i32]], ptr %70, i64 0, i64 3
  %72 = getelementptr inbounds [8 x i32], ptr %71, i64 0, i64 0
  call void @accum_mul_q120_bc(ptr noundef %62, ptr noundef %67, ptr noundef %72)
  br label %73

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

76:                                               ; preds = %23
  %77 = load ptr, ptr %14, align 8, !tbaa !5
  %78 = getelementptr inbounds [4 x i64], ptr %77, i64 0
  %79 = getelementptr inbounds [4 x i64], ptr %78, i64 0, i64 0
  %80 = getelementptr inbounds [4 x [16 x i64]], ptr %11, i64 0, i64 0
  %81 = getelementptr inbounds [16 x i64], ptr %80, i64 0, i64 0
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  call void @accum_to_q120b(ptr noundef %79, ptr noundef %81, ptr noundef %82)
  %83 = load ptr, ptr %14, align 8, !tbaa !5
  %84 = getelementptr inbounds [4 x i64], ptr %83, i64 1
  %85 = getelementptr inbounds [4 x i64], ptr %84, i64 0, i64 0
  %86 = getelementptr inbounds [4 x [16 x i64]], ptr %11, i64 0, i64 1
  %87 = getelementptr inbounds [16 x i64], ptr %86, i64 0, i64 0
  %88 = load ptr, ptr %6, align 8, !tbaa !5
  call void @accum_to_q120b(ptr noundef %85, ptr noundef %87, ptr noundef %88)
  %89 = load ptr, ptr %14, align 8, !tbaa !5
  %90 = getelementptr inbounds [4 x i64], ptr %89, i64 2
  %91 = getelementptr inbounds [4 x i64], ptr %90, i64 0, i64 0
  %92 = getelementptr inbounds [4 x [16 x i64]], ptr %11, i64 0, i64 2
  %93 = getelementptr inbounds [16 x i64], ptr %92, i64 0, i64 0
  %94 = load ptr, ptr %6, align 8, !tbaa !5
  call void @accum_to_q120b(ptr noundef %91, ptr noundef %93, ptr noundef %94)
  %95 = load ptr, ptr %14, align 8, !tbaa !5
  %96 = getelementptr inbounds [4 x i64], ptr %95, i64 3
  %97 = getelementptr inbounds [4 x i64], ptr %96, i64 0, i64 0
  %98 = getelementptr inbounds [4 x [16 x i64]], ptr %11, i64 0, i64 3
  %99 = getelementptr inbounds [16 x i64], ptr %98, i64 0, i64 0
  %100 = load ptr, ptr %6, align 8, !tbaa !5
  call void @accum_to_q120b(ptr noundef %97, ptr noundef %99, ptr noundef %100)
  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 512, 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_mat2cols_product_bbc_ref(ptr noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #3 {
  %6 = alloca [4 x [16 x i64]], align 16
  call void @llvm.lifetime.start.p0(i64 512, ptr nonnull %6) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(512) %6, i8 0, i64 512, 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
  %8 = getelementptr inbounds i8, ptr %6, i64 256
  %9 = getelementptr inbounds i8, ptr %6, i64 384
  br label %16

._crit_edge:                                      ; preds = %16, %5
  call void @accum_to_q120b(ptr noundef %2, ptr noundef nonnull %6, ptr noundef %0)
  %10 = getelementptr inbounds i8, ptr %2, i64 32
  %11 = getelementptr inbounds i8, ptr %6, i64 128
  call void @accum_to_q120b(ptr noundef nonnull %10, ptr noundef nonnull %11, ptr noundef %0)
  %12 = getelementptr inbounds i8, ptr %2, i64 64
  %13 = getelementptr inbounds i8, ptr %6, i64 256
  call void @accum_to_q120b(ptr noundef nonnull %12, ptr noundef nonnull %13, ptr noundef %0)
  %14 = getelementptr inbounds i8, ptr %2, i64 96
  %15 = getelementptr inbounds i8, ptr %6, i64 384
  call void @accum_to_q120b(ptr noundef nonnull %14, ptr noundef nonnull %15, ptr noundef %0)
  call void @llvm.lifetime.end.p0(i64 512, ptr nonnull %6) #4
  ret void

16:                                               ; preds = %.lr.ph, %16
  %.029 = phi i64 [ 0, %.lr.ph ], [ %23, %16 ]
  %17 = getelementptr inbounds [2 x [8 x i32]], ptr %3, i64 %.029
  %18 = getelementptr inbounds [4 x [8 x i32]], ptr %4, i64 %.029
  call void @accum_mul_q120_bc(ptr noundef nonnull %6, ptr noundef %17, ptr noundef %18)
  %19 = getelementptr inbounds i8, ptr %17, i64 32
  %20 = getelementptr inbounds i8, ptr %18, i64 32
  call void @accum_mul_q120_bc(ptr noundef nonnull %7, ptr noundef nonnull %19, ptr noundef nonnull %20)
  %21 = getelementptr inbounds i8, ptr %18, i64 64
  call void @accum_mul_q120_bc(ptr noundef nonnull %8, ptr noundef %17, ptr noundef nonnull %21)
  %22 = getelementptr inbounds i8, ptr %18, i64 96
  call void @accum_mul_q120_bc(ptr noundef nonnull %9, ptr noundef nonnull %19, ptr noundef nonnull %22)
  %23 = add nuw i64 %.029, 1
  %exitcond.not = icmp eq i64 %23, %1
  br i1 %exitcond.not, label %._crit_edge, label %16, !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