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

; 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 }
%struct.commonNaN = type { i8 }
%union.ui16_f16 = type { i16 }
%struct.extFloat80M = type { i64, i16 }

; Function Attrs: nounwind uwtable
define dso_local i16 @extF80M_to_f16(ptr noundef %0) #0 {
  %2 = alloca %struct.float16_t, align 2
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i8, align 1
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca %struct.commonNaN, align 1
  %10 = alloca i16, align 2
  %11 = alloca i16, align 2
  %12 = alloca %union.ui16_f16, align 2
  %13 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 2, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 2, ptr %11) #5
  call void @llvm.lifetime.start.p0(i64 2, ptr %12) #5
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %14, ptr %4, align 8, !tbaa !5
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.extFloat80M, ptr %15, i32 0, i32 1
  %17 = load i16, ptr %16, align 8, !tbaa !9
  %18 = zext i16 %17 to i64
  store i64 %18, ptr %5, align 8, !tbaa !13
  %19 = load i64, ptr %5, align 8, !tbaa !13
  %20 = trunc i64 %19 to i16
  %21 = zext i16 %20 to i32
  %22 = ashr i32 %21, 15
  %23 = icmp ne i32 %22, 0
  %24 = zext i1 %23 to i8
  store i8 %24, ptr %6, align 1, !tbaa !14
  %25 = load i64, ptr %5, align 8, !tbaa !13
  %26 = and i64 %25, 32767
  %27 = trunc i64 %26 to i32
  store i32 %27, ptr %7, align 4, !tbaa !16
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.extFloat80M, ptr %28, i32 0, i32 0
  %30 = load i64, ptr %29, align 8, !tbaa !18
  store i64 %30, ptr %8, align 8, !tbaa !13
  %31 = load i32, ptr %7, align 4, !tbaa !16
  %32 = icmp eq i32 %31, 32767
  br i1 %32, label %33, label %55

33:                                               ; preds = %1
  %34 = load i64, ptr %8, align 8, !tbaa !13
  %35 = and i64 %34, 9223372036854775807
  %36 = icmp ne i64 %35, 0
  br i1 %36, label %37, label %45

37:                                               ; preds = %33
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.extFloat80M, ptr %38, i32 0, i32 0
  %40 = load i64, ptr %39, align 8, !tbaa !18
  %41 = and i64 %40, 4611686018427387904
  %42 = icmp ne i64 %41, 0
  br i1 %42, label %44, label %43

43:                                               ; preds = %37
  call void @softfloat_raiseFlags(i8 noundef zeroext 16)
  br label %44

44:                                               ; preds = %43, %37
  store i16 32256, ptr %10, align 2, !tbaa !19
  br label %54

45:                                               ; preds = %33
  %46 = load i8, ptr %6, align 1, !tbaa !14, !range !20, !noundef !21
  %47 = trunc i8 %46 to i1
  %48 = zext i1 %47 to i16
  %49 = zext i16 %48 to i32
  %50 = shl i32 %49, 15
  %51 = add nsw i32 %50, 31744
  %52 = add nsw i32 %51, 0
  %53 = trunc i32 %52 to i16
  store i16 %53, ptr %10, align 2, !tbaa !19
  br label %54

54:                                               ; preds = %45, %44
  br label %89

55:                                               ; preds = %1
  %56 = load i64, ptr %8, align 8, !tbaa !13
  %57 = and i64 %56, -9223372036854775808
  %58 = icmp ne i64 %57, 0
  br i1 %58, label %75, label %59

59:                                               ; preds = %55
  %60 = load i64, ptr %8, align 8, !tbaa !13
  %61 = icmp ne i64 %60, 0
  br i1 %61, label %71, label %62

62:                                               ; preds = %59
  %63 = load i8, ptr %6, align 1, !tbaa !14, !range !20, !noundef !21
  %64 = trunc i8 %63 to i1
  %65 = zext i1 %64 to i16
  %66 = zext i16 %65 to i32
  %67 = shl i32 %66, 15
  %68 = add nsw i32 %67, 0
  %69 = add nsw i32 %68, 0
  %70 = trunc i32 %69 to i16
  store i16 %70, ptr %10, align 2, !tbaa !19
  br label %89

71:                                               ; preds = %59
  %72 = call i32 @softfloat_normExtF80SigM(ptr noundef %8)
  %73 = load i32, ptr %7, align 4, !tbaa !16
  %74 = add nsw i32 %73, %72
  store i32 %74, ptr %7, align 4, !tbaa !16
  br label %75

75:                                               ; preds = %71, %55
  %76 = load i64, ptr %8, align 8, !tbaa !13
  %77 = call i64 @softfloat_shortShiftRightJam64(i64 noundef %76, i8 noundef zeroext 49)
  %78 = trunc i64 %77 to i16
  store i16 %78, ptr %11, align 2, !tbaa !19
  %79 = load i32, ptr %7, align 4, !tbaa !16
  %80 = sub nsw i32 %79, 16369
  store i32 %80, ptr %7, align 4, !tbaa !16
  %81 = load i8, ptr %6, align 1, !tbaa !14, !range !20, !noundef !21
  %82 = trunc i8 %81 to i1
  %83 = load i32, ptr %7, align 4, !tbaa !16
  %84 = sext i32 %83 to i64
  %85 = load i16, ptr %11, align 2, !tbaa !19
  %86 = zext i16 %85 to i64
  %87 = call i16 @softfloat_roundPackToF16(i1 noundef zeroext %82, i64 noundef %84, i64 noundef %86)
  %88 = getelementptr inbounds %struct.float16_t, ptr %2, i32 0, i32 0
  store i16 %87, ptr %88, align 2
  store i32 1, ptr %13, align 4
  br label %91

89:                                               ; preds = %62, %54
  %90 = load i16, ptr %10, align 2, !tbaa !19
  store i16 %90, ptr %12, align 2, !tbaa !22
  call void @llvm.memcpy.p0.p0.i64(ptr align 2 %2, ptr align 2 %12, i64 2, i1 false), !tbaa.struct !23
  store i32 1, ptr %13, align 4
  br label %91

91:                                               ; preds = %89, %75
  call void @llvm.lifetime.end.p0(i64 2, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 2, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 2, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  %92 = getelementptr inbounds %struct.float16_t, ptr %2, i32 0, i32 0
  %93 = load i16, ptr %92, align 2
  ret i16 %93
}

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

declare void @softfloat_raiseFlags(i8 noundef zeroext) #2

declare i32 @softfloat_normExtF80SigM(ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @softfloat_shortShiftRightJam64(i64 noundef, i8 noundef zeroext) #3

declare i16 @softfloat_roundPackToF16(i1 noundef zeroext, i64 noundef, i64 noundef) #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) #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 = { "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 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !12, i64 8}
!10 = !{!"extFloat80M", !11, i64 0, !12, i64 8}
!11 = !{!"long", !7, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"_Bool", !7, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"int", !7, i64 0}
!18 = !{!10, !11, i64 0}
!19 = !{!12, !12, i64 0}
!20 = !{i8 0, i8 2}
!21 = !{}
!22 = !{!7, !7, i64 0}
!23 = !{i64 0, i64 2, !19}


; 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 @extF80M_to_f16(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load i16, ptr %3, align 8, !tbaa !5
  %5 = icmp slt i16 %4, 0
  %6 = and i16 %4, 32767
  %7 = zext nneg i16 %6 to i32
  %8 = load i64, ptr %0, align 8, !tbaa !11
  store i64 %8, ptr %2, align 8, !tbaa !12
  %9 = icmp eq i16 %6, 32767
  br i1 %9, label %10, label %17

10:                                               ; preds = %1
  %11 = and i64 %8, 9223372036854775807
  %.not19 = icmp eq i64 %11, 0
  br i1 %.not19, label %15, label %12

12:                                               ; preds = %10
  %13 = and i64 %8, 4611686018427387904
  %.not21 = icmp eq i64 %13, 0
  br i1 %.not21, label %14, label %30

14:                                               ; preds = %12
  tail call void @softfloat_raiseFlags(i8 noundef zeroext 16) #4
  br label %30

15:                                               ; preds = %10
  %16 = and i16 %4, -1024
  br label %30

17:                                               ; preds = %1
  %.not = icmp sgt i64 %8, -1
  br i1 %.not, label %18, label %23

18:                                               ; preds = %17
  %.not18 = icmp eq i64 %8, 0
  br i1 %.not18, label %19, label %20

19:                                               ; preds = %18
  %.lobit = and i16 %4, -32768
  br label %30

20:                                               ; preds = %18
  %21 = call i32 @softfloat_normExtF80SigM(ptr noundef nonnull %2) #4
  %22 = add nsw i32 %21, %7
  %.pre = load i64, ptr %2, align 8, !tbaa !12
  br label %23

23:                                               ; preds = %20, %17
  %24 = phi i64 [ %8, %17 ], [ %.pre, %20 ]
  %.0 = phi i32 [ %7, %17 ], [ %22, %20 ]
  %25 = call i64 @softfloat_shortShiftRightJam64(i64 noundef %24, i8 noundef zeroext 49)
  %26 = add nsw i32 %.0, -16369
  %27 = sext i32 %26 to i64
  %28 = and i64 %25, 65535
  %29 = call i16 @softfloat_roundPackToF16(i1 noundef zeroext %5, i64 noundef %27, i64 noundef %28) #4
  br label %30

30:                                               ; preds = %19, %15, %14, %12, %23
  %.sroa.015.0 = phi i16 [ %29, %23 ], [ %16, %15 ], [ %.lobit, %19 ], [ 32256, %14 ], [ 32256, %12 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  ret i16 %.sroa.015.0
}

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

declare void @softfloat_raiseFlags(i8 noundef zeroext) local_unnamed_addr #2

declare i32 @softfloat_normExtF80SigM(ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @softfloat_shortShiftRightJam64(i64 noundef, i8 noundef zeroext) local_unnamed_addr #3

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

; Function Attrs: mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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, !10, i64 8}
!6 = !{!"extFloat80M", !7, i64 0, !10, i64 8}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!7, !7, i64 0}


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