; LLVM IR from tfhe/spqlios-arithmetic :: spqlios/q120 (q120_arithmetic_simple)

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

@q120_b_from_znx64_simple.OQ = external hidden constant [4 x i64], align 16

; 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 @q120_b_from_znx64_simple(i64 noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  store i64 %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %12 = load ptr, ptr %5, align 8, !tbaa !9
  store ptr %12, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  store i64 0, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  store i64 0, ptr %9, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %73, %3
  %14 = load i64, ptr %9, align 8, !tbaa !5
  %15 = load i64, ptr %4, align 8, !tbaa !5
  %16 = icmp ult i64 %14, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %78

18:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %19 = load ptr, ptr %6, align 8, !tbaa !9
  %20 = load i64, ptr %9, align 8, !tbaa !5
  %21 = getelementptr inbounds i64, ptr %19, i64 %20
  %22 = load i64, ptr %21, align 8, !tbaa !5
  %23 = and i64 %22, 9223372036854775807
  store i64 %23, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %24 = load ptr, ptr %6, align 8, !tbaa !9
  %25 = load i64, ptr %9, align 8, !tbaa !5
  %26 = getelementptr inbounds i64, ptr %24, i64 %25
  %27 = load i64, ptr %26, align 8, !tbaa !5
  %28 = and i64 %27, -9223372036854775808
  store i64 %28, ptr %11, align 8, !tbaa !5
  %29 = load i64, ptr %10, align 8, !tbaa !5
  %30 = load i64, ptr %11, align 8, !tbaa !5
  %31 = icmp ne i64 %30, 0
  %32 = zext i1 %31 to i64
  %33 = load i64, ptr @q120_b_from_znx64_simple.OQ, align 16, !tbaa !5
  %34 = select i1 %31, i64 %33, i64 0
  %35 = add i64 %29, %34
  %36 = load ptr, ptr %7, align 8, !tbaa !9
  %37 = load i64, ptr %8, align 8, !tbaa !5
  %38 = add i64 %37, 0
  %39 = getelementptr inbounds i64, ptr %36, i64 %38
  store i64 %35, ptr %39, align 8, !tbaa !5
  %40 = load i64, ptr %10, align 8, !tbaa !5
  %41 = load i64, ptr %11, align 8, !tbaa !5
  %42 = icmp ne i64 %41, 0
  %43 = zext i1 %42 to i64
  %44 = load i64, ptr getelementptr inbounds ([4 x i64], ptr @q120_b_from_znx64_simple.OQ, i64 0, i64 1), align 8, !tbaa !5
  %45 = select i1 %42, i64 %44, i64 0
  %46 = add i64 %40, %45
  %47 = load ptr, ptr %7, align 8, !tbaa !9
  %48 = load i64, ptr %8, align 8, !tbaa !5
  %49 = add i64 %48, 1
  %50 = getelementptr inbounds i64, ptr %47, i64 %49
  store i64 %46, ptr %50, align 8, !tbaa !5
  %51 = load i64, ptr %10, align 8, !tbaa !5
  %52 = load i64, ptr %11, align 8, !tbaa !5
  %53 = icmp ne i64 %52, 0
  %54 = zext i1 %53 to i64
  %55 = load i64, ptr getelementptr inbounds ([4 x i64], ptr @q120_b_from_znx64_simple.OQ, i64 0, i64 2), align 16, !tbaa !5
  %56 = select i1 %53, i64 %55, i64 0
  %57 = add i64 %51, %56
  %58 = load ptr, ptr %7, align 8, !tbaa !9
  %59 = load i64, ptr %8, align 8, !tbaa !5
  %60 = add i64 %59, 2
  %61 = getelementptr inbounds i64, ptr %58, i64 %60
  store i64 %57, ptr %61, align 8, !tbaa !5
  %62 = load i64, ptr %10, align 8, !tbaa !5
  %63 = load i64, ptr %11, align 8, !tbaa !5
  %64 = icmp ne i64 %63, 0
  %65 = zext i1 %64 to i64
  %66 = load i64, ptr getelementptr inbounds ([4 x i64], ptr @q120_b_from_znx64_simple.OQ, i64 0, i64 3), align 8, !tbaa !5
  %67 = select i1 %64, i64 %66, i64 0
  %68 = add i64 %62, %67
  %69 = load ptr, ptr %7, align 8, !tbaa !9
  %70 = load i64, ptr %8, align 8, !tbaa !5
  %71 = add i64 %70, 3
  %72 = getelementptr inbounds i64, ptr %69, i64 %71
  store i64 %68, ptr %72, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  br label %73

73:                                               ; preds = %18
  %74 = load i64, ptr %8, align 8, !tbaa !5
  %75 = add i64 %74, 4
  store i64 %75, ptr %8, align 8, !tbaa !5
  %76 = load i64, ptr %9, align 8, !tbaa !5
  %77 = add i64 %76, 1
  store i64 %77, ptr %9, align 8, !tbaa !5
  br label %13, !llvm.loop !11

78:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #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"}


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

@q120_b_from_znx64_simple.OQ = external hidden local_unnamed_addr constant [4 x i64], align 16

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @q120_b_from_znx64_simple(i64 noundef %0, ptr nocapture noundef writeonly %1, ptr nocapture noundef readonly %2) local_unnamed_addr #0 {
  %.not27 = icmp eq i64 %0, 0
  br i1 %.not27, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %4 = load <4 x i64>, ptr @q120_b_from_znx64_simple.OQ, align 16, !tbaa !5
  br label %5

._crit_edge:                                      ; preds = %5, %3
  ret void

5:                                                ; preds = %.lr.ph, %5
  %.026 = phi i64 [ 0, %.lr.ph ], [ %16, %5 ]
  %.02425 = phi i64 [ 0, %.lr.ph ], [ %17, %5 ]
  %6 = getelementptr inbounds i64, ptr %2, i64 %.02425
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = and i64 %7, 9223372036854775807
  %.not = icmp sgt i64 %7, -1
  %9 = getelementptr inbounds i64, ptr %1, i64 %.026
  %10 = insertelement <4 x i1> poison, i1 %.not, i64 0
  %11 = shufflevector <4 x i1> %10, <4 x i1> poison, <4 x i32> zeroinitializer
  %12 = select <4 x i1> %11, <4 x i64> zeroinitializer, <4 x i64> %4
  %13 = insertelement <4 x i64> poison, i64 %8, i64 0
  %14 = shufflevector <4 x i64> %13, <4 x i64> poison, <4 x i32> zeroinitializer
  %15 = add <4 x i64> %12, %14
  store <4 x i64> %15, ptr %9, align 8, !tbaa !5
  %16 = add i64 %.026, 4
  %17 = add nuw i64 %.02425, 1
  %exitcond.not = icmp eq i64 %17, %0
  br i1 %exitcond.not, label %._crit_edge, label %5, !llvm.loop !9
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: readwrite) 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: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass