; LLVM IR from ShahjalalShohag/code-library :: Math/Faulhaber Formula Fastest.ll (Z9Bernoullii)

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

%struct.poly = type { %"class.std::vector.6" }
%"class.std::vector.6" = type { %"struct.std::_Vector_base.7" }
%"struct.std::_Vector_base.7" = type { %"struct.std::_Vector_base<modint<1000000007>, std::allocator<modint<1000000007>>>::_Vector_impl" }
%"struct.std::_Vector_base<modint<1000000007>, std::allocator<modint<1000000007>>>::_Vector_impl" = type { %"struct.std::_Vector_base<modint<1000000007>, std::allocator<modint<1000000007>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<modint<1000000007>, std::allocator<modint<1000000007>>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%struct.modint = type { i32 }

; 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: 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) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6modintILi1000000007EEC2Ei(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) unnamed_addr #2 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z9Bernoullii(ptr dead_on_unwind noalias writable sret(%struct.poly) align 8 %0, i32 noundef %1) #4 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca %struct.poly, align 8
  %6 = alloca %struct.modint, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca %struct.modint, align 4
  %11 = alloca %struct.modint, align 4
  store ptr %0, ptr %3, align 8
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 24, ptr %5) #6
  %12 = load i32, ptr %4, align 4, !tbaa !5
  call void @_ZN4polyC2IJiEEEDpT_(ptr noundef nonnull align 8 dereferenceable(24) %5, i32 noundef %12)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  invoke void @_ZN6modintILi1000000007EEC2Ei(ptr noundef nonnull align 4 dereferenceable(4) %6, i32 noundef 1)
          to label %13 unwind label %21

13:                                               ; preds = %2
  %14 = getelementptr inbounds %struct.poly, ptr %5, i32 0, i32 0
  %15 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorI6modintILi1000000007EESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %14, i64 noundef 0) #6
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %15, ptr align 4 %6, i64 4, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  store i32 1, ptr %9, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %43, %13
  %17 = load i32, ptr %9, align 4, !tbaa !5
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %25, label %20

20:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  br label %50

21:                                               ; preds = %2
  %22 = landingpad { ptr, i32 }
          cleanup
  %23 = extractvalue { ptr, i32 } %22, 0
  store ptr %23, ptr %7, align 8
  %24 = extractvalue { ptr, i32 } %22, 1
  store i32 %24, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  br label %57

25:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  %26 = getelementptr inbounds %struct.poly, ptr %5, i32 0, i32 0
  %27 = load i32, ptr %9, align 4, !tbaa !5
  %28 = sub nsw i32 %27, 1
  %29 = sext i32 %28 to i64
  %30 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorI6modintILi1000000007EESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %26, i64 noundef %29) #6
  %31 = load i32, ptr %9, align 4, !tbaa !5
  %32 = add nsw i32 %31, 1
  invoke void @_ZN6modintILi1000000007EEC2Ei(ptr noundef nonnull align 4 dereferenceable(4) %11, i32 noundef %32)
          to label %33 unwind label %46

33:                                               ; preds = %25
  %34 = getelementptr inbounds %struct.modint, ptr %11, i32 0, i32 0
  %35 = load i32, ptr %34, align 4
  %36 = invoke i32 @_ZNK6modintILi1000000007EEdvES0_(ptr noundef nonnull align 4 dereferenceable(4) %30, i32 %35)
          to label %37 unwind label %46

37:                                               ; preds = %33
  %38 = getelementptr inbounds %struct.modint, ptr %10, i32 0, i32 0
  store i32 %36, ptr %38, align 4
  %39 = getelementptr inbounds %struct.poly, ptr %5, i32 0, i32 0
  %40 = load i32, ptr %9, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorI6modintILi1000000007EESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %39, i64 noundef %41) #6
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %42, ptr align 4 %10, i64 4, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  br label %43

43:                                               ; preds = %37
  %44 = load i32, ptr %9, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %9, align 4, !tbaa !5
  br label %16, !llvm.loop !10

46:                                               ; preds = %33, %25
  %47 = landingpad { ptr, i32 }
          cleanup
  %48 = extractvalue { ptr, i32 } %47, 0
  store ptr %48, ptr %7, align 8
  %49 = extractvalue { ptr, i32 } %47, 1
  store i32 %49, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  br label %57

50:                                               ; preds = %20
  %51 = load i32, ptr %4, align 4, !tbaa !5
  invoke void @_ZNK4poly7inverseEi(ptr dead_on_unwind writable sret(%struct.poly) align 8 %0, ptr noundef nonnull align 8 dereferenceable(24) %5, i32 noundef %51)
          to label %52 unwind label %53

52:                                               ; preds = %50
  call void @_ZN4polyD2Ev(ptr noundef nonnull align 8 dereferenceable(24) %5) #6
  call void @llvm.lifetime.end.p0(i64 24, ptr %5) #6
  ret void

53:                                               ; preds = %50
  %54 = landingpad { ptr, i32 }
          cleanup
  %55 = extractvalue { ptr, i32 } %54, 0
  store ptr %55, ptr %7, align 8
  %56 = extractvalue { ptr, i32 } %54, 1
  store i32 %56, ptr %8, align 4
  br label %57

57:                                               ; preds = %53, %46, %21
  call void @_ZN4polyD2Ev(ptr noundef nonnull align 8 dereferenceable(24) %5) #6
  call void @llvm.lifetime.end.p0(i64 24, ptr %5) #6
  br label %58

58:                                               ; preds = %57
  %59 = load ptr, ptr %7, align 8
  %60 = load i32, ptr %8, align 4
  %61 = insertvalue { ptr, i32 } poison, ptr %59, 0
  %62 = insertvalue { ptr, i32 } %61, i32 %60, 1
  resume { ptr, i32 } %62
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4polyC2IJiEEEDpT_(ptr noundef nonnull align 8 dereferenceable(24), i32 noundef) unnamed_addr #4 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorI6modintILi1000000007EESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #2 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local i32 @_ZNK6modintILi1000000007EEdvES0_(ptr noundef nonnull align 4 dereferenceable(4), i32) #5 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK4poly7inverseEi(ptr dead_on_unwind noalias writable sret(%struct.poly) align 8, ptr noundef nonnull align 8 dereferenceable(24), i32 noundef) #4 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = { 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 = { 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 #5 = { inlinehint 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 #6 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{i64 0, i64 4, !5}
!10 = distinct !{!10, !11}
!11 = !{!"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"

%struct.poly = type { %"class.std::vector.6" }
%"class.std::vector.6" = type { %"struct.std::_Vector_base.7" }
%"struct.std::_Vector_base.7" = type { %"struct.std::_Vector_base<modint<1000000007>, std::allocator<modint<1000000007>>>::_Vector_impl" }
%"struct.std::_Vector_base<modint<1000000007>, std::allocator<modint<1000000007>>>::_Vector_impl" = type { %"struct.std::_Vector_base<modint<1000000007>, std::allocator<modint<1000000007>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<modint<1000000007>, std::allocator<modint<1000000007>>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%struct.modint = type { i32 }

; Function Attrs: mustprogress 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6modintILi1000000007EEC2Ei(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) unnamed_addr #1 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z9Bernoullii(ptr dead_on_unwind noalias writable sret(%struct.poly) align 8 %0, i32 noundef %1) local_unnamed_addr #3 personality ptr @__gxx_personality_v0 {
  %3 = alloca %struct.poly, align 8
  %4 = alloca %struct.modint, align 4
  %5 = alloca %struct.modint, align 4
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #5
  call void @_ZN4polyC2IJiEEEDpT_(ptr noundef nonnull align 8 dereferenceable(24) %3, i32 noundef %1)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #5
  call void @_ZN6modintILi1000000007EEC2Ei(ptr noundef nonnull align 4 dereferenceable(4) %4, i32 noundef 1)
  %6 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorI6modintILi1000000007EESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef 0) #5
  %7 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %7, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #5
  %8 = icmp sgt i32 %1, 1
  br i1 %8, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %2
  %wide.trip.count = zext nneg i32 %1 to i64
  br label %.lr.ph

._crit_edge:                                      ; preds = %14, %2
  invoke void @_ZNK4poly7inverseEi(ptr dead_on_unwind writable sret(%struct.poly) align 8 %0, ptr noundef nonnull align 8 dereferenceable(24) %3, i32 noundef %1)
          to label %18 unwind label %19

.lr.ph:                                           ; preds = %.lr.ph.preheader, %14
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next, %14 ]
  %9 = add nsw i64 %indvars.iv, -1
  %10 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorI6modintILi1000000007EESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef %9) #5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %11 = trunc nuw nsw i64 %indvars.iv.next to i32
  call void @_ZN6modintILi1000000007EEC2Ei(ptr noundef nonnull align 4 dereferenceable(4) %5, i32 noundef %11)
  %12 = load i32, ptr %5, align 4
  %13 = invoke i32 @_ZNK6modintILi1000000007EEdvES0_(ptr noundef nonnull align 4 dereferenceable(4) %10, i32 %12)
          to label %14 unwind label %16

14:                                               ; preds = %.lr.ph
  %15 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorI6modintILi1000000007EESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef %indvars.iv) #5
  store i32 %13, ptr %15, align 4, !tbaa !5
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

16:                                               ; preds = %.lr.ph
  %17 = landingpad { ptr, i32 }
          cleanup
  br label %21

18:                                               ; preds = %._crit_edge
  call void @_ZN4polyD2Ev(ptr noundef nonnull align 8 dereferenceable(24) %3) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #5
  ret void

19:                                               ; preds = %._crit_edge
  %20 = landingpad { ptr, i32 }
          cleanup
  br label %21

21:                                               ; preds = %19, %16
  %.pn = phi { ptr, i32 } [ %17, %16 ], [ %20, %19 ]
  call void @_ZN4polyD2Ev(ptr noundef nonnull align 8 dereferenceable(24) %3) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #5
  resume { ptr, i32 } %.pn
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4polyC2IJiEEEDpT_(ptr noundef nonnull align 8 dereferenceable(24), i32 noundef) unnamed_addr #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt6vectorI6modintILi1000000007EESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local i32 @_ZNK6modintILi1000000007EEdvES0_(ptr noundef nonnull align 4 dereferenceable(4), i32) local_unnamed_addr #4 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNK4poly7inverseEi(ptr dead_on_unwind noalias writable sret(%struct.poly) align 8, ptr noundef nonnull align 8 dereferenceable(24), i32 noundef) local_unnamed_addr #3 align 2

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


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