; LLVM IR from gem5/gem5 :: ext/softfloat (f64_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.float64_t = type { i64 }
%union.ui64_f64 = type { i64 }

; Function Attrs: nounwind uwtable
define dso_local i64 @f64_to_i64(i64 %0, i8 noundef zeroext %1, i1 noundef zeroext %2) #0 {
  %4 = alloca i64, align 8
  %5 = alloca %struct.float64_t, align 8
  %6 = alloca i8, align 1
  %7 = alloca i8, align 1
  %8 = alloca %union.ui64_f64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i8, align 1
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca [3 x i32], align 4
  %15 = alloca i32, align 4
  %16 = getelementptr inbounds %struct.float64_t, ptr %5, i32 0, i32 0
  store i64 %0, ptr %16, align 8
  store i8 %1, ptr %6, align 1, !tbaa !5
  %17 = zext i1 %2 to i8
  store i8 %17, ptr %7, align 1, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.start.p0(i64 12, ptr %14) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %8, ptr align 8 %5, i64 8, i1 false), !tbaa.struct !10
  %18 = load i64, ptr %8, align 8, !tbaa !5
  store i64 %18, ptr %9, align 8, !tbaa !11
  %19 = load i64, ptr %9, align 8, !tbaa !11
  %20 = lshr i64 %19, 63
  %21 = icmp ne i64 %20, 0
  %22 = zext i1 %21 to i8
  store i8 %22, ptr %10, align 1, !tbaa !8
  %23 = load i64, ptr %9, align 8, !tbaa !11
  %24 = lshr i64 %23, 52
  %25 = and i64 %24, 2047
  store i64 %25, ptr %11, align 8, !tbaa !11
  %26 = load i64, ptr %9, align 8, !tbaa !11
  %27 = and i64 %26, 4503599627370495
  store i64 %27, ptr %12, align 8, !tbaa !11
  %28 = load i64, ptr %11, align 8, !tbaa !11
  %29 = icmp ne i64 %28, 0
  br i1 %29, label %30, label %33

30:                                               ; preds = %3
  %31 = load i64, ptr %12, align 8, !tbaa !11
  %32 = or i64 %31, 4503599627370496
  store i64 %32, ptr %12, align 8, !tbaa !11
  br label %33

33:                                               ; preds = %30, %3
  %34 = load i64, ptr %11, align 8, !tbaa !11
  %35 = sub nsw i64 1075, %34
  store i64 %35, ptr %13, align 8, !tbaa !11
  %36 = getelementptr inbounds [3 x i32], ptr %14, i64 0, i64 0
  store i32 0, ptr %36, align 4, !tbaa !13
  %37 = load i64, ptr %13, align 8, !tbaa !11
  %38 = icmp sle i64 %37, 0
  br i1 %38, label %39, label %55

39:                                               ; preds = %33
  %40 = load i64, ptr %13, align 8, !tbaa !11
  %41 = icmp slt i64 %40, -11
  br i1 %41, label %42, label %43

42:                                               ; preds = %39
  br label %75

43:                                               ; preds = %39
  %44 = load i64, ptr %13, align 8, !tbaa !11
  %45 = sub nsw i64 0, %44
  %46 = load i64, ptr %12, align 8, !tbaa !11
  %47 = shl i64 %46, %45
  store i64 %47, ptr %12, align 8, !tbaa !11
  %48 = load i64, ptr %12, align 8, !tbaa !11
  %49 = lshr i64 %48, 32
  %50 = trunc i64 %49 to i32
  %51 = getelementptr inbounds [3 x i32], ptr %14, i64 0, i64 2
  store i32 %50, ptr %51, align 4, !tbaa !13
  %52 = load i64, ptr %12, align 8, !tbaa !11
  %53 = trunc i64 %52 to i32
  %54 = getelementptr inbounds [3 x i32], ptr %14, i64 0, i64 1
  store i32 %53, ptr %54, align 4, !tbaa !13
  br label %67

55:                                               ; preds = %33
  %56 = load i64, ptr %12, align 8, !tbaa !11
  %57 = lshr i64 %56, 32
  %58 = trunc i64 %57 to i32
  %59 = getelementptr inbounds [3 x i32], ptr %14, i64 0, i64 2
  store i32 %58, ptr %59, align 4, !tbaa !13
  %60 = load i64, ptr %12, align 8, !tbaa !11
  %61 = trunc i64 %60 to i32
  %62 = getelementptr inbounds [3 x i32], ptr %14, i64 0, i64 1
  store i32 %61, ptr %62, align 4, !tbaa !13
  %63 = getelementptr inbounds [3 x i32], ptr %14, i64 0, i64 0
  %64 = load i64, ptr %13, align 8, !tbaa !11
  %65 = trunc i64 %64 to i32
  %66 = getelementptr inbounds [3 x i32], ptr %14, i64 0, i64 0
  call void @softfloat_shiftRightJamM(i8 noundef zeroext 3, ptr noundef %63, i32 noundef %65, ptr noundef %66)
  br label %67

67:                                               ; preds = %55, %43
  %68 = load i8, ptr %10, align 1, !tbaa !8, !range !15, !noundef !16
  %69 = trunc i8 %68 to i1
  %70 = getelementptr inbounds [3 x i32], ptr %14, i64 0, i64 0
  %71 = load i8, ptr %6, align 1, !tbaa !5
  %72 = load i8, ptr %7, align 1, !tbaa !8, !range !15, !noundef !16
  %73 = trunc i8 %72 to i1
  %74 = call i64 @softfloat_roundMToI64(i1 noundef zeroext %69, ptr noundef %70, i8 noundef zeroext %71, i1 noundef zeroext %73)
  store i64 %74, ptr %4, align 8
  store i32 1, ptr %15, align 4
  br label %90

75:                                               ; preds = %42
  call void @softfloat_raiseFlags(i8 noundef zeroext 16)
  %76 = load i64, ptr %11, align 8, !tbaa !11
  %77 = icmp eq i64 %76, 2047
  br i1 %77, label %78, label %83

78:                                               ; preds = %75
  %79 = load i64, ptr %9, align 8, !tbaa !11
  %80 = and i64 %79, 4503599627370495
  %81 = icmp ne i64 %80, 0
  br i1 %81, label %82, label %83

82:                                               ; preds = %78
  br label %88

83:                                               ; preds = %78, %75
  %84 = load i8, ptr %10, align 1, !tbaa !8, !range !15, !noundef !16
  %85 = trunc i8 %84 to i1
  %86 = zext i1 %85 to i64
  %87 = select i1 %85, i64 -9223372036854775808, i64 9223372036854775807
  br label %88

88:                                               ; preds = %83, %82
  %89 = phi i64 [ 9223372036854775807, %82 ], [ %87, %83 ]
  store i64 %89, ptr %4, align 8
  store i32 1, ptr %15, align 4
  br label %90

90:                                               ; preds = %88, %67
  call void @llvm.lifetime.end.p0(i64 12, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %91 = load i64, ptr %4, align 8
  ret i64 %91
}

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

; 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) #2

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

declare i64 @softfloat_roundMToI64(i1 noundef zeroext, ptr noundef, i8 noundef zeroext, i1 noundef zeroext) #3

declare void @softfloat_raiseFlags(i8 noundef zeroext) #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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"_Bool", !6, i64 0}
!10 = !{i64 0, i64 8, !11}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !6, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !6, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}


; 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 @f64_to_i64(i64 %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 = icmp slt i64 %0, 0
  %6 = lshr i64 %0, 52
  %7 = and i64 %6, 2047
  %8 = and i64 %0, 4503599627370495
  %9 = or disjoint i64 %8, 4503599627370496
  %.neg = add nsw i64 %7, -1075
  store i32 0, ptr %4, align 4, !tbaa !5
  %10 = icmp ugt i64 %7, 1074
  br i1 %10, label %11, label %20

11:                                               ; preds = %3
  %12 = icmp ugt i64 %7, 1086
  br i1 %12, label %30, label %13

13:                                               ; preds = %11
  %14 = shl nuw i64 %9, %.neg
  %15 = lshr i64 %14, 32
  %16 = trunc nuw i64 %15 to i32
  %17 = getelementptr inbounds i8, ptr %4, i64 8
  store i32 %16, ptr %17, align 4, !tbaa !5
  %18 = trunc i64 %14 to i32
  %19 = getelementptr inbounds i8, ptr %4, i64 4
  store i32 %18, ptr %19, align 4, !tbaa !5
  br label %28

20:                                               ; preds = %3
  %.not = icmp eq i64 %7, 0
  %spec.select = select i1 %.not, i64 %8, i64 %9
  %21 = lshr i64 %spec.select, 32
  %22 = trunc nuw nsw i64 %21 to i32
  %23 = getelementptr inbounds i8, ptr %4, i64 8
  store i32 %22, ptr %23, align 4, !tbaa !5
  %24 = trunc i64 %spec.select to i32
  %25 = getelementptr inbounds i8, ptr %4, i64 4
  store i32 %24, ptr %25, align 4, !tbaa !5
  %26 = trunc nuw nsw i64 %7 to i32
  %27 = sub nuw nsw i32 1075, %26
  call void @softfloat_shiftRightJamM(i8 noundef zeroext 3, ptr noundef nonnull %4, i32 noundef %27, ptr noundef nonnull %4) #3
  br label %28

28:                                               ; preds = %20, %13
  %29 = call i64 @softfloat_roundMToI64(i1 noundef zeroext %5, ptr noundef nonnull %4, i8 noundef zeroext %1, i1 noundef zeroext %2) #3
  br label %34

30:                                               ; preds = %11
  tail call void @softfloat_raiseFlags(i8 noundef zeroext 16) #3
  %31 = icmp ne i64 %7, 2047
  %.not25 = icmp eq i64 %8, 0
  %or.cond = or i1 %.not25, %31
  %32 = and i1 %5, %or.cond
  %33 = select i1 %32, i64 -9223372036854775808, i64 9223372036854775807
  br label %34

34:                                               ; preds = %30, %28
  %.0 = phi i64 [ %33, %30 ], [ %29, %28 ]
  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_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

declare void @softfloat_raiseFlags(i8 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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