; LLVM IR from mhsitu/welding_robot :: coppeliaSim-client/common/stack/stackArray.ll (ZN11CStackArray14buildOntoStackEi)

; 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.CStackArray = type <{ %class.CStackObject.base, [4 x i8], %"class.std::vector", %"class.std::vector.0", %"class.std::vector.5", i8, [7 x i8] }>
%class.CStackObject.base = type <{ ptr, i32 }>
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<CStackObject *, std::allocator<CStackObject *>>::_Vector_impl" }
%"struct.std::_Vector_base<CStackObject *, std::allocator<CStackObject *>>::_Vector_impl" = type { %"struct.std::_Vector_base<CStackObject *, std::allocator<CStackObject *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<CStackObject *, std::allocator<CStackObject *>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector.0" = type { %"struct.std::_Vector_base.1" }
%"struct.std::_Vector_base.1" = type { %"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl" }
%"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl" = type { %"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl_data" }
%"struct.std::_Vector_base<double, std::allocator<double>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"class.std::vector.5" = type { %"struct.std::_Vector_base.6" }
%"struct.std::_Vector_base.6" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl" = type { %"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" }
%"struct.std::_Vector_base<int, std::allocator<int>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@simPopStackItem = external global ptr, align 8
@simPushDoubleOntoStack = external global ptr, align 8

; 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 @_ZNKSt6vectorIP12CStackObjectSaIS1_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 @_ZNSt6vectorIP12CStackObjectSaIS1_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 void @_ZN11CStackArray14buildOntoStackEi(ptr noundef nonnull align 8 dereferenceable(89) %0, i32 noundef %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %7 = load ptr, ptr %3, align 8
  %8 = load ptr, ptr @simPopStackItem, align 8, !tbaa !5
  %9 = load i32, ptr %4, align 4, !tbaa !9
  %10 = call noundef i32 %8(i32 noundef %9, i32 noundef 0)
  %11 = getelementptr inbounds %class.CStackArray, ptr %7, i32 0, i32 3
  %12 = call noundef i64 @_ZNKSt6vectorIdSaIdEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %11) #4
  %13 = icmp ugt i64 %12, 0
  br i1 %13, label %14, label %33

14:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  store i64 0, ptr %5, align 8, !tbaa !11
  br label %15

15:                                               ; preds = %29, %14
  %16 = load i64, ptr %5, align 8, !tbaa !11
  %17 = getelementptr inbounds %class.CStackArray, ptr %7, i32 0, i32 3
  %18 = call noundef i64 @_ZNKSt6vectorIdSaIdEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %17) #4
  %19 = icmp ult i64 %16, %18
  br i1 %19, label %21, label %20

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

21:                                               ; preds = %15
  %22 = load ptr, ptr @simPushDoubleOntoStack, align 8, !tbaa !5
  %23 = load i32, ptr %4, align 4, !tbaa !9
  %24 = getelementptr inbounds %class.CStackArray, ptr %7, i32 0, i32 3
  %25 = load i64, ptr %5, align 8, !tbaa !11
  %26 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %24, i64 noundef %25) #4
  %27 = load double, ptr %26, align 8, !tbaa !13
  %28 = call noundef i32 %22(i32 noundef %23, double noundef %27)
  br label %29

29:                                               ; preds = %21
  %30 = load i64, ptr %5, align 8, !tbaa !11
  %31 = add i64 %30, 1
  store i64 %31, ptr %5, align 8, !tbaa !11
  br label %15, !llvm.loop !15

32:                                               ; preds = %20
  br label %55

33:                                               ; preds = %2
  %34 = getelementptr inbounds %class.CStackArray, ptr %7, i32 0, i32 2
  %35 = call noundef i64 @_ZNKSt6vectorIP12CStackObjectSaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %34) #4
  %36 = icmp ugt i64 %35, 0
  br i1 %36, label %37, label %54

37:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store i64 0, ptr %6, align 8, !tbaa !11
  br label %38

38:                                               ; preds = %50, %37
  %39 = load i64, ptr %6, align 8, !tbaa !11
  %40 = getelementptr inbounds %class.CStackArray, ptr %7, i32 0, i32 2
  %41 = call noundef i64 @_ZNKSt6vectorIP12CStackObjectSaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %40) #4
  %42 = icmp ult i64 %39, %41
  br i1 %42, label %44, label %43

43:                                               ; preds = %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %53

44:                                               ; preds = %38
  %45 = load i32, ptr %4, align 4, !tbaa !9
  %46 = getelementptr inbounds %class.CStackArray, ptr %7, i32 0, i32 2
  %47 = load i64, ptr %6, align 8, !tbaa !11
  %48 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP12CStackObjectSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %46, i64 noundef %47) #4
  %49 = load ptr, ptr %48, align 8, !tbaa !5
  call void @_ZN12CStackObject18buildItemOntoStackEiPS_(i32 noundef %45, ptr noundef %49)
  br label %50

50:                                               ; preds = %44
  %51 = load i64, ptr %6, align 8, !tbaa !11
  %52 = add i64 %51, 1
  store i64 %52, ptr %6, align 8, !tbaa !11
  br label %38, !llvm.loop !17

53:                                               ; preds = %43
  br label %54

54:                                               ; preds = %53, %33
  br label %55

55:                                               ; preds = %54, %32
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIdSaIdEE4sizeEv(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 @_ZNSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 align 2

declare void @_ZN12CStackObject18buildItemOntoStackEiPS_(i32 noundef, ptr noundef) #3

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 = { "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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


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

@simPopStackItem = external local_unnamed_addr global ptr, align 8
@simPushDoubleOntoStack = external local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIP12CStackObjectSaIS1_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 @_ZNSt6vectorIP12CStackObjectSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN11CStackArray14buildOntoStackEi(ptr noundef nonnull align 8 dereferenceable(89) %0, i32 noundef %1) local_unnamed_addr #1 align 2 {
  %3 = load ptr, ptr @simPopStackItem, align 8, !tbaa !5
  %4 = tail call noundef i32 %3(i32 noundef %1, i32 noundef 0)
  %5 = getelementptr inbounds i8, ptr %0, i64 40
  %6 = tail call noundef i64 @_ZNKSt6vectorIdSaIdEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %5) #3
  %.not = icmp eq i64 %6, 0
  br i1 %.not, label %15, label %.preheader11

.preheader11:                                     ; preds = %2
  %7 = tail call noundef i64 @_ZNKSt6vectorIdSaIdEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %5) #3
  %.not16 = icmp eq i64 %7, 0
  br i1 %.not16, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader11, %.lr.ph
  %.0913 = phi i64 [ %12, %.lr.ph ], [ 0, %.preheader11 ]
  %8 = load ptr, ptr @simPushDoubleOntoStack, align 8, !tbaa !5
  %9 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24) %5, i64 noundef %.0913) #3
  %10 = load double, ptr %9, align 8, !tbaa !9
  %11 = tail call noundef i32 %8(i32 noundef %1, double noundef %10)
  %12 = add nuw i64 %.0913, 1
  %13 = tail call noundef i64 @_ZNKSt6vectorIdSaIdEE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %5) #3
  %14 = icmp ult i64 %12, %13
  br i1 %14, label %.lr.ph, label %.loopexit, !llvm.loop !11

15:                                               ; preds = %2
  %16 = getelementptr inbounds i8, ptr %0, i64 16
  %17 = tail call noundef i64 @_ZNKSt6vectorIP12CStackObjectSaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %16) #3
  %.not10 = icmp eq i64 %17, 0
  br i1 %.not10, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %15
  %18 = tail call noundef i64 @_ZNKSt6vectorIP12CStackObjectSaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %16) #3
  %.not17 = icmp eq i64 %18, 0
  br i1 %.not17, label %.loopexit, label %.lr.ph15

.lr.ph15:                                         ; preds = %.preheader, %.lr.ph15
  %.014 = phi i64 [ %21, %.lr.ph15 ], [ 0, %.preheader ]
  %19 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP12CStackObjectSaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %16, i64 noundef %.014) #3
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  tail call void @_ZN12CStackObject18buildItemOntoStackEiPS_(i32 noundef %1, ptr noundef %20)
  %21 = add nuw i64 %.014, 1
  %22 = tail call noundef i64 @_ZNKSt6vectorIP12CStackObjectSaIS1_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %16) #3
  %23 = icmp ult i64 %21, %22
  br i1 %23, label %.lr.ph15, label %.loopexit, !llvm.loop !13

.loopexit:                                        ; preds = %.lr.ph, %.lr.ph15, %.preheader11, %.preheader, %15
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIdSaIdEE4sizeEv(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 @_ZNSt6vectorIdSaIdEEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

declare void @_ZN12CStackObject18buildItemOntoStackEiPS_(i32 noundef, ptr noundef) local_unnamed_addr #2

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 = { "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, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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