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

; 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_i64(i32 %0, i8 noundef zeroext %1, i1 noundef zeroext %2) #0 {
  %4 = alloca i64, align 8
  %5 = alloca %struct.float32_t, align 4
  %6 = alloca i8, align 1
  %7 = alloca i8, align 1
  %8 = alloca %union.ui32_f32, align 4
  %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 = alloca [3 x i32], align 4
  %15 = alloca i32, align 4
  %16 = getelementptr inbounds %struct.float32_t, ptr %5, i32 0, i32 0
  store i32 %0, ptr %16, align 4
  store i8 %1, ptr %6, align 1, !tbaa !5
  %17 = zext i1 %2 to i8
  store i8 %17, ptr %7, align 1, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 4, 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 8, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 12, ptr %14) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %8, ptr align 4 %5, i64 4, i1 false), !tbaa.struct !10
  %18 = load i32, ptr %8, align 4, !tbaa !5
  %19 = zext i32 %18 to i64
  store i64 %19, ptr %9, align 8, !tbaa !13
  %20 = load i64, ptr %9, align 8, !tbaa !13
  %21 = trunc i64 %20 to i32
  %22 = lshr i32 %21, 31
  %23 = icmp ne i32 %22, 0
  %24 = zext i1 %23 to i8
  store i8 %24, ptr %10, align 1, !tbaa !8
  %25 = load i64, ptr %9, align 8, !tbaa !13
  %26 = lshr i64 %25, 23
  %27 = and i64 %26, 255
  store i64 %27, ptr %11, align 8, !tbaa !13
  %28 = load i64, ptr %9, align 8, !tbaa !13
  %29 = and i64 %28, 8388607
  store i64 %29, ptr %12, align 8, !tbaa !13
  %30 = load i64, ptr %11, align 8, !tbaa !13
  %31 = sub nsw i64 190, %30
  store i64 %31, ptr %13, align 8, !tbaa !13
  %32 = load i64, ptr %13, align 8, !tbaa !13
  %33 = icmp slt i64 %32, 0
  br i1 %33, label %34, label %48

34:                                               ; preds = %3
  call void @softfloat_raiseFlags(i8 noundef zeroext 16)
  %35 = load i64, ptr %11, align 8, !tbaa !13
  %36 = icmp eq i64 %35, 255
  br i1 %36, label %37, label %41

37:                                               ; preds = %34
  %38 = load i64, ptr %12, align 8, !tbaa !13
  %39 = icmp ne i64 %38, 0
  br i1 %39, label %40, label %41

40:                                               ; preds = %37
  br label %46

41:                                               ; preds = %37, %34
  %42 = load i8, ptr %10, align 1, !tbaa !8, !range !15, !noundef !16
  %43 = trunc i8 %42 to i1
  %44 = zext i1 %43 to i64
  %45 = select i1 %43, i64 -9223372036854775808, i64 9223372036854775807
  br label %46

46:                                               ; preds = %41, %40
  %47 = phi i64 [ 9223372036854775807, %40 ], [ %45, %41 ]
  store i64 %47, ptr %4, align 8
  store i32 1, ptr %15, align 4
  br label %76

48:                                               ; preds = %3
  %49 = load i64, ptr %11, align 8, !tbaa !13
  %50 = icmp ne i64 %49, 0
  br i1 %50, label %51, label %54

51:                                               ; preds = %48
  %52 = load i64, ptr %12, align 8, !tbaa !13
  %53 = or i64 %52, 8388608
  store i64 %53, ptr %12, align 8, !tbaa !13
  br label %54

54:                                               ; preds = %51, %48
  %55 = load i64, ptr %12, align 8, !tbaa !13
  %56 = shl i64 %55, 8
  %57 = trunc i64 %56 to i32
  %58 = getelementptr inbounds [3 x i32], ptr %14, i64 0, i64 2
  store i32 %57, ptr %58, align 4, !tbaa !11
  %59 = getelementptr inbounds [3 x i32], ptr %14, i64 0, i64 1
  store i32 0, ptr %59, align 4, !tbaa !11
  %60 = getelementptr inbounds [3 x i32], ptr %14, i64 0, i64 0
  store i32 0, ptr %60, align 4, !tbaa !11
  %61 = load i64, ptr %13, align 8, !tbaa !13
  %62 = icmp ne i64 %61, 0
  br i1 %62, label %63, label %68

63:                                               ; preds = %54
  %64 = getelementptr inbounds [3 x i32], ptr %14, i64 0, i64 0
  %65 = load i64, ptr %13, align 8, !tbaa !13
  %66 = trunc i64 %65 to i32
  %67 = getelementptr inbounds [3 x i32], ptr %14, i64 0, i64 0
  call void @softfloat_shiftRightJamM(i8 noundef zeroext 3, ptr noundef %64, i32 noundef %66, ptr noundef %67)
  br label %68

68:                                               ; preds = %63, %54
  %69 = load i8, ptr %10, align 1, !tbaa !8, !range !15, !noundef !16
  %70 = trunc i8 %69 to i1
  %71 = getelementptr inbounds [3 x i32], ptr %14, i64 0, i64 0
  %72 = load i8, ptr %6, align 1, !tbaa !5
  %73 = load i8, ptr %7, align 1, !tbaa !8, !range !15, !noundef !16
  %74 = trunc i8 %73 to i1
  %75 = call i64 @softfloat_roundMToI64(i1 noundef zeroext %70, ptr noundef %71, i8 noundef zeroext %72, i1 noundef zeroext %74)
  store i64 %75, ptr %4, align 8
  store i32 1, ptr %15, align 4
  br label %76

76:                                               ; preds = %68, %46
  call void @llvm.lifetime.end.p0(i64 12, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, 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 4, ptr %8) #4
  %77 = load i64, ptr %4, align 8
  ret i64 %77
}

; 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

declare void @softfloat_raiseFlags(i8 noundef zeroext) #3

declare void @softfloat_shiftRightJamM(i8 noundef zeroext, ptr noundef, i32 noundef, ptr noundef) #3

declare i64 @softfloat_roundMToI64(i1 noundef zeroext, ptr noundef, i8 noundef zeroext, i1 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"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_i64(i32 %0, i8 noundef zeroext %1, i1 noundef zeroext %2) local_unnamed_addr #0 {
  %4 = alloca [3 x i32], align 4
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %4) #3
  %5 = zext i32 %0 to i64
  %6 = icmp slt i32 %0, 0
  %7 = lshr i64 %5, 23
  %8 = and i64 %7, 255
  %9 = and i64 %5, 8388607
  %10 = icmp ugt i64 %8, 190
  br i1 %10, label %11, label %15

11:                                               ; preds = %3
  tail call void @softfloat_raiseFlags(i8 noundef zeroext 16) #3
  %12 = icmp eq i64 %8, 255
  %13 = icmp ne i64 %9, 0
  %or.cond = and i1 %13, %12
  %14 = select i1 %6, i64 -9223372036854775808, i64 9223372036854775807
  %spec.select = select i1 %or.cond, i64 9223372036854775807, i64 %14
  br label %25

15:                                               ; preds = %3
  %.not = icmp eq i64 %8, 0
  %16 = or disjoint i64 %9, 8388608
  %spec.select22 = select i1 %.not, i64 %9, i64 %16
  %.019.tr = trunc nuw nsw i64 %spec.select22 to i32
  %17 = shl nuw i32 %.019.tr, 8
  %18 = getelementptr inbounds i8, ptr %4, i64 8
  store i32 %17, ptr %18, align 4, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %4, i64 4
  store i32 0, ptr %19, align 4, !tbaa !5
  store i32 0, ptr %4, align 4, !tbaa !5
  %.not21 = icmp eq i64 %8, 190
  br i1 %.not21, label %23, label %20

20:                                               ; preds = %15
  %21 = trunc nuw nsw i64 %8 to i32
  %22 = sub nuw nsw i32 190, %21
  call void @softfloat_shiftRightJamM(i8 noundef zeroext 3, ptr noundef nonnull %4, i32 noundef %22, ptr noundef nonnull %4) #3
  br label %23

23:                                               ; preds = %20, %15
  %24 = call i64 @softfloat_roundMToI64(i1 noundef zeroext %6, ptr noundef nonnull %4, i8 noundef zeroext %1, i1 noundef zeroext %2) #3
  br label %25

25:                                               ; preds = %23, %11
  %.0 = phi i64 [ %spec.select, %11 ], [ %24, %23 ]
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %4) #3
  ret i64 %.0
}

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

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

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

declare i64 @softfloat_roundMToI64(i1 noundef zeroext, ptr noundef, i8 noundef zeroext, i1 noundef zeroext) 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 = { 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"}


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