; LLVM IR from tfhe/spqlios-arithmetic :: spqlios/coeffs (coeffs_arithmetic)

; 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 @rnx_rotate_inplace_f64(i64 noundef %0, i64 noundef %1, ptr noundef %2) #1 {
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca double, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca double, align 8
  store i64 %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %16 = load i64, ptr %4, align 8, !tbaa !5
  %17 = mul i64 2, %16
  %18 = sub i64 %17, 1
  store i64 %18, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %19 = load i64, ptr %4, align 8, !tbaa !5
  %20 = sub i64 %19, 1
  store i64 %20, 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
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  store i64 0, ptr %10, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %65, %3
  %22 = load i64, ptr %9, align 8, !tbaa !5
  %23 = load i64, ptr %4, align 8, !tbaa !5
  %24 = icmp ult i64 %22, %23
  br i1 %24, label %25, label %68

25:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %26 = load i64, ptr %10, align 8, !tbaa !5
  store i64 %26, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %27 = load ptr, ptr %6, align 8, !tbaa !9
  %28 = load i64, ptr %11, align 8, !tbaa !5
  %29 = getelementptr inbounds double, ptr %27, i64 %28
  %30 = load double, ptr %29, align 8, !tbaa !11
  store double %30, ptr %12, align 8, !tbaa !11
  br label %31

31:                                               ; preds = %61, %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  %32 = load i64, ptr %11, align 8, !tbaa !5
  %33 = load i64, ptr %5, align 8, !tbaa !5
  %34 = add i64 %32, %33
  %35 = load i64, ptr %7, align 8, !tbaa !5
  %36 = and i64 %34, %35
  store i64 %36, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #2
  %37 = load i64, ptr %13, align 8, !tbaa !5
  %38 = load i64, ptr %8, align 8, !tbaa !5
  %39 = and i64 %37, %38
  store i64 %39, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #2
  %40 = load ptr, ptr %6, align 8, !tbaa !9
  %41 = load i64, ptr %14, align 8, !tbaa !5
  %42 = getelementptr inbounds double, ptr %40, i64 %41
  %43 = load double, ptr %42, align 8, !tbaa !11
  store double %43, ptr %15, align 8, !tbaa !11
  %44 = load i64, ptr %13, align 8, !tbaa !5
  %45 = load i64, ptr %4, align 8, !tbaa !5
  %46 = icmp ult i64 %44, %45
  br i1 %46, label %47, label %49

47:                                               ; preds = %31
  %48 = load double, ptr %12, align 8, !tbaa !11
  br label %52

49:                                               ; preds = %31
  %50 = load double, ptr %12, align 8, !tbaa !11
  %51 = fneg double %50
  br label %52

52:                                               ; preds = %49, %47
  %53 = phi double [ %48, %47 ], [ %51, %49 ]
  %54 = load ptr, ptr %6, align 8, !tbaa !9
  %55 = load i64, ptr %14, align 8, !tbaa !5
  %56 = getelementptr inbounds double, ptr %54, i64 %55
  store double %53, ptr %56, align 8, !tbaa !11
  %57 = load double, ptr %15, align 8, !tbaa !11
  store double %57, ptr %12, align 8, !tbaa !11
  %58 = load i64, ptr %9, align 8, !tbaa !5
  %59 = add i64 %58, 1
  store i64 %59, ptr %9, align 8, !tbaa !5
  %60 = load i64, ptr %14, align 8, !tbaa !5
  store i64 %60, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  br label %61

61:                                               ; preds = %52
  %62 = load i64, ptr %11, align 8, !tbaa !5
  %63 = load i64, ptr %10, align 8, !tbaa !5
  %64 = icmp ne i64 %62, %63
  br i1 %64, label %31, label %65, !llvm.loop !13

65:                                               ; preds = %61
  %66 = load i64, ptr %10, align 8, !tbaa !5
  %67 = add i64 %66, 1
  store i64 %67, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  br label %21, !llvm.loop !15

68:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  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 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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(argmem: readwrite) uwtable
define dso_local void @rnx_rotate_inplace_f64(i64 noundef %0, i64 noundef %1, ptr nocapture noundef %2) local_unnamed_addr #0 {
  %4 = shl i64 %0, 1
  %5 = add i64 %4, -1
  %6 = add i64 %0, -1
  %.not31 = icmp eq i64 %0, 0
  br i1 %.not31, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3, %19
  %.030 = phi i64 [ %18, %19 ], [ 0, %3 ]
  %.02529 = phi i64 [ %20, %19 ], [ 0, %3 ]
  %7 = getelementptr inbounds double, ptr %2, i64 %.02529
  %8 = load double, ptr %7, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %9, %.lr.ph
  %.027 = phi double [ %8, %.lr.ph ], [ %14, %9 ]
  %.026 = phi i64 [ %.02529, %.lr.ph ], [ %12, %9 ]
  %.1 = phi i64 [ %.030, %.lr.ph ], [ %18, %9 ]
  %10 = add i64 %.026, %1
  %11 = and i64 %10, %5
  %12 = and i64 %11, %6
  %13 = getelementptr inbounds double, ptr %2, i64 %12
  %14 = load double, ptr %13, align 8, !tbaa !5
  %15 = icmp ult i64 %11, %0
  %16 = fneg double %.027
  %17 = select i1 %15, double %.027, double %16
  store double %17, ptr %13, align 8, !tbaa !5
  %18 = add i64 %.1, 1
  %.not = icmp eq i64 %12, %.02529
  br i1 %.not, label %19, label %9, !llvm.loop !9

19:                                               ; preds = %9
  %20 = add i64 %.02529, 1
  %21 = icmp ult i64 %18, %0
  br i1 %21, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %19, %3
  ret void
}

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


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