; LLVM IR from NVIDIA/DALI :: dali/operators/math/expressions (broadcasting)

; 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.dali::span.4" = type { ptr, i64 }

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

; 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 i32 @_ZN4dali4expr13BroadcastNdimENS_4spanIPKNS_11TensorShapeILin1EEELln1EEE(ptr, i64) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN4dali4expr21TryBroadcastShapeImplINS_11TensorShapeILin1EEEEEbRlRKT_i(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(56), i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN4dali4expr12CanBroadcastENS_4spanIPKNS_11TensorShapeILin1EEELln1EEE(ptr %0, i64 %1) #1 {
  %3 = alloca i1, align 1
  %4 = alloca %"class.dali::span.4", align 8
  %5 = alloca i32, align 4
  %6 = alloca %"class.dali::span.4", align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = getelementptr inbounds { ptr, i64 }, ptr %4, i32 0, i32 0
  store ptr %0, ptr %11, align 8
  %12 = getelementptr inbounds { ptr, i64 }, ptr %4, i32 0, i32 1
  store i64 %1, ptr %12, align 8
  %13 = call noundef i64 @_ZNK4dali4spanIPKNS_11TensorShapeILin1EEELln1EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %4) #4
  %14 = icmp slt i64 %13, 2
  br i1 %14, label %15, label %16

15:                                               ; preds = %2
  store i1 true, ptr %3, align 1
  br label %59

16:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %6, ptr align 8 %4, i64 16, i1 false), !tbaa.struct !5
  %17 = getelementptr inbounds { ptr, i64 }, ptr %6, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8
  %19 = getelementptr inbounds { ptr, i64 }, ptr %6, i32 0, i32 1
  %20 = load i64, ptr %19, align 8
  %21 = call noundef i32 @_ZN4dali4expr13BroadcastNdimENS_4spanIPKNS_11TensorShapeILin1EEELln1EEE(ptr %18, i64 %20)
  store i32 %21, ptr %5, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !12
  br label %22

22:                                               ; preds = %52, %16
  %23 = load i32, ptr %7, align 4, !tbaa !12
  %24 = load i32, ptr %5, align 4, !tbaa !12
  %25 = icmp slt i32 %23, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %22
  store i32 2, ptr %8, align 4
  br label %55

27:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store i64 1, ptr %9, align 8, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %10, align 4, !tbaa !12
  br label %28

28:                                               ; preds = %43, %27
  %29 = load i32, ptr %10, align 4, !tbaa !12
  %30 = sext i32 %29 to i64
  %31 = call noundef i64 @_ZNK4dali4spanIPKNS_11TensorShapeILin1EEELln1EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %4) #4
  %32 = icmp slt i64 %30, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %28
  store i32 5, ptr %8, align 4
  br label %46

34:                                               ; preds = %28
  %35 = load i32, ptr %10, align 4, !tbaa !12
  %36 = sext i32 %35 to i64
  %37 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK4dali4spanIPKNS_11TensorShapeILin1EEELln1EEixEl(ptr noundef nonnull align 8 dereferenceable(16) %4, i64 noundef %36)
  %38 = load ptr, ptr %37, align 8, !tbaa !6
  %39 = load i32, ptr %7, align 4, !tbaa !12
  %40 = call noundef zeroext i1 @_ZN4dali4expr21TryBroadcastShapeImplINS_11TensorShapeILin1EEEEEbRlRKT_i(ptr noundef nonnull align 8 dereferenceable(8) %9, ptr noundef nonnull align 8 dereferenceable(56) %38, i32 noundef %39)
  br i1 %40, label %42, label %41

41:                                               ; preds = %34
  store i1 false, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %46

42:                                               ; preds = %34
  br label %43

43:                                               ; preds = %42
  %44 = load i32, ptr %10, align 4, !tbaa !12
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %10, align 4, !tbaa !12
  br label %28, !llvm.loop !14

46:                                               ; preds = %41, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  %47 = load i32, ptr %8, align 4
  switch i32 %47, label %49 [
    i32 5, label %48
  ]

48:                                               ; preds = %46
  store i32 0, ptr %8, align 4
  br label %49

49:                                               ; preds = %48, %46
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  %50 = load i32, ptr %8, align 4
  switch i32 %50, label %55 [
    i32 0, label %51
  ]

51:                                               ; preds = %49
  br label %52

52:                                               ; preds = %51
  %53 = load i32, ptr %7, align 4, !tbaa !12
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %7, align 4, !tbaa !12
  br label %22, !llvm.loop !16

55:                                               ; preds = %49, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  %56 = load i32, ptr %8, align 4
  switch i32 %56, label %58 [
    i32 2, label %57
  ]

57:                                               ; preds = %55
  store i1 true, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %58

58:                                               ; preds = %57, %55
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %59

59:                                               ; preds = %58, %15
  %60 = load i1, ptr %3, align 1
  ret i1 %60
}

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 }

!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 = !{i64 0, i64 8, !6, i64 8, i64 8, !10}
!6 = !{!7, !7, i64 0}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !8, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


; 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.dali::span.4" = type { ptr, i64 }

; 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 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 i32 @_ZN4dali4expr13BroadcastNdimENS_4spanIPKNS_11TensorShapeILin1EEELln1EEE(ptr, i64) local_unnamed_addr #1

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZN4dali4expr21TryBroadcastShapeImplINS_11TensorShapeILin1EEEEEbRlRKT_i(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(56), i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN4dali4expr12CanBroadcastENS_4spanIPKNS_11TensorShapeILin1EEELln1EEE(ptr %0, i64 %1) local_unnamed_addr #1 {
  %3 = alloca %"class.dali::span.4", align 8
  %4 = alloca i64, align 8
  store ptr %0, ptr %3, align 8
  %5 = getelementptr inbounds i8, ptr %3, i64 8
  store i64 %1, ptr %5, align 8
  %6 = call noundef i64 @_ZNK4dali4spanIPKNS_11TensorShapeILin1EEELln1EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %3) #3
  %7 = icmp slt i64 %6, 2
  br i1 %7, label %.critedge19, label %8

8:                                                ; preds = %2
  %.sroa.0.0.copyload = load ptr, ptr %3, align 8, !tbaa !5
  %.sroa.2.0.copyload = load i64, ptr %5, align 8, !tbaa !9
  %9 = call noundef i32 @_ZN4dali4expr13BroadcastNdimENS_4spanIPKNS_11TensorShapeILin1EEELln1EEE(ptr %.sroa.0.0.copyload, i64 %.sroa.2.0.copyload)
  %.not17.not22 = icmp sgt i32 %9, 0
  br i1 %.not17.not22, label %.lr.ph25, label %.critedge19

.lr.ph25:                                         ; preds = %8, %._crit_edge
  %.01323 = phi i32 [ %17, %._crit_edge ], [ 0, %8 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  store i64 1, ptr %4, align 8, !tbaa !9
  %10 = call noundef i64 @_ZNK4dali4spanIPKNS_11TensorShapeILin1EEELln1EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %3) #3
  %.not20 = icmp sgt i64 %10, 0
  br i1 %.not20, label %.lr.ph, label %._crit_edge

11:                                               ; preds = %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %12 = call noundef i64 @_ZNK4dali4spanIPKNS_11TensorShapeILin1EEELln1EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %3) #3
  %.not = icmp sgt i64 %12, %indvars.iv.next
  br i1 %.not, label %.lr.ph, label %._crit_edge, !llvm.loop !11

.lr.ph:                                           ; preds = %.lr.ph25, %11
  %indvars.iv = phi i64 [ %indvars.iv.next, %11 ], [ 0, %.lr.ph25 ]
  %13 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK4dali4spanIPKNS_11TensorShapeILin1EEELln1EEixEl(ptr noundef nonnull align 8 dereferenceable(16) %3, i64 noundef %indvars.iv)
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  %15 = call noundef zeroext i1 @_ZN4dali4expr21TryBroadcastShapeImplINS_11TensorShapeILin1EEEEEbRlRKT_i(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 8 dereferenceable(56) %14, i32 noundef %.01323)
  br i1 %15, label %11, label %16

16:                                               ; preds = %.lr.ph
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  br label %.critedge19

._crit_edge:                                      ; preds = %11, %.lr.ph25
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  %17 = add nuw nsw i32 %.01323, 1
  %exitcond.not = icmp eq i32 %17, %9
  br i1 %exitcond.not, label %.critedge19, label %.lr.ph25, !llvm.loop !13

.critedge19:                                      ; preds = %._crit_edge, %8, %16, %2
  %.4 = phi i1 [ true, %2 ], [ false, %16 ], [ true, %8 ], [ true, %._crit_edge ]
  ret i1 %.4
}

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


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