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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z10UNI_MEMSETPvim(ptr noundef, i32 noundef, i64 noundef) #0

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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z8str_copyPcPKcii(ptr noundef, ptr noundef, i32 noundef, i32 noundef) #3

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z16mt_create_weightPKc8DataTypejjj(ptr dead_on_unwind noalias writable sret(%struct.WeightSpec) align 8 %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) #4 {
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !11
  store i32 %4, ptr %10, align 4, !tbaa !11
  store i32 %5, ptr %11, align 4, !tbaa !11
  call void @_ZN10WeightSpecC2Ev(ptr noundef nonnull align 8 dereferenceable(176) %0) #5
  call void @_Z10UNI_MEMSETPvim(ptr noundef %0, i32 noundef 0, i64 noundef 176)
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = call i64 @strlen(ptr noundef %13) #6
  %15 = icmp ult i64 %14, 127
  br i1 %15, label %16, label %19

16:                                               ; preds = %6
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = call i64 @strlen(ptr noundef %17) #6
  br label %20

19:                                               ; preds = %6
  br label %20

20:                                               ; preds = %19, %16
  %21 = phi i64 [ %18, %16 ], [ 127, %19 ]
  %22 = trunc i64 %21 to i32
  store i32 %22, ptr %12, align 4, !tbaa !11
  %23 = getelementptr inbounds %struct.WeightSpec, ptr %0, i32 0, i32 0
  %24 = getelementptr inbounds [128 x i8], ptr %23, i64 0, i64 0
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = load i32, ptr %12, align 4, !tbaa !11
  %27 = call noundef i32 @_Z8str_copyPcPKcii(ptr noundef %24, ptr noundef %25, i32 noundef %26, i32 noundef 128)
  %28 = load i32, ptr %12, align 4, !tbaa !11
  %29 = icmp ult i32 %28, 128
  br i1 %29, label %30, label %35

30:                                               ; preds = %20
  %31 = getelementptr inbounds %struct.WeightSpec, ptr %0, i32 0, i32 0
  %32 = load i32, ptr %12, align 4, !tbaa !11
  %33 = zext i32 %32 to i64
  %34 = getelementptr inbounds [128 x i8], ptr %31, i64 0, i64 %33
  store i8 0, ptr %34, align 1, !tbaa !13
  br label %35

35:                                               ; preds = %30, %20
  %36 = load i32, ptr %8, align 4, !tbaa !9
  %37 = getelementptr inbounds %struct.WeightSpec, ptr %0, i32 0, i32 1
  store i32 %36, ptr %37, align 8, !tbaa !14
  %38 = load i32, ptr %9, align 4, !tbaa !11
  %39 = getelementptr inbounds %struct.WeightSpec, ptr %0, i32 0, i32 2
  store i32 %38, ptr %39, align 4, !tbaa !16
  %40 = load i32, ptr %9, align 4, !tbaa !11
  %41 = call noundef ptr @_Z9mt_mallocj(i32 noundef %40)
  %42 = getelementptr inbounds %struct.WeightSpec, ptr %0, i32 0, i32 3
  store ptr %41, ptr %42, align 8, !tbaa !17
  %43 = load i32, ptr %10, align 4, !tbaa !11
  %44 = getelementptr inbounds %struct.WeightSpec, ptr %0, i32 0, i32 4
  store i32 %43, ptr %44, align 8, !tbaa !18
  %45 = load i32, ptr %10, align 4, !tbaa !11
  %46 = call noundef ptr @_Z9mt_mallocj(i32 noundef %45)
  %47 = getelementptr inbounds %struct.WeightSpec, ptr %0, i32 0, i32 5
  store ptr %46, ptr %47, align 8, !tbaa !19
  %48 = load i32, ptr %11, align 4, !tbaa !11
  %49 = getelementptr inbounds %struct.WeightSpec, ptr %0, i32 0, i32 6
  store i32 %48, ptr %49, align 8, !tbaa !20
  %50 = load i32, ptr %11, align 4, !tbaa !11
  %51 = zext i32 %50 to i64
  %52 = mul i64 16, %51
  %53 = trunc i64 %52 to i32
  %54 = call noundef ptr @_Z9mt_mallocj(i32 noundef %53)
  %55 = getelementptr inbounds %struct.WeightSpec, ptr %0, i32 0, i32 7
  store ptr %54, ptr %55, align 8, !tbaa !21
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  ret void
}

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind willreturn memory(read) "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 = { 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 #4 = { 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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }

!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 = !{!"_ZTS8DataType", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !10, i64 128}
!15 = !{!"_ZTS10WeightSpec", !7, i64 0, !10, i64 128, !12, i64 132, !6, i64 136, !12, i64 144, !6, i64 152, !12, i64 160, !6, i64 168}
!16 = !{!15, !12, i64 132}
!17 = !{!15, !6, i64 136}
!18 = !{!15, !12, i64 144}
!19 = !{!15, !6, i64 152}
!20 = !{!15, !12, i64 160}
!21 = !{!15, !6, i64 168}


; 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 nounwind uwtable
declare dso_local void @_Z10UNI_MEMSETPvim(ptr noundef, i32 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #1

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z16mt_create_weightPKc8DataTypejjj(ptr dead_on_unwind noalias nonnull writable sret(%struct.WeightSpec) align 8 %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) local_unnamed_addr #3 {
  tail call void @_ZN10WeightSpecC2Ev(ptr noundef nonnull align 8 dereferenceable(176) %0) #5
  tail call void @_Z10UNI_MEMSETPvim(ptr noundef nonnull %0, i32 noundef 0, i64 noundef 176)
  %7 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #6
  %spec.select13 = tail call i64 @llvm.umin.i64(i64 %7, i64 127)
  %spec.select = trunc nuw nsw i64 %spec.select13 to i32
  %8 = tail call noundef i32 @_Z8str_copyPcPKcii(ptr noundef nonnull %0, ptr noundef %1, i32 noundef %spec.select, i32 noundef 128)
  %9 = getelementptr inbounds [128 x i8], ptr %0, i64 0, i64 %spec.select13
  store i8 0, ptr %9, align 1, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 128
  store i32 %2, ptr %10, align 8, !tbaa !8
  %11 = getelementptr inbounds i8, ptr %0, i64 132
  store i32 %3, ptr %11, align 4, !tbaa !13
  %12 = tail call noundef ptr @_Z9mt_mallocj(i32 noundef %3)
  %13 = getelementptr inbounds i8, ptr %0, i64 136
  store ptr %12, ptr %13, align 8, !tbaa !14
  %14 = getelementptr inbounds i8, ptr %0, i64 144
  store i32 %4, ptr %14, align 8, !tbaa !15
  %15 = tail call noundef ptr @_Z9mt_mallocj(i32 noundef %4)
  %16 = getelementptr inbounds i8, ptr %0, i64 152
  store ptr %15, ptr %16, align 8, !tbaa !16
  %17 = getelementptr inbounds i8, ptr %0, i64 160
  store i32 %5, ptr %17, align 8, !tbaa !17
  %18 = shl i32 %5, 4
  %19 = tail call noundef ptr @_Z9mt_mallocj(i32 noundef %18)
  %20 = getelementptr inbounds i8, ptr %0, i64 168
  store ptr %19, ptr %20, align 8, !tbaa !18
  ret void
}

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #4

attributes #0 = { 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 #1 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !10, i64 128}
!9 = !{!"_ZTS10WeightSpec", !6, i64 0, !10, i64 128, !11, i64 132, !12, i64 136, !11, i64 144, !12, i64 152, !11, i64 160, !12, i64 168}
!10 = !{!"_ZTS8DataType", !6, i64 0}
!11 = !{!"int", !6, i64 0}
!12 = !{!"any pointer", !6, i64 0}
!13 = !{!9, !11, i64 132}
!14 = !{!9, !12, i64 136}
!15 = !{!9, !11, i64 144}
!16 = !{!9, !12, i64 152}
!17 = !{!9, !11, i64 160}
!18 = !{!9, !12, i64 168}


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