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

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

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

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

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

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

43:                                               ; preds = %42, %36
  store i64 9221120237041090560, ptr %10, align 8, !tbaa !13
  br label %51

44:                                               ; preds = %32
  %45 = load i8, ptr %6, align 1, !tbaa !14, !range !19, !noundef !20
  %46 = trunc i8 %45 to i1
  %47 = zext i1 %46 to i64
  %48 = shl i64 %47, 63
  %49 = add i64 %48, 9218868437227405312
  %50 = add i64 %49, 0
  store i64 %50, ptr %10, align 8, !tbaa !13
  br label %51

51:                                               ; preds = %44, %43
  br label %82

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

56:                                               ; preds = %52
  %57 = load i64, ptr %8, align 8, !tbaa !13
  %58 = icmp ne i64 %57, 0
  br i1 %58, label %66, label %59

59:                                               ; preds = %56
  %60 = load i8, ptr %6, align 1, !tbaa !14, !range !19, !noundef !20
  %61 = trunc i8 %60 to i1
  %62 = zext i1 %61 to i64
  %63 = shl i64 %62, 63
  %64 = add i64 %63, 0
  %65 = add i64 %64, 0
  store i64 %65, ptr %10, align 8, !tbaa !13
  br label %82

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

70:                                               ; preds = %66, %52
  %71 = load i64, ptr %8, align 8, !tbaa !13
  %72 = call i64 @softfloat_shortShiftRightJam64(i64 noundef %71, i8 noundef zeroext 1)
  store i64 %72, ptr %8, align 8, !tbaa !13
  %73 = load i32, ptr %7, align 4, !tbaa !16
  %74 = sub nsw i32 %73, 15361
  store i32 %74, ptr %7, align 4, !tbaa !16
  %75 = load i8, ptr %6, align 1, !tbaa !14, !range !19, !noundef !20
  %76 = trunc i8 %75 to i1
  %77 = load i32, ptr %7, align 4, !tbaa !16
  %78 = sext i32 %77 to i64
  %79 = load i64, ptr %8, align 8, !tbaa !13
  %80 = call i64 @softfloat_roundPackToF64(i1 noundef zeroext %76, i64 noundef %78, i64 noundef %79)
  %81 = getelementptr inbounds %struct.float64_t, ptr %2, i32 0, i32 0
  store i64 %80, ptr %81, align 8
  store i32 1, ptr %12, align 4
  br label %84

82:                                               ; preds = %59, %51
  %83 = load i64, ptr %10, align 8, !tbaa !13
  store i64 %83, ptr %11, align 8, !tbaa !21
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %2, ptr align 8 %11, i64 8, i1 false), !tbaa.struct !22
  store i32 1, ptr %12, align 4
  br label %84

84:                                               ; preds = %82, %70
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, 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
  %85 = getelementptr inbounds %struct.float64_t, ptr %2, i32 0, i32 0
  %86 = load i64, ptr %85, align 8
  ret i64 %86
}

; 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 i64 @softfloat_roundPackToF64(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 8, !13}


; 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 i64 @extF80M_to_f64(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
  %.not18 = icmp eq i64 %11, 0
  br i1 %.not18, label %15, label %12

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

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

15:                                               ; preds = %10
  %.lobit19 = lshr i16 %4, 15
  %16 = zext nneg i16 %.lobit19 to i64
  %17 = shl nuw i64 %16, 63
  %18 = or disjoint i64 %17, 9218868437227405312
  br label %33

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

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

21:                                               ; preds = %20
  %.lobit = lshr i16 %4, 15
  %22 = zext nneg i16 %.lobit to i64
  %23 = shl nuw i64 %22, 63
  br label %33

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 ]
  %.015 = phi i32 [ %7, %19 ], [ %26, %24 ]
  %29 = call i64 @softfloat_shortShiftRightJam64(i64 noundef %28, i8 noundef zeroext 1)
  store i64 %29, ptr %2, align 8, !tbaa !12
  %30 = add nsw i32 %.015, -15361
  %31 = sext i32 %30 to i64
  %32 = call i64 @softfloat_roundPackToF64(i1 noundef zeroext %5, i64 noundef %31, i64 noundef %29) #4
  br label %33

33:                                               ; preds = %21, %15, %14, %12, %27
  %.sroa.014.0 = phi i64 [ %32, %27 ], [ %18, %15 ], [ %23, %21 ], [ 9221120237041090560, %14 ], [ 9221120237041090560, %12 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  ret i64 %.sroa.014.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 i64 @softfloat_roundPackToF64(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