; LLVM IR from alibaba/euler :: euler/core/framework/tensor.ll (ZN5euler6TensorD2Ev)

; 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.euler::Tensor" = type { %"class.euler::RefCountedPtr.1" }
%"class.euler::RefCountedPtr.1" = type { ptr }
%"class.euler::Tensor::State" = type <{ %"class.euler::RefCounted", %"class.euler::RefCountedPtr.0", %"class.euler::TensorShape", i32, [4 x i8] }>
%"class.euler::RefCounted" = type { ptr, %"struct.std::atomic" }
%"struct.std::atomic" = type { %"struct.std::__atomic_base" }
%"struct.std::__atomic_base" = type { i64 }
%"class.euler::RefCountedPtr.0" = type { ptr }
%"class.euler::TensorShape" = type { i64, %"class.std::vector" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<unsigned long, std::allocator<unsigned long>>::_Vector_impl" }
%"struct.std::_Vector_base<unsigned long, std::allocator<unsigned long>>::_Vector_impl" = type { %"struct.std::_Vector_base<unsigned long, std::allocator<unsigned long>>::_Vector_impl_data" }
%"struct.std::_Vector_base<unsigned long, std::allocator<unsigned long>>::_Vector_impl_data" = type { ptr, ptr, ptr }

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #0

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) #1

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZNK5euler6Tensor3RawIPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEPT_v(ptr noundef nonnull align 8 dereferenceable(8)) #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK5euler6Tensor11NumElementsEv(ptr noundef nonnull align 8 dereferenceable(8)) #3 align 2

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN5euler6TensorD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %0) unnamed_addr #4 align 2 personality ptr @__gxx_personality_v0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8
  %6 = invoke noundef zeroext i1 @_ZNK5euler6Tensor11InitializedEv(ptr noundef nonnull align 8 dereferenceable(8) %5)
          to label %7 unwind label %47

7:                                                ; preds = %1
  br i1 %6, label %8, label %45

8:                                                ; preds = %7
  %9 = getelementptr inbounds %"class.euler::Tensor", ptr %5, i32 0, i32 0
  %10 = invoke noundef ptr @_ZNK5euler13RefCountedPtrINS_6Tensor5StateEEptEv(ptr noundef nonnull align 8 dereferenceable(8) %9)
          to label %11 unwind label %47

11:                                               ; preds = %8
  %12 = getelementptr inbounds %"class.euler::Tensor::State", ptr %10, i32 0, i32 3
  %13 = load i32, ptr %12, align 8, !tbaa !9
  %14 = icmp eq i32 %13, 11
  br i1 %14, label %15, label %45

15:                                               ; preds = %11
  %16 = getelementptr inbounds %"class.euler::Tensor", ptr %5, i32 0, i32 0
  %17 = invoke noundef ptr @_ZNK5euler13RefCountedPtrINS_6Tensor5StateEEptEv(ptr noundef nonnull align 8 dereferenceable(8) %16)
          to label %18 unwind label %47

18:                                               ; preds = %15
  %19 = getelementptr inbounds %"class.euler::Tensor::State", ptr %17, i32 0, i32 1
  %20 = invoke noundef ptr @_ZNK5euler13RefCountedPtrINS_6BufferEEptEv(ptr noundef nonnull align 8 dereferenceable(8) %19)
          to label %21 unwind label %47

21:                                               ; preds = %18
  %22 = invoke noundef zeroext i1 @_ZNK5euler6Buffer3ownEv(ptr noundef nonnull align 8 dereferenceable(56) %20)
          to label %23 unwind label %47

23:                                               ; preds = %21
  br i1 %22, label %24, label %45

24:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %25 = invoke noundef ptr @_ZNK5euler6Tensor3RawIPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEPT_v(ptr noundef nonnull align 8 dereferenceable(8) %5)
          to label %26 unwind label %47

26:                                               ; preds = %24
  store ptr %25, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 0, ptr %4, align 4, !tbaa !22
  br label %27

27:                                               ; preds = %41, %26
  %28 = load i32, ptr %4, align 4, !tbaa !22
  %29 = invoke noundef i32 @_ZNK5euler6Tensor11NumElementsEv(ptr noundef nonnull align 8 dereferenceable(8) %5)
          to label %30 unwind label %47

30:                                               ; preds = %27
  %31 = icmp slt i32 %28, %29
  br i1 %31, label %33, label %32

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

33:                                               ; preds = %30
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = load ptr, ptr %34, align 8, !tbaa !5
  %36 = icmp eq ptr %35, null
  br i1 %36, label %38, label %37

37:                                               ; preds = %33
  call void @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev(ptr noundef nonnull align 8 dereferenceable(32) %35) #5
  call void @_ZdlPvm(ptr noundef %35, i64 noundef 32) #6
  br label %38

38:                                               ; preds = %37, %33
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds ptr, ptr %39, i32 1
  store ptr %40, ptr %3, align 8, !tbaa !5
  br label %41

41:                                               ; preds = %38
  %42 = load i32, ptr %4, align 4, !tbaa !22
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %4, align 4, !tbaa !22
  br label %27, !llvm.loop !24

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

45:                                               ; preds = %44, %23, %11, %7
  %46 = getelementptr inbounds %"class.euler::Tensor", ptr %5, i32 0, i32 0
  call void @_ZN5euler13RefCountedPtrINS_6Tensor5StateEED2Ev(ptr noundef nonnull align 8 dereferenceable(8) %46) #5
  ret void

47:                                               ; preds = %27, %24, %21, %18, %15, %8, %1
  %48 = landingpad { ptr, i32 }
          catch ptr null
  %49 = extractvalue { ptr, i32 } %48, 0
  call void @__clang_call_terminate(ptr %49) #7
  unreachable
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZNK5euler6Tensor11InitializedEv(ptr noundef nonnull align 8 dereferenceable(8)) #3 align 2

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK5euler6Buffer3ownEv(ptr noundef nonnull align 8 dereferenceable(56)) #4 align 2

; Function Attrs: mustprogress nounwind uwtable
declare void @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev(ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #4 align 2

attributes #0 = { nobuiltin nounwind "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 = { noinline noreturn nounwind uwtable "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #5 = { nounwind }
attributes #6 = { builtin nounwind }
attributes #7 = { noreturn 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, !21, i64 56}
!10 = !{!"_ZTSN5euler6Tensor5StateE", !11, i64 0, !15, i64 16, !16, i64 24, !21, i64 56}
!11 = !{!"_ZTSN5euler10RefCountedE", !12, i64 8}
!12 = !{!"_ZTSSt6atomicIlE", !13, i64 0}
!13 = !{!"_ZTSSt13__atomic_baseIlE", !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!"_ZTSN5euler13RefCountedPtrINS_6BufferEEE", !6, i64 0}
!16 = !{!"_ZTSN5euler11TensorShapeE", !14, i64 0, !17, i64 8}
!17 = !{!"_ZTSSt6vectorImSaImEE", !18, i64 0}
!18 = !{!"_ZTSSt12_Vector_baseImSaImEE", !19, i64 0}
!19 = !{!"_ZTSNSt12_Vector_baseImSaImEE12_Vector_implE", !20, i64 0}
!20 = !{!"_ZTSNSt12_Vector_baseImSaImEE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!21 = !{!"_ZTSN5euler8DataTypeE", !7, i64 0}
!22 = !{!23, !23, i64 0}
!23 = !{!"int", !7, 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: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) local_unnamed_addr #0

declare i32 @__gxx_personality_v0(...)

; Function Attrs: noinline noreturn nounwind uwtable
declare hidden void @__clang_call_terminate(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZNK5euler6Tensor3RawIPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEPT_v(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK5euler6Tensor11NumElementsEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2 align 2

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN5euler6TensorD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %0) unnamed_addr #3 align 2 personality ptr @__gxx_personality_v0 {
  %2 = invoke noundef zeroext i1 @_ZNK5euler6Tensor11InitializedEv(ptr noundef nonnull align 8 dereferenceable(8) %0)
          to label %3 unwind label %.loopexit.split-lp

3:                                                ; preds = %1
  br i1 %2, label %4, label %.loopexit6

4:                                                ; preds = %3
  %5 = tail call noundef ptr @_ZNK5euler13RefCountedPtrINS_6Tensor5StateEEptEv(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %6 = getelementptr inbounds i8, ptr %5, i64 56
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %8 = icmp eq i32 %7, 11
  br i1 %8, label %9, label %.loopexit6

9:                                                ; preds = %4
  %10 = tail call noundef ptr @_ZNK5euler13RefCountedPtrINS_6Tensor5StateEEptEv(ptr noundef nonnull align 8 dereferenceable(8) %0)
  %11 = getelementptr inbounds i8, ptr %10, i64 16
  %12 = tail call noundef ptr @_ZNK5euler13RefCountedPtrINS_6BufferEEptEv(ptr noundef nonnull align 8 dereferenceable(8) %11)
  %13 = tail call noundef zeroext i1 @_ZNK5euler6Buffer3ownEv(ptr noundef nonnull align 8 dereferenceable(56) %12)
  br i1 %13, label %14, label %.loopexit6

14:                                               ; preds = %9
  %15 = invoke noundef ptr @_ZNK5euler6Tensor3RawIPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEPT_v(ptr noundef nonnull align 8 dereferenceable(8) %0)
          to label %.preheader unwind label %.loopexit.split-lp

.preheader:                                       ; preds = %14, %23
  %.04 = phi ptr [ %24, %23 ], [ %15, %14 ]
  %.0 = phi i32 [ %25, %23 ], [ 0, %14 ]
  %16 = invoke noundef i32 @_ZNK5euler6Tensor11NumElementsEv(ptr noundef nonnull align 8 dereferenceable(8) %0)
          to label %17 unwind label %.loopexit

17:                                               ; preds = %.preheader
  %18 = icmp slt i32 %.0, %16
  br i1 %18, label %19, label %.loopexit6

19:                                               ; preds = %17
  %20 = load ptr, ptr %.04, align 8, !tbaa !21
  %21 = icmp eq ptr %20, null
  br i1 %21, label %23, label %22

22:                                               ; preds = %19
  tail call void @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev(ptr noundef nonnull align 8 dereferenceable(32) %20) #4
  tail call void @_ZdlPvm(ptr noundef nonnull %20, i64 noundef 32) #5
  br label %23

23:                                               ; preds = %22, %19
  %24 = getelementptr inbounds i8, ptr %.04, i64 8
  %25 = add nuw nsw i32 %.0, 1
  br label %.preheader, !llvm.loop !22

.loopexit6:                                       ; preds = %17, %9, %4, %3
  tail call void @_ZN5euler13RefCountedPtrINS_6Tensor5StateEED2Ev(ptr noundef nonnull align 8 dereferenceable(8) %0) #4
  ret void

.loopexit:                                        ; preds = %.preheader
  %lpad.loopexit = landingpad { ptr, i32 }
          catch ptr null
  br label %26

.loopexit.split-lp:                               ; preds = %1, %14
  %lpad.loopexit.split-lp = landingpad { ptr, i32 }
          catch ptr null
  br label %26

26:                                               ; preds = %.loopexit.split-lp, %.loopexit
  %lpad.phi = phi { ptr, i32 } [ %lpad.loopexit, %.loopexit ], [ %lpad.loopexit.split-lp, %.loopexit.split-lp ]
  %27 = extractvalue { ptr, i32 } %lpad.phi, 0
  tail call void @__clang_call_terminate(ptr %27) #6
  unreachable
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZNK5euler6Tensor11InitializedEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK5euler13RefCountedPtrINS_6Tensor5StateEEptEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK5euler13RefCountedPtrINS_6BufferEEptEv(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK5euler6Buffer3ownEv(ptr noundef nonnull align 8 dereferenceable(56)) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare void @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev(ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #3 align 2

attributes #0 = { nobuiltin nounwind "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 = { noinline noreturn nounwind uwtable "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 = { 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 }
attributes #5 = { builtin nounwind }
attributes #6 = { noreturn 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, !20, i64 56}
!6 = !{!"_ZTSN5euler6Tensor5StateE", !7, i64 0, !13, i64 16, !15, i64 24, !20, i64 56}
!7 = !{!"_ZTSN5euler10RefCountedE", !8, i64 8}
!8 = !{!"_ZTSSt6atomicIlE", !9, i64 0}
!9 = !{!"_ZTSSt13__atomic_baseIlE", !10, i64 0}
!10 = !{!"long", !11, i64 0}
!11 = !{!"omnipotent char", !12, i64 0}
!12 = !{!"Simple C++ TBAA"}
!13 = !{!"_ZTSN5euler13RefCountedPtrINS_6BufferEEE", !14, i64 0}
!14 = !{!"any pointer", !11, i64 0}
!15 = !{!"_ZTSN5euler11TensorShapeE", !10, i64 0, !16, i64 8}
!16 = !{!"_ZTSSt6vectorImSaImEE", !17, i64 0}
!17 = !{!"_ZTSSt12_Vector_baseImSaImEE", !18, i64 0}
!18 = !{!"_ZTSNSt12_Vector_baseImSaImEE12_Vector_implE", !19, i64 0}
!19 = !{!"_ZTSNSt12_Vector_baseImSaImEE17_Vector_impl_dataE", !14, i64 0, !14, i64 8, !14, i64 16}
!20 = !{!"_ZTSN5euler8DataTypeE", !11, i64 0}
!21 = !{!14, !14, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


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