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

; 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 @ui64_to_f32(i64 noundef %0) #0 {
  %2 = alloca %struct.float32_t, align 4
  %3 = alloca i64, align 8
  %4 = alloca i8, align 1
  %5 = alloca %union.ui32_f32, align 4
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  store i64 %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %8 = load i64, ptr %3, align 8, !tbaa !5
  %9 = call zeroext i8 @softfloat_countLeadingZeros64(i64 noundef %8)
  %10 = zext i8 %9 to i32
  %11 = sub nsw i32 %10, 40
  %12 = trunc i32 %11 to i8
  store i8 %12, ptr %4, align 1, !tbaa !9
  %13 = load i8, ptr %4, align 1, !tbaa !9
  %14 = sext i8 %13 to i32
  %15 = icmp sle i32 0, %14
  br i1 %15, label %16, label %36

16:                                               ; preds = %1
  %17 = load i64, ptr %3, align 8, !tbaa !5
  %18 = icmp ne i64 %17, 0
  br i1 %18, label %19, label %32

19:                                               ; preds = %16
  %20 = load i8, ptr %4, align 1, !tbaa !9
  %21 = sext i8 %20 to i32
  %22 = sub nsw i32 149, %21
  %23 = shl i32 %22, 23
  %24 = add i32 0, %23
  %25 = zext i32 %24 to i64
  %26 = load i64, ptr %3, align 8, !tbaa !5
  %27 = load i8, ptr %4, align 1, !tbaa !9
  %28 = sext i8 %27 to i32
  %29 = zext i32 %28 to i64
  %30 = shl i64 %26, %29
  %31 = add i64 %25, %30
  br label %33

32:                                               ; preds = %16
  br label %33

33:                                               ; preds = %32, %19
  %34 = phi i64 [ %31, %19 ], [ 0, %32 ]
  %35 = trunc i64 %34 to i32
  store i32 %35, ptr %5, align 4, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %2, ptr align 4 %5, i64 4, i1 false), !tbaa.struct !10
  store i32 1, ptr %7, align 4
  br label %66

36:                                               ; preds = %1
  %37 = load i8, ptr %4, align 1, !tbaa !9
  %38 = sext i8 %37 to i32
  %39 = add nsw i32 %38, 7
  %40 = trunc i32 %39 to i8
  store i8 %40, ptr %4, align 1, !tbaa !9
  %41 = load i8, ptr %4, align 1, !tbaa !9
  %42 = sext i8 %41 to i32
  %43 = icmp slt i32 %42, 0
  br i1 %43, label %44, label %51

44:                                               ; preds = %36
  %45 = load i64, ptr %3, align 8, !tbaa !5
  %46 = load i8, ptr %4, align 1, !tbaa !9
  %47 = sext i8 %46 to i32
  %48 = sub nsw i32 0, %47
  %49 = trunc i32 %48 to i8
  %50 = call i64 @softfloat_shortShiftRightJam64(i64 noundef %45, i8 noundef zeroext %49)
  br label %57

51:                                               ; preds = %36
  %52 = load i64, ptr %3, align 8, !tbaa !5
  %53 = load i8, ptr %4, align 1, !tbaa !9
  %54 = sext i8 %53 to i32
  %55 = zext i32 %54 to i64
  %56 = shl i64 %52, %55
  br label %57

57:                                               ; preds = %51, %44
  %58 = phi i64 [ %50, %44 ], [ %56, %51 ]
  store i64 %58, ptr %6, align 8, !tbaa !5
  %59 = load i8, ptr %4, align 1, !tbaa !9
  %60 = sext i8 %59 to i32
  %61 = sub nsw i32 156, %60
  %62 = sext i32 %61 to i64
  %63 = load i64, ptr %6, align 8, !tbaa !5
  %64 = call i32 @softfloat_roundPackToF32(i1 noundef zeroext false, i64 noundef %62, i64 noundef %63)
  %65 = getelementptr inbounds %struct.float32_t, ptr %2, i32 0, i32 0
  store i32 %64, ptr %65, align 4
  store i32 1, ptr %7, align 4
  br label %66

66:                                               ; preds = %57, %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #5
  %67 = getelementptr inbounds %struct.float32_t, ptr %2, i32 0, i32 0
  %68 = load i32, ptr %67, align 4
  ret i32 %68
}

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

declare zeroext i8 @softfloat_countLeadingZeros64(i64 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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @softfloat_shortShiftRightJam64(i64 noundef, i8 noundef zeroext) #4

declare i32 @softfloat_roundPackToF32(i1 noundef zeroext, i64 noundef, i64 noundef) #2

; 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 = { "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 = { 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 #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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{i64 0, i64 4, !11}
!11 = !{!12, !12, i64 0}
!12 = !{!"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 @ui64_to_f32(i64 noundef %0) local_unnamed_addr #0 {
  %2 = tail call zeroext i8 @softfloat_countLeadingZeros64(i64 noundef %0) #3
  %3 = add i8 %2, -40
  %4 = icmp sgt i8 %3, -1
  br i1 %4, label %5, label %13

5:                                                ; preds = %1
  %6 = zext nneg i8 %3 to i32
  %.not = icmp eq i64 %0, 0
  %7 = zext nneg i8 %3 to i64
  %8 = shl i64 %0, %7
  %9 = trunc i64 %8 to i32
  %10 = shl nuw nsw i32 %6, 23
  %reass.sub19 = sub i32 %9, %10
  %11 = add i32 %reass.sub19, 1249902592
  %12 = select i1 %.not, i32 0, i32 %11
  br label %28

13:                                               ; preds = %1
  %14 = add nsw i8 %2, -33
  %15 = sext i8 %14 to i32
  %16 = icmp slt i8 %2, 33
  br i1 %16, label %17, label %20

17:                                               ; preds = %13
  %18 = sub nsw i8 33, %2
  %19 = tail call i64 @softfloat_shortShiftRightJam64(i64 noundef %0, i8 noundef zeroext %18)
  br label %23

20:                                               ; preds = %13
  %21 = zext nneg i32 %15 to i64
  %22 = shl i64 %0, %21
  br label %23

23:                                               ; preds = %20, %17
  %24 = phi i64 [ %19, %17 ], [ %22, %20 ]
  %25 = sub nsw i32 156, %15
  %26 = zext nneg i32 %25 to i64
  %27 = tail call i32 @softfloat_roundPackToF32(i1 noundef zeroext false, i64 noundef %26, i64 noundef %24) #3
  br label %28

28:                                               ; preds = %23, %5
  %.sroa.014.0 = phi i32 [ %12, %5 ], [ %27, %23 ]
  ret i32 %.sroa.014.0
}

declare zeroext i8 @softfloat_countLeadingZeros64(i64 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @softfloat_shortShiftRightJam64(i64 noundef, i8 noundef zeroext) local_unnamed_addr #2

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