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

; 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 void @softfloat_shortShiftRightM(i8 noundef zeroext %0, ptr noundef %1, i8 noundef zeroext %2, ptr noundef %3) #0 {
  %5 = alloca i8, align 1
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca ptr, align 8
  %9 = alloca i8, align 1
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store i8 %0, ptr %5, align 1, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !8
  store i8 %2, ptr %7, align 1, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  %14 = load i8, ptr %7, align 1, !tbaa !5
  %15 = zext i8 %14 to i32
  %16 = sub nsw i32 0, %15
  %17 = trunc i32 %16 to i8
  store i8 %17, ptr %9, align 1, !tbaa !5
  store i32 0, ptr %10, align 4, !tbaa !10
  %18 = load i8, ptr %5, align 1, !tbaa !5
  %19 = zext i8 %18 to i32
  %20 = sub nsw i32 %19, 1
  store i32 %20, ptr %11, align 4, !tbaa !10
  %21 = load ptr, ptr %6, align 8, !tbaa !8
  %22 = load i32, ptr %10, align 4, !tbaa !10
  %23 = zext i32 %22 to i64
  %24 = getelementptr inbounds i32, ptr %21, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !10
  %26 = load i8, ptr %7, align 1, !tbaa !5
  %27 = zext i8 %26 to i32
  %28 = lshr i32 %25, %27
  store i32 %28, ptr %12, align 4, !tbaa !10
  br label %29

29:                                               ; preds = %33, %4
  %30 = load i32, ptr %10, align 4, !tbaa !10
  %31 = load i32, ptr %11, align 4, !tbaa !10
  %32 = icmp ne i32 %30, %31
  br i1 %32, label %33, label %57

33:                                               ; preds = %29
  %34 = load ptr, ptr %6, align 8, !tbaa !8
  %35 = load i32, ptr %10, align 4, !tbaa !10
  %36 = add i32 %35, 1
  %37 = zext i32 %36 to i64
  %38 = getelementptr inbounds i32, ptr %34, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !10
  store i32 %39, ptr %13, align 4, !tbaa !10
  %40 = load i32, ptr %13, align 4, !tbaa !10
  %41 = load i8, ptr %9, align 1, !tbaa !5
  %42 = zext i8 %41 to i32
  %43 = and i32 %42, 31
  %44 = shl i32 %40, %43
  %45 = load i32, ptr %12, align 4, !tbaa !10
  %46 = or i32 %44, %45
  %47 = load ptr, ptr %8, align 8, !tbaa !8
  %48 = load i32, ptr %10, align 4, !tbaa !10
  %49 = zext i32 %48 to i64
  %50 = getelementptr inbounds i32, ptr %47, i64 %49
  store i32 %46, ptr %50, align 4, !tbaa !10
  %51 = load i32, ptr %10, align 4, !tbaa !10
  %52 = add i32 %51, 1
  store i32 %52, ptr %10, align 4, !tbaa !10
  %53 = load i32, ptr %13, align 4, !tbaa !10
  %54 = load i8, ptr %7, align 1, !tbaa !5
  %55 = zext i8 %54 to i32
  %56 = lshr i32 %53, %55
  store i32 %56, ptr %12, align 4, !tbaa !10
  br label %29, !llvm.loop !12

57:                                               ; preds = %29
  %58 = load i32, ptr %12, align 4, !tbaa !10
  %59 = load ptr, ptr %8, align 8, !tbaa !8
  %60 = load i32, ptr %10, align 4, !tbaa !10
  %61 = zext i32 %60 to i64
  %62 = getelementptr inbounds i32, ptr %59, i64 %61
  store i32 %58, ptr %62, align 4, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #2
  ret void
}

; 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 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 = { 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 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !6, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; 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: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @softfloat_shortShiftRightM(i8 noundef zeroext %0, ptr nocapture noundef readonly %1, i8 noundef zeroext %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #0 {
  %5 = zext nneg i8 %2 to i32
  %6 = zext i8 %0 to i32
  %7 = add nsw i32 %6, -1
  %8 = load i32, ptr %1, align 4, !tbaa !5
  %.01920 = lshr i32 %8, %5
  %.not21 = icmp eq i32 %7, 0
  br i1 %.not21, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4
  %9 = sub i8 0, %2
  %10 = and i8 %9, 31
  %11 = zext nneg i8 %10 to i32
  %12 = zext i32 %7 to i64
  %xtraiter = and i64 %12, 1
  %13 = icmp eq i32 %7, 1
  br i1 %13, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %12, 4294967294
  br label %14

14:                                               ; preds = %14, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.1, %14 ]
  %.01923 = phi i32 [ %.01920, %.lr.ph.new ], [ %.019.1, %14 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %14 ]
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %15 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv.next
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = shl i32 %16, %11
  %18 = or i32 %17, %.01923
  %19 = getelementptr inbounds i32, ptr %3, i64 %indvars.iv
  store i32 %18, ptr %19, align 4, !tbaa !5
  %.019 = lshr i32 %16, %5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %20 = getelementptr inbounds i32, ptr %1, i64 %indvars.iv.next.1
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = shl i32 %21, %11
  %23 = or i32 %22, %.019
  %24 = getelementptr inbounds i32, ptr %3, i64 %indvars.iv.next
  store i32 %23, ptr %24, align 4, !tbaa !5
  %.019.1 = lshr i32 %21, %5
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %14, !llvm.loop !9

._crit_edge.loopexit.unr-lcssa:                   ; preds = %14, %.lr.ph
  %.019.lcssa29.ph = phi i32 [ poison, %.lr.ph ], [ %.019.1, %14 ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.1, %14 ]
  %.01923.unr = phi i32 [ %.01920, %.lr.ph ], [ %.019.1, %14 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge.loopexit, label %._crit_edge.loopexit.epilog-lcssa

._crit_edge.loopexit.epilog-lcssa:                ; preds = %._crit_edge.loopexit.unr-lcssa
  %25 = getelementptr i32, ptr %1, i64 %indvars.iv.unr
  %26 = getelementptr i8, ptr %25, i64 4
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = shl i32 %27, %11
  %29 = or i32 %28, %.01923.unr
  %30 = getelementptr inbounds i32, ptr %3, i64 %indvars.iv.unr
  store i32 %29, ptr %30, align 4, !tbaa !5
  %.019.epil = lshr i32 %27, %5
  br label %._crit_edge.loopexit

._crit_edge.loopexit:                             ; preds = %._crit_edge.loopexit.unr-lcssa, %._crit_edge.loopexit.epilog-lcssa
  %.019.lcssa29 = phi i32 [ %.019.lcssa29.ph, %._crit_edge.loopexit.unr-lcssa ], [ %.019.epil, %._crit_edge.loopexit.epilog-lcssa ]
  %31 = zext i32 %7 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %4, %._crit_edge.loopexit
  %.0.lcssa = phi i64 [ %31, %._crit_edge.loopexit ], [ 0, %4 ]
  %.019.lcssa = phi i32 [ %.019.lcssa29, %._crit_edge.loopexit ], [ %.01920, %4 ]
  %32 = getelementptr inbounds i32, ptr %3, i64 %.0.lcssa
  store i32 %.019.lcssa, ptr %32, align 4, !tbaa !5
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: readwrite) 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" }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass