; LLVM IR from gem5/gem5 :: ext/systemc/src/sysc/datatypes/int/sc_nbutils.ll (ZN5sc_dt13vec_div_smallEiPKjjPj)

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN5sc_dt8low_halfEj(i32 noundef) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN5sc_dt9high_halfEj(i32 noundef) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN5sc_dt6concatEjj(i32 noundef, i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5sc_dt13vec_div_smallEiPKjjPj(i32 noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) #2 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %13 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %13, ptr %10, align 8, !tbaa !9
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = load ptr, ptr %6, align 8, !tbaa !9
  %16 = sext i32 %14 to i64
  %17 = getelementptr inbounds i32, ptr %15, i64 %16
  store ptr %17, ptr %6, align 8, !tbaa !9
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = load ptr, ptr %8, align 8, !tbaa !9
  %20 = sext i32 %18 to i64
  %21 = getelementptr inbounds i32, ptr %19, i64 %20
  store ptr %21, ptr %8, align 8, !tbaa !9
  br label %22

22:                                               ; preds = %26, %4
  %23 = load ptr, ptr %10, align 8, !tbaa !9
  %24 = load ptr, ptr %6, align 8, !tbaa !9
  %25 = icmp ult ptr %23, %24
  br i1 %25, label %26, label %53

26:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %27 = load ptr, ptr %6, align 8, !tbaa !9
  %28 = getelementptr inbounds i32, ptr %27, i32 -1
  store ptr %28, ptr %6, align 8, !tbaa !9
  %29 = load i32, ptr %28, align 4, !tbaa !5
  store i32 %29, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %30 = load i32, ptr %9, align 4, !tbaa !5
  %31 = load i32, ptr %11, align 4, !tbaa !5
  %32 = call noundef i32 @_ZN5sc_dt9high_halfEj(i32 noundef %31)
  %33 = call noundef i32 @_ZN5sc_dt6concatEjj(i32 noundef %30, i32 noundef %32)
  store i32 %33, ptr %12, align 4, !tbaa !5
  %34 = load i32, ptr %12, align 4, !tbaa !5
  %35 = load i32, ptr %7, align 4, !tbaa !5
  %36 = udiv i32 %34, %35
  store i32 %36, ptr %9, align 4, !tbaa !5
  %37 = load i32, ptr %12, align 4, !tbaa !5
  %38 = load i32, ptr %7, align 4, !tbaa !5
  %39 = urem i32 %37, %38
  %40 = load i32, ptr %11, align 4, !tbaa !5
  %41 = call noundef i32 @_ZN5sc_dt8low_halfEj(i32 noundef %40)
  %42 = call noundef i32 @_ZN5sc_dt6concatEjj(i32 noundef %39, i32 noundef %41)
  store i32 %42, ptr %12, align 4, !tbaa !5
  %43 = load i32, ptr %9, align 4, !tbaa !5
  %44 = load i32, ptr %12, align 4, !tbaa !5
  %45 = load i32, ptr %7, align 4, !tbaa !5
  %46 = udiv i32 %44, %45
  %47 = call noundef i32 @_ZN5sc_dt6concatEjj(i32 noundef %43, i32 noundef %46)
  %48 = load ptr, ptr %8, align 8, !tbaa !9
  %49 = getelementptr inbounds i32, ptr %48, i32 -1
  store ptr %49, ptr %8, align 8, !tbaa !9
  store i32 %47, ptr %49, align 4, !tbaa !5
  %50 = load i32, ptr %12, align 4, !tbaa !5
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = urem i32 %50, %51
  store i32 %52, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %22, !llvm.loop !11

53:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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" }
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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !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 i32 @_ZN5sc_dt8low_halfEj(i32 noundef) local_unnamed_addr #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN5sc_dt9high_halfEj(i32 noundef) local_unnamed_addr #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN5sc_dt6concatEjj(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN5sc_dt13vec_div_smallEiPKjjPj(i32 noundef %0, ptr noundef readonly %1, i32 noundef %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #1 {
  %5 = icmp sgt i32 %0, 0
  br i1 %5, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %4
  %6 = zext nneg i32 %0 to i64
  %7 = getelementptr inbounds i32, ptr %3, i64 %6
  %8 = getelementptr inbounds i32, ptr %1, i64 %6
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.024 = phi ptr [ %9, %.lr.ph ], [ %8, %.lr.ph.preheader ]
  %.02023 = phi ptr [ %19, %.lr.ph ], [ %7, %.lr.ph.preheader ]
  %.02122 = phi i32 [ %20, %.lr.ph ], [ 0, %.lr.ph.preheader ]
  %9 = getelementptr inbounds i8, ptr %.024, i64 -4
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = tail call noundef i32 @_ZN5sc_dt9high_halfEj(i32 noundef %10)
  %12 = tail call noundef i32 @_ZN5sc_dt6concatEjj(i32 noundef %.02122, i32 noundef %11)
  %13 = udiv i32 %12, %2
  %14 = urem i32 %12, %2
  %15 = tail call noundef i32 @_ZN5sc_dt8low_halfEj(i32 noundef %10)
  %16 = tail call noundef i32 @_ZN5sc_dt6concatEjj(i32 noundef %14, i32 noundef %15)
  %17 = udiv i32 %16, %2
  %18 = tail call noundef i32 @_ZN5sc_dt6concatEjj(i32 noundef %13, i32 noundef %17)
  %19 = getelementptr inbounds i8, ptr %.02023, i64 -4
  store i32 %18, ptr %19, align 4, !tbaa !5
  %20 = urem i32 %16, %2
  %21 = icmp ugt ptr %9, %1
  br i1 %21, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %4
  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 = { 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" }

!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: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass