; LLVM IR from huawei-noah/bolt :: model_tools/src (model_data_type_converter)

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_Z23getMaxQuantizationErrorPhi(ptr noundef, i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_Z17quantizationErrorP9ModelSpecNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca float, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca float, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 -1, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %30, %2
  %11 = load i32, ptr %7, align 4, !tbaa !9
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.ModelSpec, ptr %12, i32 0, i32 11
  %14 = load i32, ptr %13, align 8, !tbaa !11
  %15 = icmp slt i32 %11, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %10
  store i32 2, ptr %8, align 4
  br label %33

17:                                               ; preds = %10
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.ModelSpec, ptr %18, i32 0, i32 12
  %20 = load ptr, ptr %19, align 8, !tbaa !14
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds %struct.WeightSpec, ptr %20, i64 %22
  %24 = getelementptr inbounds %struct.WeightSpec, ptr %23, i32 0, i32 0
  %25 = getelementptr inbounds [128 x i8], ptr %24, i64 0, i64 0
  %26 = call noundef zeroext i1 @_ZSteqIcSt11char_traitsIcESaIcEEbPKT_RKNSt7__cxx1112basic_stringIS3_T0_T1_EE(ptr noundef %25, ptr noundef nonnull align 8 dereferenceable(32) %1)
  br i1 %26, label %27, label %29

27:                                               ; preds = %17
  %28 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %28, ptr %6, align 4, !tbaa !9
  store i32 2, ptr %8, align 4
  br label %33

29:                                               ; preds = %17
  br label %30

30:                                               ; preds = %29
  %31 = load i32, ptr %7, align 4, !tbaa !9
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %7, align 4, !tbaa !9
  br label %10, !llvm.loop !15

33:                                               ; preds = %27, %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %34

34:                                               ; preds = %33
  %35 = load i32, ptr %6, align 4, !tbaa !9
  %36 = icmp eq i32 %35, -1
  br i1 %36, label %37, label %38

37:                                               ; preds = %34
  store float 0.000000e+00, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %78

38:                                               ; preds = %34
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.ModelSpec, ptr %39, i32 0, i32 12
  %41 = load ptr, ptr %40, align 8, !tbaa !14
  %42 = load i32, ptr %6, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds %struct.WeightSpec, ptr %41, i64 %43
  %45 = getelementptr inbounds %struct.WeightSpec, ptr %44, i32 0, i32 1
  %46 = load i32, ptr %45, align 8, !tbaa !17
  %47 = icmp eq i32 %46, 6
  br i1 %47, label %48, label %77

48:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.ModelSpec, ptr %49, i32 0, i32 12
  %51 = load ptr, ptr %50, align 8, !tbaa !14
  %52 = load i32, ptr %6, align 4, !tbaa !9
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds %struct.WeightSpec, ptr %51, i64 %53
  %55 = getelementptr inbounds %struct.WeightSpec, ptr %54, i32 0, i32 3
  %56 = load ptr, ptr %55, align 8, !tbaa !19
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.ModelSpec, ptr %57, i32 0, i32 12
  %59 = load ptr, ptr %58, align 8, !tbaa !14
  %60 = load i32, ptr %6, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds %struct.WeightSpec, ptr %59, i64 %61
  %63 = getelementptr inbounds %struct.WeightSpec, ptr %62, i32 0, i32 2
  %64 = load i32, ptr %63, align 4, !tbaa !20
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.ModelSpec, ptr %65, i32 0, i32 12
  %67 = load ptr, ptr %66, align 8, !tbaa !14
  %68 = load i32, ptr %6, align 4, !tbaa !9
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds %struct.WeightSpec, ptr %67, i64 %69
  %71 = getelementptr inbounds %struct.WeightSpec, ptr %70, i32 0, i32 1
  %72 = load i32, ptr %71, align 8, !tbaa !17
  %73 = call noundef i32 @_Z7bytesOf8DataType(i32 noundef %72)
  %74 = udiv i32 %64, %73
  %75 = call noundef float @_Z23getMaxQuantizationErrorPhi(ptr noundef %56, i32 noundef %74)
  store float %75, ptr %9, align 4, !tbaa !21
  %76 = load float, ptr %9, align 4, !tbaa !21
  store float %76, ptr %3, align 4
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %78

77:                                               ; preds = %38
  store float 0.000000e+00, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %78

78:                                               ; preds = %77, %48, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %79 = load float, ptr %3, align 4
  ret float %79
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZSteqIcSt11char_traitsIcESaIcEEbPKT_RKNSt7__cxx1112basic_stringIS3_T0_T1_EE(ptr noundef, ptr noundef nonnull align 8 dereferenceable(32)) #2

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

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 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 = { 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 = { 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 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!18, !13, i64 128}
!18 = !{!"_ZTS10WeightSpec", !7, i64 0, !13, i64 128, !10, i64 132, !6, i64 136, !10, i64 144, !6, i64 152, !10, i64 160, !6, i64 168}
!19 = !{!18, !6, i64 136}
!20 = !{!18, !10, i64 132}
!21 = !{!22, !22, i64 0}
!22 = !{!"float", !7, 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.WeightSpec = type { [128 x i8], i32, i32, ptr, i32, ptr, i32, ptr }

; Function Attrs: mustprogress uwtable
declare dso_local noundef float @_Z23getMaxQuantizationErrorPhi(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_Z17quantizationErrorP9ModelSpecNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 192
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph, label %.thread

.lr.ph:                                           ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 200
  br label %7

7:                                                ; preds = %.lr.ph, %11
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %11 ]
  %8 = load ptr, ptr %6, align 8, !tbaa !12
  %9 = getelementptr inbounds %struct.WeightSpec, ptr %8, i64 %indvars.iv
  %10 = tail call noundef zeroext i1 @_ZSteqIcSt11char_traitsIcESaIcEEbPKT_RKNSt7__cxx1112basic_stringIS3_T0_T1_EE(ptr noundef %9, ptr noundef nonnull align 8 dereferenceable(32) %1)
  br i1 %10, label %15, label %11

11:                                               ; preds = %7
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %12 = load i32, ptr %3, align 8, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = icmp slt i64 %indvars.iv.next, %13
  br i1 %14, label %7, label %.thread, !llvm.loop !13

15:                                               ; preds = %7
  %16 = load ptr, ptr %6, align 8, !tbaa !12
  %17 = and i64 %indvars.iv, 4294967295
  %18 = getelementptr inbounds %struct.WeightSpec, ptr %16, i64 %17
  %19 = getelementptr inbounds i8, ptr %18, i64 128
  %20 = load i32, ptr %19, align 8, !tbaa !15
  %21 = icmp eq i32 %20, 6
  br i1 %21, label %22, label %.thread

22:                                               ; preds = %15
  %23 = getelementptr inbounds i8, ptr %18, i64 136
  %24 = load ptr, ptr %23, align 8, !tbaa !17
  %25 = getelementptr inbounds i8, ptr %18, i64 132
  %26 = load i32, ptr %25, align 4, !tbaa !18
  %27 = tail call noundef i32 @_Z7bytesOf8DataType(i32 noundef 6)
  %28 = udiv i32 %26, %27
  %29 = tail call noundef float @_Z23getMaxQuantizationErrorPhi(ptr noundef %24, i32 noundef %28)
  br label %.thread

.thread:                                          ; preds = %11, %2, %15, %22
  %.0 = phi float [ %29, %22 ], [ 0.000000e+00, %15 ], [ 0.000000e+00, %2 ], [ 0.000000e+00, %11 ]
  ret float %.0
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZSteqIcSt11char_traitsIcESaIcEEbPKT_RKNSt7__cxx1112basic_stringIS3_T0_T1_EE(ptr noundef, ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z7bytesOf8DataType(i32 noundef) local_unnamed_addr #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 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 #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" }

!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 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !10, i64 128}
!16 = !{!"_ZTS10WeightSpec", !8, i64 0, !10, i64 128, !7, i64 132, !11, i64 136, !7, i64 144, !11, i64 152, !7, i64 160, !11, i64 168}
!17 = !{!16, !11, i64 136}
!18 = !{!16, !7, i64 132}


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