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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @extF80M_to_f32(ptr noundef %0) #0 {
  %2 = alloca %struct.float32_t, align 4
  %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 i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca %union.ui32_f32, align 4
  %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 4, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.start.p0(i64 4, 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 %53

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 i32 2143289344, ptr %10, align 4, !tbaa !16
  br label %52

45:                                               ; preds = %33
  %46 = load i8, ptr %6, align 1, !tbaa !14, !range !19, !noundef !20
  %47 = trunc i8 %46 to i1
  %48 = zext i1 %47 to i32
  %49 = shl i32 %48, 31
  %50 = add i32 %49, 2139095040
  %51 = add i32 %50, 0
  store i32 %51, ptr %10, align 4, !tbaa !16
  br label %52

52:                                               ; preds = %45, %44
  br label %85

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

57:                                               ; preds = %53
  %58 = load i64, ptr %8, align 8, !tbaa !13
  %59 = icmp ne i64 %58, 0
  br i1 %59, label %67, label %60

60:                                               ; preds = %57
  %61 = load i8, ptr %6, align 1, !tbaa !14, !range !19, !noundef !20
  %62 = trunc i8 %61 to i1
  %63 = zext i1 %62 to i32
  %64 = shl i32 %63, 31
  %65 = add i32 %64, 0
  %66 = add i32 %65, 0
  store i32 %66, ptr %10, align 4, !tbaa !16
  br label %85

67:                                               ; preds = %57
  %68 = call i32 @softfloat_normExtF80SigM(ptr noundef %8)
  %69 = load i32, ptr %7, align 4, !tbaa !16
  %70 = add nsw i32 %69, %68
  store i32 %70, ptr %7, align 4, !tbaa !16
  br label %71

71:                                               ; preds = %67, %53
  %72 = load i64, ptr %8, align 8, !tbaa !13
  %73 = call i64 @softfloat_shortShiftRightJam64(i64 noundef %72, i8 noundef zeroext 33)
  %74 = trunc i64 %73 to i32
  store i32 %74, ptr %11, align 4, !tbaa !16
  %75 = load i32, ptr %7, align 4, !tbaa !16
  %76 = sub nsw i32 %75, 16257
  store i32 %76, ptr %7, align 4, !tbaa !16
  %77 = load i8, ptr %6, align 1, !tbaa !14, !range !19, !noundef !20
  %78 = trunc i8 %77 to i1
  %79 = load i32, ptr %7, align 4, !tbaa !16
  %80 = sext i32 %79 to i64
  %81 = load i32, ptr %11, align 4, !tbaa !16
  %82 = zext i32 %81 to i64
  %83 = call i32 @softfloat_roundPackToF32(i1 noundef zeroext %78, i64 noundef %80, i64 noundef %82)
  %84 = getelementptr inbounds %struct.float32_t, ptr %2, i32 0, i32 0
  store i32 %83, ptr %84, align 4
  store i32 1, ptr %13, align 4
  br label %87

85:                                               ; preds = %60, %52
  %86 = load i32, ptr %10, align 4, !tbaa !16
  store i32 %86, ptr %12, align 4, !tbaa !21
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %2, ptr align 4 %12, i64 4, i1 false), !tbaa.struct !22
  store i32 1, ptr %13, align 4
  br label %87

87:                                               ; preds = %85, %71
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4, 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
  %88 = getelementptr inbounds %struct.float32_t, ptr %2, i32 0, i32 0
  %89 = load i32, ptr %88, align 4
  ret i32 %89
}

; 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 i32 @softfloat_roundPackToF32(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 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!7, !7, i64 0}
!22 = !{i64 0, i64 4, !16}


; 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 i32 @extF80M_to_f32(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 %19

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 %34

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

15:                                               ; preds = %10
  %.lobit20 = lshr i16 %4, 15
  %16 = zext nneg i16 %.lobit20 to i32
  %17 = shl nuw i32 %16, 31
  %18 = or disjoint i32 %17, 2139095040
  br label %34

19:                                               ; preds = %1
  %.not = icmp sgt i64 %8, -1
  br i1 %.not, label %20, label %27

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

21:                                               ; preds = %20
  %.lobit = lshr i16 %4, 15
  %22 = zext nneg i16 %.lobit to i32
  %23 = shl nuw i32 %22, 31
  br label %34

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

27:                                               ; preds = %24, %19
  %28 = phi i64 [ %8, %19 ], [ %.pre, %24 ]
  %.0 = phi i32 [ %7, %19 ], [ %26, %24 ]
  %29 = call i64 @softfloat_shortShiftRightJam64(i64 noundef %28, i8 noundef zeroext 33)
  %30 = add nsw i32 %.0, -16257
  %31 = sext i32 %30 to i64
  %32 = and i64 %29, 4294967295
  %33 = call i32 @softfloat_roundPackToF32(i1 noundef zeroext %5, i64 noundef %31, i64 noundef %32) #4
  br label %34

34:                                               ; preds = %21, %15, %14, %12, %27
  %.sroa.015.0 = phi i32 [ %33, %27 ], [ %18, %15 ], [ %23, %21 ], [ 2143289344, %14 ], [ 2143289344, %12 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  ret i32 %.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 i32 @softfloat_roundPackToF32(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,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass