; 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 i32 @_ZNK4dali15TensorShapeBaseINS_11SmallVectorIlLm6ESaIlEEELin1EE10sample_dimEv(ptr noundef nonnull align 8 dereferenceable(56)) #3 align 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
define dso_local noundef zeroext i1 @_ZN4dali4expr16NeedBroadcastingENS_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 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = getelementptr inbounds { ptr, i64 }, ptr %4, i32 0, i32 0
  store ptr %0, ptr %13, align 8
  %14 = getelementptr inbounds { ptr, i64 }, ptr %4, i32 0, i32 1
  store i64 %1, ptr %14, align 8
  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
  %15 = getelementptr inbounds { ptr, i64 }, ptr %6, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8
  %17 = getelementptr inbounds { ptr, i64 }, ptr %6, i32 0, i32 1
  %18 = load i64, ptr %17, align 8
  %19 = call noundef i32 @_ZN4dali4expr13BroadcastNdimENS_4spanIPKNS_11TensorShapeILin1EEELln1EEE(ptr %16, i64 %18)
  store i32 %19, 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 %20

20:                                               ; preds = %76, %2
  %21 = load i32, ptr %7, align 4, !tbaa !12
  %22 = load i32, ptr %5, align 4, !tbaa !12
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  store i32 2, ptr %8, align 4
  br label %79

25:                                               ; preds = %20
  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 %26

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

31:                                               ; preds = %26
  store i32 5, ptr %8, align 4
  br label %70

32:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %33 = load i32, ptr %10, align 4, !tbaa !12
  %34 = sext i32 %33 to i64
  %35 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK4dali4spanIPKNS_11TensorShapeILin1EEELln1EEixEl(ptr noundef nonnull align 8 dereferenceable(16) %4, i64 noundef %34)
  %36 = load ptr, ptr %35, align 8, !tbaa !6
  store ptr %36, ptr %11, align 8, !tbaa !6
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %37 = load i32, ptr %7, align 4, !tbaa !12
  %38 = load ptr, ptr %11, align 8, !tbaa !6
  %39 = call noundef i32 @_ZNK4dali15TensorShapeBaseINS_11SmallVectorIlLm6ESaIlEEELin1EE10sample_dimEv(ptr noundef nonnull align 8 dereferenceable(56) %38) #4
  %40 = icmp slt i32 %37, %39
  br i1 %40, label %41, label %50

41:                                               ; preds = %32
  %42 = load ptr, ptr %11, align 8, !tbaa !6
  %43 = load ptr, ptr %11, align 8, !tbaa !6
  %44 = call noundef i32 @_ZNK4dali15TensorShapeBaseINS_11SmallVectorIlLm6ESaIlEEELin1EE10sample_dimEv(ptr noundef nonnull align 8 dereferenceable(56) %43) #4
  %45 = sub nsw i32 %44, 1
  %46 = load i32, ptr %7, align 4, !tbaa !12
  %47 = sub nsw i32 %45, %46
  %48 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK4dali15TensorShapeBaseINS_11SmallVectorIlLm6ESaIlEEELin1EEixEi(ptr noundef nonnull align 8 dereferenceable(56) %42, i32 noundef %47)
  %49 = load i64, ptr %48, align 8, !tbaa !10
  br label %51

50:                                               ; preds = %32
  br label %51

51:                                               ; preds = %50, %41
  %52 = phi i64 [ %49, %41 ], [ 1, %50 ]
  store i64 %52, ptr %12, align 8, !tbaa !10
  %53 = load i64, ptr %9, align 8, !tbaa !10
  %54 = icmp eq i64 %53, -1
  br i1 %54, label %55, label %57

55:                                               ; preds = %51
  %56 = load i64, ptr %12, align 8, !tbaa !10
  store i64 %56, ptr %9, align 8, !tbaa !10
  br label %63

57:                                               ; preds = %51
  %58 = load i64, ptr %9, align 8, !tbaa !10
  %59 = load i64, ptr %12, align 8, !tbaa !10
  %60 = icmp ne i64 %58, %59
  br i1 %60, label %61, label %62

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

62:                                               ; preds = %57
  br label %63

63:                                               ; preds = %62, %55
  store i32 0, ptr %8, align 4
  br label %64

64:                                               ; preds = %63, %61
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  %65 = load i32, ptr %8, align 4
  switch i32 %65, label %70 [
    i32 0, label %66
  ]

66:                                               ; preds = %64
  br label %67

67:                                               ; preds = %66
  %68 = load i32, ptr %10, align 4, !tbaa !12
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %10, align 4, !tbaa !12
  br label %26, !llvm.loop !14

70:                                               ; preds = %64, %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  %71 = load i32, ptr %8, align 4
  switch i32 %71, label %73 [
    i32 5, label %72
  ]

72:                                               ; preds = %70
  store i32 0, ptr %8, align 4
  br label %73

73:                                               ; preds = %72, %70
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  %74 = load i32, ptr %8, align 4
  switch i32 %74, label %79 [
    i32 0, label %75
  ]

75:                                               ; preds = %73
  br label %76

76:                                               ; preds = %75
  %77 = load i32, ptr %7, align 4, !tbaa !12
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %7, align 4, !tbaa !12
  br label %20, !llvm.loop !16

79:                                               ; preds = %73, %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  %80 = load i32, ptr %8, align 4
  switch i32 %80, label %82 [
    i32 2, label %81
  ]

81:                                               ; preds = %79
  store i1 false, ptr %3, align 1
  store i32 1, ptr %8, align 4
  br label %82

82:                                               ; preds = %81, %79
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  %83 = load i1, ptr %3, align 1
  ret i1 %83
}

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

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 uwtable
declare dso_local noundef i32 @_ZN4dali4expr13BroadcastNdimENS_4spanIPKNS_11TensorShapeILin1EEELln1EEE(ptr, i64) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN4dali4expr16NeedBroadcastingENS_4spanIPKNS_11TensorShapeILin1EEELln1EEE(ptr %0, i64 %1) local_unnamed_addr #0 {
  %3 = alloca %"class.dali::span.4", align 8
  store ptr %0, ptr %3, align 8
  %4 = getelementptr inbounds i8, ptr %3, i64 8
  store i64 %1, ptr %4, align 8
  %5 = tail call noundef i32 @_ZN4dali4expr13BroadcastNdimENS_4spanIPKNS_11TensorShapeILin1EEELln1EEE(ptr %0, i64 %1)
  %.not3244 = icmp sgt i32 %5, 0
  br i1 %.not3244, label %.preheader, label %.critedge34

.preheader:                                       ; preds = %2, %.critedge
  %.not3246 = phi i1 [ %.not32, %.critedge ], [ true, %2 ]
  %.02245 = phi i32 [ %23, %.critedge ], [ 0, %2 ]
  %6 = call noundef i64 @_ZNK4dali4spanIPKNS_11TensorShapeILin1EEELln1EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %3) #2
  %.not3141 = icmp sgt i64 %6, 0
  br i1 %.not3141, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %.preheader
  %7 = xor i32 %.02245, -1
  br label %8

8:                                                ; preds = %.lr.ph, %.thread
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %.thread ]
  %.02442 = phi i64 [ -1, %.lr.ph ], [ %.22637, %.thread ]
  %9 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK4dali4spanIPKNS_11TensorShapeILin1EEELln1EEixEl(ptr noundef nonnull align 8 dereferenceable(16) %3, i64 noundef %indvars.iv)
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  %11 = call noundef i32 @_ZNK4dali15TensorShapeBaseINS_11SmallVectorIlLm6ESaIlEEELin1EE10sample_dimEv(ptr noundef nonnull align 8 dereferenceable(56) %10) #2
  %12 = icmp slt i32 %.02245, %11
  br i1 %12, label %13, label %18

13:                                               ; preds = %8
  %14 = call noundef i32 @_ZNK4dali15TensorShapeBaseINS_11SmallVectorIlLm6ESaIlEEELin1EE10sample_dimEv(ptr noundef nonnull align 8 dereferenceable(56) %10) #2
  %15 = add i32 %14, %7
  %16 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNK4dali15TensorShapeBaseINS_11SmallVectorIlLm6ESaIlEEELin1EEixEi(ptr noundef nonnull align 8 dereferenceable(56) %10, i32 noundef %15)
  %17 = load i64, ptr %16, align 8, !tbaa !9
  br label %18

18:                                               ; preds = %8, %13
  %19 = phi i64 [ %17, %13 ], [ 1, %8 ]
  %20 = icmp eq i64 %.02442, -1
  br i1 %20, label %.thread, label %21

21:                                               ; preds = %18
  %.not = icmp eq i64 %.02442, %19
  br i1 %.not, label %.thread, label %.critedge34

.thread:                                          ; preds = %18, %21
  %.22637 = phi i64 [ %.02442, %21 ], [ %19, %18 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %22 = call noundef i64 @_ZNK4dali4spanIPKNS_11TensorShapeILin1EEELln1EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %3) #2
  %.not31 = icmp sgt i64 %22, %indvars.iv.next
  br i1 %.not31, label %8, label %.critedge, !llvm.loop !11

.critedge:                                        ; preds = %.thread, %.preheader
  %23 = add nuw nsw i32 %.02245, 1
  %.not32 = icmp slt i32 %23, %5
  %exitcond.not = icmp eq i32 %23, %5
  br i1 %exitcond.not, label %.critedge34, label %.preheader, !llvm.loop !13

.critedge34:                                      ; preds = %.critedge, %21, %2
  %.not3240 = phi i1 [ false, %2 ], [ %.not3246, %21 ], [ %.not32, %.critedge ]
  ret i1 %.not3240
}

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

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 = { 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 = { 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: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass