; LLVM IR from rociodellasala/TP3_SO :: Kernel (lib)

; 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 ptr @memcpy(ptr noundef %0, ptr noundef %1, i64 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = ptrtoint ptr %12 to i64
  %14 = urem i64 %13, 4
  %15 = icmp eq i64 %14, 0
  br i1 %15, label %16, label %45

16:                                               ; preds = %3
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = ptrtoint ptr %17 to i64
  %19 = urem i64 %18, 4
  %20 = icmp eq i64 %19, 0
  br i1 %20, label %21, label %45

21:                                               ; preds = %16
  %22 = load i64, ptr %6, align 8, !tbaa !9
  %23 = urem i64 %22, 4
  %24 = icmp eq i64 %23, 0
  br i1 %24, label %25, label %45

25:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %26, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %27, ptr %9, align 8, !tbaa !5
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %28

28:                                               ; preds = %41, %25
  %29 = load i64, ptr %7, align 8, !tbaa !9
  %30 = load i64, ptr %6, align 8, !tbaa !9
  %31 = udiv i64 %30, 4
  %32 = icmp ult i64 %29, %31
  br i1 %32, label %33, label %44

33:                                               ; preds = %28
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = load i64, ptr %7, align 8, !tbaa !9
  %36 = getelementptr inbounds i32, ptr %34, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !11
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = load i64, ptr %7, align 8, !tbaa !9
  %40 = getelementptr inbounds i32, ptr %38, i64 %39
  store i32 %37, ptr %40, align 4, !tbaa !11
  br label %41

41:                                               ; preds = %33
  %42 = load i64, ptr %7, align 8, !tbaa !9
  %43 = add i64 %42, 1
  store i64 %43, ptr %7, align 8, !tbaa !9
  br label %28, !llvm.loop !13

44:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %64

45:                                               ; preds = %21, %16, %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %46, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %47, ptr %11, align 8, !tbaa !5
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %48

48:                                               ; preds = %60, %45
  %49 = load i64, ptr %7, align 8, !tbaa !9
  %50 = load i64, ptr %6, align 8, !tbaa !9
  %51 = icmp ult i64 %49, %50
  br i1 %51, label %52, label %63

52:                                               ; preds = %48
  %53 = load ptr, ptr %11, align 8, !tbaa !5
  %54 = load i64, ptr %7, align 8, !tbaa !9
  %55 = getelementptr inbounds i8, ptr %53, i64 %54
  %56 = load i8, ptr %55, align 1, !tbaa !15
  %57 = load ptr, ptr %10, align 8, !tbaa !5
  %58 = load i64, ptr %7, align 8, !tbaa !9
  %59 = getelementptr inbounds i8, ptr %57, i64 %58
  store i8 %56, ptr %59, align 1, !tbaa !15
  br label %60

60:                                               ; preds = %52
  %61 = load i64, ptr %7, align 8, !tbaa !9
  %62 = add i64 %61, 1
  store i64 %62, ptr %7, align 8, !tbaa !9
  br label %48, !llvm.loop !16

63:                                               ; preds = %48
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  br label %64

64:                                               ; preds = %63, %44
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret ptr %65
}

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 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !14}


; 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 noundef ptr @memcpy(ptr noundef returned %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = ptrtoint ptr %1 to i64
  %5 = ptrtoint ptr %0 to i64
  %6 = ptrtoint ptr %1 to i64
  %7 = ptrtoint ptr %0 to i64
  %8 = ptrtoint ptr %1 to i64
  %9 = or i64 %8, %7
  %10 = or i64 %9, %2
  %11 = and i64 %10, 3
  %or.cond24 = icmp eq i64 %11, 0
  %.not30 = icmp eq i64 %2, 0
  br i1 %or.cond24, label %.preheader, label %.preheader25

.preheader25:                                     ; preds = %3
  br i1 %.not30, label %.loopexit, label %iter.check

iter.check:                                       ; preds = %.preheader25
  %min.iters.check = icmp ult i64 %2, 8
  %12 = sub i64 %7, %6
  %diff.check = icmp ult i64 %12, 32
  %or.cond = or i1 %min.iters.check, %diff.check
  br i1 %or.cond, label %.lr.ph.preheader, label %vector.main.loop.iter.check

vector.main.loop.iter.check:                      ; preds = %iter.check
  %min.iters.check35 = icmp ult i64 %2, 32
  br i1 %min.iters.check35, label %vec.epilog.ph, label %vector.ph

vector.ph:                                        ; preds = %vector.main.loop.iter.check
  %n.vec = and i64 %2, -32
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %13 = getelementptr inbounds i8, ptr %1, i64 %index
  %14 = getelementptr inbounds i8, ptr %13, i64 16
  %wide.load = load <16 x i8>, ptr %13, align 1, !tbaa !5
  %wide.load36 = load <16 x i8>, ptr %14, align 1, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %0, i64 %index
  %16 = getelementptr inbounds i8, ptr %15, i64 16
  store <16 x i8> %wide.load, ptr %15, align 1, !tbaa !5
  store <16 x i8> %wide.load36, ptr %16, align 1, !tbaa !5
  %index.next = add nuw i64 %index, 32
  %17 = icmp eq i64 %index.next, %n.vec
  br i1 %17, label %middle.block, label %vector.body, !llvm.loop !8

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %2
  br i1 %cmp.n, label %.loopexit, label %vec.epilog.iter.check

vec.epilog.iter.check:                            ; preds = %middle.block
  %n.vec.remaining = and i64 %2, 24
  %min.epilog.iters.check = icmp eq i64 %n.vec.remaining, 0
  br i1 %min.epilog.iters.check, label %.lr.ph.preheader, label %vec.epilog.ph

.lr.ph.preheader:                                 ; preds = %vec.epilog.middle.block, %iter.check, %vec.epilog.iter.check
  %.127.ph = phi i64 [ 0, %iter.check ], [ %n.vec, %vec.epilog.iter.check ], [ %n.vec38, %vec.epilog.middle.block ]
  %xtraiter = and i64 %2, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader, %.lr.ph.prol
  %.127.prol = phi i64 [ %21, %.lr.ph.prol ], [ %.127.ph, %.lr.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader ]
  %18 = getelementptr inbounds i8, ptr %1, i64 %.127.prol
  %19 = load i8, ptr %18, align 1, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %0, i64 %.127.prol
  store i8 %19, ptr %20, align 1, !tbaa !5
  %21 = add nuw i64 %.127.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 %.lr.ph.prol.loopexit, label %.lr.ph.prol, !llvm.loop !12

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader
  %.127.unr = phi i64 [ %.127.ph, %.lr.ph.preheader ], [ %21, %.lr.ph.prol ]
  %22 = sub i64 %.127.ph, %2
  %23 = icmp ugt i64 %22, -4
  br i1 %23, label %.loopexit, label %.lr.ph

vec.epilog.ph:                                    ; preds = %vector.main.loop.iter.check, %vec.epilog.iter.check
  %vec.epilog.resume.val = phi i64 [ %n.vec, %vec.epilog.iter.check ], [ 0, %vector.main.loop.iter.check ]
  %n.vec38 = and i64 %2, -8
  br label %vec.epilog.vector.body

vec.epilog.vector.body:                           ; preds = %vec.epilog.vector.body, %vec.epilog.ph
  %index39 = phi i64 [ %vec.epilog.resume.val, %vec.epilog.ph ], [ %index.next41, %vec.epilog.vector.body ]
  %24 = getelementptr inbounds i8, ptr %1, i64 %index39
  %wide.load40 = load <8 x i8>, ptr %24, align 1, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %0, i64 %index39
  store <8 x i8> %wide.load40, ptr %25, align 1, !tbaa !5
  %index.next41 = add nuw i64 %index39, 8
  %26 = icmp eq i64 %index.next41, %n.vec38
  br i1 %26, label %vec.epilog.middle.block, label %vec.epilog.vector.body, !llvm.loop !14

vec.epilog.middle.block:                          ; preds = %vec.epilog.vector.body
  %cmp.n42 = icmp eq i64 %n.vec38, %2
  br i1 %cmp.n42, label %.loopexit, label %.lr.ph.preheader

.preheader:                                       ; preds = %3
  br i1 %.not30, label %.loopexit, label %.lr.ph29.preheader

.lr.ph29.preheader:                               ; preds = %.preheader
  %27 = lshr i64 %2, 2
  %umax = tail call i64 @llvm.umax.i64(i64 %27, i64 1)
  %min.iters.check46 = icmp ult i64 %2, 32
  %28 = sub i64 %5, %4
  %diff.check44 = icmp ult i64 %28, 32
  %or.cond57 = or i1 %min.iters.check46, %diff.check44
  br i1 %or.cond57, label %.lr.ph29.preheader58, label %vector.ph47

vector.ph47:                                      ; preds = %.lr.ph29.preheader
  %n.vec49 = and i64 %umax, 4611686018427387896
  br label %vector.body51

vector.body51:                                    ; preds = %vector.body51, %vector.ph47
  %index52 = phi i64 [ 0, %vector.ph47 ], [ %index.next55, %vector.body51 ]
  %29 = getelementptr inbounds i32, ptr %1, i64 %index52
  %30 = getelementptr inbounds i8, ptr %29, i64 16
  %wide.load53 = load <4 x i32>, ptr %29, align 4, !tbaa !15
  %wide.load54 = load <4 x i32>, ptr %30, align 4, !tbaa !15
  %31 = getelementptr inbounds i32, ptr %0, i64 %index52
  %32 = getelementptr inbounds i8, ptr %31, i64 16
  store <4 x i32> %wide.load53, ptr %31, align 4, !tbaa !15
  store <4 x i32> %wide.load54, ptr %32, align 4, !tbaa !15
  %index.next55 = add nuw i64 %index52, 8
  %33 = icmp eq i64 %index.next55, %n.vec49
  br i1 %33, label %middle.block45, label %vector.body51, !llvm.loop !17

middle.block45:                                   ; preds = %vector.body51
  %cmp.n56 = icmp eq i64 %27, %n.vec49
  br i1 %cmp.n56, label %.loopexit, label %.lr.ph29.preheader58

.lr.ph29.preheader58:                             ; preds = %middle.block45, %.lr.ph29.preheader
  %.028.ph = phi i64 [ 0, %.lr.ph29.preheader ], [ %n.vec49, %middle.block45 ]
  %xtraiter60 = and i64 %umax, 3
  %lcmp.mod61.not = icmp eq i64 %xtraiter60, 0
  br i1 %lcmp.mod61.not, label %.lr.ph29.prol.loopexit, label %.lr.ph29.prol

.lr.ph29.prol:                                    ; preds = %.lr.ph29.preheader58, %.lr.ph29.prol
  %.028.prol = phi i64 [ %37, %.lr.ph29.prol ], [ %.028.ph, %.lr.ph29.preheader58 ]
  %prol.iter62 = phi i64 [ %prol.iter62.next, %.lr.ph29.prol ], [ 0, %.lr.ph29.preheader58 ]
  %34 = getelementptr inbounds i32, ptr %1, i64 %.028.prol
  %35 = load i32, ptr %34, align 4, !tbaa !15
  %36 = getelementptr inbounds i32, ptr %0, i64 %.028.prol
  store i32 %35, ptr %36, align 4, !tbaa !15
  %37 = add nuw nsw i64 %.028.prol, 1
  %prol.iter62.next = add i64 %prol.iter62, 1
  %prol.iter62.cmp.not = icmp eq i64 %prol.iter62.next, %xtraiter60
  br i1 %prol.iter62.cmp.not, label %.lr.ph29.prol.loopexit, label %.lr.ph29.prol, !llvm.loop !18

.lr.ph29.prol.loopexit:                           ; preds = %.lr.ph29.prol, %.lr.ph29.preheader58
  %.028.unr = phi i64 [ %.028.ph, %.lr.ph29.preheader58 ], [ %37, %.lr.ph29.prol ]
  %38 = sub nsw i64 %.028.ph, %umax
  %39 = icmp ugt i64 %38, -4
  br i1 %39, label %.loopexit, label %.lr.ph29

.lr.ph29:                                         ; preds = %.lr.ph29.prol.loopexit, %.lr.ph29
  %.028 = phi i64 [ %55, %.lr.ph29 ], [ %.028.unr, %.lr.ph29.prol.loopexit ]
  %40 = getelementptr inbounds i32, ptr %1, i64 %.028
  %41 = load i32, ptr %40, align 4, !tbaa !15
  %42 = getelementptr inbounds i32, ptr %0, i64 %.028
  store i32 %41, ptr %42, align 4, !tbaa !15
  %43 = add nuw nsw i64 %.028, 1
  %44 = getelementptr inbounds i32, ptr %1, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !15
  %46 = getelementptr inbounds i32, ptr %0, i64 %43
  store i32 %45, ptr %46, align 4, !tbaa !15
  %47 = add nuw nsw i64 %.028, 2
  %48 = getelementptr inbounds i32, ptr %1, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !15
  %50 = getelementptr inbounds i32, ptr %0, i64 %47
  store i32 %49, ptr %50, align 4, !tbaa !15
  %51 = add nuw nsw i64 %.028, 3
  %52 = getelementptr inbounds i32, ptr %1, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !15
  %54 = getelementptr inbounds i32, ptr %0, i64 %51
  store i32 %53, ptr %54, align 4, !tbaa !15
  %55 = add nuw nsw i64 %.028, 4
  %exitcond32.not.3 = icmp eq i64 %27, %55
  br i1 %exitcond32.not.3, label %.loopexit, label %.lr.ph29, !llvm.loop !19

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %.127 = phi i64 [ %71, %.lr.ph ], [ %.127.unr, %.lr.ph.prol.loopexit ]
  %56 = getelementptr inbounds i8, ptr %1, i64 %.127
  %57 = load i8, ptr %56, align 1, !tbaa !5
  %58 = getelementptr inbounds i8, ptr %0, i64 %.127
  store i8 %57, ptr %58, align 1, !tbaa !5
  %59 = add nuw i64 %.127, 1
  %60 = getelementptr inbounds i8, ptr %1, i64 %59
  %61 = load i8, ptr %60, align 1, !tbaa !5
  %62 = getelementptr inbounds i8, ptr %0, i64 %59
  store i8 %61, ptr %62, align 1, !tbaa !5
  %63 = add nuw i64 %.127, 2
  %64 = getelementptr inbounds i8, ptr %1, i64 %63
  %65 = load i8, ptr %64, align 1, !tbaa !5
  %66 = getelementptr inbounds i8, ptr %0, i64 %63
  store i8 %65, ptr %66, align 1, !tbaa !5
  %67 = add nuw i64 %.127, 3
  %68 = getelementptr inbounds i8, ptr %1, i64 %67
  %69 = load i8, ptr %68, align 1, !tbaa !5
  %70 = getelementptr inbounds i8, ptr %0, i64 %67
  store i8 %69, ptr %70, align 1, !tbaa !5
  %71 = add nuw i64 %.127, 4
  %exitcond.not.3 = icmp eq i64 %71, %2
  br i1 %exitcond.not.3, label %.loopexit, label %.lr.ph, !llvm.loop !20

.loopexit:                                        ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %.lr.ph29.prol.loopexit, %.lr.ph29, %middle.block, %vec.epilog.middle.block, %middle.block45, %.preheader25, %.preheader
  ret ptr %0
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #1

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


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