; LLVM IR from gem5/gem5 :: ext/softfloat (s_normRoundPackToF16)

; 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.float16_t = type { i16 }
%union.ui16_f16 = type { i16 }

; Function Attrs: nounwind uwtable
define dso_local i16 @softfloat_normRoundPackToF16(i1 noundef zeroext %0, i64 noundef %1, i64 noundef %2) #0 {
  %4 = alloca %struct.float16_t, align 2
  %5 = alloca i8, align 1
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i8, align 1
  %9 = alloca %union.ui16_f16, align 2
  %10 = alloca i32, align 4
  %11 = zext i1 %0 to i8
  store i8 %11, ptr %5, align 1, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store i64 %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 2, ptr %9) #5
  %12 = load i64, ptr %7, align 8, !tbaa !9
  %13 = trunc i64 %12 to i16
  %14 = call zeroext i8 @softfloat_countLeadingZeros16(i16 noundef zeroext %13)
  %15 = zext i8 %14 to i32
  %16 = sub nsw i32 %15, 1
  %17 = trunc i32 %16 to i8
  store i8 %17, ptr %8, align 1, !tbaa !11
  %18 = load i8, ptr %8, align 1, !tbaa !11
  %19 = sext i8 %18 to i64
  %20 = load i64, ptr %6, align 8, !tbaa !9
  %21 = sub nsw i64 %20, %19
  store i64 %21, ptr %6, align 8, !tbaa !9
  %22 = load i8, ptr %8, align 1, !tbaa !11
  %23 = sext i8 %22 to i32
  %24 = icmp sle i32 4, %23
  br i1 %24, label %25, label %55

25:                                               ; preds = %3
  %26 = load i64, ptr %6, align 8, !tbaa !9
  %27 = trunc i64 %26 to i32
  %28 = icmp ult i32 %27, 29
  br i1 %28, label %29, label %55

29:                                               ; preds = %25
  %30 = load i8, ptr %5, align 1, !tbaa !5, !range !12, !noundef !13
  %31 = trunc i8 %30 to i1
  %32 = zext i1 %31 to i16
  %33 = zext i16 %32 to i32
  %34 = shl i32 %33, 15
  %35 = load i64, ptr %7, align 8, !tbaa !9
  %36 = icmp ne i64 %35, 0
  br i1 %36, label %37, label %39

37:                                               ; preds = %29
  %38 = load i64, ptr %6, align 8, !tbaa !9
  br label %40

39:                                               ; preds = %29
  br label %40

40:                                               ; preds = %39, %37
  %41 = phi i64 [ %38, %37 ], [ 0, %39 ]
  %42 = trunc i64 %41 to i16
  %43 = zext i16 %42 to i32
  %44 = shl i32 %43, 10
  %45 = add nsw i32 %34, %44
  %46 = sext i32 %45 to i64
  %47 = load i64, ptr %7, align 8, !tbaa !9
  %48 = load i8, ptr %8, align 1, !tbaa !11
  %49 = sext i8 %48 to i32
  %50 = sub nsw i32 %49, 4
  %51 = zext i32 %50 to i64
  %52 = shl i64 %47, %51
  %53 = add i64 %46, %52
  %54 = trunc i64 %53 to i16
  store i16 %54, ptr %9, align 2, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %4, ptr align 2 %9, i64 2, i1 false), !tbaa.struct !14
  store i32 1, ptr %10, align 4
  br label %66

55:                                               ; preds = %25, %3
  %56 = load i8, ptr %5, align 1, !tbaa !5, !range !12, !noundef !13
  %57 = trunc i8 %56 to i1
  %58 = load i64, ptr %6, align 8, !tbaa !9
  %59 = load i64, ptr %7, align 8, !tbaa !9
  %60 = load i8, ptr %8, align 1, !tbaa !11
  %61 = sext i8 %60 to i32
  %62 = zext i32 %61 to i64
  %63 = shl i64 %59, %62
  %64 = call i16 @softfloat_roundPackToF16(i1 noundef zeroext %57, i64 noundef %58, i64 noundef %63)
  %65 = getelementptr inbounds %struct.float16_t, ptr %4, i32 0, i32 0
  store i16 %64, ptr %65, align 2
  store i32 1, ptr %10, align 4
  br label %66

66:                                               ; preds = %55, %40
  call void @llvm.lifetime.end.p0(i64 2, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #5
  %67 = getelementptr inbounds %struct.float16_t, ptr %4, i32 0, i32 0
  %68 = load i16, ptr %67, align 2
  ret i16 %68
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i8 @softfloat_countLeadingZeros16(i16 noundef zeroext) #2

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

declare i16 @softfloat_roundPackToF16(i1 noundef zeroext, i64 noundef, i64 noundef) #4

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

attributes #0 = { 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 = { inlinehint 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { "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 }

!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 = !{!"_Bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{i8 0, i8 2}
!13 = !{}
!14 = !{i64 0, i64 2, !15}
!15 = !{!16, !16, i64 0}
!16 = !{!"short", !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: nounwind uwtable
define dso_local i16 @softfloat_normRoundPackToF16(i1 noundef zeroext %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = trunc i64 %2 to i16
  %5 = tail call zeroext i8 @softfloat_countLeadingZeros16(i16 noundef zeroext %4)
  %6 = add i8 %5, -1
  %7 = sext i8 %6 to i64
  %8 = sub nsw i64 %1, %7
  %9 = sext i8 %6 to i32
  %10 = icmp sgt i8 %6, 3
  %11 = trunc i64 %8 to i32
  %12 = icmp ult i32 %11, 29
  %or.cond = select i1 %10, i1 %12, i1 false
  br i1 %or.cond, label %13, label %22

13:                                               ; preds = %3
  %14 = select i1 %0, i64 32768, i64 0
  %.not = icmp eq i64 %2, 0
  %15 = shl i64 %8, 10
  %.masked = select i1 %.not, i64 0, i64 %15
  %16 = add nsw i32 %9, -4
  %17 = zext nneg i32 %16 to i64
  %18 = shl i64 %2, %17
  %19 = add i64 %18, %14
  %20 = add i64 %19, %.masked
  %21 = trunc i64 %20 to i16
  br label %26

22:                                               ; preds = %3
  %23 = zext nneg i32 %9 to i64
  %24 = shl i64 %2, %23
  %25 = tail call i16 @softfloat_roundPackToF16(i1 noundef zeroext %0, i64 noundef %8, i64 noundef %24) #3
  br label %26

26:                                               ; preds = %22, %13
  %.sroa.016.0 = phi i16 [ %21, %13 ], [ %25, %22 ]
  ret i16 %.sroa.016.0
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i8 @softfloat_countLeadingZeros16(i16 noundef zeroext) local_unnamed_addr #1

declare i16 @softfloat_roundPackToF16(i1 noundef zeroext, i64 noundef, i64 noundef) local_unnamed_addr #2

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


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