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

; 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.extFloat80M = type { i64, i16 }

; Function Attrs: nounwind uwtable
define dso_local void @softfloat_normRoundPackMToExtF80M(i1 noundef zeroext %0, i32 noundef %1, ptr noundef %2, i8 noundef zeroext %3, ptr noundef %4) #0 {
  %6 = alloca i8, align 1
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i8, align 1
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = zext i1 %0 to i8
  store i8 %14, ptr %6, align 1, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !11
  store i8 %3, ptr %9, align 1, !tbaa !13
  store ptr %4, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i64 0, ptr %11, align 8, !tbaa !14
  %15 = load ptr, ptr %8, align 8, !tbaa !11
  %16 = getelementptr inbounds i32, ptr %15, i64 2
  %17 = load i32, ptr %16, align 4, !tbaa !9
  store i32 %17, ptr %12, align 4, !tbaa !9
  %18 = load i32, ptr %12, align 4, !tbaa !9
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %45, label %20

20:                                               ; preds = %5
  store i64 32, ptr %11, align 8, !tbaa !14
  %21 = load ptr, ptr %8, align 8, !tbaa !11
  %22 = getelementptr inbounds i32, ptr %21, i64 1
  %23 = load i32, ptr %22, align 4, !tbaa !9
  store i32 %23, ptr %12, align 4, !tbaa !9
  %24 = load i32, ptr %12, align 4, !tbaa !9
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %44, label %26

26:                                               ; preds = %20
  store i64 64, ptr %11, align 8, !tbaa !14
  %27 = load ptr, ptr %8, align 8, !tbaa !11
  %28 = getelementptr inbounds i32, ptr %27, i64 0
  %29 = load i32, ptr %28, align 4, !tbaa !9
  store i32 %29, ptr %12, align 4, !tbaa !9
  %30 = load i32, ptr %12, align 4, !tbaa !9
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %43, label %32

32:                                               ; preds = %26
  %33 = load i8, ptr %6, align 1, !tbaa !5, !range !16, !noundef !17
  %34 = trunc i8 %33 to i1
  %35 = zext i1 %34 to i64
  %36 = shl i64 %35, 15
  %37 = or i64 %36, 0
  %38 = trunc i64 %37 to i16
  %39 = load ptr, ptr %10, align 8, !tbaa !11
  %40 = getelementptr inbounds %struct.extFloat80M, ptr %39, i32 0, i32 1
  store i16 %38, ptr %40, align 8, !tbaa !18
  %41 = load ptr, ptr %10, align 8, !tbaa !11
  %42 = getelementptr inbounds %struct.extFloat80M, ptr %41, i32 0, i32 0
  store i64 0, ptr %42, align 8, !tbaa !21
  store i32 1, ptr %13, align 4
  br label %70

43:                                               ; preds = %26
  br label %44

44:                                               ; preds = %43, %20
  br label %45

45:                                               ; preds = %44, %5
  %46 = load i32, ptr %12, align 4, !tbaa !9
  %47 = call zeroext i8 @softfloat_countLeadingZeros32(i32 noundef %46)
  %48 = zext i8 %47 to i64
  %49 = load i64, ptr %11, align 8, !tbaa !14
  %50 = add nsw i64 %49, %48
  store i64 %50, ptr %11, align 8, !tbaa !14
  %51 = load i64, ptr %11, align 8, !tbaa !14
  %52 = icmp ne i64 %51, 0
  br i1 %52, label %53, label %63

53:                                               ; preds = %45
  %54 = load i64, ptr %11, align 8, !tbaa !14
  %55 = load i32, ptr %7, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  %57 = sub nsw i64 %56, %54
  %58 = trunc i64 %57 to i32
  store i32 %58, ptr %7, align 4, !tbaa !9
  %59 = load ptr, ptr %8, align 8, !tbaa !11
  %60 = load i64, ptr %11, align 8, !tbaa !14
  %61 = trunc i64 %60 to i32
  %62 = load ptr, ptr %8, align 8, !tbaa !11
  call void @softfloat_shiftLeftM(i8 noundef zeroext 3, ptr noundef %59, i32 noundef %61, ptr noundef %62)
  br label %63

63:                                               ; preds = %53, %45
  %64 = load i8, ptr %6, align 1, !tbaa !5, !range !16, !noundef !17
  %65 = trunc i8 %64 to i1
  %66 = load i32, ptr %7, align 4, !tbaa !9
  %67 = load ptr, ptr %8, align 8, !tbaa !11
  %68 = load i8, ptr %9, align 1, !tbaa !13
  %69 = load ptr, ptr %10, align 8, !tbaa !11
  call void @softfloat_roundPackMToExtF80M(i1 noundef zeroext %65, i32 noundef %66, ptr noundef %67, i8 noundef zeroext %68, ptr noundef %69)
  store i32 0, ptr %13, align 4
  br label %70

70:                                               ; preds = %63, %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  %71 = load i32, ptr %13, align 4
  switch i32 %71, label %73 [
    i32 0, label %72
    i32 1, label %72
  ]

72:                                               ; preds = %70, %70
  ret void

73:                                               ; preds = %70
  unreachable
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i8 @softfloat_countLeadingZeros32(i32 noundef) #2

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

declare void @softfloat_roundPackMToExtF80M(i1 noundef zeroext, i32 noundef, ptr noundef, i8 noundef zeroext, ptr noundef) #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 = { 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 = { "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 = !{!"_Bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!19, !20, i64 8}
!19 = !{!"extFloat80M", !15, i64 0, !20, i64 8}
!20 = !{!"short", !7, i64 0}
!21 = !{!19, !15, 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 void @softfloat_normRoundPackMToExtF80M(i1 noundef zeroext %0, i32 noundef %1, ptr noundef %2, i8 noundef zeroext %3, ptr noundef %4) local_unnamed_addr #0 {
  %6 = getelementptr inbounds i8, ptr %2, i64 8
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %8, label %16

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %2, i64 4
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %.not27 = icmp eq i32 %10, 0
  br i1 %.not27, label %11, label %16

11:                                               ; preds = %8
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %.not28 = icmp eq i32 %12, 0
  br i1 %.not28, label %13, label %16

13:                                               ; preds = %11
  %14 = select i1 %0, i16 -32768, i16 0
  %15 = getelementptr inbounds i8, ptr %4, i64 8
  store i16 %14, ptr %15, align 8, !tbaa !9
  store i64 0, ptr %4, align 8, !tbaa !13
  br label %24

16:                                               ; preds = %8, %11, %5
  %.021 = phi i64 [ 0, %5 ], [ 32, %8 ], [ 64, %11 ]
  %.0 = phi i32 [ %7, %5 ], [ %10, %8 ], [ %12, %11 ]
  %17 = tail call zeroext i8 @softfloat_countLeadingZeros32(i32 noundef %.0)
  %18 = zext i8 %17 to i64
  %19 = add nuw nsw i64 %.021, %18
  %.not29 = icmp eq i64 %19, 0
  br i1 %.not29, label %23, label %20

20:                                               ; preds = %16
  %21 = trunc nuw nsw i64 %19 to i32
  %22 = sub i32 %1, %21
  tail call void @softfloat_shiftLeftM(i8 noundef zeroext 3, ptr noundef nonnull %2, i32 noundef %21, ptr noundef nonnull %2) #3
  br label %23

23:                                               ; preds = %20, %16
  %.022 = phi i32 [ %22, %20 ], [ %1, %16 ]
  tail call void @softfloat_roundPackMToExtF80M(i1 noundef zeroext %0, i32 noundef %.022, ptr noundef nonnull %2, i8 noundef zeroext %3, ptr noundef %4) #3
  br label %24

24:                                               ; preds = %23, %13
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i8 @softfloat_countLeadingZeros32(i32 noundef) local_unnamed_addr #1

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

declare void @softfloat_roundPackMToExtF80M(i1 noundef zeroext, i32 noundef, ptr noundef, i8 noundef zeroext, ptr noundef) 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)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !12, i64 8}
!10 = !{!"extFloat80M", !11, i64 0, !12, i64 8}
!11 = !{!"long", !7, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!10, !11, i64 0}


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