; LLVM IR from HRI-EU/Rcs :: src/RcsCore/MotionControlLayer.ll (ZN3Rcs18MotionControlLayer23notifyEmergencyRecoveryEv)

; 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.Rcs::MotionControlLayer" = type { ptr, ptr, ptr, %"class.std::vector", ptr, i8, i8, i8, i8, i32, i32, double, double, double, double }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<Rcs::HardwareComponent *, std::allocator<Rcs::HardwareComponent *>>::_Vector_impl" }
%"struct.std::_Vector_base<Rcs::HardwareComponent *, std::allocator<Rcs::HardwareComponent *>>::_Vector_impl" = type { %"struct.std::_Vector_base<Rcs::HardwareComponent *, std::allocator<Rcs::HardwareComponent *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<Rcs::HardwareComponent *, std::allocator<Rcs::HardwareComponent *>>::_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 i64 @_ZNKSt6vectorIPN3Rcs17HardwareComponentESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIPN3Rcs17HardwareComponentESaIS2_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 uwtable
define dso_local noundef zeroext i1 @_ZN3Rcs18MotionControlLayer23notifyEmergencyRecoveryEv(ptr noundef nonnull align 8 dereferenceable(104) %0) unnamed_addr #2 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  %5 = getelementptr inbounds %"class.Rcs::MotionControlLayer", ptr %4, i32 0, i32 8
  store i8 0, ptr %5, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  store i64 0, ptr %3, align 8, !tbaa !18
  br label %6

6:                                                ; preds = %30, %1
  %7 = load i64, ptr %3, align 8, !tbaa !18
  %8 = getelementptr inbounds %"class.Rcs::MotionControlLayer", ptr %4, i32 0, i32 3
  %9 = call noundef i64 @_ZNKSt6vectorIPN3Rcs17HardwareComponentESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %8) #3
  %10 = icmp ult i64 %7, %9
  br i1 %10, label %12, label %11

11:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  br label %33

12:                                               ; preds = %6
  %13 = getelementptr inbounds %"class.Rcs::MotionControlLayer", ptr %4, i32 0, i32 8
  %14 = load i8, ptr %13, align 1, !tbaa !9, !range !20, !noundef !21
  %15 = trunc i8 %14 to i1
  br i1 %15, label %26, label %16

16:                                               ; preds = %12
  %17 = getelementptr inbounds %"class.Rcs::MotionControlLayer", ptr %4, i32 0, i32 3
  %18 = load i64, ptr %3, align 8, !tbaa !18
  %19 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIPN3Rcs17HardwareComponentESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %17, i64 noundef %18) #3
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  %21 = load ptr, ptr %20, align 8, !tbaa !22
  %22 = getelementptr inbounds ptr, ptr %21, i64 11
  %23 = load ptr, ptr %22, align 8
  %24 = call noundef zeroext i1 %23(ptr noundef nonnull align 8 dereferenceable(25) %20)
  %25 = xor i1 %24, true
  br label %26

26:                                               ; preds = %16, %12
  %27 = phi i1 [ true, %12 ], [ %25, %16 ]
  %28 = getelementptr inbounds %"class.Rcs::MotionControlLayer", ptr %4, i32 0, i32 8
  %29 = zext i1 %27 to i8
  store i8 %29, ptr %28, align 1, !tbaa !9
  br label %30

30:                                               ; preds = %26
  %31 = load i64, ptr %3, align 8, !tbaa !18
  %32 = add i64 %31, 1
  store i64 %32, ptr %3, align 8, !tbaa !18
  br label %6, !llvm.loop !24

33:                                               ; preds = %11
  %34 = getelementptr inbounds %"class.Rcs::MotionControlLayer", ptr %4, i32 0, i32 8
  %35 = load i8, ptr %34, align 1, !tbaa !9, !range !20, !noundef !21
  %36 = trunc i8 %35 to i1
  %37 = xor i1 %36, true
  ret i1 %37
}

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 = { 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, !15, i64 59}
!10 = !{!"_ZTSN3Rcs18MotionControlLayerE", !6, i64 8, !6, i64 16, !11, i64 24, !6, i64 48, !15, i64 56, !15, i64 57, !15, i64 58, !15, i64 59, !16, i64 60, !16, i64 64, !17, i64 72, !17, i64 80, !17, i64 88, !17, i64 96}
!11 = !{!"_ZTSSt6vectorIPN3Rcs17HardwareComponentESaIS2_EE", !12, i64 0}
!12 = !{!"_ZTSSt12_Vector_baseIPN3Rcs17HardwareComponentESaIS2_EE", !13, i64 0}
!13 = !{!"_ZTSNSt12_Vector_baseIPN3Rcs17HardwareComponentESaIS2_EE12_Vector_implE", !14, i64 0}
!14 = !{!"_ZTSNSt12_Vector_baseIPN3Rcs17HardwareComponentESaIS2_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!15 = !{!"bool", !7, i64 0}
!16 = !{!"int", !7, i64 0}
!17 = !{!"double", !7, i64 0}
!18 = !{!19, !19, i64 0}
!19 = !{!"long", !7, i64 0}
!20 = !{i8 0, i8 2}
!21 = !{}
!22 = !{!23, !23, i64 0}
!23 = !{!"vtable pointer", !8, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"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 nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIPN3Rcs17HardwareComponentESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN3Rcs18MotionControlLayer23notifyEmergencyRecoveryEv(ptr noundef nonnull align 8 dereferenceable(104) %0) unnamed_addr #1 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 59
  store i8 0, ptr %2, align 1, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 24
  %4 = tail call noundef i64 @_ZNKSt6vectorIPN3Rcs17HardwareComponentESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %3) #2
  %.not = icmp eq i64 %4, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %18, %1
  %5 = load i8, ptr %2, align 1, !tbaa !5, !range !17, !noundef !18
  %6 = trunc nuw i8 %5 to i1
  %7 = xor i1 %6, true
  ret i1 %7

.lr.ph:                                           ; preds = %1, %18
  %.03 = phi i64 [ %21, %18 ], [ 0, %1 ]
  %8 = load i8, ptr %2, align 1, !tbaa !5, !range !17, !noundef !18
  %9 = trunc nuw i8 %8 to i1
  br i1 %9, label %18, label %10

10:                                               ; preds = %.lr.ph
  %11 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIPN3Rcs17HardwareComponentESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef %.03) #2
  %12 = load ptr, ptr %11, align 8, !tbaa !19
  %13 = load ptr, ptr %12, align 8, !tbaa !20
  %14 = getelementptr inbounds i8, ptr %13, i64 88
  %15 = load ptr, ptr %14, align 8
  %16 = tail call noundef zeroext i1 %15(ptr noundef nonnull align 8 dereferenceable(25) %12)
  %17 = xor i1 %16, true
  br label %18

18:                                               ; preds = %10, %.lr.ph
  %19 = phi i1 [ true, %.lr.ph ], [ %17, %10 ]
  %20 = zext i1 %19 to i8
  store i8 %20, ptr %2, align 1, !tbaa !5
  %21 = add nuw i64 %.03, 1
  %22 = tail call noundef i64 @_ZNKSt6vectorIPN3Rcs17HardwareComponentESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %3) #2
  %23 = icmp ult i64 %21, %22
  br i1 %23, label %.lr.ph, label %._crit_edge, !llvm.loop !22
}

attributes #0 = { 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 #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 = { 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, !14, i64 59}
!6 = !{!"_ZTSN3Rcs18MotionControlLayerE", !7, i64 8, !7, i64 16, !10, i64 24, !7, i64 48, !14, i64 56, !14, i64 57, !14, i64 58, !14, i64 59, !15, i64 60, !15, i64 64, !16, i64 72, !16, i64 80, !16, i64 88, !16, i64 96}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSSt6vectorIPN3Rcs17HardwareComponentESaIS2_EE", !11, i64 0}
!11 = !{!"_ZTSSt12_Vector_baseIPN3Rcs17HardwareComponentESaIS2_EE", !12, i64 0}
!12 = !{!"_ZTSNSt12_Vector_baseIPN3Rcs17HardwareComponentESaIS2_EE12_Vector_implE", !13, i64 0}
!13 = !{!"_ZTSNSt12_Vector_baseIPN3Rcs17HardwareComponentESaIS2_EE17_Vector_impl_dataE", !7, i64 0, !7, i64 8, !7, i64 16}
!14 = !{!"bool", !8, i64 0}
!15 = !{!"int", !8, i64 0}
!16 = !{!"double", !8, i64 0}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!7, !7, i64 0}
!20 = !{!21, !21, i64 0}
!21 = !{!"vtable pointer", !9, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


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