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

; 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.ModelSpec = type { i32, i32, [128 x i8], i32, i32, ptr, ptr, i32, ptr, i32, ptr, i32, ptr, i32, ptr, ptr }

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_Z9mt_mallocj(i32 noundef) #1

; 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 @_Z18mt_insert_operatorP9ModelSpeci12OperatorSpec(ptr noundef %0, i32 noundef %1, ptr noundef byval(%struct.OperatorSpec) align 8 %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = icmp eq ptr null, %10
  br i1 %11, label %12, label %13

12:                                               ; preds = %3
  store i32 1, ptr %4, align 4
  br label %79

13:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.ModelSpec, ptr %14, i32 0, i32 9
  %16 = load i32, ptr %15, align 8, !tbaa !11
  %17 = add nsw i32 %16, 1
  %18 = sext i32 %17 to i64
  %19 = mul i64 1304, %18
  %20 = trunc i64 %19 to i32
  %21 = call noundef ptr @_Z9mt_mallocj(i32 noundef %20)
  store ptr %21, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %38, %13
  %23 = load i32, ptr %8, align 4, !tbaa !9
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = icmp slt i32 %23, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %41

27:                                               ; preds = %22
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.ModelSpec, ptr %28, i32 0, i32 10
  %30 = load ptr, ptr %29, align 8, !tbaa !14
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds %struct.OperatorSpec, ptr %30, i64 %32
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = load i32, ptr %8, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds %struct.OperatorSpec, ptr %34, i64 %36
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %37, ptr align 8 %33, i64 1300, i1 false), !tbaa.struct !15
  br label %38

38:                                               ; preds = %27
  %39 = load i32, ptr %8, align 4, !tbaa !9
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %8, align 4, !tbaa !9
  br label %22, !llvm.loop !19

41:                                               ; preds = %26
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = load i32, ptr %6, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds %struct.OperatorSpec, ptr %42, i64 %44
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %45, ptr align 8 %2, i64 1300, i1 false), !tbaa.struct !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %46 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %46, ptr %9, align 4, !tbaa !9
  br label %47

47:                                               ; preds = %66, %41
  %48 = load i32, ptr %9, align 4, !tbaa !9
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.ModelSpec, ptr %49, i32 0, i32 9
  %51 = load i32, ptr %50, align 8, !tbaa !11
  %52 = icmp slt i32 %48, %51
  br i1 %52, label %54, label %53

53:                                               ; preds = %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %69

54:                                               ; preds = %47
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.ModelSpec, ptr %55, i32 0, i32 10
  %57 = load ptr, ptr %56, align 8, !tbaa !14
  %58 = load i32, ptr %9, align 4, !tbaa !9
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds %struct.OperatorSpec, ptr %57, i64 %59
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = load i32, ptr %9, align 4, !tbaa !9
  %63 = add nsw i32 %62, 1
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds %struct.OperatorSpec, ptr %61, i64 %64
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %65, ptr align 8 %60, i64 1300, i1 false), !tbaa.struct !15
  br label %66

66:                                               ; preds = %54
  %67 = load i32, ptr %9, align 4, !tbaa !9
  %68 = add nsw i32 %67, 1
  store i32 %68, ptr %9, align 4, !tbaa !9
  br label %47, !llvm.loop !21

69:                                               ; preds = %53
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.ModelSpec, ptr %70, i32 0, i32 10
  call void @_Z7mt_freeI12OperatorSpecEvRPT_(ptr noundef nonnull align 8 dereferenceable(8) %71)
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.ModelSpec, ptr %73, i32 0, i32 10
  store ptr %72, ptr %74, align 8, !tbaa !14
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.ModelSpec, ptr %75, i32 0, i32 9
  %77 = load i32, ptr %76, align 8, !tbaa !11
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %76, align 8, !tbaa !11
  store i32 0, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %79

79:                                               ; preds = %69, %12
  %80 = load i32, ptr %4, align 4
  ret i32 %80
}

; 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: inlinehint mustprogress uwtable
declare dso_local void @_Z7mt_freeI12OperatorSpecEvRPT_(ptr noundef nonnull align 8 dereferenceable(8)) #1

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 = { 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 = { 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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 176}
!12 = !{!"_ZTS9ModelSpec", !10, i64 0, !10, i64 4, !7, i64 8, !13, i64 136, !10, i64 140, !6, i64 144, !6, i64 152, !10, i64 160, !6, i64 168, !10, i64 176, !6, i64 184, !10, i64 192, !6, i64 200, !10, i64 208, !6, i64 216, !6, i64 224}
!13 = !{!"_ZTS8DataType", !7, i64 0}
!14 = !{!12, !6, i64 184}
!15 = !{i64 0, i64 128, !16, i64 128, i64 4, !17, i64 132, i64 4, !9, i64 136, i64 8, !5, i64 144, i64 4, !9, i64 152, i64 8, !5, i64 160, i64 8, !5, i64 168, i64 4, !9, i64 176, i64 8, !5, i64 184, i64 1116, !16}
!16 = !{!7, !7, i64 0}
!17 = !{!18, !18, i64 0}
!18 = !{!"_ZTS12OperatorType", !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !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.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 }

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

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 2) i32 @_Z18mt_insert_operatorP9ModelSpeci12OperatorSpec(ptr noundef %0, i32 noundef %1, ptr nocapture noundef readonly byval(%struct.OperatorSpec) align 8 %2) local_unnamed_addr #1 {
  %4 = icmp eq ptr %0, null
  br i1 %4, label %39, label %5

5:                                                ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 176
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %8 = mul i32 %7, 1304
  %9 = add i32 %8, 1304
  %10 = tail call noundef ptr @_Z9mt_mallocj(i32 noundef %9)
  %11 = icmp sgt i32 %1, 0
  br i1 %11, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %5
  %12 = getelementptr inbounds i8, ptr %0, i64 184
  %wide.trip.count = zext nneg i32 %1 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %13 = icmp eq i32 %1, 1
  br i1 %13, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  br label %22

._crit_edge.loopexit.unr-lcssa:                   ; preds = %22, %.lr.ph
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.1, %22 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %._crit_edge.loopexit.epilog-lcssa

._crit_edge.loopexit.epilog-lcssa:                ; preds = %._crit_edge.loopexit.unr-lcssa
  %14 = load ptr, ptr %12, align 8, !tbaa !12
  %15 = getelementptr inbounds %struct.OperatorSpec, ptr %14, i64 %indvars.iv.unr
  %16 = getelementptr inbounds %struct.OperatorSpec, ptr %10, i64 %indvars.iv.unr
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(1300) %16, ptr noundef nonnull align 8 dereferenceable(1300) %15, i64 1300, i1 false), !tbaa.struct !13
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.epilog-lcssa, %._crit_edge.loopexit.unr-lcssa, %5
  %17 = sext i32 %1 to i64
  %18 = getelementptr inbounds %struct.OperatorSpec, ptr %10, i64 %17
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(1300) %18, ptr noundef nonnull align 8 dereferenceable(1300) %2, i64 1300, i1 false), !tbaa.struct !13
  %19 = load i32, ptr %6, align 8, !tbaa !5
  %20 = icmp sgt i32 %19, %1
  br i1 %20, label %.lr.ph30, label %._crit_edge31

.lr.ph30:                                         ; preds = %._crit_edge
  %21 = getelementptr inbounds i8, ptr %0, i64 184
  br label %32

22:                                               ; preds = %22, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.1, %22 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %22 ]
  %23 = load ptr, ptr %12, align 8, !tbaa !12
  %24 = getelementptr inbounds %struct.OperatorSpec, ptr %23, i64 %indvars.iv
  %25 = getelementptr inbounds %struct.OperatorSpec, ptr %10, i64 %indvars.iv
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(1300) %25, ptr noundef nonnull align 8 dereferenceable(1300) %24, i64 1300, i1 false), !tbaa.struct !13
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %26 = load ptr, ptr %12, align 8, !tbaa !12
  %27 = getelementptr inbounds %struct.OperatorSpec, ptr %26, i64 %indvars.iv.next
  %28 = getelementptr inbounds %struct.OperatorSpec, ptr %10, i64 %indvars.iv.next
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(1300) %28, ptr noundef nonnull align 8 dereferenceable(1300) %27, i64 1300, i1 false), !tbaa.struct !13
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %22, !llvm.loop !19

._crit_edge31:                                    ; preds = %32, %._crit_edge
  %29 = getelementptr inbounds i8, ptr %0, i64 184
  tail call void @_Z7mt_freeI12OperatorSpecEvRPT_(ptr noundef nonnull align 8 dereferenceable(8) %29)
  store ptr %10, ptr %29, align 8, !tbaa !12
  %30 = load i32, ptr %6, align 8, !tbaa !5
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %6, align 8, !tbaa !5
  br label %39

32:                                               ; preds = %.lr.ph30, %32
  %indvars.iv33 = phi i64 [ %17, %.lr.ph30 ], [ %indvars.iv.next34, %32 ]
  %33 = load ptr, ptr %21, align 8, !tbaa !12
  %34 = getelementptr inbounds %struct.OperatorSpec, ptr %33, i64 %indvars.iv33
  %indvars.iv.next34 = add nsw i64 %indvars.iv33, 1
  %35 = getelementptr inbounds %struct.OperatorSpec, ptr %10, i64 %indvars.iv.next34
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(1300) %35, ptr noundef nonnull align 8 dereferenceable(1300) %34, i64 1300, i1 false), !tbaa.struct !13
  %36 = load i32, ptr %6, align 8, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = icmp slt i64 %indvars.iv.next34, %37
  br i1 %38, label %32, label %._crit_edge31, !llvm.loop !21

39:                                               ; preds = %3, %._crit_edge31
  %.024 = phi i32 [ 0, %._crit_edge31 ], [ 1, %3 ]
  ret i32 %.024
}

; Function Attrs: mustprogress 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) #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z7mt_freeI12OperatorSpecEvRPT_(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0

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 = { 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 nocallback nofree nounwind willreturn memory(argmem: readwrite) }

!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 176}
!6 = !{!"_ZTS9ModelSpec", !7, i64 0, !7, i64 4, !8, i64 8, !10, i64 136, !7, i64 140, !11, i64 144, !11, i64 152, !7, i64 160, !11, i64 168, !7, i64 176, !11, i64 184, !7, i64 192, !11, i64 200, !7, i64 208, !11, i64 216, !11, i64 224}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTS8DataType", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !11, i64 184}
!13 = !{i64 0, i64 128, !14, i64 128, i64 4, !15, i64 132, i64 4, !17, i64 136, i64 8, !18, i64 144, i64 4, !17, i64 152, i64 8, !18, i64 160, i64 8, !18, i64 168, i64 4, !17, i64 176, i64 8, !18, i64 184, i64 1116, !14}
!14 = !{!8, !8, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"_ZTS12OperatorType", !8, i64 0}
!17 = !{!7, !7, i64 0}
!18 = !{!11, !11, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


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