; LLVM IR from tfhe/spqlios-arithmetic :: test/testlib (negacyclic_polynomial)

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

%class.polynomial.6 = type { %"class.std::vector.7" }
%"class.std::vector.7" = type { %"struct.std::_Vector_base.8" }
%"struct.std::_Vector_base.8" = type { %"struct.std::_Vector_base<__int128, std::allocator<__int128>>::_Vector_impl" }
%"struct.std::_Vector_base<__int128, std::allocator<__int128>>::_Vector_impl" = type { %"struct.std::_Vector_base<__int128, std::allocator<__int128>>::_Vector_impl_data" }
%"struct.std::_Vector_base<__int128, std::allocator<__int128>>::_Vector_impl_data" = type { ptr, ptr, ptr }

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

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z24random_polynomial_boundsInE10polynomialIT_EmS1_S1_(ptr dead_on_unwind noalias writable sret(%class.polynomial.6) align 8 %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4, i64 noundef %5) #1 personality ptr @__gxx_personality_v0 {
  %7 = alloca ptr, align 8
  %8 = alloca i128, align 16
  %9 = alloca i128, align 16
  %10 = alloca i64, align 8
  %11 = alloca i128, align 16
  %12 = alloca i128, align 16
  %13 = alloca i1, align 1
  %14 = alloca i64, align 8
  %15 = alloca i128, align 16
  %16 = alloca i128, align 16
  %17 = alloca ptr, align 8
  %18 = alloca i32, align 4
  %19 = alloca i128, align 16
  %20 = alloca i128, align 16
  store ptr %0, ptr %7, align 8
  %21 = getelementptr inbounds { i64, i64 }, ptr %8, i32 0, i32 0
  store i64 %2, ptr %21, align 16
  %22 = getelementptr inbounds { i64, i64 }, ptr %8, i32 0, i32 1
  store i64 %3, ptr %22, align 8
  %23 = load i128, ptr %8, align 16, !tbaa !5
  %24 = getelementptr inbounds { i64, i64 }, ptr %9, i32 0, i32 0
  store i64 %4, ptr %24, align 16
  %25 = getelementptr inbounds { i64, i64 }, ptr %9, i32 0, i32 1
  store i64 %5, ptr %25, align 8
  %26 = load i128, ptr %9, align 16, !tbaa !5
  store i64 %1, ptr %10, align 8, !tbaa !9
  store i128 %23, ptr %11, align 16, !tbaa !5
  store i128 %26, ptr %12, align 16, !tbaa !5
  store i1 false, ptr %13, align 1
  %27 = load i64, ptr %10, align 8, !tbaa !9
  call void @_ZN10polynomialInEC1Em(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %27)
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  store i64 0, ptr %14, align 8, !tbaa !9
  br label %28

28:                                               ; preds = %57, %6
  %29 = load i64, ptr %14, align 8, !tbaa !9
  %30 = load i64, ptr %10, align 8, !tbaa !9
  %31 = icmp ult i64 %29, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  br label %64

33:                                               ; preds = %28
  %34 = load i64, ptr %14, align 8, !tbaa !9
  %35 = load i128, ptr %11, align 16, !tbaa !5
  %36 = load i128, ptr %12, align 16, !tbaa !5
  store i128 %35, ptr %15, align 16, !tbaa !5
  %37 = getelementptr inbounds { i64, i64 }, ptr %15, i32 0, i32 0
  %38 = load i64, ptr %37, align 16
  %39 = getelementptr inbounds { i64, i64 }, ptr %15, i32 0, i32 1
  %40 = load i64, ptr %39, align 8
  store i128 %36, ptr %16, align 16, !tbaa !5
  %41 = getelementptr inbounds { i64, i64 }, ptr %16, i32 0, i32 0
  %42 = load i64, ptr %41, align 16
  %43 = getelementptr inbounds { i64, i64 }, ptr %16, i32 0, i32 1
  %44 = load i64, ptr %43, align 8
  %45 = invoke noundef { i64, i64 } @_Z19uniform_i128_boundsnn(i64 noundef %38, i64 noundef %40, i64 noundef %42, i64 noundef %44)
          to label %46 unwind label %60

46:                                               ; preds = %33
  %47 = getelementptr inbounds { i64, i64 }, ptr %19, i32 0, i32 0
  %48 = extractvalue { i64, i64 } %45, 0
  store i64 %48, ptr %47, align 16
  %49 = getelementptr inbounds { i64, i64 }, ptr %19, i32 0, i32 1
  %50 = extractvalue { i64, i64 } %45, 1
  store i64 %50, ptr %49, align 8
  %51 = load i128, ptr %19, align 16, !tbaa !5
  store i128 %51, ptr %20, align 16, !tbaa !5
  %52 = getelementptr inbounds { i64, i64 }, ptr %20, i32 0, i32 0
  %53 = load i64, ptr %52, align 16
  %54 = getelementptr inbounds { i64, i64 }, ptr %20, i32 0, i32 1
  %55 = load i64, ptr %54, align 8
  invoke void @_ZN10polynomialInE9set_coeffEln(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %34, i64 noundef %53, i64 noundef %55)
          to label %56 unwind label %60

56:                                               ; preds = %46
  br label %57

57:                                               ; preds = %56
  %58 = load i64, ptr %14, align 8, !tbaa !9
  %59 = add i64 %58, 1
  store i64 %59, ptr %14, align 8, !tbaa !9
  br label %28, !llvm.loop !11

60:                                               ; preds = %46, %33
  %61 = landingpad { ptr, i32 }
          cleanup
  %62 = extractvalue { ptr, i32 } %61, 0
  store ptr %62, ptr %17, align 8
  %63 = extractvalue { ptr, i32 } %61, 1
  store i32 %63, ptr %18, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @_ZN10polynomialInED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %0) #4
  br label %68

64:                                               ; preds = %32
  store i1 true, ptr %13, align 1
  %65 = load i1, ptr %13, align 1
  br i1 %65, label %67, label %66

66:                                               ; preds = %64
  call void @_ZN10polynomialInED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %0) #4
  br label %67

67:                                               ; preds = %66, %64
  ret void

68:                                               ; preds = %60
  %69 = load ptr, ptr %17, align 8
  %70 = load i32, ptr %18, align 4
  %71 = insertvalue { ptr, i32 } poison, ptr %69, 0
  %72 = insertvalue { ptr, i32 } %71, i32 %70, 1
  resume { ptr, i32 } %72
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN10polynomialInE9set_coeffEln(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef, i64 noundef, i64 noundef) #1 align 2

declare noundef { i64, i64 } @_Z19uniform_i128_boundsnn(i64 noundef, i64 noundef, i64 noundef, i64 noundef) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN10polynomialInED2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #3 align 2

declare void @_ZN10polynomialInEC1Em(ptr, i64)

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { "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 #3 = { inlinehint mustprogress 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 #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 = !{!"__int128", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !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"

%class.polynomial.6 = type { %"class.std::vector.7" }
%"class.std::vector.7" = type { %"struct.std::_Vector_base.8" }
%"struct.std::_Vector_base.8" = type { %"struct.std::_Vector_base<__int128, std::allocator<__int128>>::_Vector_impl" }
%"struct.std::_Vector_base<__int128, std::allocator<__int128>>::_Vector_impl" = type { %"struct.std::_Vector_base<__int128, std::allocator<__int128>>::_Vector_impl_data" }
%"struct.std::_Vector_base<__int128, std::allocator<__int128>>::_Vector_impl_data" = type { ptr, ptr, ptr }

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
define dso_local void @_Z24random_polynomial_boundsInE10polynomialIT_EmS1_S1_(ptr dead_on_unwind noalias writable sret(%class.polynomial.6) align 8 %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4, i64 noundef %5) local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
  tail call void @_ZN10polynomialInEC1Em(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %1)
  %.not = icmp eq i64 %1, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %6, %11
  %.019 = phi i64 [ %12, %11 ], [ 0, %6 ]
  %7 = invoke noundef { i64, i64 } @_Z19uniform_i128_boundsnn(i64 noundef %2, i64 noundef %3, i64 noundef %4, i64 noundef %5)
          to label %8 unwind label %13

8:                                                ; preds = %.lr.ph
  %9 = extractvalue { i64, i64 } %7, 0
  %10 = extractvalue { i64, i64 } %7, 1
  invoke void @_ZN10polynomialInE9set_coeffEln(ptr noundef nonnull align 8 dereferenceable(24) %0, i64 noundef %.019, i64 noundef %9, i64 noundef %10)
          to label %11 unwind label %13

11:                                               ; preds = %8
  %12 = add nuw i64 %.019, 1
  %exitcond.not = icmp eq i64 %12, %1
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5

13:                                               ; preds = %8, %.lr.ph
  %14 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZN10polynomialInED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %0) #3
  resume { ptr, i32 } %14

._crit_edge:                                      ; preds = %11, %6
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN10polynomialInE9set_coeffEln(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef, i64 noundef, i64 noundef) local_unnamed_addr #0 align 2

declare noundef { i64, i64 } @_Z19uniform_i128_boundsnn(i64 noundef, i64 noundef, i64 noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN10polynomialInED2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #2 align 2

declare void @_ZN10polynomialInEC1Em(ptr, i64) local_unnamed_addr

attributes #0 = { mustprogress 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 = { "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 = { inlinehint mustprogress 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 #3 = { 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"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass