; LLVM IR from gem5/gem5 :: ext/softfloat (i64_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 @i64_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 i64, align 8
  %6 = alloca i8, align 1
  %7 = alloca %union.ui32_f32, align 4
  %8 = alloca i64, align 8
  %9 = 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 8, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %10 = load i64, ptr %3, align 8, !tbaa !5
  %11 = icmp slt i64 %10, 0
  %12 = zext i1 %11 to i8
  store i8 %12, ptr %4, align 1, !tbaa !9
  %13 = load i8, ptr %4, align 1, !tbaa !9, !range !11, !noundef !12
  %14 = trunc i8 %13 to i1
  br i1 %14, label %15, label %18

15:                                               ; preds = %1
  %16 = load i64, ptr %3, align 8, !tbaa !5
  %17 = sub i64 0, %16
  br label %20

18:                                               ; preds = %1
  %19 = load i64, ptr %3, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %18, %15
  %21 = phi i64 [ %17, %15 ], [ %19, %18 ]
  store i64 %21, ptr %5, align 8, !tbaa !5
  %22 = load i64, ptr %5, align 8, !tbaa !5
  %23 = call zeroext i8 @softfloat_countLeadingZeros64(i64 noundef %22)
  %24 = zext i8 %23 to i32
  %25 = sub nsw i32 %24, 40
  %26 = trunc i32 %25 to i8
  store i8 %26, ptr %6, align 1, !tbaa !13
  %27 = load i8, ptr %6, align 1, !tbaa !13
  %28 = sext i8 %27 to i32
  %29 = icmp sle i32 0, %28
  br i1 %29, label %30, label %54

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

33:                                               ; preds = %30
  %34 = load i8, ptr %4, align 1, !tbaa !9, !range !11, !noundef !12
  %35 = trunc i8 %34 to i1
  %36 = zext i1 %35 to i32
  %37 = shl i32 %36, 31
  %38 = load i8, ptr %6, align 1, !tbaa !13
  %39 = sext i8 %38 to i32
  %40 = sub nsw i32 149, %39
  %41 = shl i32 %40, 23
  %42 = add i32 %37, %41
  %43 = zext i32 %42 to i64
  %44 = load i64, ptr %5, align 8, !tbaa !5
  %45 = load i8, ptr %6, align 1, !tbaa !13
  %46 = sext i8 %45 to i32
  %47 = zext i32 %46 to i64
  %48 = shl i64 %44, %47
  %49 = add i64 %43, %48
  br label %51

50:                                               ; preds = %30
  br label %51

51:                                               ; preds = %50, %33
  %52 = phi i64 [ %49, %33 ], [ 0, %50 ]
  %53 = trunc i64 %52 to i32
  store i32 %53, ptr %7, align 4, !tbaa !13
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %2, ptr align 4 %7, i64 4, i1 false), !tbaa.struct !14
  store i32 1, ptr %9, align 4
  br label %86

54:                                               ; preds = %20
  %55 = load i8, ptr %6, align 1, !tbaa !13
  %56 = sext i8 %55 to i32
  %57 = add nsw i32 %56, 7
  %58 = trunc i32 %57 to i8
  store i8 %58, ptr %6, align 1, !tbaa !13
  %59 = load i8, ptr %6, align 1, !tbaa !13
  %60 = sext i8 %59 to i32
  %61 = icmp slt i32 %60, 0
  br i1 %61, label %62, label %69

62:                                               ; preds = %54
  %63 = load i64, ptr %5, align 8, !tbaa !5
  %64 = load i8, ptr %6, align 1, !tbaa !13
  %65 = sext i8 %64 to i32
  %66 = sub nsw i32 0, %65
  %67 = trunc i32 %66 to i8
  %68 = call i64 @softfloat_shortShiftRightJam64(i64 noundef %63, i8 noundef zeroext %67)
  br label %75

69:                                               ; preds = %54
  %70 = load i64, ptr %5, align 8, !tbaa !5
  %71 = load i8, ptr %6, align 1, !tbaa !13
  %72 = sext i8 %71 to i32
  %73 = zext i32 %72 to i64
  %74 = shl i64 %70, %73
  br label %75

75:                                               ; preds = %69, %62
  %76 = phi i64 [ %68, %62 ], [ %74, %69 ]
  store i64 %76, ptr %8, align 8, !tbaa !5
  %77 = load i8, ptr %4, align 1, !tbaa !9, !range !11, !noundef !12
  %78 = trunc i8 %77 to i1
  %79 = load i8, ptr %6, align 1, !tbaa !13
  %80 = sext i8 %79 to i32
  %81 = sub nsw i32 156, %80
  %82 = sext i32 %81 to i64
  %83 = load i64, ptr %8, align 8, !tbaa !5
  %84 = call i32 @softfloat_roundPackToF32(i1 noundef zeroext %78, i64 noundef %82, i64 noundef %83)
  %85 = getelementptr inbounds %struct.float32_t, ptr %2, i32 0, i32 0
  store i32 %84, ptr %85, align 4
  store i32 1, ptr %9, align 4
  br label %86

86:                                               ; preds = %75, %51
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #5
  %87 = getelementptr inbounds %struct.float32_t, ptr %2, i32 0, i32 0
  %88 = load i32, ptr %87, align 4
  ret i32 %88
}

; 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 = !{!10, !10, i64 0}
!10 = !{!"_Bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!7, !7, i64 0}
!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 @i64_to_f32(i64 noundef %0) local_unnamed_addr #0 {
  %2 = icmp slt i64 %0, 0
  %3 = tail call i64 @llvm.abs.i64(i64 %0, i1 false)
  %4 = tail call zeroext i8 @softfloat_countLeadingZeros64(i64 noundef %3) #4
  %5 = add i8 %4, -40
  %6 = sext i8 %5 to i32
  %7 = icmp sgt i8 %5, -1
  br i1 %7, label %8, label %17

8:                                                ; preds = %1
  %.not = icmp eq i64 %0, 0
  br i1 %.not, label %32, label %9

9:                                                ; preds = %8
  %sh.diff = lshr i64 %0, 32
  %tr.sh.diff = trunc nuw i64 %sh.diff to i32
  %10 = and i32 %tr.sh.diff, -2147483648
  %11 = zext nneg i32 %6 to i64
  %12 = shl i64 %3, %11
  %13 = trunc i64 %12 to i32
  %reass.sub = or disjoint i32 %10, 1249902592
  %14 = shl nuw nsw i32 %6, 23
  %15 = sub nuw nsw i32 %reass.sub, %14
  %16 = add i32 %15, %13
  br label %32

17:                                               ; preds = %1
  %18 = add nsw i8 %4, -33
  %19 = sext i8 %18 to i32
  %20 = icmp slt i8 %4, 33
  br i1 %20, label %21, label %24

21:                                               ; preds = %17
  %22 = sub nsw i8 33, %4
  %23 = tail call i64 @softfloat_shortShiftRightJam64(i64 noundef %3, i8 noundef zeroext %22)
  br label %27

24:                                               ; preds = %17
  %25 = zext nneg i32 %19 to i64
  %26 = shl i64 %3, %25
  br label %27

27:                                               ; preds = %24, %21
  %28 = phi i64 [ %23, %21 ], [ %26, %24 ]
  %29 = sub nsw i32 156, %19
  %30 = zext nneg i32 %29 to i64
  %31 = tail call i32 @softfloat_roundPackToF32(i1 noundef zeroext %2, i64 noundef %30, i64 noundef %28) #4
  br label %32

32:                                               ; preds = %9, %8, %27
  %.sroa.020.0 = phi i32 [ %31, %27 ], [ %16, %9 ], [ 0, %8 ]
  ret i32 %.sroa.020.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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.abs.i64(i64, i1 immarg) #3

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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)"}


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