; LLVM IR from gbanegas/CryptoSith :: gf/GFieldPol.ll (ZN11galoisfield9GFieldPol8simplifyERS0_)

; 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.galoisfield::GFieldPol" = type { ptr, %"class.std::vector" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<galoisfield::GFieldElement, std::allocator<galoisfield::GFieldElement>>::_Vector_impl" }
%"struct.std::_Vector_base<galoisfield::GFieldElement, std::allocator<galoisfield::GFieldElement>>::_Vector_impl" = type { %"struct.std::_Vector_base<galoisfield::GFieldElement, std::allocator<galoisfield::GFieldElement>>::_Vector_impl_data" }
%"struct.std::_Vector_base<galoisfield::GFieldElement, std::allocator<galoisfield::GFieldElement>>::_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

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

; Function Attrs: 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 noundef i64 @_ZNKSt6vectorIN11galoisfield13GFieldElementESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN11galoisfield9GFieldPol8simplifyERS0_(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(32) %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8
  %8 = getelementptr inbounds %"class.galoisfield::GFieldPol", ptr %7, i32 0, i32 1
  %9 = call noundef i64 @_ZNKSt6vectorIN11galoisfield13GFieldElementESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %8) #4
  %10 = icmp ugt i64 %9, 0
  br i1 %10, label %11, label %42

11:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %"class.galoisfield::GFieldPol", ptr %12, i32 0, i32 1
  %14 = call noundef i64 @_ZNKSt6vectorIN11galoisfield13GFieldElementESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %13) #4
  %15 = sub i64 %14, 1
  store i64 %15, ptr %5, align 8, !tbaa !9
  br label %16

16:                                               ; preds = %36, %11
  %17 = load i64, ptr %5, align 8, !tbaa !9
  %18 = icmp uge i64 %17, 0
  br i1 %18, label %19, label %24

19:                                               ; preds = %16
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %"class.galoisfield::GFieldPol", ptr %20, i32 0, i32 1
  %22 = call noundef i64 @_ZNKSt6vectorIN11galoisfield13GFieldElementESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %21) #4
  %23 = icmp ugt i64 %22, 0
  br label %24

24:                                               ; preds = %19, %16
  %25 = phi i1 [ false, %16 ], [ %23, %19 ]
  br i1 %25, label %26, label %41

26:                                               ; preds = %24
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %"class.galoisfield::GFieldPol", ptr %27, i32 0, i32 1
  %29 = load i64, ptr %5, align 8, !tbaa !9
  %30 = call noundef nonnull align 8 dereferenceable(12) ptr @_ZNSt6vectorIN11galoisfield13GFieldElementESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %28, i64 noundef %29) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !11
  %31 = call noundef zeroext i1 @_ZNK11galoisfield13GFieldElementeqERKi(ptr noundef nonnull align 8 dereferenceable(12) %30, ptr noundef nonnull align 4 dereferenceable(4) %6)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br i1 %31, label %32, label %35

32:                                               ; preds = %26
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %"class.galoisfield::GFieldPol", ptr %33, i32 0, i32 1
  call void @_ZNSt6vectorIN11galoisfield13GFieldElementESaIS1_EE8pop_backEv(ptr noundef nonnull align 8 dereferenceable(24) %34) #4
  br label %36

35:                                               ; preds = %26
  br label %41

36:                                               ; preds = %32
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %"class.galoisfield::GFieldPol", ptr %37, i32 0, i32 1
  %39 = call noundef i64 @_ZNKSt6vectorIN11galoisfield13GFieldElementESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %38) #4
  %40 = sub i64 %39, 1
  store i64 %40, ptr %5, align 8, !tbaa !9
  br label %16, !llvm.loop !13

41:                                               ; preds = %35, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %42

42:                                               ; preds = %41, %2
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK11galoisfield13GFieldElementeqERKi(ptr noundef nonnull align 8 dereferenceable(12), ptr noundef nonnull align 4 dereferenceable(4)) #3 align 2

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

attributes #0 = { 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 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

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

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

; 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 noundef i64 @_ZNKSt6vectorIN11galoisfield13GFieldElementESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN11galoisfield9GFieldPol8simplifyERS0_(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(32) %1) local_unnamed_addr #1 align 2 {
  %3 = alloca i32, align 4
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = tail call noundef i64 @_ZNKSt6vectorIN11galoisfield13GFieldElementESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %4) #3
  %.not = icmp eq i64 %5, 0
  br i1 %.not, label %.critedge, label %6

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %1, i64 8
  %8 = tail call noundef i64 @_ZNKSt6vectorIN11galoisfield13GFieldElementESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %7) #3
  %9 = tail call noundef i64 @_ZNKSt6vectorIN11galoisfield13GFieldElementESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %7) #3
  %.not78 = icmp eq i64 %9, 0
  br i1 %.not78, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %6, %12
  %.0.in9 = phi i64 [ %13, %12 ], [ %8, %6 ]
  %.0 = add i64 %.0.in9, -1
  %10 = call noundef nonnull align 8 dereferenceable(12) ptr @_ZNSt6vectorIN11galoisfield13GFieldElementESaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %7, i64 noundef %.0) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  %11 = call noundef zeroext i1 @_ZNK11galoisfield13GFieldElementeqERKi(ptr noundef nonnull align 8 dereferenceable(12) %10, ptr noundef nonnull align 4 dereferenceable(4) %3)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  br i1 %11, label %12, label %.critedge

12:                                               ; preds = %.lr.ph
  call void @_ZNSt6vectorIN11galoisfield13GFieldElementESaIS1_EE8pop_backEv(ptr noundef nonnull align 8 dereferenceable(24) %7) #3
  %13 = call noundef i64 @_ZNKSt6vectorIN11galoisfield13GFieldElementESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %7) #3
  %14 = call noundef i64 @_ZNKSt6vectorIN11galoisfield13GFieldElementESaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %7) #3
  %.not7 = icmp eq i64 %14, 0
  br i1 %.not7, label %.critedge, label %.lr.ph, !llvm.loop !9

.critedge:                                        ; preds = %.lr.ph, %12, %6, %2
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK11galoisfield13GFieldElementeqERKi(ptr noundef nonnull align 8 dereferenceable(12), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6vectorIN11galoisfield13GFieldElementESaIS1_EE8pop_backEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #1 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 = { 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,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass