; LLVM IR from gem5/gem5 :: ext/softfloat (f32_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.float32_t = type { i32 }
%union.ui32_f32 = type { i32 }

; Function Attrs: nounwind uwtable
define dso_local i64 @f32_to_i32(i32 %0, i8 noundef zeroext %1, i1 noundef zeroext %2) #0 {
  %4 = alloca %struct.float32_t, align 4
  %5 = alloca i8, align 1
  %6 = alloca i8, align 1
  %7 = alloca %union.ui32_f32, align 4
  %8 = alloca i64, align 8
  %9 = alloca i8, align 1
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = getelementptr inbounds %struct.float32_t, ptr %4, i32 0, i32 0
  store i32 %0, ptr %14, align 4
  store i8 %1, ptr %5, align 1, !tbaa !5
  %15 = zext i1 %2 to i8
  store i8 %15, ptr %6, align 1, !tbaa !8
  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
  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 4 %7, ptr align 4 %4, i64 4, i1 false), !tbaa.struct !10
  %16 = load i32, ptr %7, align 4, !tbaa !5
  %17 = zext i32 %16 to i64
  store i64 %17, ptr %8, align 8, !tbaa !13
  %18 = load i64, ptr %8, align 8, !tbaa !13
  %19 = trunc i64 %18 to i32
  %20 = lshr i32 %19, 31
  %21 = icmp ne i32 %20, 0
  %22 = zext i1 %21 to i8
  store i8 %22, ptr %9, align 1, !tbaa !8
  %23 = load i64, ptr %8, align 8, !tbaa !13
  %24 = lshr i64 %23, 23
  %25 = and i64 %24, 255
  store i64 %25, ptr %10, align 8, !tbaa !13
  %26 = load i64, ptr %8, align 8, !tbaa !13
  %27 = and i64 %26, 8388607
  store i64 %27, ptr %11, align 8, !tbaa !13
  %28 = load i64, ptr %10, align 8, !tbaa !13
  %29 = icmp eq i64 %28, 255
  br i1 %29, label %30, label %34

30:                                               ; preds = %3
  %31 = load i64, ptr %11, align 8, !tbaa !13
  %32 = icmp ne i64 %31, 0
  br i1 %32, label %33, label %34

33:                                               ; preds = %30
  store i8 0, ptr %9, align 1, !tbaa !8
  br label %34

34:                                               ; preds = %33, %30, %3
  %35 = load i64, ptr %10, align 8, !tbaa !13
  %36 = icmp ne i64 %35, 0
  br i1 %36, label %37, label %40

37:                                               ; preds = %34
  %38 = load i64, ptr %11, align 8, !tbaa !13
  %39 = or i64 %38, 8388608
  store i64 %39, ptr %11, align 8, !tbaa !13
  br label %40

40:                                               ; preds = %37, %34
  %41 = load i64, ptr %11, align 8, !tbaa !13
  %42 = shl i64 %41, 32
  store i64 %42, ptr %12, align 8, !tbaa !13
  %43 = load i64, ptr %10, align 8, !tbaa !13
  %44 = sub nsw i64 170, %43
  store i64 %44, ptr %13, align 8, !tbaa !13
  %45 = load i64, ptr %13, align 8, !tbaa !13
  %46 = icmp slt i64 0, %45
  br i1 %46, label %47, label %51

47:                                               ; preds = %40
  %48 = load i64, ptr %12, align 8, !tbaa !13
  %49 = load i64, ptr %13, align 8, !tbaa !13
  %50 = call i64 @softfloat_shiftRightJam64(i64 noundef %48, i64 noundef %49)
  store i64 %50, ptr %12, align 8, !tbaa !13
  br label %51

51:                                               ; preds = %47, %40
  %52 = load i8, ptr %9, align 1, !tbaa !8, !range !15, !noundef !16
  %53 = trunc i8 %52 to i1
  %54 = load i64, ptr %12, align 8, !tbaa !13
  %55 = load i8, ptr %5, align 1, !tbaa !5
  %56 = load i8, ptr %6, align 1, !tbaa !8, !range !15, !noundef !16
  %57 = trunc i8 %56 to i1
  %58 = call i64 @softfloat_roundToI32(i1 noundef zeroext %53, i64 noundef %54, i8 noundef zeroext %55, i1 noundef zeroext %57)
  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 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
  ret i64 %58
}

; 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 4, !11}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !6, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !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 @f32_to_i32(i32 %0, i8 noundef zeroext %1, i1 noundef zeroext %2) local_unnamed_addr #0 {
  %4 = zext i32 %0 to i64
  %5 = lshr i64 %4, 23
  %6 = and i64 %5, 255
  %7 = and i64 %4, 8388607
  %.not = icmp eq i64 %6, 0
  %8 = shl nuw nsw i64 %7, 32
  %9 = or disjoint i64 %8, 36028797018963968
  %10 = select i1 %.not, i64 %8, i64 %9
  %11 = icmp ult i64 %6, 170
  br i1 %11, label %12, label %15

12:                                               ; preds = %3
  %13 = sub nuw nsw i64 170, %6
  %14 = tail call i64 @softfloat_shiftRightJam64(i64 noundef %10, i64 noundef %13)
  br label %15

15:                                               ; preds = %12, %3
  %.018 = phi i64 [ %14, %12 ], [ %10, %3 ]
  %16 = icmp eq i64 %7, 0
  %17 = icmp ne i64 %6, 255
  %18 = icmp slt i32 %0, 0
  %or.cond.not = or i1 %16, %17
  %spec.select = and i1 %18, %or.cond.not
  %19 = tail call i64 @softfloat_roundToI32(i1 noundef zeroext %spec.select, i64 noundef %.018, i8 noundef zeroext %1, i1 noundef zeroext %2) #3
  ret i64 %19
}

; 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

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: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass