; LLVM IR from gem5/gem5 :: ext/softfloat (extF80M_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.extFloat80M = type { i64, i16 }

; Function Attrs: nounwind uwtable
define dso_local i64 @extF80M_to_i64(ptr noundef %0, i8 noundef zeroext %1, i1 noundef zeroext %2) #0 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca i8, align 1
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i8, align 1
  %11 = alloca i32, align 4
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  %14 = alloca [3 x i32], align 4
  %15 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i8 %1, ptr %6, align 1, !tbaa !9
  %16 = zext i1 %2 to i8
  store i8 %16, ptr %7, align 1, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 12, ptr %14) #3
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %17, ptr %8, align 8, !tbaa !5
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.extFloat80M, ptr %18, i32 0, i32 1
  %20 = load i16, ptr %19, align 8, !tbaa !12
  %21 = zext i16 %20 to i64
  store i64 %21, ptr %9, align 8, !tbaa !16
  %22 = load i64, ptr %9, align 8, !tbaa !16
  %23 = trunc i64 %22 to i16
  %24 = zext i16 %23 to i32
  %25 = ashr i32 %24, 15
  %26 = icmp ne i32 %25, 0
  %27 = zext i1 %26 to i8
  store i8 %27, ptr %10, align 1, !tbaa !10
  %28 = load i64, ptr %9, align 8, !tbaa !16
  %29 = and i64 %28, 32767
  %30 = trunc i64 %29 to i32
  store i32 %30, ptr %11, align 4, !tbaa !17
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.extFloat80M, ptr %31, i32 0, i32 0
  %33 = load i64, ptr %32, align 8, !tbaa !19
  store i64 %33, ptr %12, align 8, !tbaa !16
  %34 = load i32, ptr %11, align 4, !tbaa !17
  %35 = sub nsw i32 16446, %34
  store i32 %35, ptr %13, align 4, !tbaa !17
  %36 = load i32, ptr %13, align 4, !tbaa !17
  %37 = icmp slt i32 %36, 0
  br i1 %37, label %38, label %53

38:                                               ; preds = %3
  call void @softfloat_raiseFlags(i8 noundef zeroext 16)
  %39 = load i32, ptr %11, align 4, !tbaa !17
  %40 = icmp eq i32 %39, 32767
  br i1 %40, label %41, label %46

41:                                               ; preds = %38
  %42 = load i64, ptr %12, align 8, !tbaa !16
  %43 = and i64 %42, 9223372036854775807
  %44 = icmp ne i64 %43, 0
  br i1 %44, label %45, label %46

45:                                               ; preds = %41
  br label %51

46:                                               ; preds = %41, %38
  %47 = load i8, ptr %10, align 1, !tbaa !10, !range !20, !noundef !21
  %48 = trunc i8 %47 to i1
  %49 = zext i1 %48 to i64
  %50 = select i1 %48, i64 -9223372036854775808, i64 9223372036854775807
  br label %51

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

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

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

68:                                               ; preds = %64, %53
  %69 = load i8, ptr %10, align 1, !tbaa !10, !range !20, !noundef !21
  %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 !9
  %73 = load i8, ptr %7, align 1, !tbaa !10, !range !20, !noundef !21
  %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, %51
  call void @llvm.lifetime.end.p0(i64 12, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %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

declare void @softfloat_raiseFlags(i8 noundef zeroext) #2

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

declare i64 @softfloat_roundMToI64(i1 noundef zeroext, ptr noundef, i8 noundef zeroext, i1 noundef zeroext) #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 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"_Bool", !7, i64 0}
!12 = !{!13, !15, i64 8}
!13 = !{!"extFloat80M", !14, i64 0, !15, i64 8}
!14 = !{!"long", !7, i64 0}
!15 = !{!"short", !7, i64 0}
!16 = !{!14, !14, i64 0}
!17 = !{!18, !18, i64 0}
!18 = !{!"int", !7, i64 0}
!19 = !{!13, !14, i64 0}
!20 = !{i8 0, i8 2}
!21 = !{}


; 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 @extF80M_to_i64(ptr nocapture noundef readonly %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 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i16, ptr %5, align 8, !tbaa !5
  %7 = icmp slt i16 %6, 0
  %8 = and i16 %6, 32767
  %9 = zext nneg i16 %8 to i32
  %10 = load i64, ptr %0, align 8, !tbaa !11
  %11 = sub nsw i32 16446, %9
  %12 = icmp ugt i16 %8, 16446
  br i1 %12, label %13, label %18

13:                                               ; preds = %3
  tail call void @softfloat_raiseFlags(i8 noundef zeroext 16) #3
  %14 = icmp ne i16 %8, 32767
  %15 = and i64 %10, 9223372036854775807
  %.not18 = icmp eq i64 %15, 0
  %or.cond = select i1 %14, i1 true, i1 %.not18
  %16 = and i1 %7, %or.cond
  %17 = select i1 %16, i64 -9223372036854775808, i64 9223372036854775807
  br label %27

18:                                               ; preds = %3
  %19 = lshr i64 %10, 32
  %20 = trunc nuw i64 %19 to i32
  %21 = getelementptr inbounds i8, ptr %4, i64 8
  store i32 %20, ptr %21, align 4, !tbaa !12
  %22 = trunc i64 %10 to i32
  %23 = getelementptr inbounds i8, ptr %4, i64 4
  store i32 %22, ptr %23, align 4, !tbaa !12
  store i32 0, ptr %4, align 4, !tbaa !12
  %.not = icmp eq i16 %8, 16446
  br i1 %.not, label %25, label %24

24:                                               ; preds = %18
  call void @softfloat_shiftRightJamM(i8 noundef zeroext 3, ptr noundef nonnull %4, i32 noundef %11, ptr noundef nonnull %4) #3
  br label %25

25:                                               ; preds = %24, %18
  %26 = call i64 @softfloat_roundMToI64(i1 noundef zeroext %7, ptr noundef nonnull %4, i8 noundef zeroext %1, i1 noundef zeroext %2) #3
  br label %27

27:                                               ; preds = %25, %13
  %.0 = phi i64 [ %17, %13 ], [ %26, %25 ]
  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, !10, i64 8}
!6 = !{!"extFloat80M", !7, i64 0, !10, i64 8}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !8, i64 0}


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