; LLVM IR from huawei-noah/bolt :: common/model_spec/src/model_serialize.ll (Z17get_operator_sizeRK12OperatorSpec)

; 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.OperatorSpec = type <{ [128 x i8], i32, i32, ptr, i32, [4 x i8], ptr, ptr, i32, [4 x i8], ptr, %union.ParameterSpec, [4 x i8] }>
%union.ParameterSpec = type { %struct.MultiHeadAttentionParamSpec }
%struct.MultiHeadAttentionParamSpec = type { [6 x %struct.FullyConnectedParamSpec], %struct.PowerParamSpec, [2 x i8], i32, [4 x %struct.ReshapeParamSpec], [2 x %struct.EltwiseParamSpec] }
%struct.FullyConnectedParamSpec = type { i32, i32, [32 x i32] }
%struct.PowerParamSpec = type { float, float, float }
%struct.ReshapeParamSpec = type { [8 x i32], i32, i32, i32 }
%struct.EltwiseParamSpec = type { i32, %struct.EltwiseSumSpec, i32, %union.ActivationSpec }
%struct.EltwiseSumSpec = type { [8 x float], i32 }
%union.ActivationSpec = type { %struct.ClipParamSpec }
%struct.ClipParamSpec = type { float, float }
%struct.QuantSpec = 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: mustprogress uwtable
define dso_local noundef i32 @_Z17get_operator_sizeRK12OperatorSpec(ptr noundef nonnull align 8 dereferenceable(1300) %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.OperatorSpec, ptr %5, i32 0, i32 2
  %7 = load i32, ptr %6, align 4, !tbaa !9
  %8 = mul i32 %7, 128
  %9 = zext i32 %8 to i64
  %10 = mul i64 %9, 1
  %11 = add i64 144, %10
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.OperatorSpec, ptr %12, i32 0, i32 4
  %14 = load i32, ptr %13, align 8, !tbaa !13
  %15 = mul i32 %14, 128
  %16 = zext i32 %15 to i64
  %17 = mul i64 %16, 1
  %18 = add i64 %11, %17
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.OperatorSpec, ptr %19, i32 0, i32 2
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.OperatorSpec, ptr %22, i32 0, i32 4
  %24 = load i32, ptr %23, align 8, !tbaa !13
  %25 = add i32 %21, %24
  %26 = zext i32 %25 to i64
  %27 = mul i64 %26, 4
  %28 = add i64 %18, %27
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.OperatorSpec, ptr %29, i32 0, i32 1
  %31 = load i32, ptr %30, align 8, !tbaa !14
  %32 = call noundef i32 @_Z27get_operator_parameter_sizei12OperatorType(i32 noundef 20220831, i32 noundef %31)
  %33 = sext i32 %32 to i64
  %34 = add i64 %28, %33
  %35 = trunc i64 %34 to i32
  store i32 %35, ptr %3, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !15
  br label %36

36:                                               ; preds = %62, %1
  %37 = load i32, ptr %4, align 4, !tbaa !15
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.OperatorSpec, ptr %38, i32 0, i32 8
  %40 = load i32, ptr %39, align 8, !tbaa !16
  %41 = icmp ult i32 %37, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %65

43:                                               ; preds = %36
  %44 = load i32, ptr %3, align 4, !tbaa !15
  %45 = zext i32 %44 to i64
  %46 = add i64 %45, 4
  %47 = trunc i64 %46 to i32
  store i32 %47, ptr %3, align 4, !tbaa !15
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.OperatorSpec, ptr %48, i32 0, i32 10
  %50 = load ptr, ptr %49, align 8, !tbaa !17
  %51 = load i32, ptr %4, align 4, !tbaa !15
  %52 = zext i32 %51 to i64
  %53 = getelementptr inbounds %struct.QuantSpec, ptr %50, i64 %52
  %54 = getelementptr inbounds %struct.QuantSpec, ptr %53, i32 0, i32 0
  %55 = load i32, ptr %54, align 8, !tbaa !18
  %56 = sext i32 %55 to i64
  %57 = mul i64 %56, 4
  %58 = load i32, ptr %3, align 4, !tbaa !15
  %59 = zext i32 %58 to i64
  %60 = add i64 %59, %57
  %61 = trunc i64 %60 to i32
  store i32 %61, ptr %3, align 4, !tbaa !15
  br label %62

62:                                               ; preds = %43
  %63 = load i32, ptr %4, align 4, !tbaa !15
  %64 = add i32 %63, 1
  store i32 %64, ptr %4, align 4, !tbaa !15
  br label %36, !llvm.loop !20

65:                                               ; preds = %42
  %66 = load i32, ptr %3, align 4, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret i32 %66
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z27get_operator_parameter_sizei12OperatorType(i32 noundef, i32 noundef) #2

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 = { 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 #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, !12, i64 132}
!10 = !{!"_ZTS12OperatorSpec", !7, i64 0, !11, i64 128, !12, i64 132, !6, i64 136, !12, i64 144, !6, i64 152, !6, i64 160, !12, i64 168, !6, i64 176, !7, i64 184}
!11 = !{!"_ZTS12OperatorType", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !12, i64 144}
!14 = !{!10, !11, i64 128}
!15 = !{!12, !12, i64 0}
!16 = !{!10, !12, i64 168}
!17 = !{!10, !6, i64 176}
!18 = !{!19, !12, i64 0}
!19 = !{!"_ZTS9QuantSpec", !12, i64 0, !6, i64 8}
!20 = distinct !{!20, !21}
!21 = !{!"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"

%struct.QuantSpec = type { i32, ptr }

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z17get_operator_sizeRK12OperatorSpec(ptr nocapture noundef nonnull readonly align 8 dereferenceable(1300) %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 132
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 144
  %5 = load i32, ptr %4, align 8, !tbaa !12
  %6 = add i32 %5, %3
  %7 = getelementptr inbounds i8, ptr %0, i64 128
  %8 = load i32, ptr %7, align 8, !tbaa !13
  %9 = tail call noundef i32 @_Z27get_operator_parameter_sizei12OperatorType(i32 noundef 20220831, i32 noundef %8)
  %reass.mul = mul i32 %6, 132
  %10 = add i32 %9, 144
  %11 = add i32 %10, %reass.mul
  %12 = getelementptr inbounds i8, ptr %0, i64 168
  %13 = load i32, ptr %12, align 8, !tbaa !14
  %.not = icmp eq i32 %13, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %14 = getelementptr inbounds i8, ptr %0, i64 176
  %15 = load ptr, ptr %14, align 8, !tbaa !15
  %wide.trip.count = zext i32 %13 to i64
  %min.iters.check = icmp ult i32 %13, 9
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph ], [ %n.vec, %middle.block ]
  %.01213.ph = phi i32 [ %11, %.lr.ph ], [ %57, %middle.block ]
  br label %scalar.ph

vector.ph:                                        ; preds = %.lr.ph
  %n.mod.vf = and i64 %wide.trip.count, 7
  %16 = icmp eq i64 %n.mod.vf, 0
  %17 = select i1 %16, i64 8, i64 %n.mod.vf
  %n.vec = sub nsw i64 %wide.trip.count, %17
  %18 = insertelement <4 x i32> <i32 poison, i32 0, i32 0, i32 0>, i32 %11, i64 0
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <4 x i32> [ %18, %vector.ph ], [ %54, %vector.body ]
  %vec.phi16 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %55, %vector.body ]
  %19 = or disjoint i64 %index, 1
  %20 = or disjoint i64 %index, 2
  %21 = or disjoint i64 %index, 3
  %22 = or disjoint i64 %index, 4
  %23 = or disjoint i64 %index, 5
  %24 = or disjoint i64 %index, 6
  %25 = or disjoint i64 %index, 7
  %26 = add <4 x i32> %vec.phi, <i32 4, i32 4, i32 4, i32 4>
  %27 = add <4 x i32> %vec.phi16, <i32 4, i32 4, i32 4, i32 4>
  %28 = getelementptr inbounds %struct.QuantSpec, ptr %15, i64 %index
  %29 = getelementptr inbounds %struct.QuantSpec, ptr %15, i64 %19
  %30 = getelementptr inbounds %struct.QuantSpec, ptr %15, i64 %20
  %31 = getelementptr inbounds %struct.QuantSpec, ptr %15, i64 %21
  %32 = getelementptr inbounds %struct.QuantSpec, ptr %15, i64 %22
  %33 = getelementptr inbounds %struct.QuantSpec, ptr %15, i64 %23
  %34 = getelementptr inbounds %struct.QuantSpec, ptr %15, i64 %24
  %35 = getelementptr inbounds %struct.QuantSpec, ptr %15, i64 %25
  %36 = load i32, ptr %28, align 8, !tbaa !16
  %37 = load i32, ptr %29, align 8, !tbaa !16
  %38 = load i32, ptr %30, align 8, !tbaa !16
  %39 = load i32, ptr %31, align 8, !tbaa !16
  %40 = insertelement <4 x i32> poison, i32 %36, i64 0
  %41 = insertelement <4 x i32> %40, i32 %37, i64 1
  %42 = insertelement <4 x i32> %41, i32 %38, i64 2
  %43 = insertelement <4 x i32> %42, i32 %39, i64 3
  %44 = load i32, ptr %32, align 8, !tbaa !16
  %45 = load i32, ptr %33, align 8, !tbaa !16
  %46 = load i32, ptr %34, align 8, !tbaa !16
  %47 = load i32, ptr %35, align 8, !tbaa !16
  %48 = insertelement <4 x i32> poison, i32 %44, i64 0
  %49 = insertelement <4 x i32> %48, i32 %45, i64 1
  %50 = insertelement <4 x i32> %49, i32 %46, i64 2
  %51 = insertelement <4 x i32> %50, i32 %47, i64 3
  %52 = shl <4 x i32> %43, <i32 2, i32 2, i32 2, i32 2>
  %53 = shl <4 x i32> %51, <i32 2, i32 2, i32 2, i32 2>
  %54 = add <4 x i32> %26, %52
  %55 = add <4 x i32> %27, %53
  %index.next = add nuw i64 %index, 8
  %56 = icmp eq i64 %index.next, %n.vec
  br i1 %56, label %middle.block, label %vector.body, !llvm.loop !18

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <4 x i32> %55, %54
  %57 = tail call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx)
  br label %scalar.ph.preheader

._crit_edge:                                      ; preds = %scalar.ph, %1
  %.012.lcssa = phi i32 [ %11, %1 ], [ %62, %scalar.ph ]
  ret i32 %.012.lcssa

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %.01213 = phi i32 [ %62, %scalar.ph ], [ %.01213.ph, %scalar.ph.preheader ]
  %58 = add i32 %.01213, 4
  %59 = getelementptr inbounds %struct.QuantSpec, ptr %15, i64 %indvars.iv
  %60 = load i32, ptr %59, align 8, !tbaa !16
  %61 = shl i32 %60, 2
  %62 = add i32 %58, %61
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %scalar.ph, !llvm.loop !22
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z27get_operator_parameter_sizei12OperatorType(i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.add.v4i32(<4 x i32>) #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 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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, !10, i64 132}
!6 = !{!"_ZTS12OperatorSpec", !7, i64 0, !9, i64 128, !10, i64 132, !11, i64 136, !10, i64 144, !11, i64 152, !11, i64 160, !10, i64 168, !11, i64 176, !7, i64 184}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"_ZTS12OperatorType", !7, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!6, !10, i64 144}
!13 = !{!6, !9, i64 128}
!14 = !{!6, !10, i64 168}
!15 = !{!6, !11, i64 176}
!16 = !{!17, !10, i64 0}
!17 = !{!"_ZTS9QuantSpec", !10, i64 0, !11, i64 8}
!18 = distinct !{!18, !19, !20, !21}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!"llvm.loop.isvectorized", i32 1}
!21 = !{!"llvm.loop.unroll.runtime.disable"}
!22 = distinct !{!22, !19, !21, !20}


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