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

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

31:                                               ; preds = %71, %4
  %32 = load i32, ptr %12, align 4, !tbaa !5
  %33 = icmp sge i32 %32, 0
  br i1 %33, label %35, label %34

34:                                               ; preds = %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %74

35:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %36 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %36, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  store i32 0, ptr %14, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %41, %35
  %38 = load ptr, ptr %13, align 8, !tbaa !9
  %39 = load ptr, ptr %9, align 8, !tbaa !9
  %40 = icmp ult ptr %38, %39
  br i1 %40, label %41, label %54

41:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %42 = load ptr, ptr %13, align 8, !tbaa !9
  %43 = load i32, ptr %42, align 4, !tbaa !5
  store i32 %43, ptr %15, align 4, !tbaa !5
  %44 = load i32, ptr %15, align 4, !tbaa !5
  %45 = load i32, ptr %11, align 4, !tbaa !5
  %46 = and i32 %44, %45
  %47 = shl i32 %46, 8
  %48 = load i32, ptr %14, align 4, !tbaa !5
  %49 = or i32 %47, %48
  %50 = load ptr, ptr %13, align 8, !tbaa !9
  %51 = getelementptr inbounds i32, ptr %50, i32 1
  store ptr %51, ptr %13, align 8, !tbaa !9
  store i32 %49, ptr %50, align 4, !tbaa !5
  %52 = load i32, ptr %15, align 4, !tbaa !5
  %53 = lshr i32 %52, 22
  store i32 %53, ptr %14, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  br label %37, !llvm.loop !12

54:                                               ; preds = %37
  %55 = load ptr, ptr %13, align 8, !tbaa !9
  %56 = load ptr, ptr %9, align 8, !tbaa !9
  %57 = icmp ult ptr %55, %56
  br i1 %57, label %58, label %61

58:                                               ; preds = %54
  %59 = load i32, ptr %14, align 4, !tbaa !5
  %60 = load ptr, ptr %13, align 8, !tbaa !9
  store i32 %59, ptr %60, align 4, !tbaa !5
  br label %61

61:                                               ; preds = %58, %54
  %62 = load ptr, ptr %6, align 8, !tbaa !9
  %63 = load i32, ptr %12, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds i8, ptr %62, i64 %64
  %66 = load i8, ptr %65, align 1, !tbaa !11
  %67 = zext i8 %66 to i32
  %68 = load ptr, ptr %8, align 8, !tbaa !9
  %69 = load i32, ptr %68, align 4, !tbaa !5
  %70 = or i32 %69, %67
  store i32 %70, ptr %68, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  br label %71

71:                                               ; preds = %61
  %72 = load i32, ptr %12, align 4, !tbaa !5
  %73 = add nsw i32 %72, -1
  store i32 %73, ptr %12, align 4, !tbaa !5
  br label %31, !llvm.loop !14

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 #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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


; 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: mustprogress nounwind uwtable
define dso_local void @_ZN5sc_dt13vec_from_charEiPKhiPj(i32 noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = sext i32 %2 to i64
  %6 = getelementptr inbounds i32, ptr %3, i64 %5
  %7 = tail call noundef i32 @_ZN5sc_dt12one_and_onesEi(i32 noundef 22)
  %8 = sext i32 %0 to i64
  %9 = getelementptr i8, ptr %1, i64 %8
  %10 = getelementptr i8, ptr %9, i64 -1
  %11 = load i8, ptr %10, align 1, !tbaa !5
  %12 = zext i8 %11 to i32
  store i32 %12, ptr %3, align 4, !tbaa !8
  %13 = icmp sgt i32 %0, 1
  br i1 %13, label %.preheader.lr.ph, label %._crit_edge28

.preheader.lr.ph:                                 ; preds = %4
  %14 = add nsw i32 %0, -2
  %15 = icmp sgt i32 %2, 0
  %16 = zext i32 %14 to i64
  br i1 %15, label %.preheader.us, label %.preheader.preheader

.preheader.preheader:                             ; preds = %.preheader.lr.ph
  %17 = add nuw nsw i64 %16, 1
  %min.iters.check = icmp ult i32 %14, 11
  br i1 %min.iters.check, label %.preheader.preheader40, label %vector.memcheck

.preheader.preheader40:                           ; preds = %middle.block, %vector.memcheck, %.preheader.preheader
  %indvars.iv.ph = phi i64 [ %16, %vector.memcheck ], [ %16, %.preheader.preheader ], [ %ind.end, %middle.block ]
  %.ph = phi i32 [ %12, %vector.memcheck ], [ %12, %.preheader.preheader ], [ %35, %middle.block ]
  %18 = add nsw i64 %indvars.iv.ph, 1
  %xtraiter = and i64 %18, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader.prol.loopexit, label %.preheader.prol

.preheader.prol:                                  ; preds = %.preheader.preheader40, %.preheader.prol
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %.preheader.prol ], [ %indvars.iv.ph, %.preheader.preheader40 ]
  %19 = phi i32 [ %23, %.preheader.prol ], [ %.ph, %.preheader.preheader40 ]
  %prol.iter = phi i64 [ %prol.iter.next, %.preheader.prol ], [ 0, %.preheader.preheader40 ]
  %20 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv.prol
  %21 = load i8, ptr %20, align 1, !tbaa !5
  %22 = zext i8 %21 to i32
  %23 = or i32 %19, %22
  store i32 %23, ptr %3, align 4, !tbaa !8
  %indvars.iv.next.prol = add nsw i64 %indvars.iv.prol, -1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.preheader.prol.loopexit, label %.preheader.prol, !llvm.loop !10

.preheader.prol.loopexit:                         ; preds = %.preheader.prol, %.preheader.preheader40
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %.preheader.preheader40 ], [ %indvars.iv.next.prol, %.preheader.prol ]
  %.unr = phi i32 [ %.ph, %.preheader.preheader40 ], [ %23, %.preheader.prol ]
  %24 = icmp ult i64 %indvars.iv.ph, 3
  br i1 %24, label %._crit_edge28, label %.preheader.preheader40.new

.preheader.preheader40.new:                       ; preds = %.preheader.prol.loopexit
  %invariant.gep = getelementptr i8, ptr %1, i64 -1
  %invariant.gep45 = getelementptr i8, ptr %1, i64 -2
  br label %.preheader

vector.memcheck:                                  ; preds = %.preheader.preheader
  %scevgep = getelementptr i8, ptr %3, i64 4
  %25 = getelementptr i8, ptr %1, i64 %16
  %scevgep36 = getelementptr i8, ptr %25, i64 1
  %bound0 = icmp ugt ptr %scevgep36, %3
  %bound1 = icmp ugt ptr %scevgep, %1
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %.preheader.preheader40, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %17, 8589934584
  %ind.end = sub nsw i64 %16, %n.vec
  %26 = insertelement <4 x i32> <i32 poison, i32 0, i32 0, i32 0>, i32 %12, i64 0
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <4 x i32> [ %26, %vector.ph ], [ %32, %vector.body ]
  %vec.phi37 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %33, %vector.body ]
  %offset.idx = sub i64 %16, %index
  %27 = getelementptr inbounds i8, ptr %1, i64 %offset.idx
  %28 = getelementptr inbounds i8, ptr %27, i64 -3
  %29 = getelementptr inbounds i8, ptr %27, i64 -7
  %wide.load = load <4 x i8>, ptr %28, align 1, !tbaa !5, !alias.scope !12
  %reverse = shufflevector <4 x i8> %wide.load, <4 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
  %wide.load38 = load <4 x i8>, ptr %29, align 1, !tbaa !5, !alias.scope !12
  %reverse39 = shufflevector <4 x i8> %wide.load38, <4 x i8> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
  %30 = zext <4 x i8> %reverse to <4 x i32>
  %31 = zext <4 x i8> %reverse39 to <4 x i32>
  %32 = or <4 x i32> %vec.phi, %30
  %33 = or <4 x i32> %vec.phi37, %31
  %index.next = add nuw i64 %index, 8
  %34 = icmp eq i64 %index.next, %n.vec
  br i1 %34, label %middle.block, label %vector.body, !llvm.loop !15

middle.block:                                     ; preds = %vector.body
  %bin.rdx = or <4 x i32> %33, %32
  %35 = tail call i32 @llvm.vector.reduce.or.v4i32(<4 x i32> %bin.rdx)
  store i32 %35, ptr %3, align 4, !tbaa !8
  %cmp.n = icmp eq i64 %17, %n.vec
  br i1 %cmp.n, label %._crit_edge28, label %.preheader.preheader40

.preheader.us:                                    ; preds = %.preheader.lr.ph, %._crit_edge.us
  %indvars.iv31 = phi i64 [ %indvars.iv.next32, %._crit_edge.us ], [ %16, %.preheader.lr.ph ]
  br label %36

36:                                               ; preds = %.preheader.us, %36
  %.02326.us = phi i32 [ 0, %.preheader.us ], [ %42, %36 ]
  %.02425.us = phi ptr [ %3, %.preheader.us ], [ %41, %36 ]
  %37 = load i32, ptr %.02425.us, align 4, !tbaa !8
  %38 = and i32 %37, %7
  %39 = shl i32 %38, 8
  %40 = or i32 %39, %.02326.us
  %41 = getelementptr inbounds i8, ptr %.02425.us, i64 4
  store i32 %40, ptr %.02425.us, align 4, !tbaa !8
  %42 = lshr i32 %37, 22
  %43 = icmp ult ptr %41, %6
  br i1 %43, label %36, label %._crit_edge.us, !llvm.loop !19

._crit_edge.us:                                   ; preds = %36
  %44 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv31
  %45 = load i8, ptr %44, align 1, !tbaa !5
  %46 = zext i8 %45 to i32
  %47 = load i32, ptr %3, align 4, !tbaa !8
  %48 = or i32 %47, %46
  store i32 %48, ptr %3, align 4, !tbaa !8
  %indvars.iv.next32 = add nsw i64 %indvars.iv31, -1
  %49 = icmp sgt i64 %indvars.iv31, 0
  br i1 %49, label %.preheader.us, label %._crit_edge28, !llvm.loop !20

.preheader:                                       ; preds = %.preheader, %.preheader.preheader40.new
  %indvars.iv = phi i64 [ %indvars.iv.unr, %.preheader.preheader40.new ], [ %indvars.iv.next.3, %.preheader ]
  %50 = phi i32 [ %.unr, %.preheader.preheader40.new ], [ %64, %.preheader ]
  %51 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv
  %52 = load i8, ptr %51, align 1, !tbaa !5
  %53 = zext i8 %52 to i32
  %54 = or i32 %50, %53
  store i32 %54, ptr %3, align 4, !tbaa !8
  %gep = getelementptr i8, ptr %invariant.gep, i64 %indvars.iv
  %55 = load i8, ptr %gep, align 1, !tbaa !5
  %56 = zext i8 %55 to i32
  %57 = or i32 %54, %56
  store i32 %57, ptr %3, align 4, !tbaa !8
  %gep46 = getelementptr i8, ptr %invariant.gep45, i64 %indvars.iv
  %58 = load i8, ptr %gep46, align 1, !tbaa !5
  %59 = zext i8 %58 to i32
  %60 = or i32 %57, %59
  store i32 %60, ptr %3, align 4, !tbaa !8
  %indvars.iv.next.2 = add nsw i64 %indvars.iv, -3
  %61 = getelementptr inbounds i8, ptr %1, i64 %indvars.iv.next.2
  %62 = load i8, ptr %61, align 1, !tbaa !5
  %63 = zext i8 %62 to i32
  %64 = or i32 %60, %63
  store i32 %64, ptr %3, align 4, !tbaa !8
  %indvars.iv.next.3 = add nsw i64 %indvars.iv, -4
  %.not.3 = icmp eq i64 %indvars.iv.next.2, 0
  br i1 %.not.3, label %._crit_edge28, label %.preheader, !llvm.loop !21

._crit_edge28:                                    ; preds = %.preheader.prol.loopexit, %.preheader, %._crit_edge.us, %middle.block, %4
  ret void
}

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.or.v4i32(<4 x i32>) #2

attributes #0 = { 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 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.unroll.disable"}
!12 = !{!13}
!13 = distinct !{!13, !14}
!14 = distinct !{!14, !"LVerDomain"}
!15 = distinct !{!15, !16, !17, !18}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!"llvm.loop.isvectorized", i32 1}
!18 = !{!"llvm.loop.unroll.runtime.disable"}
!19 = distinct !{!19, !16}
!20 = distinct !{!20, !16}
!21 = distinct !{!21, !16, !17}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass