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

; 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.ModelSpec = type { i32, i32, [128 x i8], i32, i32, ptr, ptr, i32, ptr, i32, ptr, i32, ptr, i32, ptr, ptr }
%struct.WeightSpec = type { [128 x i8], i32, i32, ptr, i32, ptr, 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: 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: 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: mustprogress uwtable
define dso_local noundef i32 @_Z16mt_insert_weightP9ModelSpecP10WeightSpeci(ptr noundef %0, ptr noundef %1, i32 noundef %2) #3 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = icmp eq ptr null, %11
  br i1 %12, label %13, label %14

13:                                               ; preds = %3
  store i32 1, ptr %4, align 4
  br label %82

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

24:                                               ; preds = %42, %14
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.ModelSpec, ptr %26, i32 0, i32 11
  %28 = load i32, ptr %27, align 8, !tbaa !11
  %29 = icmp slt i32 %25, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  br label %45

31:                                               ; preds = %24
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.ModelSpec, ptr %32, i32 0, i32 12
  %34 = load ptr, ptr %33, align 8, !tbaa !14
  %35 = load i32, ptr %9, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds %struct.WeightSpec, ptr %34, i64 %36
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = load i32, ptr %9, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds %struct.WeightSpec, ptr %38, i64 %40
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %41, ptr align 8 %37, i64 176, i1 false), !tbaa.struct !15
  br label %42

42:                                               ; preds = %31
  %43 = load i32, ptr %9, align 4, !tbaa !9
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %9, align 4, !tbaa !9
  br label %24, !llvm.loop !18

45:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %46

46:                                               ; preds = %64, %45
  %47 = load i32, ptr %10, align 4, !tbaa !9
  %48 = load i32, ptr %7, align 4, !tbaa !9
  %49 = icmp slt i32 %47, %48
  br i1 %49, label %51, label %50

50:                                               ; preds = %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  br label %67

51:                                               ; preds = %46
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = load i32, ptr %10, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds %struct.WeightSpec, ptr %52, i64 %54
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.ModelSpec, ptr %57, i32 0, i32 11
  %59 = load i32, ptr %58, align 8, !tbaa !11
  %60 = load i32, ptr %10, align 4, !tbaa !9
  %61 = add nsw i32 %59, %60
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds %struct.WeightSpec, ptr %56, i64 %62
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %63, ptr align 8 %55, i64 176, i1 false), !tbaa.struct !15
  br label %64

64:                                               ; preds = %51
  %65 = load i32, ptr %10, align 4, !tbaa !9
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %10, align 4, !tbaa !9
  br label %46, !llvm.loop !20

67:                                               ; preds = %50
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.ModelSpec, ptr %68, i32 0, i32 12
  %70 = load ptr, ptr %69, align 8, !tbaa !14
  %71 = icmp eq ptr %70, null
  br i1 %71, label %73, label %72

72:                                               ; preds = %67
  call void @_ZdlPvm(ptr noundef %70, i64 noundef 176) #6
  br label %73

73:                                               ; preds = %72, %67
  %74 = load ptr, ptr %8, align 8, !tbaa !5
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.ModelSpec, ptr %75, i32 0, i32 12
  store ptr %74, ptr %76, align 8, !tbaa !14
  %77 = load i32, ptr %7, align 4, !tbaa !9
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.ModelSpec, ptr %78, i32 0, i32 11
  %80 = load i32, ptr %79, align 8, !tbaa !11
  %81 = add nsw i32 %80, %77
  store i32 %81, ptr %79, align 8, !tbaa !11
  store i32 0, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %82

82:                                               ; preds = %73, %13
  %83 = load i32, ptr %4, align 4
  ret i32 %83
}

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #4

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { nobuiltin nounwind "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 = { nounwind }
attributes #6 = { builtin 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 192}
!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 200}
!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 4, !9, i64 168, i64 8, !5}
!16 = !{!7, !7, i64 0}
!17 = !{!13, !13, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 2) i32 @_Z16mt_insert_weightP9ModelSpecP10WeightSpeci(ptr noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #2 {
  %4 = icmp eq ptr %0, null
  br i1 %4, label %48, label %5

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

.lr.ph:                                           ; preds = %5
  %13 = getelementptr inbounds i8, ptr %0, i64 200
  br label %16

.preheader:                                       ; preds = %16, %5
  %14 = icmp sgt i32 %2, 0
  br i1 %14, label %.lr.ph30.preheader, label %._crit_edge

.lr.ph30.preheader:                               ; preds = %.preheader
  %wide.trip.count = zext nneg i32 %2 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %15 = icmp eq i32 %2, 1
  br i1 %15, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph30.preheader.new

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

16:                                               ; preds = %.lr.ph, %16
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %16 ]
  %17 = load ptr, ptr %13, align 8, !tbaa !12
  %18 = getelementptr inbounds %struct.WeightSpec, ptr %17, i64 %indvars.iv
  %19 = getelementptr inbounds %struct.WeightSpec, ptr %10, i64 %indvars.iv
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(176) %19, ptr noundef nonnull align 8 dereferenceable(176) %18, i64 176, i1 false), !tbaa.struct !13
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %20 = load i32, ptr %6, align 8, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = icmp slt i64 %indvars.iv.next, %21
  br i1 %22, label %16, label %.preheader, !llvm.loop !18

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph30, %.lr.ph30.preheader
  %indvars.iv32.unr = phi i64 [ 0, %.lr.ph30.preheader ], [ %indvars.iv.next33.1, %.lr.ph30 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph30.epil

.lr.ph30.epil:                                    ; preds = %._crit_edge.loopexit.unr-lcssa
  %23 = getelementptr inbounds %struct.WeightSpec, ptr %1, i64 %indvars.iv32.unr
  %24 = load i32, ptr %6, align 8, !tbaa !5
  %25 = trunc nuw nsw i64 %indvars.iv32.unr to i32
  %26 = add nsw i32 %24, %25
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds %struct.WeightSpec, ptr %10, i64 %27
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(176) %28, ptr noundef nonnull align 8 dereferenceable(176) %23, i64 176, i1 false), !tbaa.struct !13
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph30.epil, %._crit_edge.loopexit.unr-lcssa, %.preheader
  %29 = getelementptr inbounds i8, ptr %0, i64 200
  %30 = load ptr, ptr %29, align 8, !tbaa !12
  %31 = icmp eq ptr %30, null
  br i1 %31, label %45, label %44

.lr.ph30:                                         ; preds = %.lr.ph30, %.lr.ph30.preheader.new
  %indvars.iv32 = phi i64 [ 0, %.lr.ph30.preheader.new ], [ %indvars.iv.next33.1, %.lr.ph30 ]
  %niter = phi i64 [ 0, %.lr.ph30.preheader.new ], [ %niter.next.1, %.lr.ph30 ]
  %32 = getelementptr inbounds %struct.WeightSpec, ptr %1, i64 %indvars.iv32
  %33 = load i32, ptr %6, align 8, !tbaa !5
  %34 = trunc nuw nsw i64 %indvars.iv32 to i32
  %35 = add nsw i32 %33, %34
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds %struct.WeightSpec, ptr %10, i64 %36
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(176) %37, ptr noundef nonnull align 8 dereferenceable(176) %32, i64 176, i1 false), !tbaa.struct !13
  %indvars.iv.next33 = or disjoint i64 %indvars.iv32, 1
  %38 = getelementptr inbounds %struct.WeightSpec, ptr %1, i64 %indvars.iv.next33
  %39 = load i32, ptr %6, align 8, !tbaa !5
  %40 = trunc nuw nsw i64 %indvars.iv.next33 to i32
  %41 = add nsw i32 %39, %40
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds %struct.WeightSpec, ptr %10, i64 %42
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(176) %43, ptr noundef nonnull align 8 dereferenceable(176) %38, i64 176, i1 false), !tbaa.struct !13
  %indvars.iv.next33.1 = add nuw nsw i64 %indvars.iv32, 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 %.lr.ph30, !llvm.loop !20

44:                                               ; preds = %._crit_edge
  tail call void @_ZdlPvm(ptr noundef nonnull %30, i64 noundef 176) #4
  br label %45

45:                                               ; preds = %44, %._crit_edge
  store ptr %10, ptr %29, align 8, !tbaa !12
  %46 = load i32, ptr %6, align 8, !tbaa !5
  %47 = add nsw i32 %46, %2
  store i32 %47, ptr %6, align 8, !tbaa !5
  br label %48

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

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { nobuiltin nounwind "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 = { builtin 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 192}
!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 200}
!13 = !{i64 0, i64 128, !14, i64 128, i64 4, !15, i64 132, i64 4, !16, i64 136, i64 8, !17, i64 144, i64 4, !16, i64 152, i64 8, !17, i64 160, i64 4, !16, i64 168, i64 8, !17}
!14 = !{!8, !8, i64 0}
!15 = !{!10, !10, i64 0}
!16 = !{!7, !7, i64 0}
!17 = !{!11, !11, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


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