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

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

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

32:                                               ; preds = %4
  %33 = load i64, ptr %12, align 8, !tbaa !11
  %34 = and i64 %33, 9223372036854775807
  %35 = icmp ne i64 %34, 0
  br i1 %35, label %36, label %37

36:                                               ; preds = %32
  store i8 0, ptr %10, align 1, !tbaa !8
  br label %37

37:                                               ; preds = %36, %32, %4
  %38 = load i64, ptr %11, align 8, !tbaa !11
  %39 = sub nsw i64 16434, %38
  store i64 %39, ptr %13, align 8, !tbaa !11
  %40 = load i64, ptr %13, align 8, !tbaa !11
  %41 = icmp sle i64 %40, 0
  br i1 %41, label %42, label %43

42:                                               ; preds = %37
  store i64 1, ptr %13, align 8, !tbaa !11
  br label %43

43:                                               ; preds = %42, %37
  %44 = load i64, ptr %12, align 8, !tbaa !11
  %45 = load i64, ptr %13, align 8, !tbaa !11
  %46 = call i64 @softfloat_shiftRightJam64(i64 noundef %44, i64 noundef %45)
  store i64 %46, ptr %12, align 8, !tbaa !11
  %47 = load i8, ptr %10, align 1, !tbaa !8, !range !15, !noundef !16
  %48 = trunc i8 %47 to i1
  %49 = load i64, ptr %12, align 8, !tbaa !11
  %50 = load i8, ptr %6, align 1, !tbaa !5
  %51 = load i8, ptr %7, align 1, !tbaa !8, !range !15, !noundef !16
  %52 = trunc i8 %51 to i1
  %53 = call i64 @softfloat_roundToI32(i1 noundef zeroext %48, i64 noundef %49, i8 noundef zeroext %50, i1 noundef zeroext %52)
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #5
  ret i64 %53
}

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

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

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

declare i64 @softfloat_roundToI32(i1 noundef zeroext, i64 noundef, i8 noundef zeroext, i1 noundef zeroext) #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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"_Bool", !6, i64 0}
!10 = !{i64 0, i64 8, !11, i64 8, i64 2, !13}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !6, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"short", !6, i64 0}
!15 = !{i8 0, i8 2}
!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 i64 @extF80_to_i32(i64 %0, i16 %1, i8 noundef zeroext %2, i1 noundef zeroext %3) local_unnamed_addr #0 {
  %5 = and i16 %1, 32767
  %6 = icmp ne i16 %5, 32767
  %7 = and i64 %0, 9223372036854775807
  %.not = icmp eq i64 %7, 0
  %or.cond = or i1 %.not, %6
  %8 = icmp slt i16 %1, 0
  %9 = zext nneg i16 %5 to i64
  %10 = sub nsw i64 16434, %9
  %spec.store.select = tail call i64 @llvm.smax.i64(i64 %10, i64 1)
  %11 = tail call i64 @softfloat_shiftRightJam64(i64 noundef %0, i64 noundef %spec.store.select)
  %12 = and i1 %8, %or.cond
  %13 = tail call i64 @softfloat_roundToI32(i1 noundef zeroext %12, i64 noundef %11, i8 noundef zeroext %2, i1 noundef zeroext %3) #4
  ret i64 %13
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @softfloat_shiftRightJam64(i64 noundef, i64 noundef) local_unnamed_addr #1

declare i64 @softfloat_roundToI32(i1 noundef zeroext, i64 noundef, i8 noundef zeroext, i1 noundef zeroext) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smax.i64(i64, i64) #3

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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)"}


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