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

; 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
define dso_local noundef signext i8 @_Z16roundNearestEvenf(float noundef %0) #1 {
  %2 = alloca i8, align 1
  %3 = alloca float, align 4
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  store float %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #3
  %6 = load float, ptr %3, align 4, !tbaa !5
  %7 = call noundef float @_ZSt5roundf(float noundef %6)
  %8 = fptosi float %7 to i8
  store i8 %8, ptr %4, align 1, !tbaa !9
  %9 = load i8, ptr %4, align 1, !tbaa !9
  %10 = sext i8 %9 to i32
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %12, label %30

12:                                               ; preds = %1
  %13 = load i8, ptr %4, align 1, !tbaa !9
  %14 = sitofp i8 %13 to float
  %15 = fpext float %14 to double
  %16 = load float, ptr %3, align 4, !tbaa !5
  %17 = fpext float %16 to double
  %18 = fadd double %17, 5.000000e-01
  %19 = fcmp oeq double %15, %18
  br i1 %19, label %20, label %30

20:                                               ; preds = %12
  %21 = load i8, ptr %4, align 1, !tbaa !9
  %22 = sext i8 %21 to i32
  %23 = srem i32 %22, 2
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %30

25:                                               ; preds = %20
  %26 = load i8, ptr %4, align 1, !tbaa !9
  %27 = sext i8 %26 to i32
  %28 = sub nsw i32 %27, 1
  %29 = trunc i32 %28 to i8
  store i8 %29, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %54

30:                                               ; preds = %20, %12, %1
  %31 = load i8, ptr %4, align 1, !tbaa !9
  %32 = sext i8 %31 to i32
  %33 = icmp slt i32 %32, 0
  br i1 %33, label %34, label %52

34:                                               ; preds = %30
  %35 = load i8, ptr %4, align 1, !tbaa !9
  %36 = sitofp i8 %35 to float
  %37 = fpext float %36 to double
  %38 = load float, ptr %3, align 4, !tbaa !5
  %39 = fpext float %38 to double
  %40 = fsub double %39, 5.000000e-01
  %41 = fcmp oeq double %37, %40
  br i1 %41, label %42, label %52

42:                                               ; preds = %34
  %43 = load i8, ptr %4, align 1, !tbaa !9
  %44 = sext i8 %43 to i32
  %45 = srem i32 %44, 2
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %47, label %52

47:                                               ; preds = %42
  %48 = load i8, ptr %4, align 1, !tbaa !9
  %49 = sext i8 %48 to i32
  %50 = add nsw i32 %49, 1
  %51 = trunc i32 %50 to i8
  store i8 %51, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %54

52:                                               ; preds = %42, %34, %30
  %53 = load i8, ptr %4, align 1, !tbaa !9
  store i8 %53, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %54

54:                                               ; preds = %52, %47, %25
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #3
  %55 = load i8, ptr %2, align 1
  ret i8 %55
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt5roundf(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 = { 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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !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"

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef signext i8 @_Z16roundNearestEvenf(float noundef %0) local_unnamed_addr #0 {
  %2 = tail call noundef float @_ZSt5roundf(float noundef %0)
  %3 = fptosi float %2 to i8
  %4 = zext i8 %3 to i32
  %5 = icmp sgt i8 %3, 0
  br i1 %5, label %6, label %13

6:                                                ; preds = %1
  %7 = uitofp nneg i8 %3 to double
  %8 = fpext float %0 to double
  %9 = fadd double %8, 5.000000e-01
  %10 = fcmp oeq double %9, %7
  %11 = and i32 %4, 1
  %.not = icmp ne i32 %11, 0
  %or.cond.not = and i1 %10, %.not
  %12 = sext i1 %or.cond.not to i8
  %spec.select15 = add nsw i8 %12, %3
  br label %.thread

13:                                               ; preds = %1
  %14 = icmp slt i8 %3, 0
  br i1 %14, label %15, label %.thread

15:                                               ; preds = %13
  %16 = sitofp i8 %3 to double
  %17 = fpext float %0 to double
  %18 = fadd double %17, -5.000000e-01
  %19 = fcmp oeq double %18, %16
  %20 = and i32 %4, 1
  %.not13 = icmp ne i32 %20, 0
  %or.cond14.not = and i1 %19, %.not13
  %21 = zext i1 %or.cond14.not to i8
  %spec.select = add nsw i8 %21, %3
  br label %.thread

.thread:                                          ; preds = %6, %15, %13
  %.0 = phi i8 [ 0, %13 ], [ %spec.select, %15 ], [ %spec.select15, %6 ]
  ret i8 %.0
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt5roundf(float noundef) local_unnamed_addr #0

attributes #0 = { 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)"}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass