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

; 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.float64_t = type { i64 }
%union.ui64_f64 = type { i64 }

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

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

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

35:                                               ; preds = %28
  %36 = load i64, ptr %6, align 8, !tbaa !9
  br label %38

37:                                               ; preds = %28
  br label %38

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

49:                                               ; preds = %24, %3
  %50 = load i8, ptr %5, align 1, !tbaa !5, !range !12, !noundef !13
  %51 = trunc i8 %50 to i1
  %52 = load i64, ptr %6, align 8, !tbaa !9
  %53 = load i64, ptr %7, align 8, !tbaa !9
  %54 = load i8, ptr %8, align 1, !tbaa !11
  %55 = sext i8 %54 to i32
  %56 = zext i32 %55 to i64
  %57 = shl i64 %53, %56
  %58 = call i64 @softfloat_roundPackToF64(i1 noundef zeroext %51, i64 noundef %52, i64 noundef %57)
  %59 = getelementptr inbounds %struct.float64_t, ptr %4, i32 0, i32 0
  store i64 %58, ptr %59, align 8
  store i32 1, ptr %10, align 4
  br label %60

60:                                               ; preds = %49, %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #4
  %61 = getelementptr inbounds %struct.float64_t, ptr %4, i32 0, i32 0
  %62 = load i64, ptr %61, align 8
  ret i64 %62
}

; 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

declare i64 @softfloat_roundPackToF64(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 = { 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 8, !9}


; 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 @softfloat_normRoundPackToF64(i1 noundef zeroext %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = tail call zeroext i8 @softfloat_countLeadingZeros64(i64 noundef %2) #2
  %5 = add i8 %4, -1
  %6 = sext i8 %5 to i64
  %7 = sub nsw i64 %1, %6
  %8 = sext i8 %5 to i32
  %9 = icmp sgt i8 %5, 9
  %10 = trunc i64 %7 to i32
  %11 = icmp ult i32 %10, 2045
  %or.cond = select i1 %9, i1 %11, i1 false
  br i1 %or.cond, label %12, label %21

12:                                               ; preds = %3
  %13 = select i1 %0, i64 -9223372036854775808, i64 0
  %.not = icmp eq i64 %2, 0
  %14 = shl i64 %7, 52
  %15 = select i1 %.not, i64 0, i64 %14
  %16 = or disjoint i64 %15, %13
  %17 = add nsw i32 %8, -10
  %18 = zext nneg i32 %17 to i64
  %19 = shl i64 %2, %18
  %20 = add i64 %16, %19
  br label %25

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

25:                                               ; preds = %21, %12
  %.sroa.016.0 = phi i64 [ %20, %12 ], [ %24, %21 ]
  ret i64 %.sroa.016.0
}

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

declare i64 @softfloat_roundPackToF64(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 = { 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