; 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: nounwind uwtable
define dso_local void @q120x2_extract_1blk_from_contiguous_q120b_ref(i64 noundef %0, i64 noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4) #1 {
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca i32, align 4
  %15 = alloca i64, align 8
  store i64 %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !9
  store ptr %4, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %16 = load ptr, ptr %10, align 8, !tbaa !9
  store ptr %16, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %17 = load ptr, ptr %9, align 8, !tbaa !9
  store ptr %17, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  store i64 0, ptr %13, align 8, !tbaa !5
  br label %18

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

22:                                               ; preds = %18
  store i32 2, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  br label %52

23:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #2
  store i64 0, ptr %15, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %39, %23
  %25 = load i64, ptr %15, align 8, !tbaa !5
  %26 = icmp ult i64 %25, 8
  br i1 %26, label %28, label %27

27:                                               ; preds = %24
  store i32 5, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #2
  br label %42

28:                                               ; preds = %24
  %29 = load ptr, ptr %11, align 8, !tbaa !9
  %30 = load i64, ptr %8, align 8, !tbaa !5
  %31 = mul i64 8, %30
  %32 = load i64, ptr %15, align 8, !tbaa !5
  %33 = add i64 %31, %32
  %34 = getelementptr inbounds i64, ptr %29, i64 %33
  %35 = load i64, ptr %34, align 8, !tbaa !5
  %36 = load ptr, ptr %12, align 8, !tbaa !9
  %37 = load i64, ptr %15, align 8, !tbaa !5
  %38 = getelementptr inbounds i64, ptr %36, i64 %37
  store i64 %35, ptr %38, align 8, !tbaa !5
  br label %39

39:                                               ; preds = %28
  %40 = load i64, ptr %15, align 8, !tbaa !5
  %41 = add i64 %40, 1
  store i64 %41, ptr %15, align 8, !tbaa !5
  br label %24, !llvm.loop !11

42:                                               ; preds = %27
  %43 = load i64, ptr %6, align 8, !tbaa !5
  %44 = mul i64 4, %43
  %45 = load ptr, ptr %11, align 8, !tbaa !9
  %46 = getelementptr inbounds i64, ptr %45, i64 %44
  store ptr %46, ptr %11, align 8, !tbaa !9
  %47 = load ptr, ptr %12, align 8, !tbaa !9
  %48 = getelementptr inbounds i64, ptr %47, i64 8
  store ptr %48, ptr %12, align 8, !tbaa !9
  br label %49

49:                                               ; preds = %42
  %50 = load i64, ptr %13, align 8, !tbaa !5
  %51 = add i64 %50, 1
  store i64 %51, ptr %13, align 8, !tbaa !5
  br label %18, !llvm.loop !13

52:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @q120x2_extract_1blk_from_contiguous_q120b_ref(i64 noundef %0, i64 noundef %1, i64 noundef %2, ptr nocapture noundef writeonly %3, ptr nocapture noundef readonly %4) local_unnamed_addr #0 {
  %.not = icmp eq i64 %1, 0
  br i1 %.not, label %._crit_edge, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %5
  %6 = shl i64 %2, 3
  %.idx = shl i64 %0, 5
  %7 = or disjoint i64 %6, 1
  %8 = or disjoint i64 %6, 2
  %9 = or disjoint i64 %6, 3
  %10 = or disjoint i64 %6, 4
  %11 = or disjoint i64 %6, 5
  %12 = or disjoint i64 %6, 6
  %13 = or disjoint i64 %6, 7
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %.preheader
  %.01420 = phi i64 [ 0, %.preheader.lr.ph ], [ %39, %.preheader ]
  %.01519 = phi ptr [ %3, %.preheader.lr.ph ], [ %38, %.preheader ]
  %.01618 = phi ptr [ %4, %.preheader.lr.ph ], [ %37, %.preheader ]
  %14 = getelementptr inbounds i64, ptr %.01618, i64 %6
  %15 = load i64, ptr %14, align 8, !tbaa !5
  store i64 %15, ptr %.01519, align 8, !tbaa !5
  %16 = getelementptr inbounds i64, ptr %.01618, i64 %7
  %17 = load i64, ptr %16, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %.01519, i64 8
  store i64 %17, ptr %18, align 8, !tbaa !5
  %19 = getelementptr inbounds i64, ptr %.01618, i64 %8
  %20 = load i64, ptr %19, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %.01519, i64 16
  store i64 %20, ptr %21, align 8, !tbaa !5
  %22 = getelementptr inbounds i64, ptr %.01618, i64 %9
  %23 = load i64, ptr %22, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %.01519, i64 24
  store i64 %23, ptr %24, align 8, !tbaa !5
  %25 = getelementptr inbounds i64, ptr %.01618, i64 %10
  %26 = load i64, ptr %25, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %.01519, i64 32
  store i64 %26, ptr %27, align 8, !tbaa !5
  %28 = getelementptr inbounds i64, ptr %.01618, i64 %11
  %29 = load i64, ptr %28, align 8, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %.01519, i64 40
  store i64 %29, ptr %30, align 8, !tbaa !5
  %31 = getelementptr inbounds i64, ptr %.01618, i64 %12
  %32 = load i64, ptr %31, align 8, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %.01519, i64 48
  store i64 %32, ptr %33, align 8, !tbaa !5
  %34 = getelementptr inbounds i64, ptr %.01618, i64 %13
  %35 = load i64, ptr %34, align 8, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %.01519, i64 56
  store i64 %35, ptr %36, align 8, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %.01618, i64 %.idx
  %38 = getelementptr inbounds i8, ptr %.01519, i64 64
  %39 = add nuw i64 %.01420, 1
  %exitcond.not = icmp eq i64 %39, %1
  br i1 %exitcond.not, label %._crit_edge, label %.preheader, !llvm.loop !9

._crit_edge:                                      ; preds = %.preheader, %5
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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" }

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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