; LLVM IR from interpretml/interpret :: shared/libebm/Tensor.ll (ZN14NAMESPACE_MAIN6Tensor25MultiplyAndCheckForIssuesEd)

; 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.NAMESPACE_MAIN::Tensor" = type { i64, i64, i64, i64, ptr, i8, [1 x %"struct.NAMESPACE_MAIN::Tensor::DimensionInfo"] }
%"struct.NAMESPACE_MAIN::Tensor::DimensionInfo" = type { i64, ptr, i64 }

@.str = external hidden unnamed_addr constant [80 x i8], align 1
@__func__._ZN14NAMESPACE_MAIN6Tensor25MultiplyAndCheckForIssuesEd = external hidden unnamed_addr constant [26 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [74 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [77 x i8], align 1
@__PRETTY_FUNCTION__._ZN14NAMESPACE_MAIN6Tensor25MultiplyAndCheckForIssuesEd = external hidden unnamed_addr constant [69 x i8], align 1

declare void @LogAssertFailure(i64 noundef, ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef zeroext i1 @_ZN14NAMESPACE_MAINL15IsMultiplyErrorImEEbT_S1_(i64 noundef, i64 noundef) #2

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN14NAMESPACE_MAIN6Tensor25MultiplyAndCheckForIssuesEd(ptr noundef nonnull align 8 dereferenceable(72) %0, double noundef %1) #4 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca double, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store double %1, ptr %4, align 8, !tbaa !9
  %13 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  %14 = load double, ptr %4, align 8, !tbaa !9
  store double %14, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %15 = call noundef ptr @_ZN14NAMESPACE_MAIN6Tensor13GetDimensionsEv(ptr noundef nonnull align 8 dereferenceable(72) %13)
  store ptr %15, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  %16 = getelementptr inbounds %"class.NAMESPACE_MAIN::Tensor", ptr %13, i32 0, i32 1
  %17 = load i64, ptr %16, align 8, !tbaa !11
  store i64 %17, ptr %7, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  store i64 0, ptr %8, align 8, !tbaa !15
  br label %18

18:                                               ; preds = %43, %2
  %19 = load i64, ptr %8, align 8, !tbaa !15
  %20 = getelementptr inbounds %"class.NAMESPACE_MAIN::Tensor", ptr %13, i32 0, i32 3
  %21 = load i64, ptr %20, align 8, !tbaa !16
  %22 = icmp ult i64 %19, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  br label %46

24:                                               ; preds = %18
  %25 = load i64, ptr %7, align 8, !tbaa !15
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = load i64, ptr %8, align 8, !tbaa !15
  %28 = getelementptr inbounds %"struct.NAMESPACE_MAIN::Tensor::DimensionInfo", ptr %26, i64 %27
  %29 = getelementptr inbounds %"struct.NAMESPACE_MAIN::Tensor::DimensionInfo", ptr %28, i32 0, i32 0
  %30 = load i64, ptr %29, align 8, !tbaa !17
  %31 = call noundef zeroext i1 @_ZN14NAMESPACE_MAINL15IsMultiplyErrorImEEbT_S1_(i64 noundef %25, i64 noundef %30) #6
  br i1 %31, label %32, label %34

32:                                               ; preds = %24
  call void @LogAssertFailure(i64 noundef 213, ptr noundef @.str, ptr noundef @__func__._ZN14NAMESPACE_MAIN6Tensor25MultiplyAndCheckForIssuesEd, ptr noundef @.str.19)
  call void @__assert_fail(ptr noundef @.str.20, ptr noundef @.str, i32 noundef 213, ptr noundef @__PRETTY_FUNCTION__._ZN14NAMESPACE_MAIN6Tensor25MultiplyAndCheckForIssuesEd) #7
  unreachable

33:                                               ; No predecessors!
  br label %34

34:                                               ; preds = %33, %24
  %35 = phi i1 [ true, %24 ], [ false, %33 ]
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = load i64, ptr %8, align 8, !tbaa !15
  %38 = getelementptr inbounds %"struct.NAMESPACE_MAIN::Tensor::DimensionInfo", ptr %36, i64 %37
  %39 = getelementptr inbounds %"struct.NAMESPACE_MAIN::Tensor::DimensionInfo", ptr %38, i32 0, i32 0
  %40 = load i64, ptr %39, align 8, !tbaa !17
  %41 = load i64, ptr %7, align 8, !tbaa !15
  %42 = mul i64 %41, %40
  store i64 %42, ptr %7, align 8, !tbaa !15
  br label %43

43:                                               ; preds = %34
  %44 = load i64, ptr %8, align 8, !tbaa !15
  %45 = add i64 %44, 1
  store i64 %45, ptr %8, align 8, !tbaa !15
  br label %18, !llvm.loop !19

46:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  %47 = getelementptr inbounds %"class.NAMESPACE_MAIN::Tensor", ptr %13, i32 0, i32 4
  %48 = load ptr, ptr %47, align 8, !tbaa !21
  %49 = getelementptr inbounds double, ptr %48, i64 0
  store ptr %49, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  %50 = getelementptr inbounds %"class.NAMESPACE_MAIN::Tensor", ptr %13, i32 0, i32 4
  %51 = load ptr, ptr %50, align 8, !tbaa !21
  %52 = load i64, ptr %7, align 8, !tbaa !15
  %53 = getelementptr inbounds double, ptr %51, i64 %52
  store ptr %53, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  store i32 0, ptr %11, align 4, !tbaa !22
  br label %54

54:                                               ; preds = %73, %46
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #6
  %55 = load ptr, ptr %9, align 8, !tbaa !5
  %56 = load double, ptr %55, align 8, !tbaa !9
  %57 = load double, ptr %5, align 8, !tbaa !9
  %58 = fmul double %56, %57
  store double %58, ptr %12, align 8, !tbaa !9
  %59 = load double, ptr %12, align 8, !tbaa !9
  %60 = call noundef zeroext i1 @_ZSt5isnand(double noundef %59)
  br i1 %60, label %64, label %61

61:                                               ; preds = %54
  %62 = load double, ptr %12, align 8, !tbaa !9
  %63 = call noundef zeroext i1 @_ZSt5isinfd(double noundef %62)
  br label %64

64:                                               ; preds = %61, %54
  %65 = phi i1 [ true, %54 ], [ %63, %61 ]
  %66 = zext i1 %65 to i32
  %67 = load i32, ptr %11, align 4, !tbaa !22
  %68 = or i32 %67, %66
  store i32 %68, ptr %11, align 4, !tbaa !22
  %69 = load double, ptr %12, align 8, !tbaa !9
  %70 = load ptr, ptr %9, align 8, !tbaa !5
  store double %69, ptr %70, align 8, !tbaa !9
  %71 = load ptr, ptr %9, align 8, !tbaa !5
  %72 = getelementptr inbounds double, ptr %71, i32 1
  store ptr %72, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  br label %73

73:                                               ; preds = %64
  %74 = load ptr, ptr %10, align 8, !tbaa !5
  %75 = load ptr, ptr %9, align 8, !tbaa !5
  %76 = icmp ne ptr %74, %75
  br i1 %76, label %54, label %77, !llvm.loop !24

77:                                               ; preds = %73
  %78 = load i32, ptr %11, align 4, !tbaa !22
  %79 = icmp ne i32 %78, 0
  %80 = xor i1 %79, true
  %81 = xor i1 %80, true
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  ret i1 %81
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZSt5isnand(double noundef) #5

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZSt5isinfd(double noundef) #5

attributes #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 = { noreturn 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 #2 = { 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 #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { 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 = { 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, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !13, i64 8}
!12 = !{!"_ZTSN14NAMESPACE_MAIN6TensorE", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !6, i64 32, !14, i64 40, !7, i64 48}
!13 = !{!"long", !7, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{!13, !13, i64 0}
!16 = !{!12, !13, i64 24}
!17 = !{!18, !13, i64 0}
!18 = !{!"_ZTSN14NAMESPACE_MAIN6Tensor13DimensionInfoE", !13, i64 0, !6, i64 8, !13, i64 16}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!12, !6, i64 32}
!22 = !{!23, !23, i64 0}
!23 = !{!"int", !7, i64 0}
!24 = distinct !{!24, !20}


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

%"struct.NAMESPACE_MAIN::Tensor::DimensionInfo" = type { i64, ptr, i64 }

@.str = external hidden unnamed_addr constant [80 x i8], align 1
@__func__._ZN14NAMESPACE_MAIN6Tensor25MultiplyAndCheckForIssuesEd = external hidden unnamed_addr constant [26 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [74 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [77 x i8], align 1
@__PRETTY_FUNCTION__._ZN14NAMESPACE_MAIN6Tensor25MultiplyAndCheckForIssuesEd = external hidden unnamed_addr constant [69 x i8], align 1

declare void @LogAssertFailure(i64 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef zeroext i1 @_ZN14NAMESPACE_MAINL15IsMultiplyErrorImEEbT_S1_(i64 noundef, i64 noundef) local_unnamed_addr #2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN14NAMESPACE_MAIN6Tensor25MultiplyAndCheckForIssuesEd(ptr noundef nonnull align 8 dereferenceable(72) %0, double noundef %1) local_unnamed_addr #3 align 2 {
  %3 = tail call noundef ptr @_ZN14NAMESPACE_MAIN6Tensor13GetDimensionsEv(ptr noundef nonnull align 8 dereferenceable(72) %0)
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %7 = load i64, ptr %6, align 8, !tbaa !12
  %.not28 = icmp eq i64 %7, 0
  br i1 %.not28, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %15, %2
  %.0.lcssa = phi i64 [ %5, %2 ], [ %17, %15 ]
  %8 = getelementptr inbounds i8, ptr %0, i64 32
  %9 = load ptr, ptr %8, align 8, !tbaa !13
  %10 = getelementptr inbounds double, ptr %9, i64 %.0.lcssa
  br label %21

.lr.ph:                                           ; preds = %2, %15
  %.027 = phi i64 [ %17, %15 ], [ %5, %2 ]
  %.02226 = phi i64 [ %18, %15 ], [ 0, %2 ]
  %11 = getelementptr inbounds %"struct.NAMESPACE_MAIN::Tensor::DimensionInfo", ptr %3, i64 %.02226
  %12 = load i64, ptr %11, align 8, !tbaa !14
  %13 = tail call noundef zeroext i1 @_ZN14NAMESPACE_MAINL15IsMultiplyErrorImEEbT_S1_(i64 noundef %.027, i64 noundef %12) #5
  br i1 %13, label %14, label %15

14:                                               ; preds = %.lr.ph
  tail call void @LogAssertFailure(i64 noundef 213, ptr noundef nonnull @.str, ptr noundef nonnull @__func__._ZN14NAMESPACE_MAIN6Tensor25MultiplyAndCheckForIssuesEd, ptr noundef nonnull @.str.19)
  tail call void @__assert_fail(ptr noundef nonnull @.str.20, ptr noundef nonnull @.str, i32 noundef 213, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN14NAMESPACE_MAIN6Tensor25MultiplyAndCheckForIssuesEd) #6
  unreachable

15:                                               ; preds = %.lr.ph
  %16 = load i64, ptr %11, align 8, !tbaa !14
  %17 = mul i64 %16, %.027
  %18 = add nuw i64 %.02226, 1
  %19 = load i64, ptr %6, align 8, !tbaa !12
  %20 = icmp ult i64 %18, %19
  br i1 %20, label %.lr.ph, label %._crit_edge, !llvm.loop !16

21:                                               ; preds = %27, %._crit_edge
  %.023 = phi ptr [ %9, %._crit_edge ], [ %31, %27 ]
  %.021 = phi i32 [ 0, %._crit_edge ], [ %30, %27 ]
  %22 = load double, ptr %.023, align 8, !tbaa !18
  %23 = fmul double %22, %1
  %24 = tail call noundef zeroext i1 @_ZSt5isnand(double noundef %23)
  br i1 %24, label %27, label %25

25:                                               ; preds = %21
  %26 = tail call noundef zeroext i1 @_ZSt5isinfd(double noundef %23)
  br label %27

27:                                               ; preds = %25, %21
  %28 = phi i1 [ true, %21 ], [ %26, %25 ]
  %29 = zext i1 %28 to i32
  %30 = or i32 %.021, %29
  store double %23, ptr %.023, align 8, !tbaa !18
  %31 = getelementptr inbounds i8, ptr %.023, i64 8
  %.not = icmp eq ptr %10, %31
  br i1 %.not, label %32, label %21, !llvm.loop !20

32:                                               ; preds = %27
  %33 = icmp ne i32 %30, 0
  ret i1 %33
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZSt5isnand(double noundef) local_unnamed_addr #4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZSt5isinfd(double noundef) local_unnamed_addr #4

attributes #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 = { noreturn 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 #2 = { 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 #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 = { 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, !7, i64 8}
!6 = !{!"_ZTSN14NAMESPACE_MAIN6TensorE", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !11, i64 40, !8, i64 48}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"bool", !8, i64 0}
!12 = !{!6, !7, i64 24}
!13 = !{!6, !10, i64 32}
!14 = !{!15, !7, i64 0}
!15 = !{!"_ZTSN14NAMESPACE_MAIN6Tensor13DimensionInfoE", !7, i64 0, !10, i64 8, !7, i64 16}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!19, !19, i64 0}
!19 = !{!"double", !8, i64 0}
!20 = distinct !{!20, !17}


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