; LLVM IR from HANDS-FREE/OpenRE :: 3_OS/STM32F1/RTOS/uCOS-III2/uC-LIB (lib_mem)

; 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: nounwind uwtable
define dso_local void @Mem_Set(ptr noundef %0, i8 noundef zeroext %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i8 %1, ptr %5, align 1, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 8, 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
  store i32 0, ptr %8, align 4, !tbaa !10
  store i32 0, ptr %12, align 4, !tbaa !10
  br label %13

13:                                               ; preds = %24, %3
  %14 = load i32, ptr %12, align 4, !tbaa !10
  %15 = zext i32 %14 to i64
  %16 = icmp ult i64 %15, 4
  br i1 %16, label %17, label %27

17:                                               ; preds = %13
  %18 = load i32, ptr %8, align 4, !tbaa !10
  %19 = shl i32 %18, 8
  store i32 %19, ptr %8, align 4, !tbaa !10
  %20 = load i8, ptr %5, align 1, !tbaa !9
  %21 = zext i8 %20 to i32
  %22 = load i32, ptr %8, align 4, !tbaa !10
  %23 = or i32 %22, %21
  store i32 %23, ptr %8, align 4, !tbaa !10
  br label %24

24:                                               ; preds = %17
  %25 = load i32, ptr %12, align 4, !tbaa !10
  %26 = add i32 %25, 1
  store i32 %26, ptr %12, align 4, !tbaa !10
  br label %13, !llvm.loop !12

27:                                               ; preds = %13
  %28 = load i32, ptr %6, align 4, !tbaa !10
  store i32 %28, ptr %7, align 4, !tbaa !10
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = ptrtoint ptr %29 to i32
  %31 = zext i32 %30 to i64
  %32 = urem i64 %31, 4
  %33 = trunc i64 %32 to i8
  %34 = zext i8 %33 to i32
  store i32 %34, ptr %11, align 4, !tbaa !10
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %35, ptr %10, align 8, !tbaa !5
  %36 = load i32, ptr %11, align 4, !tbaa !10
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %60

38:                                               ; preds = %27
  %39 = load i32, ptr %11, align 4, !tbaa !10
  store i32 %39, ptr %12, align 4, !tbaa !10
  br label %40

40:                                               ; preds = %49, %38
  %41 = load i32, ptr %7, align 4, !tbaa !10
  %42 = icmp ugt i32 %41, 0
  br i1 %42, label %43, label %47

43:                                               ; preds = %40
  %44 = load i32, ptr %12, align 4, !tbaa !10
  %45 = zext i32 %44 to i64
  %46 = icmp ult i64 %45, 4
  br label %47

47:                                               ; preds = %43, %40
  %48 = phi i1 [ false, %40 ], [ %46, %43 ]
  br i1 %48, label %49, label %59

49:                                               ; preds = %47
  %50 = load i8, ptr %5, align 1, !tbaa !9
  %51 = load ptr, ptr %10, align 8, !tbaa !5
  %52 = getelementptr inbounds i8, ptr %51, i32 1
  store ptr %52, ptr %10, align 8, !tbaa !5
  store i8 %50, ptr %51, align 1, !tbaa !9
  %53 = load i32, ptr %7, align 4, !tbaa !10
  %54 = zext i32 %53 to i64
  %55 = sub i64 %54, 1
  %56 = trunc i64 %55 to i32
  store i32 %56, ptr %7, align 4, !tbaa !10
  %57 = load i32, ptr %12, align 4, !tbaa !10
  %58 = add i32 %57, 1
  store i32 %58, ptr %12, align 4, !tbaa !10
  br label %40, !llvm.loop !14

59:                                               ; preds = %47
  br label %60

60:                                               ; preds = %59, %27
  %61 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %61, ptr %9, align 8, !tbaa !5
  br label %62

62:                                               ; preds = %66, %60
  %63 = load i32, ptr %7, align 4, !tbaa !10
  %64 = zext i32 %63 to i64
  %65 = icmp uge i64 %64, 4
  br i1 %65, label %66, label %74

66:                                               ; preds = %62
  %67 = load i32, ptr %8, align 4, !tbaa !10
  %68 = load ptr, ptr %9, align 8, !tbaa !5
  %69 = getelementptr inbounds i32, ptr %68, i32 1
  store ptr %69, ptr %9, align 8, !tbaa !5
  store i32 %67, ptr %68, align 4, !tbaa !10
  %70 = load i32, ptr %7, align 4, !tbaa !10
  %71 = zext i32 %70 to i64
  %72 = sub i64 %71, 4
  %73 = trunc i64 %72 to i32
  store i32 %73, ptr %7, align 4, !tbaa !10
  br label %62, !llvm.loop !15

74:                                               ; preds = %62
  %75 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %75, ptr %10, align 8, !tbaa !5
  br label %76

76:                                               ; preds = %79, %74
  %77 = load i32, ptr %7, align 4, !tbaa !10
  %78 = icmp ugt i32 %77, 0
  br i1 %78, label %79, label %87

79:                                               ; preds = %76
  %80 = load i8, ptr %5, align 1, !tbaa !9
  %81 = load ptr, ptr %10, align 8, !tbaa !5
  %82 = getelementptr inbounds i8, ptr %81, i32 1
  store ptr %82, ptr %10, align 8, !tbaa !5
  store i8 %80, ptr %81, align 1, !tbaa !9
  %83 = load i32, ptr %7, align 4, !tbaa !10
  %84 = zext i32 %83 to i64
  %85 = sub i64 %84, 1
  %86 = trunc i64 %85 to i32
  store i32 %86, ptr %7, align 4, !tbaa !10
  br label %76, !llvm.loop !16

87:                                               ; preds = %76
  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 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = distinct !{!15, !13}
!16 = distinct !{!16, !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: nofree norecurse nosync nounwind memory(write, inaccessiblemem: none) uwtable
define dso_local void @Mem_Set(ptr noundef %0, i8 noundef zeroext %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = zext i8 %1 to i32
  %5 = shl nuw nsw i32 %4, 16
  %6 = shl nuw nsw i32 %4, 8
  %7 = or disjoint i32 %5, %6
  %8 = or disjoint i32 %7, %4
  %9 = shl nuw i32 %8, 8
  %10 = or disjoint i32 %9, %4
  %11 = ptrtoint ptr %0 to i64
  %12 = trunc i64 %11 to i32
  %13 = and i32 %12, 3
  %.not = icmp ne i32 %13, 0
  %14 = icmp ne i32 %2, 0
  %or.cond = and i1 %.not, %14
  br i1 %or.cond, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %3
  %15 = add i32 %2, -1
  %16 = xor i32 %13, 3
  %17 = tail call i32 @llvm.umin.i32(i32 %15, i32 %16)
  %narrow = add nuw nsw i32 %17, 1
  %18 = zext nneg i32 %narrow to i64
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(1) %0, i8 %1, i64 %18, i1 false), !tbaa !5
  %scevgep = getelementptr i8, ptr %0, i64 %18
  %19 = tail call i32 @llvm.usub.sat.i32(i32 %15, i32 %16)
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph.preheader, %3
  %.128 = phi ptr [ %0, %3 ], [ %scevgep, %.lr.ph.preheader ]
  %.126 = phi i32 [ %2, %3 ], [ %19, %.lr.ph.preheader ]
  %20 = icmp ugt i32 %.126, 3
  br i1 %20, label %.lr.ph44.preheader, label %.preheader

.lr.ph44.preheader:                               ; preds = %.loopexit
  %21 = add i32 %.126, -4
  %22 = lshr i32 %21, 2
  %narrow64 = add nuw nsw i32 %22, 1
  %23 = zext nneg i32 %narrow64 to i64
  %min.iters.check = icmp ult i32 %21, 28
  br i1 %min.iters.check, label %.lr.ph44.preheader65, label %vector.ph

.lr.ph44.preheader65:                             ; preds = %middle.block, %.lr.ph44.preheader
  %.243.ph = phi i32 [ %.126, %.lr.ph44.preheader ], [ %ind.end, %middle.block ]
  %.03042.ph = phi ptr [ %.128, %.lr.ph44.preheader ], [ %ind.end59, %middle.block ]
  br label %.lr.ph44

vector.ph:                                        ; preds = %.lr.ph44.preheader
  %n.vec = and i64 %23, 2147483640
  %.cast = trunc nuw nsw i64 %n.vec to i32
  %24 = shl i32 %.cast, 2
  %ind.end = sub i32 %.126, %24
  %25 = shl nuw nsw i64 %n.vec, 2
  %ind.end59 = getelementptr i8, ptr %.128, i64 %25
  %broadcast.splatinsert = insertelement <4 x i32> poison, i32 %10, i64 0
  %broadcast.splat = shufflevector <4 x i32> %broadcast.splatinsert, <4 x i32> poison, <4 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx62 = shl i64 %index, 2
  %next.gep = getelementptr i8, ptr %.128, i64 %offset.idx62
  %26 = getelementptr i8, ptr %next.gep, i64 16
  store <4 x i32> %broadcast.splat, ptr %next.gep, align 4, !tbaa !8
  store <4 x i32> %broadcast.splat, ptr %26, align 4, !tbaa !8
  %index.next = add nuw i64 %index, 8
  %27 = icmp eq i64 %index.next, %n.vec
  br i1 %27, label %middle.block, label %vector.body, !llvm.loop !10

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %23
  br i1 %cmp.n, label %.preheader, label %.lr.ph44.preheader65

.preheader:                                       ; preds = %.lr.ph44, %middle.block, %.loopexit
  %.030.lcssa = phi ptr [ %.128, %.loopexit ], [ %ind.end59, %middle.block ], [ %29, %.lr.ph44 ]
  %.2.lcssa = phi i32 [ %.126, %.loopexit ], [ %ind.end, %middle.block ], [ %30, %.lr.ph44 ]
  %.not3447 = icmp eq i32 %.2.lcssa, 0
  br i1 %.not3447, label %._crit_edge, label %.lr.ph50.preheader

.lr.ph50.preheader:                               ; preds = %.preheader
  %28 = zext nneg i32 %.2.lcssa to i64
  tail call void @llvm.memset.p0.i64(ptr align 1 %.030.lcssa, i8 %1, i64 %28, i1 false), !tbaa !5
  br label %._crit_edge

.lr.ph44:                                         ; preds = %.lr.ph44.preheader65, %.lr.ph44
  %.243 = phi i32 [ %30, %.lr.ph44 ], [ %.243.ph, %.lr.ph44.preheader65 ]
  %.03042 = phi ptr [ %29, %.lr.ph44 ], [ %.03042.ph, %.lr.ph44.preheader65 ]
  %29 = getelementptr inbounds i8, ptr %.03042, i64 4
  store i32 %10, ptr %.03042, align 4, !tbaa !8
  %30 = add i32 %.243, -4
  %31 = icmp ugt i32 %30, 3
  br i1 %31, label %.lr.ph44, label %.preheader, !llvm.loop !14

._crit_edge:                                      ; preds = %.lr.ph50.preheader, %.preheader
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.usub.sat.i32(i32, i32) #2

attributes #0 = { nofree norecurse nosync nounwind memory(write, inaccessiblemem: none) 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 nounwind willreturn memory(argmem: write) }
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/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = distinct !{!10, !11, !12, !13}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!"llvm.loop.isvectorized", i32 1}
!13 = !{!"llvm.loop.unroll.runtime.disable"}
!14 = distinct !{!14, !11, !13, !12}


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