; LLVM IR from huawei-noah/bolt :: compute/tensor/src/cpu/arm (scale)

; 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.TensorDesc = type { i32, i32, i32, [20 x i32] }
%struct.ScaleParamSpec = type { i32, i32 }

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z9scale_arm10TensorDescPvS0_S0_14ScaleParamSpecS_S0_(ptr noundef byval(%struct.TensorDesc) align 8 %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i64 %4, ptr noundef byval(%struct.TensorDesc) align 8 %5, ptr noundef %6) #0 {
  %8 = alloca %struct.ScaleParamSpec, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca %struct.TensorDesc, align 8
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  store i64 %4, ptr %8, align 4
  store ptr %1, ptr %9, align 8, !tbaa !5
  store ptr %2, ptr %10, align 8, !tbaa !5
  store ptr %3, ptr %11, align 8, !tbaa !5
  store ptr %6, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %14, ptr align 8 %5, i64 92, i1 false), !tbaa.struct !9
  %21 = call noundef i32 @_Z17tensorNumElements10TensorDesc(ptr noundef byval(%struct.TensorDesc) align 8 %14)
  store i32 %21, ptr %13, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  %22 = getelementptr inbounds %struct.ScaleParamSpec, ptr %8, i32 0, i32 0
  %23 = load i32, ptr %22, align 4, !tbaa !17
  %24 = getelementptr inbounds %struct.TensorDesc, ptr %5, i32 0, i32 2
  %25 = load i32, ptr %24, align 8, !tbaa !19
  %26 = add i32 %23, %25
  %27 = getelementptr inbounds %struct.TensorDesc, ptr %5, i32 0, i32 2
  %28 = load i32, ptr %27, align 8, !tbaa !19
  %29 = urem i32 %26, %28
  store i32 %29, ptr %15, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  %30 = getelementptr inbounds %struct.TensorDesc, ptr %5, i32 0, i32 3
  %31 = getelementptr inbounds %struct.TensorDesc, ptr %5, i32 0, i32 2
  %32 = load i32, ptr %31, align 8, !tbaa !19
  %33 = sub i32 %32, 1
  %34 = zext i32 %33 to i64
  %35 = getelementptr inbounds [20 x i32], ptr %30, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !14
  store i32 %36, ptr %16, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #4
  %37 = getelementptr inbounds %struct.TensorDesc, ptr %5, i32 0, i32 3
  %38 = getelementptr inbounds %struct.TensorDesc, ptr %5, i32 0, i32 2
  %39 = load i32, ptr %38, align 8, !tbaa !19
  %40 = sub i32 %39, 1
  %41 = load i32, ptr %15, align 4, !tbaa !14
  %42 = sub i32 %40, %41
  %43 = zext i32 %42 to i64
  %44 = getelementptr inbounds [20 x i32], ptr %37, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !14
  store i32 %45, ptr %17, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #4
  %46 = load i32, ptr %13, align 4, !tbaa !14
  %47 = load i32, ptr %16, align 4, !tbaa !14
  %48 = load i32, ptr %17, align 4, !tbaa !14
  %49 = mul nsw i32 %47, %48
  %50 = udiv i32 %46, %49
  store i32 %50, ptr %18, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #4
  %51 = getelementptr inbounds %struct.TensorDesc, ptr %0, i32 0, i32 3
  %52 = getelementptr inbounds %struct.TensorDesc, ptr %0, i32 0, i32 2
  %53 = load i32, ptr %52, align 8, !tbaa !19
  %54 = sub i32 %53, 1
  %55 = load i32, ptr %15, align 4, !tbaa !14
  %56 = sub i32 %54, %55
  %57 = zext i32 %56 to i64
  %58 = getelementptr inbounds [20 x i32], ptr %51, i64 0, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !14
  store i32 %59, ptr %19, align 4, !tbaa !14
  %60 = getelementptr inbounds %struct.TensorDesc, ptr %5, i32 0, i32 1
  %61 = load i32, ptr %60, align 4, !tbaa !21
  %62 = icmp eq i32 %61, 2
  br i1 %62, label %63, label %66

63:                                               ; preds = %7
  %64 = getelementptr inbounds %struct.TensorDesc, ptr %5, i32 0, i32 2
  %65 = load i32, ptr %64, align 8, !tbaa !19
  store i32 %65, ptr %15, align 4, !tbaa !14
  br label %66

66:                                               ; preds = %63, %7
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #4
  store i32 51, ptr %20, align 4, !tbaa !22
  %67 = getelementptr inbounds %struct.TensorDesc, ptr %5, i32 0, i32 0
  %68 = load i32, ptr %67, align 8, !tbaa !24
  switch i32 %68, label %69 [
  ]

69:                                               ; preds = %66
  br label %70

70:                                               ; preds = %69
  %71 = load i32, ptr %20, align 4, !tbaa !22
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  ret i32 %71
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z17tensorNumElements10TensorDesc(ptr noundef byval(%struct.TensorDesc) align 8) #2

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{i64 0, i64 4, !10, i64 4, i64 4, !12, i64 8, i64 4, !14, i64 12, i64 80, !16}
!10 = !{!11, !11, i64 0}
!11 = !{!"_ZTS8DataType", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"_ZTS10DataFormat", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!7, !7, i64 0}
!17 = !{!18, !15, i64 0}
!18 = !{!"_ZTS14ScaleParamSpec", !15, i64 0, !15, i64 4}
!19 = !{!20, !15, i64 8}
!20 = !{!"_ZTS10TensorDesc", !11, i64 0, !13, i64 4, !15, i64 8, !7, i64 12}
!21 = !{!20, !13, i64 4}
!22 = !{!23, !23, i64 0}
!23 = !{!"_ZTS2EE", !7, i64 0}
!24 = !{!20, !11, 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"

%struct.TensorDesc = type { i32, i32, i32, [20 x i32] }

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z9scale_arm10TensorDescPvS0_S0_14ScaleParamSpecS_S0_(ptr nocapture noundef readnone byval(%struct.TensorDesc) align 8 %0, ptr nocapture noundef readnone %1, ptr nocapture noundef readnone %2, ptr nocapture noundef readnone %3, i64 %4, ptr nocapture noundef readonly byval(%struct.TensorDesc) align 8 %5, ptr nocapture noundef readnone %6) local_unnamed_addr #0 {
  %8 = tail call noundef i32 @_Z17tensorNumElements10TensorDesc(ptr noundef nonnull byval(%struct.TensorDesc) align 8 %5)
  ret i32 51
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z17tensorNumElements10TensorDesc(ptr noundef byval(%struct.TensorDesc) align 8) local_unnamed_addr #1

attributes #0 = { 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 #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" }

!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)"}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass