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

; 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 }
%union.ui32_f32 = type { i32 }

; Function Attrs: nounwind uwtable
define dso_local i32 @softfloat_normRoundPackToF32(i1 noundef zeroext %0, i64 noundef %1, i64 noundef %2) #0 {
  %4 = alloca %struct.float32_t, align 4
  %5 = alloca i8, align 1
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i8, align 1
  %9 = alloca %union.ui32_f32, align 4
  %10 = alloca i32, align 4
  %11 = zext i1 %0 to i8
  store i8 %11, ptr %5, align 1, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store i64 %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %12 = load i64, ptr %7, align 8, !tbaa !9
  %13 = trunc i64 %12 to i32
  %14 = call zeroext i8 @softfloat_countLeadingZeros32(i32 noundef %13)
  %15 = zext i8 %14 to i32
  %16 = sub nsw i32 %15, 1
  %17 = trunc i32 %16 to i8
  store i8 %17, ptr %8, align 1, !tbaa !11
  %18 = load i8, ptr %8, align 1, !tbaa !11
  %19 = sext i8 %18 to i64
  %20 = load i64, ptr %6, align 8, !tbaa !9
  %21 = sub nsw i64 %20, %19
  store i64 %21, ptr %6, align 8, !tbaa !9
  %22 = load i8, ptr %8, align 1, !tbaa !11
  %23 = sext i8 %22 to i32
  %24 = icmp sle i32 7, %23
  br i1 %24, label %25, label %53

25:                                               ; preds = %3
  %26 = load i64, ptr %6, align 8, !tbaa !9
  %27 = trunc i64 %26 to i32
  %28 = icmp ult i32 %27, 253
  br i1 %28, label %29, label %53

29:                                               ; preds = %25
  %30 = load i8, ptr %5, align 1, !tbaa !5, !range !12, !noundef !13
  %31 = trunc i8 %30 to i1
  %32 = zext i1 %31 to i32
  %33 = shl i32 %32, 31
  %34 = load i64, ptr %7, align 8, !tbaa !9
  %35 = icmp ne i64 %34, 0
  br i1 %35, label %36, label %38

36:                                               ; preds = %29
  %37 = load i64, ptr %6, align 8, !tbaa !9
  br label %39

38:                                               ; preds = %29
  br label %39

39:                                               ; preds = %38, %36
  %40 = phi i64 [ %37, %36 ], [ 0, %38 ]
  %41 = trunc i64 %40 to i32
  %42 = shl i32 %41, 23
  %43 = add i32 %33, %42
  %44 = zext i32 %43 to i64
  %45 = load i64, ptr %7, align 8, !tbaa !9
  %46 = load i8, ptr %8, align 1, !tbaa !11
  %47 = sext i8 %46 to i32
  %48 = sub nsw i32 %47, 7
  %49 = zext i32 %48 to i64
  %50 = shl i64 %45, %49
  %51 = add i64 %44, %50
  %52 = trunc i64 %51 to i32
  store i32 %52, ptr %9, align 4, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %4, ptr align 4 %9, i64 4, i1 false), !tbaa.struct !14
  store i32 1, ptr %10, align 4
  br label %64

53:                                               ; preds = %25, %3
  %54 = load i8, ptr %5, align 1, !tbaa !5, !range !12, !noundef !13
  %55 = trunc i8 %54 to i1
  %56 = load i64, ptr %6, align 8, !tbaa !9
  %57 = load i64, ptr %7, align 8, !tbaa !9
  %58 = load i8, ptr %8, align 1, !tbaa !11
  %59 = sext i8 %58 to i32
  %60 = zext i32 %59 to i64
  %61 = shl i64 %57, %60
  %62 = call i32 @softfloat_roundPackToF32(i1 noundef zeroext %55, i64 noundef %56, i64 noundef %61)
  %63 = getelementptr inbounds %struct.float32_t, ptr %4, i32 0, i32 0
  store i32 %62, ptr %63, align 4
  store i32 1, ptr %10, align 4
  br label %64

64:                                               ; preds = %53, %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #5
  %65 = getelementptr inbounds %struct.float32_t, ptr %4, i32 0, i32 0
  %66 = load i32, ptr %65, align 4
  ret i32 %66
}

; 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 zeroext i8 @softfloat_countLeadingZeros32(i32 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) #3

declare i32 @softfloat_roundPackToF32(i1 noundef zeroext, i64 noundef, i64 noundef) #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 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"_Bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{i8 0, i8 2}
!13 = !{}
!14 = !{i64 0, i64 4, !15}
!15 = !{!16, !16, i64 0}
!16 = !{!"int", !7, 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"

; Function Attrs: nounwind uwtable
define dso_local i32 @softfloat_normRoundPackToF32(i1 noundef zeroext %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = trunc i64 %2 to i32
  %5 = tail call zeroext i8 @softfloat_countLeadingZeros32(i32 noundef %4)
  %6 = add i8 %5, -1
  %7 = sext i8 %6 to i64
  %8 = sub nsw i64 %1, %7
  %9 = sext i8 %6 to i32
  %10 = icmp sgt i8 %6, 6
  %11 = trunc i64 %8 to i32
  %12 = icmp ult i32 %11, 253
  %or.cond = select i1 %10, i1 %12, i1 false
  br i1 %or.cond, label %13, label %22

13:                                               ; preds = %3
  %14 = select i1 %0, i64 2147483648, i64 0
  %.not = icmp eq i64 %2, 0
  %15 = shl i64 %8, 23
  %.masked = select i1 %.not, i64 0, i64 %15
  %16 = add nsw i32 %9, -7
  %17 = zext nneg i32 %16 to i64
  %18 = shl i64 %2, %17
  %19 = add i64 %18, %14
  %20 = add i64 %19, %.masked
  %21 = trunc i64 %20 to i32
  br label %26

22:                                               ; preds = %3
  %23 = zext nneg i32 %9 to i64
  %24 = shl i64 %2, %23
  %25 = tail call i32 @softfloat_roundPackToF32(i1 noundef zeroext %0, i64 noundef %8, i64 noundef %24) #3
  br label %26

26:                                               ; preds = %22, %13
  %.sroa.016.0 = phi i32 [ %21, %13 ], [ %25, %22 ]
  ret i32 %.sroa.016.0
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i8 @softfloat_countLeadingZeros32(i32 noundef) local_unnamed_addr #1

declare i32 @softfloat_roundPackToF32(i1 noundef zeroext, i64 noundef, i64 noundef) 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)"}


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