; LLVM IR from gem5/gem5 :: ext/softfloat (f128M_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"

; Function Attrs: nounwind uwtable
define dso_local i64 @f128M_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 i32, align 4
  %10 = alloca i8, align 1
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca [4 x i32], align 16
  %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 4, 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 4, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 16, 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 i32, ptr %18, i64 3
  %20 = load i32, ptr %19, align 4, !tbaa !12
  store i32 %20, ptr %9, align 4, !tbaa !12
  %21 = load i32, ptr %9, align 4, !tbaa !12
  %22 = lshr i32 %21, 31
  %23 = icmp ne i32 %22, 0
  %24 = zext i1 %23 to i8
  store i8 %24, ptr %10, align 1, !tbaa !10
  %25 = load i32, ptr %9, align 4, !tbaa !12
  %26 = lshr i32 %25, 16
  %27 = and i32 %26, 32767
  store i32 %27, ptr %11, align 4, !tbaa !12
  %28 = load i32, ptr %9, align 4, !tbaa !12
  %29 = and i32 %28, 65535
  store i32 %29, ptr %12, align 4, !tbaa !12
  %30 = load i32, ptr %11, align 4, !tbaa !12
  %31 = sub nsw i32 16463, %30
  store i32 %31, ptr %13, align 4, !tbaa !12
  %32 = load i32, ptr %13, align 4, !tbaa !12
  %33 = icmp slt i32 %32, 17
  br i1 %33, label %34, label %61

34:                                               ; preds = %3
  call void @softfloat_raiseFlags(i8 noundef zeroext 16)
  %35 = load i32, ptr %11, align 4, !tbaa !12
  %36 = icmp eq i32 %35, 32767
  br i1 %36, label %37, label %54

37:                                               ; preds = %34
  %38 = load i32, ptr %12, align 4, !tbaa !12
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %53, label %40

40:                                               ; preds = %37
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = getelementptr inbounds i32, ptr %41, i64 2
  %43 = load i32, ptr %42, align 4, !tbaa !12
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = getelementptr inbounds i32, ptr %44, i64 1
  %46 = load i32, ptr %45, align 4, !tbaa !12
  %47 = or i32 %43, %46
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = getelementptr inbounds i32, ptr %48, i64 0
  %50 = load i32, ptr %49, align 4, !tbaa !12
  %51 = or i32 %47, %50
  %52 = icmp ne i32 %51, 0
  br i1 %52, label %53, label %54

53:                                               ; preds = %40, %37
  br label %59

54:                                               ; preds = %40, %34
  %55 = load i8, ptr %10, align 1, !tbaa !10, !range !14, !noundef !15
  %56 = trunc i8 %55 to i1
  %57 = zext i1 %56 to i64
  %58 = select i1 %56, i64 -9223372036854775808, i64 9223372036854775807
  br label %59

59:                                               ; preds = %54, %53
  %60 = phi i64 [ 9223372036854775807, %53 ], [ %58, %54 ]
  store i64 %60, ptr %4, align 8
  store i32 1, ptr %15, align 4
  br label %93

61:                                               ; preds = %3
  %62 = load i32, ptr %11, align 4, !tbaa !12
  %63 = icmp ne i32 %62, 0
  br i1 %63, label %64, label %67

64:                                               ; preds = %61
  %65 = load i32, ptr %12, align 4, !tbaa !12
  %66 = or i32 %65, 65536
  store i32 %66, ptr %12, align 4, !tbaa !12
  br label %67

67:                                               ; preds = %64, %61
  %68 = load i32, ptr %12, align 4, !tbaa !12
  %69 = getelementptr inbounds [4 x i32], ptr %14, i64 0, i64 3
  store i32 %68, ptr %69, align 4, !tbaa !12
  %70 = load ptr, ptr %8, align 8, !tbaa !5
  %71 = getelementptr inbounds i32, ptr %70, i64 2
  %72 = load i32, ptr %71, align 4, !tbaa !12
  %73 = getelementptr inbounds [4 x i32], ptr %14, i64 0, i64 2
  store i32 %72, ptr %73, align 8, !tbaa !12
  %74 = load ptr, ptr %8, align 8, !tbaa !5
  %75 = getelementptr inbounds i32, ptr %74, i64 1
  %76 = load i32, ptr %75, align 4, !tbaa !12
  %77 = getelementptr inbounds [4 x i32], ptr %14, i64 0, i64 1
  store i32 %76, ptr %77, align 4, !tbaa !12
  %78 = load ptr, ptr %8, align 8, !tbaa !5
  %79 = getelementptr inbounds i32, ptr %78, i64 0
  %80 = load i32, ptr %79, align 4, !tbaa !12
  %81 = getelementptr inbounds [4 x i32], ptr %14, i64 0, i64 0
  store i32 %80, ptr %81, align 16, !tbaa !12
  %82 = getelementptr inbounds [4 x i32], ptr %14, i64 0, i64 0
  %83 = load i32, ptr %13, align 4, !tbaa !12
  %84 = getelementptr inbounds [4 x i32], ptr %14, i64 0, i64 0
  call void @softfloat_shiftRightJamM(i8 noundef zeroext 4, ptr noundef %82, i32 noundef %83, ptr noundef %84)
  %85 = load i8, ptr %10, align 1, !tbaa !10, !range !14, !noundef !15
  %86 = trunc i8 %85 to i1
  %87 = getelementptr inbounds [4 x i32], ptr %14, i64 0, i64 0
  %88 = getelementptr inbounds i32, ptr %87, i64 0
  %89 = load i8, ptr %6, align 1, !tbaa !9
  %90 = load i8, ptr %7, align 1, !tbaa !10, !range !14, !noundef !15
  %91 = trunc i8 %90 to i1
  %92 = call i64 @softfloat_roundMToI64(i1 noundef zeroext %86, ptr noundef %88, i8 noundef zeroext %89, i1 noundef zeroext %91)
  store i64 %92, ptr %4, align 8
  store i32 1, ptr %15, align 4
  br label %93

93:                                               ; preds = %67, %59
  call void @llvm.lifetime.end.p0(i64 16, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, 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 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %94 = load i64, ptr %4, align 8
  ret i64 %94
}

; 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, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}


; 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 @f128M_to_i64(ptr nocapture noundef readonly %0, i8 noundef zeroext %1, i1 noundef zeroext %2) local_unnamed_addr #0 {
  %4 = alloca [4 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #3
  %5 = getelementptr inbounds i8, ptr %0, i64 12
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = icmp slt i32 %6, 0
  %8 = lshr i32 %6, 16
  %9 = and i32 %8, 32767
  %10 = and i32 %6, 65535
  %11 = icmp ugt i32 %9, 16446
  br i1 %11, label %12, label %25

12:                                               ; preds = %3
  tail call void @softfloat_raiseFlags(i8 noundef zeroext 16) #3
  %13 = icmp eq i32 %9, 32767
  br i1 %13, label %14, label %23

14:                                               ; preds = %12
  %.not25 = icmp eq i32 %10, 0
  br i1 %.not25, label %15, label %34

15:                                               ; preds = %14
  %16 = getelementptr inbounds i8, ptr %0, i64 8
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %0, i64 4
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = or i32 %19, %17
  %21 = load i32, ptr %0, align 4, !tbaa !5
  %22 = or i32 %20, %21
  %.not26 = icmp eq i32 %22, 0
  br i1 %.not26, label %23, label %34

23:                                               ; preds = %15, %12
  %24 = select i1 %7, i64 -9223372036854775808, i64 9223372036854775807
  br label %34

25:                                               ; preds = %3
  %26 = sub nuw nsw i32 16463, %9
  %.not = icmp eq i32 %9, 0
  %27 = or disjoint i32 %10, 65536
  %spec.select = select i1 %.not, i32 %10, i32 %27
  %28 = getelementptr inbounds i8, ptr %4, i64 12
  store i32 %spec.select, ptr %28, align 4, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %0, i64 8
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = getelementptr inbounds i8, ptr %4, i64 8
  store i32 %30, ptr %31, align 8, !tbaa !5
  %32 = load <2 x i32>, ptr %0, align 4, !tbaa !5
  store <2 x i32> %32, ptr %4, align 16, !tbaa !5
  call void @softfloat_shiftRightJamM(i8 noundef zeroext 4, ptr noundef nonnull %4, i32 noundef %26, ptr noundef nonnull %4) #3
  %33 = call i64 @softfloat_roundMToI64(i1 noundef zeroext %7, ptr noundef nonnull %4, i8 noundef zeroext %1, i1 noundef zeroext %2) #3
  br label %34

34:                                               ; preds = %23, %15, %14, %25
  %.0 = phi i64 [ %33, %25 ], [ %24, %23 ], [ 9223372036854775807, %15 ], [ 9223372036854775807, %14 ]
  call void @llvm.lifetime.end.p0(i64 16, 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, !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,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass