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

; 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"

; 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 signext i8 @_Z16roundNearestEvenf(float noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z26ws_datatype_converter_int8PhS_iPf(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca float, align 4
  %12 = alloca i32, align 4
  %13 = 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
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %14, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %15, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store float 0.000000e+00, ptr %11, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %38, %4
  %17 = load i32, ptr %12, align 4, !tbaa !9
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %41

21:                                               ; preds = %16
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  %23 = load i32, ptr %12, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds float, ptr %22, i64 %24
  %26 = load float, ptr %25, align 4, !tbaa !11
  %27 = call noundef float @_ZSt3absf(float noundef %26)
  %28 = load float, ptr %11, align 4, !tbaa !11
  %29 = fcmp ogt float %27, %28
  br i1 %29, label %30, label %37

30:                                               ; preds = %21
  %31 = load ptr, ptr %9, align 8, !tbaa !5
  %32 = load i32, ptr %12, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds float, ptr %31, i64 %33
  %35 = load float, ptr %34, align 4, !tbaa !11
  %36 = call noundef float @_ZSt3absf(float noundef %35)
  store float %36, ptr %11, align 4, !tbaa !11
  br label %37

37:                                               ; preds = %30, %21
  br label %38

38:                                               ; preds = %37
  %39 = load i32, ptr %12, align 4, !tbaa !9
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %12, align 4, !tbaa !9
  br label %16, !llvm.loop !13

41:                                               ; preds = %20
  %42 = load float, ptr %11, align 4, !tbaa !11
  %43 = fpext float %42 to double
  %44 = fdiv double 1.270000e+02, %43
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = load float, ptr %45, align 4, !tbaa !11
  %47 = fpext float %46 to double
  %48 = fcmp ogt double %44, %47
  br i1 %48, label %49, label %53

49:                                               ; preds = %41
  %50 = load float, ptr %11, align 4, !tbaa !11
  %51 = fpext float %50 to double
  %52 = fdiv double 1.270000e+02, %51
  br label %57

53:                                               ; preds = %41
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = load float, ptr %54, align 4, !tbaa !11
  %56 = fpext float %55 to double
  br label %57

57:                                               ; preds = %53, %49
  %58 = phi double [ %52, %49 ], [ %56, %53 ]
  %59 = fptrunc double %58 to float
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  store float %59, ptr %60, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %61

61:                                               ; preds = %81, %57
  %62 = load i32, ptr %13, align 4, !tbaa !9
  %63 = load i32, ptr %7, align 4, !tbaa !9
  %64 = icmp slt i32 %62, %63
  br i1 %64, label %66, label %65

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

66:                                               ; preds = %61
  %67 = load ptr, ptr %9, align 8, !tbaa !5
  %68 = load i32, ptr %13, align 4, !tbaa !9
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds float, ptr %67, i64 %69
  %71 = load float, ptr %70, align 4, !tbaa !11
  %72 = load ptr, ptr %8, align 8, !tbaa !5
  %73 = getelementptr inbounds float, ptr %72, i64 0
  %74 = load float, ptr %73, align 4, !tbaa !11
  %75 = fmul float %71, %74
  %76 = call noundef signext i8 @_Z16roundNearestEvenf(float noundef %75)
  %77 = load ptr, ptr %10, align 8, !tbaa !5
  %78 = load i32, ptr %13, align 4, !tbaa !9
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds i8, ptr %77, i64 %79
  store i8 %76, ptr %80, align 1, !tbaa !15
  br label %81

81:                                               ; preds = %66
  %82 = load i32, ptr %13, align 4, !tbaa !9
  %83 = add nsw i32 %82, 1
  store i32 %83, ptr %13, align 4, !tbaa !9
  br label %61, !llvm.loop !16

84:                                               ; preds = %65
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt3absf(float 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 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 = { 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, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !14}


; 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"

; Function Attrs: mustprogress uwtable
declare dso_local noundef signext i8 @_Z16roundNearestEvenf(float noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z26ws_datatype_converter_int8PhS_iPf(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %1, i32 noundef %2, ptr nocapture noundef %3) local_unnamed_addr #0 {
  %5 = icmp sgt i32 %2, 0
  br i1 %5, label %.lr.ph.preheader, label %._crit_edge32.critedge

.lr.ph.preheader:                                 ; preds = %4
  %wide.trip.count = zext nneg i32 %2 to i64
  br label %.lr.ph

._crit_edge.loopexit:                             ; preds = %20
  %6 = fpext float %.1 to double
  %7 = fdiv double 1.270000e+02, %6
  %8 = load float, ptr %3, align 4, !tbaa !5
  %9 = fpext float %8 to double
  %10 = fcmp ogt double %7, %9
  %11 = fptrunc double %7 to float
  %12 = select i1 %10, float %11, float %8
  store float %12, ptr %3, align 4, !tbaa !5
  br i1 %5, label %.lr.ph31.preheader, label %._crit_edge32

.lr.ph31.preheader:                               ; preds = %._crit_edge.loopexit
  %wide.trip.count37 = zext nneg i32 %2 to i64
  br label %.lr.ph31

.lr.ph:                                           ; preds = %.lr.ph.preheader, %20
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %20 ]
  %.02327 = phi float [ 0.000000e+00, %.lr.ph.preheader ], [ %.1, %20 ]
  %13 = getelementptr inbounds float, ptr %0, i64 %indvars.iv
  %14 = load float, ptr %13, align 4, !tbaa !5
  %15 = tail call noundef float @_ZSt3absf(float noundef %14)
  %16 = fcmp ogt float %15, %.02327
  br i1 %16, label %17, label %20

17:                                               ; preds = %.lr.ph
  %18 = load float, ptr %13, align 4, !tbaa !5
  %19 = tail call noundef float @_ZSt3absf(float noundef %18)
  br label %20

20:                                               ; preds = %.lr.ph, %17
  %.1 = phi float [ %19, %17 ], [ %.02327, %.lr.ph ]
  %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.loopexit, label %.lr.ph, !llvm.loop !9

._crit_edge32.critedge:                           ; preds = %4
  %21 = load float, ptr %3, align 4, !tbaa !5
  %22 = fcmp one float %21, 0x7FF0000000000000
  %23 = select i1 %22, float 0x7FF0000000000000, float %21
  store float %23, ptr %3, align 4, !tbaa !5
  br label %._crit_edge32

._crit_edge32:                                    ; preds = %.lr.ph31, %._crit_edge32.critedge, %._crit_edge.loopexit
  ret void

.lr.ph31:                                         ; preds = %.lr.ph31.preheader, %.lr.ph31
  %indvars.iv34 = phi i64 [ 0, %.lr.ph31.preheader ], [ %indvars.iv.next35, %.lr.ph31 ]
  %24 = getelementptr inbounds float, ptr %0, i64 %indvars.iv34
  %25 = load float, ptr %24, align 4, !tbaa !5
  %26 = load float, ptr %3, align 4, !tbaa !5
  %27 = fmul float %25, %26
  %28 = tail call noundef signext i8 @_Z16roundNearestEvenf(float noundef %27)
  %29 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv34
  store i8 %28, ptr %29, align 1, !tbaa !11
  %indvars.iv.next35 = add nuw nsw i64 %indvars.iv34, 1
  %exitcond38.not = icmp eq i64 %indvars.iv.next35, %wide.trip.count37
  br i1 %exitcond38.not, label %._crit_edge32, label %.lr.ph31, !llvm.loop !12
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt3absf(float noundef) local_unnamed_addr #1

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" }

!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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !10}


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