; LLVM IR from NVIDIA/tensorflow :: tensorflow/core/grappler/costs (robust_stats)

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

%"struct.std::pair" = type { double, double }
%"class.tensorflow::grappler::RobustStats" = type { double, double, double, double }

; 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
define dso_local void @_ZN10tensorflow8grappler11RobustStats8HuberMADERKSt6vectorIdSaIdEE(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(24) %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %"struct.std::pair", align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca double, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %11 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr %5) #3
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = call { double, double } @_ZN10tensorflow8grapplerL29ScaledMedianAbsoluteDeviationERKSt6vectorIdSaIdEE(ptr noundef nonnull align 8 dereferenceable(24) %12)
  %14 = getelementptr inbounds { double, double }, ptr %5, i32 0, i32 0
  %15 = extractvalue { double, double } %13, 0
  store double %15, ptr %14, align 8
  %16 = getelementptr inbounds { double, double }, ptr %5, i32 0, i32 1
  %17 = extractvalue { double, double } %13, 1
  store double %17, ptr %16, align 8
  %18 = getelementptr inbounds %"struct.std::pair", ptr %5, i32 0, i32 0
  %19 = load double, ptr %18, align 8, !tbaa !9
  %20 = getelementptr inbounds %"class.tensorflow::grappler::RobustStats", ptr %11, i32 0, i32 2
  store double %19, ptr %20, align 8, !tbaa !12
  %21 = getelementptr inbounds %"struct.std::pair", ptr %5, i32 0, i32 1
  %22 = load double, ptr %21, align 8, !tbaa !14
  %23 = getelementptr inbounds %"class.tensorflow::grappler::RobustStats", ptr %11, i32 0, i32 3
  store double %22, ptr %23, align 8, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store double 1.500000e+00, ptr %6, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %24 = getelementptr inbounds %"class.tensorflow::grappler::RobustStats", ptr %11, i32 0, i32 3
  %25 = load double, ptr %24, align 8, !tbaa !15
  %26 = fmul double 1.500000e+00, %25
  store double %26, ptr %7, align 8, !tbaa !16
  %27 = load double, ptr %7, align 8, !tbaa !16
  %28 = fcmp ogt double %27, 0.000000e+00
  br i1 %28, label %29, label %57

29:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !17
  br label %30

30:                                               ; preds = %52, %29
  %31 = load i32, ptr %8, align 4, !tbaa !17
  %32 = icmp slt i32 %31, 10
  br i1 %32, label %34, label %33

33:                                               ; preds = %30
  store i32 2, ptr %9, align 4
  br label %55

34:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %35 = getelementptr inbounds %"class.tensorflow::grappler::RobustStats", ptr %11, i32 0, i32 2
  %36 = load double, ptr %35, align 8, !tbaa !12
  store double %36, ptr %10, align 8, !tbaa !16
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %"class.tensorflow::grappler::RobustStats", ptr %11, i32 0, i32 2
  %39 = load double, ptr %38, align 8, !tbaa !12
  %40 = load double, ptr %7, align 8, !tbaa !16
  %41 = call noundef double @_ZN10tensorflow8grappler15UpdateHuberMeanERKSt6vectorIdSaIdEEdd(ptr noundef nonnull align 8 dereferenceable(24) %37, double noundef %39, double noundef %40)
  %42 = getelementptr inbounds %"class.tensorflow::grappler::RobustStats", ptr %11, i32 0, i32 2
  store double %41, ptr %42, align 8, !tbaa !12
  %43 = getelementptr inbounds %"class.tensorflow::grappler::RobustStats", ptr %11, i32 0, i32 2
  %44 = load double, ptr %43, align 8, !tbaa !12
  %45 = load double, ptr %10, align 8, !tbaa !16
  %46 = fcmp oeq double %44, %45
  br i1 %46, label %47, label %48

47:                                               ; preds = %34
  store i32 2, ptr %9, align 4
  br label %49

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

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

51:                                               ; preds = %49
  br label %52

52:                                               ; preds = %51
  %53 = load i32, ptr %8, align 4, !tbaa !17
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %8, align 4, !tbaa !17
  br label %30, !llvm.loop !19

55:                                               ; preds = %49, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %56

56:                                               ; preds = %55
  br label %57

57:                                               ; preds = %56, %2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #3
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZN10tensorflow8grappler15UpdateHuberMeanERKSt6vectorIdSaIdEEdd(ptr noundef nonnull align 8 dereferenceable(24), double noundef, double noundef) #2

; Function Attrs: mustprogress uwtable
declare hidden { double, double } @_ZN10tensorflow8grapplerL29ScaledMedianAbsoluteDeviationERKSt6vectorIdSaIdEE(ptr noundef nonnull align 8 dereferenceable(24)) #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 = { 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, !11, i64 0}
!10 = !{!"_ZTSSt4pairIddE", !11, i64 0, !11, i64 8}
!11 = !{!"double", !7, i64 0}
!12 = !{!13, !11, i64 16}
!13 = !{!"_ZTSN10tensorflow8grappler11RobustStatsE", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24}
!14 = !{!10, !11, i64 8}
!15 = !{!13, !11, i64 24}
!16 = !{!11, !11, i64 0}
!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"

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN10tensorflow8grappler11RobustStats8HuberMADERKSt6vectorIdSaIdEE(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(24) %1) local_unnamed_addr #0 align 2 {
  %3 = tail call { double, double } @_ZN10tensorflow8grapplerL29ScaledMedianAbsoluteDeviationERKSt6vectorIdSaIdEE(ptr noundef nonnull align 8 dereferenceable(24) %1)
  %4 = extractvalue { double, double } %3, 0
  %5 = extractvalue { double, double } %3, 1
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  store double %4, ptr %6, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  store double %5, ptr %7, align 8, !tbaa !10
  %8 = fmul double %5, 1.500000e+00
  %9 = fcmp ogt double %8, 0.000000e+00
  br i1 %9, label %.preheader.preheader, label %.loopexit

.preheader.preheader:                             ; preds = %2
  %10 = tail call noundef double @_ZN10tensorflow8grappler15UpdateHuberMeanERKSt6vectorIdSaIdEEdd(ptr noundef nonnull align 8 dereferenceable(24) %1, double noundef %4, double noundef %8)
  store double %10, ptr %6, align 8, !tbaa !5
  %11 = fcmp une double %10, %4
  br i1 %11, label %.preheader.1, label %.loopexit

.preheader.1:                                     ; preds = %.preheader.preheader
  %12 = tail call noundef double @_ZN10tensorflow8grappler15UpdateHuberMeanERKSt6vectorIdSaIdEEdd(ptr noundef nonnull align 8 dereferenceable(24) %1, double noundef %10, double noundef %8)
  store double %12, ptr %6, align 8, !tbaa !5
  %13 = fcmp une double %12, %10
  br i1 %13, label %.preheader.2, label %.loopexit

.preheader.2:                                     ; preds = %.preheader.1
  %14 = tail call noundef double @_ZN10tensorflow8grappler15UpdateHuberMeanERKSt6vectorIdSaIdEEdd(ptr noundef nonnull align 8 dereferenceable(24) %1, double noundef %12, double noundef %8)
  store double %14, ptr %6, align 8, !tbaa !5
  %15 = fcmp une double %14, %12
  br i1 %15, label %.preheader.3, label %.loopexit

.preheader.3:                                     ; preds = %.preheader.2
  %16 = tail call noundef double @_ZN10tensorflow8grappler15UpdateHuberMeanERKSt6vectorIdSaIdEEdd(ptr noundef nonnull align 8 dereferenceable(24) %1, double noundef %14, double noundef %8)
  store double %16, ptr %6, align 8, !tbaa !5
  %17 = fcmp une double %16, %14
  br i1 %17, label %.preheader.4, label %.loopexit

.preheader.4:                                     ; preds = %.preheader.3
  %18 = tail call noundef double @_ZN10tensorflow8grappler15UpdateHuberMeanERKSt6vectorIdSaIdEEdd(ptr noundef nonnull align 8 dereferenceable(24) %1, double noundef %16, double noundef %8)
  store double %18, ptr %6, align 8, !tbaa !5
  %19 = fcmp une double %18, %16
  br i1 %19, label %.preheader.5, label %.loopexit

.preheader.5:                                     ; preds = %.preheader.4
  %20 = tail call noundef double @_ZN10tensorflow8grappler15UpdateHuberMeanERKSt6vectorIdSaIdEEdd(ptr noundef nonnull align 8 dereferenceable(24) %1, double noundef %18, double noundef %8)
  store double %20, ptr %6, align 8, !tbaa !5
  %21 = fcmp une double %20, %18
  br i1 %21, label %.preheader.6, label %.loopexit

.preheader.6:                                     ; preds = %.preheader.5
  %22 = tail call noundef double @_ZN10tensorflow8grappler15UpdateHuberMeanERKSt6vectorIdSaIdEEdd(ptr noundef nonnull align 8 dereferenceable(24) %1, double noundef %20, double noundef %8)
  store double %22, ptr %6, align 8, !tbaa !5
  %23 = fcmp une double %22, %20
  br i1 %23, label %.preheader.7, label %.loopexit

.preheader.7:                                     ; preds = %.preheader.6
  %24 = tail call noundef double @_ZN10tensorflow8grappler15UpdateHuberMeanERKSt6vectorIdSaIdEEdd(ptr noundef nonnull align 8 dereferenceable(24) %1, double noundef %22, double noundef %8)
  store double %24, ptr %6, align 8, !tbaa !5
  %25 = fcmp une double %24, %22
  br i1 %25, label %.preheader.8, label %.loopexit

.preheader.8:                                     ; preds = %.preheader.7
  %26 = tail call noundef double @_ZN10tensorflow8grappler15UpdateHuberMeanERKSt6vectorIdSaIdEEdd(ptr noundef nonnull align 8 dereferenceable(24) %1, double noundef %24, double noundef %8)
  store double %26, ptr %6, align 8, !tbaa !5
  %27 = fcmp une double %26, %24
  br i1 %27, label %.preheader.9, label %.loopexit

.preheader.9:                                     ; preds = %.preheader.8
  %28 = tail call noundef double @_ZN10tensorflow8grappler15UpdateHuberMeanERKSt6vectorIdSaIdEEdd(ptr noundef nonnull align 8 dereferenceable(24) %1, double noundef %26, double noundef %8)
  store double %28, ptr %6, align 8, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader.9, %.preheader.preheader, %.preheader.1, %.preheader.2, %.preheader.3, %.preheader.4, %.preheader.5, %.preheader.6, %.preheader.7, %.preheader.8, %2
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZN10tensorflow8grappler15UpdateHuberMeanERKSt6vectorIdSaIdEEdd(ptr noundef nonnull align 8 dereferenceable(24), double noundef, double noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare hidden { double, double } @_ZN10tensorflow8grapplerL29ScaledMedianAbsoluteDeviationERKSt6vectorIdSaIdEE(ptr noundef nonnull align 8 dereferenceable(24)) 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 = { 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" }

!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 16}
!6 = !{!"_ZTSN10tensorflow8grappler11RobustStatsE", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 24}


; Effective O3 passes: ADCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass