; LLVM IR from gem5/gem5 :: ext/systemc/src/sysc/datatypes/fx/scfx_rep.ll (ZN5sc_dt8scfx_rep11shift_rightEi)

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

%"class.sc_dt::scfx_rep" = type <{ %"class.sc_dt::scfx_mant", i32, i32, i32, i32, i32, i8, [3 x i8] }>
%"class.sc_dt::scfx_mant" = type <{ ptr, i32, [4 x i8] }>

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZN5sc_dt9scfx_mantixEi(ptr noundef nonnull align 8 dereferenceable(12), i32 noundef) #0 align 2

; 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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZNK5sc_dt8scfx_rep4sizeEv(ptr noundef nonnull align 8 dereferenceable(37)) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5sc_dt8scfx_rep11shift_rightEi(ptr noundef nonnull align 8 dereferenceable(37) %0, i32 noundef %1) #3 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %8 = load ptr, ptr %3, align 8
  %9 = load i32, ptr %4, align 4, !tbaa !9
  %10 = icmp ne i32 %9, 0
  br i1 %10, label %11, label %50

11:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %12 = load i32, ptr %4, align 4, !tbaa !9
  %13 = sub nsw i32 32, %12
  store i32 %13, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %14 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %14, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %39, %11
  %16 = load i32, ptr %7, align 4, !tbaa !9
  %17 = call noundef i32 @_ZNK5sc_dt8scfx_rep4sizeEv(ptr noundef nonnull align 8 dereferenceable(37) %8)
  %18 = sub nsw i32 %17, 1
  %19 = icmp slt i32 %16, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %42

21:                                               ; preds = %15
  %22 = getelementptr inbounds %"class.sc_dt::scfx_rep", ptr %8, i32 0, i32 0
  %23 = load i32, ptr %7, align 4, !tbaa !9
  %24 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5sc_dt9scfx_mantixEi(ptr noundef nonnull align 8 dereferenceable(12) %22, i32 noundef %23)
  %25 = load i32, ptr %24, align 4, !tbaa !9
  %26 = load i32, ptr %6, align 4, !tbaa !9
  %27 = lshr i32 %25, %26
  %28 = getelementptr inbounds %"class.sc_dt::scfx_rep", ptr %8, i32 0, i32 0
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = add nsw i32 %29, 1
  %31 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5sc_dt9scfx_mantixEi(ptr noundef nonnull align 8 dereferenceable(12) %28, i32 noundef %30)
  %32 = load i32, ptr %31, align 4, !tbaa !9
  %33 = load i32, ptr %5, align 4, !tbaa !9
  %34 = shl i32 %32, %33
  %35 = or i32 %27, %34
  %36 = getelementptr inbounds %"class.sc_dt::scfx_rep", ptr %8, i32 0, i32 0
  %37 = load i32, ptr %7, align 4, !tbaa !9
  %38 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5sc_dt9scfx_mantixEi(ptr noundef nonnull align 8 dereferenceable(12) %36, i32 noundef %37)
  store i32 %35, ptr %38, align 4, !tbaa !9
  br label %39

39:                                               ; preds = %21
  %40 = load i32, ptr %7, align 4, !tbaa !9
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %7, align 4, !tbaa !9
  br label %15, !llvm.loop !11

42:                                               ; preds = %20
  %43 = load i32, ptr %6, align 4, !tbaa !9
  %44 = getelementptr inbounds %"class.sc_dt::scfx_rep", ptr %8, i32 0, i32 0
  %45 = call noundef i32 @_ZNK5sc_dt8scfx_rep4sizeEv(ptr noundef nonnull align 8 dereferenceable(37) %8)
  %46 = sub nsw i32 %45, 1
  %47 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5sc_dt9scfx_mantixEi(ptr noundef nonnull align 8 dereferenceable(12) %44, i32 noundef %46)
  %48 = load i32, ptr %47, align 4, !tbaa !9
  %49 = lshr i32 %48, %43
  store i32 %49, ptr %47, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %50

50:                                               ; preds = %42, %2
  ret void
}

attributes #0 = { inlinehint mustprogress 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 = { inlinehint mustprogress 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 #3 = { mustprogress 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZN5sc_dt9scfx_mantixEi(ptr noundef nonnull align 8 dereferenceable(12), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_ZNK5sc_dt8scfx_rep4sizeEv(ptr noundef nonnull align 8 dereferenceable(37)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5sc_dt8scfx_rep11shift_rightEi(ptr noundef nonnull align 8 dereferenceable(37) %0, i32 noundef %1) local_unnamed_addr #2 align 2 {
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %24, label %3

3:                                                ; preds = %2
  %4 = sub nsw i32 32, %1
  %5 = tail call noundef i32 @_ZNK5sc_dt8scfx_rep4sizeEv(ptr noundef nonnull align 8 dereferenceable(37) %0)
  %6 = icmp sgt i32 %5, 1
  br i1 %6, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %3
  %7 = tail call noundef i32 @_ZNK5sc_dt8scfx_rep4sizeEv(ptr noundef nonnull align 8 dereferenceable(37) %0)
  %8 = add nsw i32 %7, -1
  %9 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5sc_dt9scfx_mantixEi(ptr noundef nonnull align 8 dereferenceable(12) %0, i32 noundef %8)
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = lshr i32 %10, %1
  store i32 %11, ptr %9, align 4, !tbaa !5
  br label %24

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.012 = phi i32 [ %15, %.lr.ph ], [ 0, %3 ]
  %12 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5sc_dt9scfx_mantixEi(ptr noundef nonnull align 8 dereferenceable(12) %0, i32 noundef %.012)
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = lshr i32 %13, %1
  %15 = add nuw nsw i32 %.012, 1
  %16 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5sc_dt9scfx_mantixEi(ptr noundef nonnull align 8 dereferenceable(12) %0, i32 noundef %15)
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = shl i32 %17, %4
  %19 = or i32 %18, %14
  %20 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZN5sc_dt9scfx_mantixEi(ptr noundef nonnull align 8 dereferenceable(12) %0, i32 noundef %.012)
  store i32 %19, ptr %20, align 4, !tbaa !5
  %21 = tail call noundef i32 @_ZNK5sc_dt8scfx_rep4sizeEv(ptr noundef nonnull align 8 dereferenceable(37) %0)
  %22 = add nsw i32 %21, -1
  %23 = icmp slt i32 %15, %22
  br i1 %23, label %.lr.ph, label %._crit_edge, !llvm.loop !9

24:                                               ; preds = %._crit_edge, %2
  ret void
}

attributes #0 = { inlinehint mustprogress 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 = { inlinehint mustprogress 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 #2 = { mustprogress 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++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass