; 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_baa_precomp = type { i64, [4 x i64], double }

@.str.1 = external hidden unnamed_addr constant [92 x i8], align 1
@__const.vec_mat1col_product_baa_precomp.qs = external hidden unnamed_addr constant [4 x i64], align 16
@.str.2 = external hidden unnamed_addr constant [16 x i8], align 1
@__PRETTY_FUNCTION__.vec_mat1col_product_baa_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: nounwind uwtable
define dso_local void @vec_mat1col_product_baa_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 i64, align 8
  %8 = alloca double, align 8
  %9 = alloca [2 x double], align 16
  %10 = alloca double, align 8
  %11 = 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_baa_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
  %12 = call double @log2(double noundef 1.000000e+04) #5
  store double %12, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  store i64 1, ptr %7, align 8, !tbaa !11
  br label %13

13:                                               ; preds = %42, %1
  %14 = load i64, ptr %7, align 8, !tbaa !11
  %15 = icmp ult i64 %14, 64
  br i1 %15, label %17, label %16

16:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %45

17:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %18 = load i64, ptr %7, align 8, !tbaa !11
  %19 = getelementptr inbounds [4 x i64], ptr %3, i64 0, i64 0
  %20 = call double @comp_bit_size_red(i64 noundef %18, ptr noundef %19)
  store double %20, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #5
  %21 = load i64, ptr %7, align 8, !tbaa !11
  %22 = uitofp i64 %21 to double
  %23 = load double, ptr %6, align 8, !tbaa !9
  %24 = fadd double %22, %23
  store double %24, ptr %9, align 8, !tbaa !9
  %25 = getelementptr inbounds double, ptr %9, i64 1
  %26 = load i64, ptr %7, align 8, !tbaa !11
  %27 = sub i64 64, %26
  %28 = uitofp i64 %27 to double
  %29 = load double, ptr %6, align 8, !tbaa !9
  %30 = fadd double %28, %29
  %31 = load double, ptr %8, align 8, !tbaa !9
  %32 = fadd double %30, %31
  store double %32, ptr %25, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %33 = getelementptr inbounds [2 x double], ptr %9, i64 0, i64 0
  %34 = call double @comp_bit_size_sum(i64 noundef 2, ptr noundef %33)
  store double %34, ptr %10, align 8, !tbaa !9
  %35 = load double, ptr %4, align 8, !tbaa !9
  %36 = load double, ptr %10, align 8, !tbaa !9
  %37 = fcmp ogt double %35, %36
  br i1 %37, label %38, label %41

38:                                               ; preds = %17
  %39 = load double, ptr %10, align 8, !tbaa !9
  store double %39, ptr %4, align 8, !tbaa !9
  %40 = load i64, ptr %7, align 8, !tbaa !11
  store i64 %40, ptr %5, align 8, !tbaa !11
  br label %41

41:                                               ; preds = %38, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %42

42:                                               ; preds = %41
  %43 = load i64, ptr %7, align 8, !tbaa !11
  %44 = add i64 %43, 1
  store i64 %44, ptr %7, align 8, !tbaa !11
  br label %13, !llvm.loop !13

45:                                               ; preds = %16
  %46 = load double, ptr %4, align 8, !tbaa !9
  %47 = fcmp olt double %46, 6.400000e+01
  br i1 %47, label %48, label %49

48:                                               ; preds = %45
  br label %50

49:                                               ; preds = %45
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 48, ptr noundef @__PRETTY_FUNCTION__.vec_mat1col_product_baa_precomp) #6
  unreachable

50:                                               ; preds = %48
  %51 = load i64, ptr %5, align 8, !tbaa !11
  %52 = load ptr, ptr %2, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct._q120_mat1col_product_baa_precomp, ptr %52, i32 0, i32 0
  store i64 %51, ptr %53, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  store i64 0, ptr %11, align 8, !tbaa !11
  br label %54

54:                                               ; preds = %71, %50
  %55 = load i64, ptr %11, align 8, !tbaa !11
  %56 = icmp ult i64 %55, 4
  br i1 %56, label %58, label %57

57:                                               ; preds = %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  br label %74

58:                                               ; preds = %54
  %59 = load ptr, ptr %2, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct._q120_mat1col_product_baa_precomp, ptr %59, i32 0, i32 0
  %61 = load i64, ptr %60, align 8, !tbaa !15
  %62 = shl i64 1, %61
  %63 = load i64, ptr %11, align 8, !tbaa !11
  %64 = getelementptr inbounds [4 x i64], ptr %3, i64 0, i64 %63
  %65 = load i64, ptr %64, align 8, !tbaa !11
  %66 = urem i64 %62, %65
  %67 = load ptr, ptr %2, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct._q120_mat1col_product_baa_precomp, ptr %67, i32 0, i32 1
  %69 = load i64, ptr %11, align 8, !tbaa !11
  %70 = getelementptr inbounds [4 x i64], ptr %68, i64 0, i64 %69
  store i64 %66, ptr %70, align 8, !tbaa !11
  br label %71

71:                                               ; preds = %58
  %72 = load i64, ptr %11, align 8, !tbaa !11
  %73 = add i64 %72, 1
  store i64 %73, ptr %11, align 8, !tbaa !11
  br label %54, !llvm.loop !17

74:                                               ; preds = %57
  %75 = load double, ptr %4, align 8, !tbaa !9
  %76 = load ptr, ptr %2, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct._q120_mat1col_product_baa_precomp, ptr %76, i32 0, i32 2
  store double %75, ptr %77, align 8, !tbaa !18
  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
}

; 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

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_baa_precomp", !12, i64 0, !7, i64 8, !10, i64 40}
!17 = distinct !{!17, !14}
!18 = !{!16, !10, i64 40}


; 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
@__const.vec_mat1col_product_baa_precomp.qs = external hidden unnamed_addr constant [4 x i64], align 16
@.str.2 = external hidden unnamed_addr constant [16 x i8], align 1
@__PRETTY_FUNCTION__.vec_mat1col_product_baa_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: nounwind uwtable
define dso_local void @vec_mat1col_product_baa_precomp(ptr nocapture noundef writeonly %0) local_unnamed_addr #0 {
  %2 = alloca [4 x i64], align 16
  %3 = alloca [2 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_baa_precomp.qs, i64 32, i1 false)
  br label %6

4:                                                ; preds = %6
  %5 = fcmp olt double %.1, 6.400000e+01
  br i1 %5, label %20, label %19

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

19:                                               ; preds = %4
  call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 48, ptr noundef nonnull @__PRETTY_FUNCTION__.vec_mat1col_product_baa_precomp) #5
  unreachable

20:                                               ; preds = %4
  store i64 %.124, ptr %0, align 8, !tbaa !11
  %21 = shl nuw i64 1, %.124
  %22 = getelementptr inbounds i8, ptr %0, i64 8
  %23 = load i64, ptr %2, align 16, !tbaa !14
  %24 = urem i64 %21, %23
  store i64 %24, ptr %22, align 8, !tbaa !14
  %25 = getelementptr inbounds i8, ptr %2, i64 8
  %26 = load i64, ptr %25, align 8, !tbaa !14
  %27 = urem i64 %21, %26
  %28 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 %27, ptr %28, align 8, !tbaa !14
  %29 = getelementptr inbounds i8, ptr %2, i64 16
  %30 = load i64, ptr %29, align 16, !tbaa !14
  %31 = urem i64 %21, %30
  %32 = getelementptr inbounds i8, ptr %0, i64 24
  store i64 %31, ptr %32, align 8, !tbaa !14
  %33 = getelementptr inbounds i8, ptr %2, i64 24
  %34 = load i64, ptr %33, align 8, !tbaa !14
  %35 = urem i64 %21, %34
  %36 = getelementptr inbounds i8, ptr %0, i64 32
  store i64 %35, ptr %36, align 8, !tbaa !14
  %37 = getelementptr inbounds i8, ptr %0, i64 40
  store double %.1, ptr %37, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %2) #4
  ret void
}

; 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

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_baa_precomp", !13, i64 0, !7, i64 8, !6, i64 40}
!13 = !{!"long", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!12, !6, i64 40}


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