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

%struct._q120_mat1col_product_bbc_precomp = type { i64, [4 x i64], [4 x i64], double }

@.str.1 = external hidden unnamed_addr constant [92 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [16 x i8], align 1
@__const.vec_mat1col_product_bbc_precomp.qs = external hidden unnamed_addr constant [4 x i64], align 16
@__PRETTY_FUNCTION__.vec_mat1col_product_bbc_precomp = external hidden unnamed_addr constant [73 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local double @comp_bit_size_red(i64 noundef, ptr noundef) #0

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

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

; Function Attrs: nounwind
declare double @log2(double noundef) #3

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

; Function Attrs: nounwind uwtable
declare dso_local double @comp_bit_size_sum(i64 noundef, ptr noundef) #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) #4

; Function Attrs: nounwind uwtable
define dso_local void @vec_mat1col_product_bbc_precomp(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca [4 x i64], align 16
  %4 = alloca double, align 8
  %5 = alloca i64, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca i64, align 8
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  %12 = alloca [3 x double], align 16
  %13 = alloca double, align 8
  %14 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32, ptr %3) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %3, ptr align 16 @__const.vec_mat1col_product_bbc_precomp.qs, i64 32, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  store double 1.000000e+03, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  store i64 -1, ptr %5, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %15 = getelementptr inbounds [4 x i64], ptr %3, i64 0, i64 0
  %16 = call double @comp_bit_size_red(i64 noundef 32, ptr noundef %15)
  store double %16, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %17 = call double @log2(double noundef 1.000000e+04) #5
  store double %17, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %18 = load double, ptr %7, align 8, !tbaa !9
  %19 = fadd double 3.200000e+01, %18
  store double %19, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  store i64 16, ptr %9, align 8, !tbaa !11
  br label %20

20:                                               ; preds = %52, %1
  %21 = load i64, ptr %9, align 8, !tbaa !11
  %22 = icmp ult i64 %21, 32
  br i1 %22, label %24, label %23

23:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %55

24:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %25 = load double, ptr %6, align 8, !tbaa !9
  %26 = load i64, ptr %9, align 8, !tbaa !11
  %27 = uitofp i64 %26 to double
  %28 = fadd double %25, %27
  store double %28, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %29 = load double, ptr %8, align 8, !tbaa !9
  %30 = load i64, ptr %9, align 8, !tbaa !11
  %31 = uitofp i64 %30 to double
  %32 = fsub double %29, %31
  %33 = load i64, ptr %9, align 8, !tbaa !11
  %34 = add i64 32, %33
  %35 = getelementptr inbounds [4 x i64], ptr %3, i64 0, i64 0
  %36 = call double @comp_bit_size_red(i64 noundef %34, ptr noundef %35)
  %37 = fadd double %32, %36
  store double %37, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 24, ptr %12) #5
  %38 = load double, ptr %8, align 8, !tbaa !9
  store double %38, ptr %12, align 8, !tbaa !9
  %39 = getelementptr inbounds double, ptr %12, i64 1
  %40 = load double, ptr %10, align 8, !tbaa !9
  store double %40, ptr %39, align 8, !tbaa !9
  %41 = getelementptr inbounds double, ptr %12, i64 2
  %42 = load double, ptr %11, align 8, !tbaa !9
  store double %42, ptr %41, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %43 = getelementptr inbounds [3 x double], ptr %12, i64 0, i64 0
  %44 = call double @comp_bit_size_sum(i64 noundef 3, ptr noundef %43)
  store double %44, ptr %13, align 8, !tbaa !9
  %45 = load double, ptr %4, align 8, !tbaa !9
  %46 = load double, ptr %13, align 8, !tbaa !9
  %47 = fcmp ogt double %45, %46
  br i1 %47, label %48, label %51

48:                                               ; preds = %24
  %49 = load double, ptr %13, align 8, !tbaa !9
  store double %49, ptr %4, align 8, !tbaa !9
  %50 = load i64, ptr %9, align 8, !tbaa !11
  store i64 %50, ptr %5, align 8, !tbaa !11
  br label %51

51:                                               ; preds = %48, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  br label %52

52:                                               ; preds = %51
  %53 = load i64, ptr %9, align 8, !tbaa !11
  %54 = add i64 %53, 1
  store i64 %54, ptr %9, align 8, !tbaa !11
  br label %20, !llvm.loop !13

55:                                               ; preds = %23
  %56 = load double, ptr %4, align 8, !tbaa !9
  %57 = fcmp olt double %56, 6.400000e+01
  br i1 %57, label %58, label %59

58:                                               ; preds = %55
  br label %60

59:                                               ; preds = %55
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 287, ptr noundef @__PRETTY_FUNCTION__.vec_mat1col_product_bbc_precomp) #6
  unreachable

60:                                               ; preds = %58
  %61 = load i64, ptr %5, align 8, !tbaa !11
  %62 = load ptr, ptr %2, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct._q120_mat1col_product_bbc_precomp, ptr %62, i32 0, i32 0
  store i64 %61, ptr %63, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  store i64 0, ptr %14, align 8, !tbaa !11
  br label %64

64:                                               ; preds = %90, %60
  %65 = load i64, ptr %14, align 8, !tbaa !11
  %66 = icmp ult i64 %65, 4
  br i1 %66, label %68, label %67

67:                                               ; preds = %64
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  br label %93

68:                                               ; preds = %64
  %69 = load i64, ptr %14, align 8, !tbaa !11
  %70 = getelementptr inbounds [4 x i64], ptr %3, i64 0, i64 %69
  %71 = load i64, ptr %70, align 8, !tbaa !11
  %72 = urem i64 4294967296, %71
  %73 = load ptr, ptr %2, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct._q120_mat1col_product_bbc_precomp, ptr %73, i32 0, i32 1
  %75 = load i64, ptr %14, align 8, !tbaa !11
  %76 = getelementptr inbounds [4 x i64], ptr %74, i64 0, i64 %75
  store i64 %72, ptr %76, align 8, !tbaa !11
  %77 = load ptr, ptr %2, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct._q120_mat1col_product_bbc_precomp, ptr %77, i32 0, i32 0
  %79 = load i64, ptr %78, align 8, !tbaa !15
  %80 = add i64 32, %79
  %81 = shl i64 1, %80
  %82 = load i64, ptr %14, align 8, !tbaa !11
  %83 = getelementptr inbounds [4 x i64], ptr %3, i64 0, i64 %82
  %84 = load i64, ptr %83, align 8, !tbaa !11
  %85 = urem i64 %81, %84
  %86 = load ptr, ptr %2, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct._q120_mat1col_product_bbc_precomp, ptr %86, i32 0, i32 2
  %88 = load i64, ptr %14, align 8, !tbaa !11
  %89 = getelementptr inbounds [4 x i64], ptr %87, i64 0, i64 %88
  store i64 %85, ptr %89, align 8, !tbaa !11
  br label %90

90:                                               ; preds = %68
  %91 = load i64, ptr %14, align 8, !tbaa !11
  %92 = add i64 %91, 1
  store i64 %92, ptr %14, align 8, !tbaa !11
  br label %64, !llvm.loop !17

93:                                               ; preds = %67
  %94 = load double, ptr %4, align 8, !tbaa !9
  %95 = load ptr, ptr %2, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct._q120_mat1col_product_bbc_precomp, ptr %95, i32 0, i32 3
  store double %94, ptr %96, align 8, !tbaa !18
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr %3) #5
  ret void
}

attributes #0 = { 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 #1 = { noreturn nounwind "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nounwind "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nounwind }
attributes #6 = { noreturn 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 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !12, i64 0}
!16 = !{!"_q120_mat1col_product_bbc_precomp", !12, i64 0, !7, i64 8, !7, i64 40, !10, i64 72}
!17 = distinct !{!17, !14}
!18 = !{!16, !10, i64 72}


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

@.str.1 = external hidden unnamed_addr constant [92 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [16 x i8], align 1
@__const.vec_mat1col_product_bbc_precomp.qs = external hidden unnamed_addr constant [4 x i64], align 16
@__PRETTY_FUNCTION__.vec_mat1col_product_bbc_precomp = external hidden unnamed_addr constant [73 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local double @comp_bit_size_red(i64 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

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

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

; Function Attrs: nounwind uwtable
declare dso_local double @comp_bit_size_sum(i64 noundef, ptr noundef) local_unnamed_addr #0

; 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) #3

; Function Attrs: nounwind uwtable
define dso_local void @vec_mat1col_product_bbc_precomp(ptr nocapture noundef writeonly %0) local_unnamed_addr #0 {
  %2 = alloca [4 x i64], align 16
  %3 = alloca [3 x double], align 16
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %2) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %2, ptr noundef nonnull align 16 dereferenceable(32) @__const.vec_mat1col_product_bbc_precomp.qs, i64 32, i1 false)
  %4 = call double @comp_bit_size_red(i64 noundef 32, ptr noundef nonnull %2)
  %5 = getelementptr inbounds i8, ptr %3, i64 8
  %6 = insertelement <2 x double> poison, double %4, i64 0
  br label %9

7:                                                ; preds = %9
  %8 = fcmp olt double %.1, 6.400000e+01
  br i1 %8, label %22, label %21

9:                                                ; preds = %1, %9
  %.02835 = phi double [ 1.000000e+03, %1 ], [ %.1, %9 ]
  %.02934 = phi i64 [ -1, %1 ], [ %.130, %9 ]
  %.03133 = phi i64 [ 16, %1 ], [ %20, %9 ]
  %10 = uitofp nneg i64 %.03133 to double
  %11 = fsub double 0x4046A4D3C25E68DC, %10
  %12 = or disjoint i64 %.03133, 32
  %13 = call double @comp_bit_size_red(i64 noundef %12, ptr noundef nonnull %2)
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #4
  store double 0x4046A4D3C25E68DC, ptr %3, align 16, !tbaa !5
  %14 = insertelement <2 x double> %6, double %11, i64 1
  %15 = insertelement <2 x double> poison, double %10, i64 0
  %16 = insertelement <2 x double> %15, double %13, i64 1
  %17 = fadd <2 x double> %14, %16
  store <2 x double> %17, ptr %5, align 8, !tbaa !5
  %18 = call double @comp_bit_size_sum(i64 noundef 3, ptr noundef nonnull %3)
  %19 = fcmp ogt double %.02835, %18
  %.130 = select i1 %19, i64 %.03133, i64 %.02934
  %.1 = select i1 %19, double %18, double %.02835
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #4
  %20 = add nuw nsw i64 %.03133, 1
  %exitcond.not = icmp eq i64 %20, 32
  br i1 %exitcond.not, label %7, label %9, !llvm.loop !9

21:                                               ; preds = %7
  call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 287, ptr noundef nonnull @__PRETTY_FUNCTION__.vec_mat1col_product_bbc_precomp) #5
  unreachable

22:                                               ; preds = %7
  store i64 %.130, ptr %0, align 8, !tbaa !11
  %23 = getelementptr inbounds i8, ptr %0, i64 8
  %24 = add i64 %.130, 32
  %25 = shl nuw i64 1, %24
  %26 = getelementptr inbounds i8, ptr %0, i64 40
  %27 = load i64, ptr %2, align 16, !tbaa !14
  %28 = urem i64 4294967296, %27
  store i64 %28, ptr %23, align 8, !tbaa !14
  %29 = urem i64 %25, %27
  store i64 %29, ptr %26, align 8, !tbaa !14
  %30 = getelementptr inbounds i8, ptr %2, i64 8
  %31 = load i64, ptr %30, align 8, !tbaa !14
  %32 = urem i64 4294967296, %31
  %33 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 %32, ptr %33, align 8, !tbaa !14
  %34 = urem i64 %25, %31
  %35 = getelementptr inbounds i8, ptr %0, i64 48
  store i64 %34, ptr %35, align 8, !tbaa !14
  %36 = getelementptr inbounds i8, ptr %2, i64 16
  %37 = load i64, ptr %36, align 16, !tbaa !14
  %38 = urem i64 4294967296, %37
  %39 = getelementptr inbounds i8, ptr %0, i64 24
  store i64 %38, ptr %39, align 8, !tbaa !14
  %40 = urem i64 %25, %37
  %41 = getelementptr inbounds i8, ptr %0, i64 56
  store i64 %40, ptr %41, align 8, !tbaa !14
  %42 = getelementptr inbounds i8, ptr %2, i64 24
  %43 = load i64, ptr %42, align 8, !tbaa !14
  %44 = urem i64 4294967296, %43
  %45 = getelementptr inbounds i8, ptr %0, i64 32
  store i64 %44, ptr %45, align 8, !tbaa !14
  %46 = urem i64 %25, %43
  %47 = getelementptr inbounds i8, ptr %0, i64 64
  store i64 %46, ptr %47, align 8, !tbaa !14
  %48 = getelementptr inbounds i8, ptr %0, i64 72
  store double %.1, ptr %48, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %2) #4
  ret void
}

attributes #0 = { 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 #1 = { noreturn nounwind "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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind }
attributes #5 = { noreturn 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !13, i64 0}
!12 = !{!"_q120_mat1col_product_bbc_precomp", !13, i64 0, !7, i64 8, !7, i64 40, !6, i64 72}
!13 = !{!"long", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!12, !6, i64 72}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass