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

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

; Function Attrs: nounwind uwtable
define dso_local void @f128M_to_extF80M(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i8, align 1
  %9 = alloca i32, align 4
  %10 = alloca %struct.commonNaN, align 1
  %11 = alloca [4 x i32], align 16
  %12 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %11) #4
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %13, ptr %5, align 8, !tbaa !5
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %14, ptr %6, align 8, !tbaa !5
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds i32, ptr %15, i64 3
  %17 = load i32, ptr %16, align 4, !tbaa !9
  store i32 %17, ptr %7, align 4, !tbaa !9
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = lshr i32 %18, 31
  %20 = icmp ne i32 %19, 0
  %21 = zext i1 %20 to i8
  store i8 %21, ptr %8, align 1, !tbaa !11
  %22 = load i32, ptr %7, align 4, !tbaa !9
  %23 = lshr i32 %22, 16
  %24 = and i32 %23, 32767
  store i32 %24, ptr %9, align 4, !tbaa !9
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = icmp eq i32 %25, 32767
  br i1 %26, label %27, label %51

27:                                               ; preds = %2
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = call zeroext i1 @softfloat_isNaNF128M(ptr noundef %28)
  br i1 %29, label %30, label %40

30:                                               ; preds = %27
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds i32, ptr %31, i64 3
  %33 = load i32, ptr %32, align 4, !tbaa !9
  %34 = zext i32 %33 to i64
  %35 = and i64 %34, 140737488355328
  %36 = icmp ne i64 %35, 0
  br i1 %36, label %38, label %37

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

38:                                               ; preds = %37, %30
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  call void @softfloat_commonNaNToExtF80M(ptr noundef %10, ptr noundef %39)
  store i32 1, ptr %12, align 4
  br label %82

40:                                               ; preds = %27
  %41 = load i8, ptr %8, align 1, !tbaa !11, !range !13, !noundef !14
  %42 = trunc i8 %41 to i1
  %43 = zext i1 %42 to i64
  %44 = shl i64 %43, 15
  %45 = or i64 %44, 32767
  %46 = trunc i64 %45 to i16
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.extFloat80M, ptr %47, i32 0, i32 1
  store i16 %46, ptr %48, align 8, !tbaa !15
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.extFloat80M, ptr %49, i32 0, i32 0
  store i64 -9223372036854775808, ptr %50, align 8, !tbaa !19
  store i32 1, ptr %12, align 4
  br label %82

51:                                               ; preds = %2
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds [4 x i32], ptr %11, i64 0, i64 0
  %54 = call i32 @softfloat_shiftNormSigF128M(ptr noundef %52, i8 noundef zeroext 15, ptr noundef %53)
  store i32 %54, ptr %9, align 4, !tbaa !9
  %55 = load i32, ptr %9, align 4, !tbaa !9
  %56 = icmp eq i32 %55, -128
  br i1 %56, label %57, label %68

57:                                               ; preds = %51
  %58 = load i8, ptr %8, align 1, !tbaa !11, !range !13, !noundef !14
  %59 = trunc i8 %58 to i1
  %60 = zext i1 %59 to i64
  %61 = shl i64 %60, 15
  %62 = or i64 %61, 0
  %63 = trunc i64 %62 to i16
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.extFloat80M, ptr %64, i32 0, i32 1
  store i16 %63, ptr %65, align 8, !tbaa !15
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.extFloat80M, ptr %66, i32 0, i32 0
  store i64 0, ptr %67, align 8, !tbaa !19
  store i32 1, ptr %12, align 4
  br label %82

68:                                               ; preds = %51
  %69 = getelementptr inbounds [4 x i32], ptr %11, i64 0, i64 0
  %70 = load i32, ptr %69, align 16, !tbaa !9
  %71 = icmp ne i32 %70, 0
  br i1 %71, label %72, label %76

72:                                               ; preds = %68
  %73 = getelementptr inbounds [4 x i32], ptr %11, i64 0, i64 1
  %74 = load i32, ptr %73, align 4, !tbaa !9
  %75 = or i32 %74, 1
  store i32 %75, ptr %73, align 4, !tbaa !9
  br label %76

76:                                               ; preds = %72, %68
  %77 = load i8, ptr %8, align 1, !tbaa !11, !range !13, !noundef !14
  %78 = trunc i8 %77 to i1
  %79 = load i32, ptr %9, align 4, !tbaa !9
  %80 = getelementptr inbounds [4 x i32], ptr %11, i64 0, i64 1
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  call void @softfloat_roundPackMToExtF80M(i1 noundef zeroext %78, i32 noundef %79, ptr noundef %80, i8 noundef zeroext 80, ptr noundef %81)
  store i32 0, ptr %12, align 4
  br label %82

82:                                               ; preds = %76, %57, %40, %38
  call void @llvm.lifetime.end.p0(i64 16, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  %83 = load i32, ptr %12, align 4
  switch i32 %83, label %85 [
    i32 0, label %84
    i32 1, label %84
  ]

84:                                               ; preds = %82, %82
  ret void

85:                                               ; preds = %82
  unreachable
}

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

declare zeroext i1 @softfloat_isNaNF128M(ptr noundef) #2

declare void @softfloat_raiseFlags(i8 noundef zeroext) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @softfloat_commonNaNToExtF80M(ptr noundef, ptr noundef) #3

declare i32 @softfloat_shiftNormSigF128M(ptr noundef, i8 noundef zeroext, ptr noundef) #2

declare void @softfloat_roundPackMToExtF80M(i1 noundef zeroext, i32 noundef, ptr noundef, i8 noundef zeroext, ptr noundef) #2

; 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 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!16, !18, i64 8}
!16 = !{!"extFloat80M", !17, i64 0, !18, i64 8}
!17 = !{!"long", !7, i64 0}
!18 = !{!"short", !7, i64 0}
!19 = !{!16, !17, 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"

%struct.commonNaN = type { i8 }

; Function Attrs: nounwind uwtable
define dso_local void @f128M_to_extF80M(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca %struct.commonNaN, align 1
  %4 = alloca [4 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #4
  %5 = getelementptr inbounds i8, ptr %0, i64 12
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = icmp slt i32 %6, 0
  %8 = and i32 %6, 2147418112
  %9 = icmp eq i32 %8, 2147418112
  br i1 %9, label %10, label %17

10:                                               ; preds = %2
  %11 = tail call zeroext i1 @softfloat_isNaNF128M(ptr noundef nonnull %0) #4
  br i1 %11, label %12, label %13

12:                                               ; preds = %10
  tail call void @softfloat_raiseFlags(i8 noundef zeroext 16) #4
  call void @softfloat_commonNaNToExtF80M(ptr noundef nonnull %3, ptr noundef %1)
  br label %33

13:                                               ; preds = %10
  %14 = lshr i32 %6, 16
  %15 = trunc nuw i32 %14 to i16
  %16 = getelementptr inbounds i8, ptr %1, i64 8
  store i16 %15, ptr %16, align 8, !tbaa !9
  store i64 -9223372036854775808, ptr %1, align 8, !tbaa !13
  br label %33

17:                                               ; preds = %2
  %18 = call i32 @softfloat_shiftNormSigF128M(ptr noundef nonnull %0, i8 noundef zeroext 15, ptr noundef nonnull %4) #4
  %19 = icmp eq i32 %18, -128
  br i1 %19, label %20, label %25

20:                                               ; preds = %17
  %21 = lshr i32 %6, 16
  %22 = trunc nuw i32 %21 to i16
  %23 = and i16 %22, -32768
  %24 = getelementptr inbounds i8, ptr %1, i64 8
  store i16 %23, ptr %24, align 8, !tbaa !9
  store i64 0, ptr %1, align 8, !tbaa !13
  br label %33

25:                                               ; preds = %17
  %26 = load i32, ptr %4, align 16, !tbaa !5
  %.not = icmp eq i32 %26, 0
  br i1 %.not, label %31, label %27

27:                                               ; preds = %25
  %28 = getelementptr inbounds i8, ptr %4, i64 4
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = or i32 %29, 1
  store i32 %30, ptr %28, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %27, %25
  %32 = getelementptr inbounds i8, ptr %4, i64 4
  call void @softfloat_roundPackMToExtF80M(i1 noundef zeroext %7, i32 noundef %18, ptr noundef nonnull %32, i8 noundef zeroext 80, ptr noundef %1) #4
  br label %33

33:                                               ; preds = %31, %20, %13, %12
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #4
  ret void
}

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

declare zeroext i1 @softfloat_isNaNF128M(ptr noundef) local_unnamed_addr #2

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @softfloat_commonNaNToExtF80M(ptr noundef, ptr noundef) local_unnamed_addr #3

declare i32 @softfloat_shiftNormSigF128M(ptr noundef, i8 noundef zeroext, ptr noundef) local_unnamed_addr #2

declare void @softfloat_roundPackMToExtF80M(i1 noundef zeroext, i32 noundef, ptr noundef, i8 noundef zeroext, ptr 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, !6, i64 0}
!6 = !{!"int", !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 = !{!10, !11, i64 0}


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