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

; 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" = type { ptr, i64 }

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN4dali4expr19BinaryTypePromotionE13_DALIDataTypeS1_(i32 noundef, i32 noundef) #0

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN4dali4expr13TypePromotionENS0_12ArithmeticOpENS_4spanI13_DALIDataTypeLln1EEE(i32 noundef %0, ptr %1, i64 %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca %"class.dali::span", align 8
  %6 = alloca i32, align 4
  %7 = alloca i8, align 1
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = getelementptr inbounds { ptr, i64 }, ptr %5, i32 0, i32 0
  store ptr %1, ptr %15, align 8
  %16 = getelementptr inbounds { ptr, i64 }, ptr %5, i32 0, i32 1
  store i64 %2, ptr %16, align 8
  store i32 %0, ptr %6, align 4, !tbaa !5
  %17 = load i32, ptr %6, align 4, !tbaa !5
  %18 = call noundef zeroext i1 @_ZN4dali4expr18IsIntToFloatResultENS0_12ArithmeticOpE(i32 noundef %17)
  br i1 %18, label %19, label %51

19:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #3
  store i8 1, ptr %7, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store ptr %5, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %20 = load ptr, ptr %8, align 8, !tbaa !11
  %21 = call noundef ptr @_ZNK4dali4spanI13_DALIDataTypeLln1EE5beginEv(ptr noundef nonnull align 8 dereferenceable(16) %20) #3
  store ptr %21, ptr %9, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %22 = load ptr, ptr %8, align 8, !tbaa !11
  %23 = call noundef ptr @_ZNK4dali4spanI13_DALIDataTypeLln1EE3endEv(ptr noundef nonnull align 8 dereferenceable(16) %22) #3
  store ptr %23, ptr %10, align 8, !tbaa !11
  br label %24

24:                                               ; preds = %40, %19
  %25 = load ptr, ptr %9, align 8, !tbaa !11
  %26 = load ptr, ptr %10, align 8, !tbaa !11
  %27 = icmp ne ptr %25, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %43

29:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %30 = load ptr, ptr %9, align 8, !tbaa !11
  %31 = load i32, ptr %30, align 4, !tbaa !13
  store i32 %31, ptr %11, align 4, !tbaa !13
  %32 = load i8, ptr %7, align 1, !tbaa !9, !range !15, !noundef !16
  %33 = trunc i8 %32 to i1
  br i1 %33, label %34, label %37

34:                                               ; preds = %29
  %35 = load i32, ptr %11, align 4, !tbaa !13
  %36 = call noundef zeroext i1 @daliDataTypeIsIntegral(i32 noundef %35)
  br label %37

37:                                               ; preds = %34, %29
  %38 = phi i1 [ false, %29 ], [ %36, %34 ]
  %39 = zext i1 %38 to i8
  store i8 %39, ptr %7, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %40

40:                                               ; preds = %37
  %41 = load ptr, ptr %9, align 8, !tbaa !11
  %42 = getelementptr inbounds i32, ptr %41, i32 1
  store ptr %42, ptr %9, align 8, !tbaa !11
  br label %24

43:                                               ; preds = %28
  %44 = load i8, ptr %7, align 1, !tbaa !9, !range !15, !noundef !16
  %45 = trunc i8 %44 to i1
  br i1 %45, label %46, label %47

46:                                               ; preds = %43
  store i32 9, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %48

47:                                               ; preds = %43
  store i32 0, ptr %12, align 4
  br label %48

48:                                               ; preds = %47, %46
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #3
  %49 = load i32, ptr %12, align 4
  switch i32 %49, label %87 [
    i32 0, label %50
    i32 1, label %85
  ]

50:                                               ; preds = %48
  br label %51

51:                                               ; preds = %50, %3
  %52 = call noundef i64 @_ZNK4dali4spanI13_DALIDataTypeLln1EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %5) #3
  %53 = icmp eq i64 %52, 1
  br i1 %53, label %54, label %57

54:                                               ; preds = %51
  %55 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK4dali4spanI13_DALIDataTypeLln1EEixEl(ptr noundef nonnull align 8 dereferenceable(16) %5, i64 noundef 0)
  %56 = load i32, ptr %55, align 4, !tbaa !13
  store i32 %56, ptr %4, align 4
  br label %85

57:                                               ; preds = %51
  %58 = load i32, ptr %6, align 4, !tbaa !5
  %59 = call noundef zeroext i1 @_ZN4dali4expr12IsComparisonENS0_12ArithmeticOpE(i32 noundef %58)
  br i1 %59, label %60, label %61

60:                                               ; preds = %57
  store i32 11, ptr %4, align 4
  br label %85

61:                                               ; preds = %57
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %62 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK4dali4spanI13_DALIDataTypeLln1EEixEl(ptr noundef nonnull align 8 dereferenceable(16) %5, i64 noundef 0)
  %63 = load i32, ptr %62, align 4, !tbaa !13
  %64 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK4dali4spanI13_DALIDataTypeLln1EEixEl(ptr noundef nonnull align 8 dereferenceable(16) %5, i64 noundef 1)
  %65 = load i32, ptr %64, align 4, !tbaa !13
  %66 = call noundef i32 @_ZN4dali4expr19BinaryTypePromotionE13_DALIDataTypeS1_(i32 noundef %63, i32 noundef %65)
  store i32 %66, ptr %13, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  store i32 2, ptr %14, align 4, !tbaa !17
  br label %67

67:                                               ; preds = %80, %61
  %68 = load i32, ptr %14, align 4, !tbaa !17
  %69 = sext i32 %68 to i64
  %70 = call noundef i64 @_ZNK4dali4spanI13_DALIDataTypeLln1EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %5) #3
  %71 = icmp slt i64 %69, %70
  br i1 %71, label %73, label %72

72:                                               ; preds = %67
  store i32 4, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  br label %83

73:                                               ; preds = %67
  %74 = load i32, ptr %13, align 4, !tbaa !13
  %75 = load i32, ptr %14, align 4, !tbaa !17
  %76 = sext i32 %75 to i64
  %77 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK4dali4spanI13_DALIDataTypeLln1EEixEl(ptr noundef nonnull align 8 dereferenceable(16) %5, i64 noundef %76)
  %78 = load i32, ptr %77, align 4, !tbaa !13
  %79 = call noundef i32 @_ZN4dali4expr19BinaryTypePromotionE13_DALIDataTypeS1_(i32 noundef %74, i32 noundef %78)
  store i32 %79, ptr %13, align 4, !tbaa !13
  br label %80

80:                                               ; preds = %73
  %81 = load i32, ptr %14, align 4, !tbaa !17
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %14, align 4, !tbaa !17
  br label %67, !llvm.loop !19

83:                                               ; preds = %72
  %84 = load i32, ptr %13, align 4, !tbaa !13
  store i32 %84, ptr %4, align 4
  store i32 1, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %85

85:                                               ; preds = %83, %60, %54, %48
  %86 = load i32, ptr %4, align 4
  ret i32 %86

87:                                               ; preds = %48
  unreachable
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN4dali4expr18IsIntToFloatResultENS0_12ArithmeticOpE(i32 noundef) #2

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local zeroext i1 @daliDataTypeIsIntegral(i32 noundef) #2

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN4dali4expr12IsComparisonENS0_12ArithmeticOpE(i32 noundef) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"_ZTSN4dali4expr12ArithmeticOpE", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"_ZTS13_DALIDataType", !7, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!18, !18, i64 0}
!18 = !{!"int", !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"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"

%"class.dali::span" = type { ptr, i64 }

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZN4dali4expr19BinaryTypePromotionE13_DALIDataTypeS1_(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN4dali4expr13TypePromotionENS0_12ArithmeticOpENS_4spanI13_DALIDataTypeLln1EEE(i32 noundef %0, ptr %1, i64 %2) local_unnamed_addr #0 {
  %4 = alloca %"class.dali::span", align 8
  store ptr %1, ptr %4, align 8
  %5 = getelementptr inbounds i8, ptr %4, i64 8
  store i64 %2, ptr %5, align 8
  %6 = tail call noundef zeroext i1 @_ZN4dali4expr18IsIntToFloatResultENS0_12ArithmeticOpE(i32 noundef %0)
  br i1 %6, label %7, label %._crit_edge.thread

7:                                                ; preds = %3
  %8 = call noundef ptr @_ZNK4dali4spanI13_DALIDataTypeLln1EE5beginEv(ptr noundef nonnull align 8 dereferenceable(16) %4) #2
  %9 = call noundef ptr @_ZNK4dali4spanI13_DALIDataTypeLln1EE3endEv(ptr noundef nonnull align 8 dereferenceable(16) %4) #2
  %.not23 = icmp eq ptr %8, %9
  br i1 %.not23, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %7, %.lr.ph.backedge
  %.02025 = phi i1 [ %.02025.be, %.lr.ph.backedge ], [ true, %7 ]
  %.02124 = phi ptr [ %.02124.be, %.lr.ph.backedge ], [ %8, %7 ]
  br i1 %.02025, label %10, label %.thread

10:                                               ; preds = %.lr.ph
  %11 = load i32, ptr %.02124, align 4, !tbaa !5
  %12 = call noundef zeroext i1 @daliDataTypeIsIntegral(i32 noundef %11)
  %13 = getelementptr inbounds i8, ptr %.02124, i64 4
  %.not = icmp eq ptr %13, %9
  br i1 %.not, label %._crit_edge, label %.lr.ph.backedge

.lr.ph.backedge:                                  ; preds = %10, %.thread
  %.02025.be = phi i1 [ %12, %10 ], [ false, %.thread ]
  %.02124.be = phi ptr [ %13, %10 ], [ %14, %.thread ]
  br label %.lr.ph

.thread:                                          ; preds = %.lr.ph
  %14 = getelementptr inbounds i8, ptr %.02124, i64 4
  %.not33 = icmp eq ptr %14, %9
  br i1 %.not33, label %._crit_edge.thread, label %.lr.ph.backedge

._crit_edge:                                      ; preds = %10
  br i1 %12, label %.loopexit, label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %.thread, %._crit_edge, %3
  %15 = call noundef i64 @_ZNK4dali4spanI13_DALIDataTypeLln1EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %4) #2
  %16 = icmp eq i64 %15, 1
  br i1 %16, label %17, label %20

17:                                               ; preds = %._crit_edge.thread
  %18 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK4dali4spanI13_DALIDataTypeLln1EEixEl(ptr noundef nonnull align 8 dereferenceable(16) %4, i64 noundef 0)
  %19 = load i32, ptr %18, align 4, !tbaa !5
  br label %.loopexit

20:                                               ; preds = %._crit_edge.thread
  %21 = call noundef zeroext i1 @_ZN4dali4expr12IsComparisonENS0_12ArithmeticOpE(i32 noundef %0)
  br i1 %21, label %.loopexit, label %22

22:                                               ; preds = %20
  %23 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK4dali4spanI13_DALIDataTypeLln1EEixEl(ptr noundef nonnull align 8 dereferenceable(16) %4, i64 noundef 0)
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK4dali4spanI13_DALIDataTypeLln1EEixEl(ptr noundef nonnull align 8 dereferenceable(16) %4, i64 noundef 1)
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = call noundef i32 @_ZN4dali4expr19BinaryTypePromotionE13_DALIDataTypeS1_(i32 noundef %24, i32 noundef %26)
  %28 = call noundef i64 @_ZNK4dali4spanI13_DALIDataTypeLln1EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %4) #2
  %29 = icmp sgt i64 %28, 2
  br i1 %29, label %.lr.ph29, label %.loopexit

.lr.ph29:                                         ; preds = %22, %.lr.ph29
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph29 ], [ 2, %22 ]
  %.01726 = phi i32 [ %32, %.lr.ph29 ], [ %27, %22 ]
  %30 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNK4dali4spanI13_DALIDataTypeLln1EEixEl(ptr noundef nonnull align 8 dereferenceable(16) %4, i64 noundef %indvars.iv)
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = call noundef i32 @_ZN4dali4expr19BinaryTypePromotionE13_DALIDataTypeS1_(i32 noundef %.01726, i32 noundef %31)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %33 = call noundef i64 @_ZNK4dali4spanI13_DALIDataTypeLln1EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %4) #2
  %34 = icmp sgt i64 %33, %indvars.iv.next
  br i1 %34, label %.lr.ph29, label %.loopexit, !llvm.loop !9

.loopexit:                                        ; preds = %.lr.ph29, %7, %22, %20, %._crit_edge, %17
  %.1 = phi i32 [ 9, %._crit_edge ], [ %19, %17 ], [ 11, %20 ], [ %27, %22 ], [ 9, %7 ], [ %32, %.lr.ph29 ]
  ret i32 %.1
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN4dali4expr18IsIntToFloatResultENS0_12ArithmeticOpE(i32 noundef) local_unnamed_addr #1

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local zeroext i1 @daliDataTypeIsIntegral(i32 noundef) local_unnamed_addr #1

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN4dali4expr12IsComparisonENS0_12ArithmeticOpE(i32 noundef) local_unnamed_addr #1

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 = !{!"_ZTS13_DALIDataType", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass