; LLVM IR from huawei-noah/bolt :: compute/tensor/src (batch_norm)

; 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.BatchNormParamSpec = type { i32, float, float, float }
%class.Tensor = type { %"class.std::shared_ptr", %"class.std::shared_ptr.0" }
%"class.std::shared_ptr" = type { %"class.std::__shared_ptr" }
%"class.std::__shared_ptr" = type { ptr, %"class.std::__shared_count" }
%"class.std::__shared_count" = type { ptr }
%"class.std::shared_ptr.0" = type { %"class.std::__shared_ptr.1" }
%"class.std::__shared_ptr.1" = type { ptr, %"class.std::__shared_count" }
%struct.ScaleParamSpec = type { i32, i32 }
%struct.ArchInfo = type { i32, ptr }

; 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: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_Z19get_ptr_from_tensor6Tensor4Arch(ptr noundef, i32 noundef) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN6TensorC2ERKS_(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #2 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN6TensorD2Ev(ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z10batch_norm6TensorS_S_18BatchNormParamSpecS_P8ArchInfo(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 %3, <2 x float> %4, ptr noundef %5, ptr noundef %6) #3 personality ptr @__gxx_personality_v0 {
  %8 = alloca %struct.BatchNormParamSpec, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca ptr, align 8
  %16 = alloca %class.Tensor, align 8
  %17 = alloca ptr, align 8
  %18 = alloca i32, align 4
  %19 = alloca ptr, align 8
  %20 = alloca %class.Tensor, align 8
  %21 = alloca %struct.ScaleParamSpec, align 4
  %22 = alloca %class.Tensor, align 8
  %23 = alloca %struct.ScaleParamSpec, align 4
  %24 = alloca %class.Tensor, align 8
  %25 = getelementptr inbounds { i64, <2 x float> }, ptr %8, i32 0, i32 0
  store i64 %3, ptr %25, align 4
  %26 = getelementptr inbounds { i64, <2 x float> }, ptr %8, i32 0, i32 1
  store <2 x float> %4, ptr %26, align 4
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store ptr %2, ptr %11, align 8, !tbaa !5
  store ptr %5, ptr %12, align 8, !tbaa !5
  store ptr %6, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #6
  %27 = load ptr, ptr %13, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.ArchInfo, ptr %27, i32 0, i32 0
  %29 = load i32, ptr %28, align 8, !tbaa !9
  store i32 %29, ptr %14, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #6
  call void @_ZN6TensorC2ERKS_(ptr noundef nonnull align 8 dereferenceable(32) %16, ptr noundef nonnull align 8 dereferenceable(32) %1) #6
  %30 = load i32, ptr %14, align 4, !tbaa !12
  %31 = invoke noundef ptr @_Z19get_ptr_from_tensor6Tensor4Arch(ptr noundef %16, i32 noundef %30)
          to label %32 unwind label %45

32:                                               ; preds = %7
  call void @_ZN6TensorD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %16) #6
  store ptr %31, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #6
  call void @_ZN6TensorC2ERKS_(ptr noundef nonnull align 8 dereferenceable(32) %20, ptr noundef nonnull align 8 dereferenceable(32) %2) #6
  %33 = load i32, ptr %14, align 4, !tbaa !12
  %34 = invoke noundef ptr @_Z19get_ptr_from_tensor6Tensor4Arch(ptr noundef %20, i32 noundef %33)
          to label %35 unwind label %49

35:                                               ; preds = %32
  call void @_ZN6TensorD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %20) #6
  store ptr %34, ptr %19, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #6
  %36 = getelementptr inbounds %struct.BatchNormParamSpec, ptr %8, i32 0, i32 0
  %37 = load i32, ptr %36, align 4, !tbaa !13
  %38 = getelementptr inbounds %struct.ScaleParamSpec, ptr %21, i32 0, i32 0
  store i32 %37, ptr %38, align 4, !tbaa !17
  call void @_ZN6TensorC2ERKS_(ptr noundef nonnull align 8 dereferenceable(32) %22, ptr noundef nonnull align 8 dereferenceable(32) %0) #6
  %39 = load ptr, ptr %15, align 8, !tbaa !5
  %40 = load ptr, ptr %19, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %23, ptr align 4 %21, i64 8, i1 false), !tbaa.struct !19
  call void @_ZN6TensorC2ERKS_(ptr noundef nonnull align 8 dereferenceable(32) %24, ptr noundef nonnull align 8 dereferenceable(32) %5) #6
  %41 = load ptr, ptr %13, align 8, !tbaa !5
  %42 = load i64, ptr %23, align 4
  %43 = invoke noundef i32 @_Z5scale6TensorPvS0_14ScaleParamSpecS_P8ArchInfo(ptr noundef %22, ptr noundef %39, ptr noundef %40, i64 %42, ptr noundef %24, ptr noundef %41)
          to label %44 unwind label %53

44:                                               ; preds = %35
  call void @_ZN6TensorD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %24) #6
  call void @_ZN6TensorD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %22) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #6
  ret i32 %43

45:                                               ; preds = %7
  %46 = landingpad { ptr, i32 }
          cleanup
  %47 = extractvalue { ptr, i32 } %46, 0
  store ptr %47, ptr %17, align 8
  %48 = extractvalue { ptr, i32 } %46, 1
  store i32 %48, ptr %18, align 4
  call void @_ZN6TensorD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %16) #6
  br label %58

49:                                               ; preds = %32
  %50 = landingpad { ptr, i32 }
          cleanup
  %51 = extractvalue { ptr, i32 } %50, 0
  store ptr %51, ptr %17, align 8
  %52 = extractvalue { ptr, i32 } %50, 1
  store i32 %52, ptr %18, align 4
  call void @_ZN6TensorD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %20) #6
  br label %57

53:                                               ; preds = %35
  %54 = landingpad { ptr, i32 }
          cleanup
  %55 = extractvalue { ptr, i32 } %54, 0
  store ptr %55, ptr %17, align 8
  %56 = extractvalue { ptr, i32 } %54, 1
  store i32 %56, ptr %18, align 4
  call void @_ZN6TensorD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %24) #6
  call void @_ZN6TensorD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %22) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #6
  br label %57

57:                                               ; preds = %53, %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #6
  br label %58

58:                                               ; preds = %57, %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #6
  br label %59

59:                                               ; preds = %58
  %60 = load ptr, ptr %17, align 8
  %61 = load i32, ptr %18, align 4
  %62 = insertvalue { ptr, i32 } poison, ptr %60, 0
  %63 = insertvalue { ptr, i32 } %62, i32 %61, 1
  resume { ptr, i32 } %63
}

declare noundef i32 @_Z5scale6TensorPvS0_14ScaleParamSpecS_P8ArchInfo(ptr noundef, ptr noundef, ptr noundef, i64, ptr noundef, ptr noundef) #4

; 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) #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 = { 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"="64" "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 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { 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 = !{!"_ZTS8ArchInfo", !11, i64 0, !6, i64 8}
!11 = !{!"_ZTS4Arch", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !15, i64 0}
!14 = !{!"_ZTS18BatchNormParamSpec", !15, i64 0, !16, i64 4, !16, i64 8, !16, i64 12}
!15 = !{!"int", !7, i64 0}
!16 = !{!"float", !7, i64 0}
!17 = !{!18, !15, i64 0}
!18 = !{!"_ZTS14ScaleParamSpec", !15, i64 0, !15, i64 4}
!19 = !{i64 0, i64 4, !20, i64 4, i64 4, !20}
!20 = !{!15, !15, i64 0}


; 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.Tensor = type { %"class.std::shared_ptr", %"class.std::shared_ptr.0" }
%"class.std::shared_ptr" = type { %"class.std::__shared_ptr" }
%"class.std::__shared_ptr" = type { ptr, %"class.std::__shared_count" }
%"class.std::__shared_count" = type { ptr }
%"class.std::shared_ptr.0" = type { %"class.std::__shared_ptr.1" }
%"class.std::__shared_ptr.1" = type { ptr, %"class.std::__shared_count" }

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN6TensorC2ERKS_(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #1 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN6TensorD2Ev(ptr noundef nonnull align 8 dereferenceable(32)) unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z10batch_norm6TensorS_S_18BatchNormParamSpecS_P8ArchInfo(ptr noundef %0, ptr noundef nonnull %1, ptr noundef %2, i64 %3, <2 x float> %4, ptr noundef %5, ptr noundef %6) local_unnamed_addr #2 personality ptr @__gxx_personality_v0 {
  %8 = alloca %class.Tensor, align 8
  %9 = alloca %class.Tensor, align 8
  %10 = alloca %class.Tensor, align 8
  %11 = alloca %class.Tensor, align 8
  %12 = load i32, ptr %6, align 8, !tbaa !5
  call void @_ZN6TensorC2ERKS_(ptr noundef nonnull align 8 dereferenceable(32) %8, ptr noundef nonnull align 8 dereferenceable(32) %1) #4
  %13 = invoke noundef ptr @_Z19get_ptr_from_tensor6Tensor4Arch(ptr noundef nonnull %8, i32 noundef %12)
          to label %14 unwind label %19

14:                                               ; preds = %7
  call void @_ZN6TensorD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %8) #4
  call void @_ZN6TensorC2ERKS_(ptr noundef nonnull align 8 dereferenceable(32) %9, ptr noundef nonnull align 8 dereferenceable(32) %2) #4
  %15 = invoke noundef ptr @_Z19get_ptr_from_tensor6Tensor4Arch(ptr noundef nonnull %9, i32 noundef %12)
          to label %16 unwind label %21

16:                                               ; preds = %14
  call void @_ZN6TensorD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %9) #4
  call void @_ZN6TensorC2ERKS_(ptr noundef nonnull align 8 dereferenceable(32) %10, ptr noundef nonnull align 8 dereferenceable(32) %0) #4
  %.sroa.01.0.insert.ext = and i64 %3, 4294967295
  call void @_ZN6TensorC2ERKS_(ptr noundef nonnull align 8 dereferenceable(32) %11, ptr noundef nonnull align 8 dereferenceable(32) %5) #4
  %17 = invoke noundef i32 @_Z5scale6TensorPvS0_14ScaleParamSpecS_P8ArchInfo(ptr noundef nonnull %10, ptr noundef %13, ptr noundef %15, i64 %.sroa.01.0.insert.ext, ptr noundef nonnull %11, ptr noundef nonnull %6)
          to label %18 unwind label %23

18:                                               ; preds = %16
  call void @_ZN6TensorD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %11) #4
  call void @_ZN6TensorD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %10) #4
  ret i32 %17

19:                                               ; preds = %7
  %20 = landingpad { ptr, i32 }
          cleanup
  br label %25

21:                                               ; preds = %14
  %22 = landingpad { ptr, i32 }
          cleanup
  br label %25

23:                                               ; preds = %16
  %24 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN6TensorD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %11) #4
  br label %25

25:                                               ; preds = %21, %23, %19
  %.sink = phi ptr [ %9, %21 ], [ %10, %23 ], [ %8, %19 ]
  %.pn.pn = phi { ptr, i32 } [ %22, %21 ], [ %24, %23 ], [ %20, %19 ]
  call void @_ZN6TensorD2Ev(ptr noundef nonnull align 8 dereferenceable(32) %.sink) #4
  resume { ptr, i32 } %.pn.pn
}

declare noundef i32 @_Z5scale6TensorPvS0_14ScaleParamSpecS_P8ArchInfo(ptr noundef, ptr noundef, ptr noundef, i64, ptr noundef, ptr noundef) local_unnamed_addr #3

attributes #0 = { inlinehint 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 = { 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 #2 = { mustprogress uwtable "min-legal-vector-width"="64" "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 = { "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 = !{!6, !7, i64 0}
!6 = !{!"_ZTS8ArchInfo", !7, i64 0, !10, i64 8}
!7 = !{!"_ZTS4Arch", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass