; LLVM IR from NVIDIA/DALI :: dali/c_api_2 (data_objects)

; 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.std::__exception_ptr::exception_ptr" = type { ptr }
%"class.std::basic_string_view" = type { i64, ptr }

@.str.5 = external hidden unnamed_addr constant [27 x i8], align 1

; 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: mustprogress uwtable
declare dso_local noundef ptr @_ZN4dali5c_api9ToPointerEP11_DALITensor(ptr noundef) #1

declare noundef i32 @_ZN4dali5c_api9CheckInitEv() #2

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

declare ptr @__cxa_begin_catch(ptr)

declare noundef i32 @_ZN4dali5c_api11HandleErrorENSt15__exception_ptr13exception_ptrE(ptr noundef) #2

; Function Attrs: nounwind
declare void @_ZSt17current_exceptionv(ptr dead_on_unwind writable sret(%"class.std::__exception_ptr::exception_ptr") align 8) #4

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

declare void @__cxa_end_catch()

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

; Function Attrs: mustprogress uwtable
define dso_local i32 @daliTensorRefCount(ptr noundef %0, ptr noundef %1) #1 personality ptr @__gxx_personality_v0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca %"class.std::basic_string_view", align 8
  %13 = alloca %"class.std::__exception_ptr::exception_ptr", align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #7
  %14 = invoke noundef i32 @_ZN4dali5c_api9CheckInitEv()
          to label %15 unwind label %20

15:                                               ; preds = %2
  store i32 %14, ptr %6, align 4, !tbaa !9
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %24

18:                                               ; preds = %15
  %19 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %19, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %26

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

24:                                               ; preds = %15
  br label %25

25:                                               ; preds = %24
  store i32 0, ptr %9, align 4
  br label %26

26:                                               ; preds = %25, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #7
  %27 = load i32, ptr %9, align 4
  switch i32 %27, label %72 [
    i32 0, label %28
    i32 1, label %62
  ]

28:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #7
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = invoke noundef ptr @_ZN4dali5c_api9ToPointerEP11_DALITensor(ptr noundef %29)
          to label %31 unwind label %42

31:                                               ; preds = %28
  store ptr %30, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #7
  %32 = load ptr, ptr %10, align 8, !tbaa !5
  %33 = call noundef i32 @_ZNK4dali5c_api16RefCountedObject8RefCountEv(ptr noundef nonnull align 8 dereferenceable(12) %32) #7
  store i32 %33, ptr %11, align 4, !tbaa !11
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZNSt17basic_string_viewIcSt11char_traitsIcEEC2EPKc(ptr noundef nonnull align 8 dereferenceable(16) %12, ptr noundef @.str.5) #7
  %35 = getelementptr inbounds { i64, ptr }, ptr %12, i32 0, i32 0
  %36 = load i64, ptr %35, align 8
  %37 = getelementptr inbounds { i64, ptr }, ptr %12, i32 0, i32 1
  %38 = load ptr, ptr %37, align 8
  invoke void @_ZN4dali5c_api12CheckNotNullIiEEvPT_St17basic_string_viewIcSt11char_traitsIcEE(ptr noundef %34, i64 %36, ptr %38)
          to label %39 unwind label %46

39:                                               ; preds = %31
  %40 = load i32, ptr %11, align 4, !tbaa !11
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 %40, ptr %41, align 4, !tbaa !11
  store i32 0, ptr %3, align 4
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #7
  br label %62

42:                                               ; preds = %28
  %43 = landingpad { ptr, i32 }
          catch ptr null
  %44 = extractvalue { ptr, i32 } %43, 0
  store ptr %44, ptr %7, align 8
  %45 = extractvalue { ptr, i32 } %43, 1
  store i32 %45, ptr %8, align 4
  br label %50

46:                                               ; preds = %31
  %47 = landingpad { ptr, i32 }
          catch ptr null
  %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 %11) #7
  br label %50

50:                                               ; preds = %46, %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #7
  br label %51

51:                                               ; preds = %50, %20
  %52 = load ptr, ptr %7, align 8
  %53 = call ptr @__cxa_begin_catch(ptr %52) #7
  call void @_ZSt17current_exceptionv(ptr dead_on_unwind writable sret(%"class.std::__exception_ptr::exception_ptr") align 8 %13) #7
  %54 = invoke noundef i32 @_ZN4dali5c_api11HandleErrorENSt15__exception_ptr13exception_ptrE(ptr noundef %13)
          to label %55 unwind label %56

55:                                               ; preds = %51
  store i32 %54, ptr %3, align 4
  call void @_ZNSt15__exception_ptr13exception_ptrD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %13) #7
  store i32 1, ptr %9, align 4
  call void @__cxa_end_catch()
  br label %62

56:                                               ; preds = %51
  %57 = landingpad { ptr, i32 }
          cleanup
  %58 = extractvalue { ptr, i32 } %57, 0
  store ptr %58, ptr %7, align 8
  %59 = extractvalue { ptr, i32 } %57, 1
  store i32 %59, ptr %8, align 4
  call void @_ZNSt15__exception_ptr13exception_ptrD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %13) #7
  invoke void @__cxa_end_catch()
          to label %60 unwind label %69

60:                                               ; preds = %56
  br label %64

61:                                               ; No predecessors!
  unreachable

62:                                               ; preds = %55, %39, %26
  %63 = load i32, ptr %3, align 4
  ret i32 %63

64:                                               ; preds = %60
  %65 = load ptr, ptr %7, align 8
  %66 = load i32, ptr %8, align 4
  %67 = insertvalue { ptr, i32 } poison, ptr %65, 0
  %68 = insertvalue { ptr, i32 } %67, i32 %66, 1
  resume { ptr, i32 } %68

69:                                               ; preds = %56
  %70 = landingpad { ptr, i32 }
          catch ptr null
  %71 = extractvalue { ptr, i32 } %70, 0
  call void @__clang_call_terminate(ptr %71) #8
  unreachable

72:                                               ; preds = %26
  unreachable
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4dali5c_api12CheckNotNullIiEEvPT_St17basic_string_viewIcSt11char_traitsIcEE(ptr noundef, i64, ptr) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 "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 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 #6 = { 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 #7 = { nounwind }
attributes #8 = { 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, !10, i64 0}
!10 = !{!"_ZTS12daliResult_t", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}


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

%"class.std::__exception_ptr::exception_ptr" = type { ptr }
%"class.std::basic_string_view" = type { i64, ptr }

@.str.5 = external hidden unnamed_addr constant [27 x i8], align 1

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN4dali5c_api9ToPointerEP11_DALITensor(ptr noundef) local_unnamed_addr #0

declare noundef i32 @_ZN4dali5c_api9CheckInitEv() local_unnamed_addr #1

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

declare ptr @__cxa_begin_catch(ptr) local_unnamed_addr

declare noundef i32 @_ZN4dali5c_api11HandleErrorENSt15__exception_ptr13exception_ptrE(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare void @_ZSt17current_exceptionv(ptr dead_on_unwind writable sret(%"class.std::__exception_ptr::exception_ptr") align 8) local_unnamed_addr #3

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

declare void @__cxa_end_catch() local_unnamed_addr

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @daliTensorRefCount(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
  %3 = alloca %"class.std::basic_string_view", align 8
  %4 = alloca %"class.std::__exception_ptr::exception_ptr", align 8
  %5 = invoke noundef i32 @_ZN4dali5c_api9CheckInitEv()
          to label %6 unwind label %7

6:                                                ; preds = %2
  %.not.not = icmp eq i32 %5, 0
  br i1 %.not.not, label %9, label %27

7:                                                ; preds = %2
  %8 = landingpad { ptr, i32 }
          catch ptr null
  br label %21

9:                                                ; preds = %6
  %10 = invoke noundef ptr @_ZN4dali5c_api9ToPointerEP11_DALITensor(ptr noundef %0)
          to label %11 unwind label %17

11:                                               ; preds = %9
  %12 = tail call noundef i32 @_ZNK4dali5c_api16RefCountedObject8RefCountEv(ptr noundef nonnull align 8 dereferenceable(12) %10) #6
  call void @_ZNSt17basic_string_viewIcSt11char_traitsIcEEC2EPKc(ptr noundef nonnull align 8 dereferenceable(16) %3, ptr noundef @.str.5) #6
  %13 = load i64, ptr %3, align 8
  %14 = getelementptr inbounds i8, ptr %3, i64 8
  %15 = load ptr, ptr %14, align 8
  invoke void @_ZN4dali5c_api12CheckNotNullIiEEvPT_St17basic_string_viewIcSt11char_traitsIcEE(ptr noundef %1, i64 %13, ptr %15)
          to label %16 unwind label %19

16:                                               ; preds = %11
  store i32 %12, ptr %1, align 4, !tbaa !5
  br label %27

17:                                               ; preds = %9
  %18 = landingpad { ptr, i32 }
          catch ptr null
  br label %21

19:                                               ; preds = %11
  %20 = landingpad { ptr, i32 }
          catch ptr null
  br label %21

21:                                               ; preds = %17, %19, %7
  %.pn.pn = phi { ptr, i32 } [ %8, %7 ], [ %20, %19 ], [ %18, %17 ]
  %.112 = extractvalue { ptr, i32 } %.pn.pn, 0
  %22 = call ptr @__cxa_begin_catch(ptr %.112) #6
  call void @_ZSt17current_exceptionv(ptr dead_on_unwind nonnull writable sret(%"class.std::__exception_ptr::exception_ptr") align 8 %4) #6
  %23 = invoke noundef i32 @_ZN4dali5c_api11HandleErrorENSt15__exception_ptr13exception_ptrE(ptr noundef nonnull %4)
          to label %24 unwind label %25

24:                                               ; preds = %21
  call void @_ZNSt15__exception_ptr13exception_ptrD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %4) #6
  call void @__cxa_end_catch()
  br label %27

25:                                               ; preds = %21
  %26 = landingpad { ptr, i32 }
          cleanup
  call void @_ZNSt15__exception_ptr13exception_ptrD2Ev(ptr noundef nonnull align 8 dereferenceable(8) %4) #6
  invoke void @__cxa_end_catch()
          to label %28 unwind label %29

27:                                               ; preds = %6, %24, %16
  %.1 = phi i32 [ %5, %6 ], [ 0, %16 ], [ %23, %24 ]
  ret i32 %.1

28:                                               ; preds = %25
  resume { ptr, i32 } %26

29:                                               ; preds = %25
  %30 = landingpad { ptr, i32 }
          catch ptr null
  %31 = extractvalue { ptr, i32 } %30, 0
  call void @__clang_call_terminate(ptr %31) #7
  unreachable
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4dali5c_api12CheckNotNullIiEEvPT_St17basic_string_viewIcSt11char_traitsIcEE(ptr noundef, i64, ptr) local_unnamed_addr #0

attributes #0 = { 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 #1 = { "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 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 "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 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 = { 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 #6 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass