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

@zn32_vec_mat8kcols_ref = external hidden constant [4 x ptr], align 16

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

; Function Attrs: nounwind uwtable
define dso_local void @default_zn32_vmp_apply_i16_ref(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5, i64 noundef %6, i64 noundef %7) #0 {
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca i64, align 8
  %17 = alloca i64, align 8
  %18 = alloca i64, align 8
  %19 = alloca i64, align 8
  %20 = alloca i64, align 8
  %21 = alloca i32, align 4
  %22 = alloca ptr, align 8
  %23 = alloca ptr, align 8
  %24 = alloca i64, align 8
  %25 = alloca i64, align 8
  %26 = alloca i64, align 8
  %27 = alloca [32 x i32], align 16
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store i64 %2, ptr %11, align 8, !tbaa !9
  store ptr %3, ptr %12, align 8, !tbaa !5
  store i64 %4, ptr %13, align 8, !tbaa !9
  store ptr %5, ptr %14, align 8, !tbaa !5
  store i64 %6, ptr %15, align 8, !tbaa !9
  store i64 %7, ptr %16, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  %28 = load i64, ptr %13, align 8, !tbaa !9
  %29 = load i64, ptr %15, align 8, !tbaa !9
  %30 = icmp ult i64 %28, %29
  br i1 %30, label %31, label %33

31:                                               ; preds = %8
  %32 = load i64, ptr %13, align 8, !tbaa !9
  br label %35

33:                                               ; preds = %8
  %34 = load i64, ptr %15, align 8, !tbaa !9
  br label %35

35:                                               ; preds = %33, %31
  %36 = phi i64 [ %32, %31 ], [ %34, %33 ]
  store i64 %36, ptr %17, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  %37 = load i64, ptr %11, align 8, !tbaa !9
  %38 = load i64, ptr %16, align 8, !tbaa !9
  %39 = icmp ult i64 %37, %38
  br i1 %39, label %40, label %42

40:                                               ; preds = %35
  %41 = load i64, ptr %11, align 8, !tbaa !9
  br label %44

42:                                               ; preds = %35
  %43 = load i64, ptr %16, align 8, !tbaa !9
  br label %44

44:                                               ; preds = %42, %40
  %45 = phi i64 [ %41, %40 ], [ %43, %42 ]
  store i64 %45, ptr %18, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #4
  %46 = load i64, ptr %18, align 8, !tbaa !9
  %47 = lshr i64 %46, 5
  store i64 %47, ptr %19, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #4
  %48 = load i64, ptr %18, align 8, !tbaa !9
  %49 = and i64 %48, 31
  store i64 %49, ptr %20, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #4
  %50 = load i64, ptr %15, align 8, !tbaa !9
  %51 = mul i64 %50, 32
  %52 = trunc i64 %51 to i32
  store i32 %52, ptr %21, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #4
  %53 = load ptr, ptr %14, align 8, !tbaa !5
  store ptr %53, ptr %22, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #4
  %54 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %54, ptr %23, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %24) #4
  store i64 0, ptr %24, align 8, !tbaa !9
  br label %55

55:                                               ; preds = %65, %44
  %56 = load i64, ptr %24, align 8, !tbaa !9
  %57 = load i64, ptr %19, align 8, !tbaa !9
  %58 = icmp ult i64 %56, %57
  br i1 %58, label %60, label %59

59:                                               ; preds = %55
  call void @llvm.lifetime.end.p0(i64 8, ptr %24) #4
  br label %74

60:                                               ; preds = %55
  %61 = load i64, ptr %17, align 8, !tbaa !9
  %62 = load ptr, ptr %23, align 8, !tbaa !5
  %63 = load ptr, ptr %12, align 8, !tbaa !5
  %64 = load ptr, ptr %22, align 8, !tbaa !5
  call void @zn32_vec_i16_mat32cols_ref(i64 noundef %61, ptr noundef %62, ptr noundef %63, ptr noundef %64, i64 noundef 32)
  br label %65

65:                                               ; preds = %60
  %66 = load i64, ptr %24, align 8, !tbaa !9
  %67 = add i64 %66, 1
  store i64 %67, ptr %24, align 8, !tbaa !9
  %68 = load i32, ptr %21, align 4, !tbaa !11
  %69 = load ptr, ptr %22, align 8, !tbaa !5
  %70 = zext i32 %68 to i64
  %71 = getelementptr inbounds i32, ptr %69, i64 %70
  store ptr %71, ptr %22, align 8, !tbaa !5
  %72 = load ptr, ptr %23, align 8, !tbaa !5
  %73 = getelementptr inbounds i32, ptr %72, i64 32
  store ptr %73, ptr %23, align 8, !tbaa !5
  br label %55, !llvm.loop !13

74:                                               ; preds = %59
  %75 = load i64, ptr %20, align 8, !tbaa !9
  %76 = icmp ne i64 %75, 0
  br i1 %76, label %77, label %103

77:                                               ; preds = %74
  call void @llvm.lifetime.start.p0(i64 8, ptr %25) #4
  %78 = load i64, ptr %16, align 8, !tbaa !9
  %79 = load i64, ptr %19, align 8, !tbaa !9
  %80 = shl i64 %79, 5
  %81 = sub i64 %78, %80
  store i64 %81, ptr %25, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %26) #4
  %82 = load i64, ptr %25, align 8, !tbaa !9
  %83 = icmp uge i64 %82, 32
  br i1 %83, label %84, label %85

84:                                               ; preds = %77
  br label %87

85:                                               ; preds = %77
  %86 = load i64, ptr %25, align 8, !tbaa !9
  br label %87

87:                                               ; preds = %85, %84
  %88 = phi i64 [ 32, %84 ], [ %86, %85 ]
  store i64 %88, ptr %26, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 128, ptr %27) #4
  %89 = load i64, ptr %20, align 8, !tbaa !9
  %90 = sub i64 %89, 1
  %91 = lshr i64 %90, 3
  %92 = getelementptr inbounds [4 x ptr], ptr @zn32_vec_mat8kcols_ref, i64 0, i64 %91
  %93 = load ptr, ptr %92, align 8, !tbaa !5
  %94 = load i64, ptr %17, align 8, !tbaa !9
  %95 = getelementptr inbounds [32 x i32], ptr %27, i64 0, i64 0
  %96 = load ptr, ptr %12, align 8, !tbaa !5
  %97 = load ptr, ptr %22, align 8, !tbaa !5
  %98 = load i64, ptr %26, align 8, !tbaa !9
  call void %93(i64 noundef %94, ptr noundef %95, ptr noundef %96, ptr noundef %97, i64 noundef %98)
  %99 = load ptr, ptr %23, align 8, !tbaa !5
  %100 = getelementptr inbounds [32 x i32], ptr %27, i64 0, i64 0
  %101 = load i64, ptr %20, align 8, !tbaa !9
  %102 = mul i64 %101, 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %99, ptr align 16 %100, i64 %102, i1 false)
  call void @llvm.lifetime.end.p0(i64 128, ptr %27) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %26) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %25) #4
  br label %103

103:                                              ; preds = %87, %74
  %104 = load ptr, ptr %10, align 8, !tbaa !5
  %105 = load i64, ptr %18, align 8, !tbaa !9
  %106 = getelementptr inbounds i32, ptr %104, i64 %105
  %107 = load i64, ptr %11, align 8, !tbaa !9
  %108 = load i64, ptr %18, align 8, !tbaa !9
  %109 = sub i64 %107, %108
  %110 = mul i64 %109, 4
  call void @llvm.memset.p0.i64(ptr align 4 %106, i8 0, i64 %110, i1 false)
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  ret void
}

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

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

@zn32_vec_mat8kcols_ref = external hidden local_unnamed_addr constant [4 x ptr], align 16

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

; Function Attrs: nounwind uwtable
define dso_local void @default_zn32_vmp_apply_i16_ref(ptr nocapture noundef readnone %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5, i64 noundef %6, i64 noundef %7) local_unnamed_addr #0 {
  %9 = alloca [32 x i32], align 16
  %10 = tail call i64 @llvm.umin.i64(i64 %4, i64 %6)
  %11 = tail call i64 @llvm.umin.i64(i64 %2, i64 %7)
  %12 = lshr i64 %11, 5
  %13 = and i64 %11, 31
  %.not46 = icmp ult i64 %11, 32
  br i1 %.not46, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %8
  %14 = shl i64 %6, 5
  %15 = and i64 %14, 4294967264
  br label %16

._crit_edge:                                      ; preds = %16, %8
  %.038.lcssa = phi ptr [ %1, %8 ], [ %19, %16 ]
  %.0.lcssa = phi ptr [ %5, %8 ], [ %18, %16 ]
  %.not = icmp eq i64 %13, 0
  br i1 %.not, label %29, label %20

16:                                               ; preds = %.lr.ph, %16
  %.044 = phi ptr [ %5, %.lr.ph ], [ %18, %16 ]
  %.03843 = phi ptr [ %1, %.lr.ph ], [ %19, %16 ]
  %.03942 = phi i64 [ 0, %.lr.ph ], [ %17, %16 ]
  tail call void @zn32_vec_i16_mat32cols_ref(i64 noundef %10, ptr noundef %.03843, ptr noundef %3, ptr noundef %.044, i64 noundef 32)
  %17 = add nuw nsw i64 %.03942, 1
  %18 = getelementptr inbounds i32, ptr %.044, i64 %15
  %19 = getelementptr inbounds i8, ptr %.03843, i64 128
  %exitcond.not = icmp eq i64 %17, %12
  br i1 %exitcond.not, label %._crit_edge, label %16, !llvm.loop !5

20:                                               ; preds = %._crit_edge
  %21 = and i64 %11, -32
  %22 = sub i64 %7, %21
  %23 = tail call i64 @llvm.umin.i64(i64 %22, i64 32)
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %9) #5
  %24 = add nsw i64 %13, -1
  %25 = lshr i64 %24, 3
  %26 = getelementptr inbounds [4 x ptr], ptr @zn32_vec_mat8kcols_ref, i64 0, i64 %25
  %27 = load ptr, ptr %26, align 8, !tbaa !7
  call void %27(i64 noundef %10, ptr noundef nonnull %9, ptr noundef %3, ptr noundef %.0.lcssa, i64 noundef %23) #5
  %28 = shl nuw nsw i64 %13, 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %.038.lcssa, ptr nonnull align 16 %9, i64 %28, i1 false)
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %9) #5
  br label %29

29:                                               ; preds = %20, %._crit_edge
  %30 = getelementptr inbounds i32, ptr %1, i64 %11
  %31 = sub i64 %2, %11
  %32 = shl i64 %31, 2
  call void @llvm.memset.p0.i64(ptr align 4 %30, i8 0, i64 %32, i1 false)
  ret void
}

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

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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"}
!7 = !{!8, !8, i64 0}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}


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