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

; 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 }

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

37:                                               ; preds = %3
  %38 = load i64, ptr %12, align 8, !tbaa !16
  %39 = lshr i64 %38, 32
  %40 = icmp ne i64 %39, 0
  br i1 %40, label %41, label %42

41:                                               ; preds = %37
  br label %71

42:                                               ; preds = %37
  %43 = load i32, ptr %13, align 4, !tbaa !17
  %44 = icmp slt i32 -32, %43
  br i1 %44, label %45, label %51

45:                                               ; preds = %42
  %46 = load i32, ptr %13, align 4, !tbaa !17
  %47 = sub nsw i32 0, %46
  %48 = load i64, ptr %12, align 8, !tbaa !16
  %49 = zext i32 %47 to i64
  %50 = shl i64 %48, %49
  store i64 %50, ptr %12, align 8, !tbaa !16
  br label %57

51:                                               ; preds = %42
  %52 = load i64, ptr %12, align 8, !tbaa !16
  %53 = trunc i64 %52 to i32
  %54 = icmp ne i32 %53, 0
  br i1 %54, label %55, label %56

55:                                               ; preds = %51
  br label %71

56:                                               ; preds = %51
  br label %57

57:                                               ; preds = %56, %45
  br label %63

58:                                               ; preds = %3
  %59 = load i64, ptr %12, align 8, !tbaa !16
  %60 = load i32, ptr %13, align 4, !tbaa !17
  %61 = sext i32 %60 to i64
  %62 = call i64 @softfloat_shiftRightJam64(i64 noundef %59, i64 noundef %61)
  store i64 %62, ptr %12, align 8, !tbaa !16
  br label %63

63:                                               ; preds = %58, %57
  %64 = load i8, ptr %10, align 1, !tbaa !10, !range !20, !noundef !21
  %65 = trunc i8 %64 to i1
  %66 = load i64, ptr %12, align 8, !tbaa !16
  %67 = load i8, ptr %6, align 1, !tbaa !9
  %68 = load i8, ptr %7, align 1, !tbaa !10, !range !20, !noundef !21
  %69 = trunc i8 %68 to i1
  %70 = call i64 @softfloat_roundToUI32(i1 noundef zeroext %65, i64 noundef %66, i8 noundef zeroext %67, i1 noundef zeroext %69)
  store i64 %70, ptr %4, align 8
  store i32 1, ptr %14, align 4
  br label %87

71:                                               ; preds = %55, %41
  call void @softfloat_raiseFlags(i8 noundef zeroext 16)
  %72 = load i32, ptr %11, align 4, !tbaa !17
  %73 = icmp eq i32 %72, 32767
  br i1 %73, label %74, label %79

74:                                               ; preds = %71
  %75 = load i64, ptr %12, align 8, !tbaa !16
  %76 = and i64 %75, 9223372036854775807
  %77 = icmp ne i64 %76, 0
  br i1 %77, label %78, label %79

78:                                               ; preds = %74
  br label %84

79:                                               ; preds = %74, %71
  %80 = load i8, ptr %10, align 1, !tbaa !10, !range !20, !noundef !21
  %81 = trunc i8 %80 to i1
  %82 = zext i1 %81 to i64
  %83 = select i1 %81, i32 0, i32 -1
  br label %84

84:                                               ; preds = %79, %78
  %85 = phi i32 [ -1, %78 ], [ %83, %79 ]
  %86 = zext i32 %85 to i64
  store i64 %86, ptr %4, align 8
  store i32 1, ptr %14, align 4
  br label %87

87:                                               ; preds = %84, %63
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %88 = load i64, ptr %4, align 8
  ret i64 %88
}

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

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

declare i64 @softfloat_roundToUI32(i1 noundef zeroext, i64 noundef, i8 noundef zeroext, i1 noundef zeroext) #3

declare void @softfloat_raiseFlags(i8 noundef zeroext) #3

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


; 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_ui32(ptr nocapture noundef readonly %0, i8 noundef zeroext %1, i1 noundef zeroext %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i16, ptr %4, align 8, !tbaa !5
  %6 = icmp slt i16 %5, 0
  %7 = and i16 %5, 32767
  %8 = zext nneg i16 %7 to i32
  %9 = load i64, ptr %0, align 8, !tbaa !11
  %.neg = add nsw i32 %8, -16434
  %10 = icmp ugt i16 %7, 16433
  br i1 %10, label %11, label %18

11:                                               ; preds = %3
  %.not = icmp ult i64 %9, 4294967296
  br i1 %.not, label %12, label %24

12:                                               ; preds = %11
  %13 = icmp ult i16 %7, 16466
  br i1 %13, label %14, label %17

14:                                               ; preds = %12
  %15 = zext nneg i32 %.neg to i64
  %16 = shl i64 %9, %15
  br label %22

17:                                               ; preds = %12
  %.not23 = icmp eq i64 %9, 0
  br i1 %.not23, label %22, label %24

18:                                               ; preds = %3
  %19 = sub nsw i32 16434, %8
  %20 = zext nneg i32 %19 to i64
  %21 = tail call i64 @softfloat_shiftRightJam64(i64 noundef %9, i64 noundef %20)
  br label %22

22:                                               ; preds = %14, %17, %18
  %.021 = phi i64 [ %16, %14 ], [ 0, %17 ], [ %21, %18 ]
  %23 = tail call i64 @softfloat_roundToUI32(i1 noundef zeroext %6, i64 noundef %.021, i8 noundef zeroext %1, i1 noundef zeroext %2) #3
  br label %29

24:                                               ; preds = %17, %11
  tail call void @softfloat_raiseFlags(i8 noundef zeroext 16) #3
  %25 = icmp ne i16 %7, 32767
  %26 = and i64 %9, 9223372036854775807
  %.not24 = icmp eq i64 %26, 0
  %or.cond = select i1 %25, i1 true, i1 %.not24
  %27 = and i1 %6, %or.cond
  %28 = select i1 %27, i64 0, i64 4294967295
  br label %29

29:                                               ; preds = %24, %22
  %.0 = phi i64 [ %28, %24 ], [ %23, %22 ]
  ret i64 %.0
}

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

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

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

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 = { 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}


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