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

; 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 }
%struct.commonNaN = type { i8 }
%struct.exp16_sig64 = type { i64, i64 }

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

32:                                               ; preds = %2
  %33 = load i64, ptr %10, align 8, !tbaa !10
  %34 = icmp ne i64 %33, 0
  br i1 %34, label %35, label %42

35:                                               ; preds = %32
  %36 = load i64, ptr %7, align 8, !tbaa !10
  %37 = and i64 %36, 2251799813685248
  %38 = icmp ne i64 %37, 0
  br i1 %38, label %40, label %39

39:                                               ; preds = %35
  call void @softfloat_raiseFlags(i8 noundef zeroext 16)
  br label %40

40:                                               ; preds = %39, %35
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  call void @softfloat_commonNaNToF128M(ptr noundef %11, ptr noundef %41)
  store i32 1, ptr %14, align 4
  br label %110

42:                                               ; preds = %32
  %43 = load i8, ptr %8, align 1, !tbaa !13, !range !17, !noundef !18
  %44 = trunc i8 %43 to i1
  %45 = zext i1 %44 to i32
  %46 = shl i32 %45, 31
  %47 = add i32 %46, 2147418112
  %48 = add i32 %47, 0
  store i32 %48, ptr %12, align 4, !tbaa !15
  br label %102

49:                                               ; preds = %2
  %50 = load i64, ptr %9, align 8, !tbaa !10
  %51 = icmp ne i64 %50, 0
  br i1 %51, label %74, label %52

52:                                               ; preds = %49
  %53 = load i64, ptr %10, align 8, !tbaa !10
  %54 = icmp ne i64 %53, 0
  br i1 %54, label %62, label %55

55:                                               ; preds = %52
  %56 = load i8, ptr %8, align 1, !tbaa !13, !range !17, !noundef !18
  %57 = trunc i8 %56 to i1
  %58 = zext i1 %57 to i32
  %59 = shl i32 %58, 31
  %60 = add i32 %59, 0
  %61 = add i32 %60, 0
  store i32 %61, ptr %12, align 4, !tbaa !15
  br label %102

62:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 16, ptr %15) #5
  %63 = load i64, ptr %10, align 8, !tbaa !10
  %64 = call { i64, i64 } @softfloat_normSubnormalF64Sig(i64 noundef %63)
  %65 = getelementptr inbounds { i64, i64 }, ptr %15, i32 0, i32 0
  %66 = extractvalue { i64, i64 } %64, 0
  store i64 %66, ptr %65, align 8
  %67 = getelementptr inbounds { i64, i64 }, ptr %15, i32 0, i32 1
  %68 = extractvalue { i64, i64 } %64, 1
  store i64 %68, ptr %67, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %13, ptr align 8 %15, i64 16, i1 false), !tbaa.struct !19
  call void @llvm.lifetime.end.p0(i64 16, ptr %15) #5
  %69 = getelementptr inbounds %struct.exp16_sig64, ptr %13, i32 0, i32 0
  %70 = load i64, ptr %69, align 8, !tbaa !20
  %71 = sub nsw i64 %70, 1
  store i64 %71, ptr %9, align 8, !tbaa !10
  %72 = getelementptr inbounds %struct.exp16_sig64, ptr %13, i32 0, i32 1
  %73 = load i64, ptr %72, align 8, !tbaa !22
  store i64 %73, ptr %10, align 8, !tbaa !10
  br label %74

74:                                               ; preds = %62, %49
  %75 = load i64, ptr %10, align 8, !tbaa !10
  %76 = trunc i64 %75 to i32
  %77 = shl i32 %76, 28
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = getelementptr inbounds i32, ptr %78, i64 1
  store i32 %77, ptr %79, align 4, !tbaa !15
  %80 = load i64, ptr %10, align 8, !tbaa !10
  %81 = lshr i64 %80, 4
  store i64 %81, ptr %10, align 8, !tbaa !10
  %82 = load i8, ptr %8, align 1, !tbaa !13, !range !17, !noundef !18
  %83 = trunc i8 %82 to i1
  %84 = zext i1 %83 to i32
  %85 = shl i32 %84, 31
  %86 = load i64, ptr %9, align 8, !tbaa !10
  %87 = add nsw i64 %86, 15360
  %88 = trunc i64 %87 to i32
  %89 = shl i32 %88, 16
  %90 = add i32 %85, %89
  %91 = zext i32 %90 to i64
  %92 = load i64, ptr %10, align 8, !tbaa !10
  %93 = lshr i64 %92, 32
  %94 = add i64 %91, %93
  %95 = trunc i64 %94 to i32
  %96 = load ptr, ptr %5, align 8, !tbaa !5
  %97 = getelementptr inbounds i32, ptr %96, i64 3
  store i32 %95, ptr %97, align 4, !tbaa !15
  %98 = load i64, ptr %10, align 8, !tbaa !10
  %99 = trunc i64 %98 to i32
  %100 = load ptr, ptr %5, align 8, !tbaa !5
  %101 = getelementptr inbounds i32, ptr %100, i64 2
  store i32 %99, ptr %101, align 4, !tbaa !15
  store i32 1, ptr %14, align 4
  br label %110

102:                                              ; preds = %55, %42
  %103 = load i32, ptr %12, align 4, !tbaa !15
  %104 = load ptr, ptr %5, align 8, !tbaa !5
  %105 = getelementptr inbounds i32, ptr %104, i64 3
  store i32 %103, ptr %105, align 4, !tbaa !15
  %106 = load ptr, ptr %5, align 8, !tbaa !5
  %107 = getelementptr inbounds i32, ptr %106, i64 2
  store i32 0, ptr %107, align 4, !tbaa !15
  %108 = load ptr, ptr %5, align 8, !tbaa !5
  %109 = getelementptr inbounds i32, ptr %108, i64 1
  store i32 0, ptr %109, align 4, !tbaa !15
  store i32 0, ptr %14, align 4
  br label %110

110:                                              ; preds = %102, %74, %40
  call void @llvm.lifetime.end.p0(i64 16, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  %111 = load i32, ptr %14, align 4
  switch i32 %111, label %113 [
    i32 0, label %112
    i32 1, label %112
  ]

112:                                              ; preds = %110, %110
  ret void

113:                                              ; preds = %110
  unreachable
}

; 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_raiseFlags(i8 noundef zeroext) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @softfloat_commonNaNToF128M(ptr noundef, ptr noundef) #4

declare { i64, i64 } @softfloat_normSubnormalF64Sig(i64 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 = { 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 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{i64 0, i64 8, !10}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"int", !7, i64 0}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{i64 0, i64 8, !10, i64 8, i64 8, !10}
!20 = !{!21, !11, i64 0}
!21 = !{!"exp16_sig64", !11, i64 0, !11, i64 8}
!22 = !{!21, !11, i64 8}


; 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"

%struct.commonNaN = type { i8 }

; Function Attrs: nounwind uwtable
define dso_local void @f64_to_f128M(i64 %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca %struct.commonNaN, align 1
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #4
  %4 = lshr i64 %0, 52
  %5 = and i64 %4, 2047
  %6 = and i64 %0, 4503599627370495
  store i32 0, ptr %1, align 4, !tbaa !5
  switch i64 %5, label %22 [
    i64 2047, label %7
    i64 0, label %14
  ]

7:                                                ; preds = %2
  %.not37 = icmp eq i64 %6, 0
  br i1 %.not37, label %12, label %8

8:                                                ; preds = %7
  %9 = and i64 %0, 2251799813685248
  %.not40 = icmp eq i64 %9, 0
  br i1 %.not40, label %10, label %11

10:                                               ; preds = %8
  tail call void @softfloat_raiseFlags(i8 noundef zeroext 16) #4
  br label %11

11:                                               ; preds = %10, %8
  call void @softfloat_commonNaNToF128M(ptr noundef nonnull %3, ptr noundef nonnull %1)
  br label %41

12:                                               ; preds = %7
  %sh.diff38 = lshr exact i64 %0, 32
  %tr.sh.diff39 = trunc nuw i64 %sh.diff38 to i32
  %13 = or i32 %tr.sh.diff39, 2147418112
  br label %37

14:                                               ; preds = %2
  %.not34 = icmp eq i64 %6, 0
  br i1 %.not34, label %15, label %17

15:                                               ; preds = %14
  %sh.diff = lshr exact i64 %0, 32
  %tr.sh.diff = trunc nuw i64 %sh.diff to i32
  %16 = and i32 %tr.sh.diff, -2147483648
  br label %37

17:                                               ; preds = %14
  %18 = tail call { i64, i64 } @softfloat_normSubnormalF64Sig(i64 noundef %6) #4
  %19 = extractvalue { i64, i64 } %18, 0
  %20 = extractvalue { i64, i64 } %18, 1
  %21 = add nsw i64 %19, -1
  br label %22

22:                                               ; preds = %2, %17
  %.030 = phi i64 [ %20, %17 ], [ %6, %2 ]
  %.0 = phi i64 [ %21, %17 ], [ %5, %2 ]
  %23 = trunc i64 %.030 to i32
  %24 = shl i32 %23, 28
  %25 = getelementptr inbounds i8, ptr %1, i64 4
  store i32 %24, ptr %25, align 4, !tbaa !5
  %26 = lshr i64 %.030, 4
  %sh.diff35 = lshr i64 %0, 32
  %27 = and i64 %sh.diff35, 2147483648
  %28 = shl i64 %.0, 16
  %29 = lshr i64 %.030, 36
  %30 = or disjoint i64 %27, 1006632960
  %31 = add nuw nsw i64 %30, %29
  %32 = add i64 %31, %28
  %33 = trunc i64 %32 to i32
  %34 = getelementptr inbounds i8, ptr %1, i64 12
  store i32 %33, ptr %34, align 4, !tbaa !5
  %35 = trunc i64 %26 to i32
  %36 = getelementptr inbounds i8, ptr %1, i64 8
  store i32 %35, ptr %36, align 4, !tbaa !5
  br label %41

37:                                               ; preds = %15, %12
  %.031 = phi i32 [ %13, %12 ], [ %16, %15 ]
  %38 = getelementptr inbounds i8, ptr %1, i64 12
  store i32 %.031, ptr %38, align 4, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %1, i64 8
  store i32 0, ptr %39, align 4, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %1, i64 4
  store i32 0, ptr %40, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %37, %22, %11
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #4
  ret void
}

; 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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @softfloat_commonNaNToF128M(ptr noundef, ptr noundef) local_unnamed_addr #3

declare { i64, i64 } @softfloat_normSubnormalF64Sig(i64 noundef) 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 = { 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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