; LLVM IR from bnidia/push_swap :: libraries/libft (ft_realloc)

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

11:                                               ; preds = %3
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  store i64 128, ptr %12, align 8, !tbaa !9
  br label %26

13:                                               ; preds = %3
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = load i64, ptr %14, align 8, !tbaa !9
  %16 = icmp ule i64 %15, 33554432
  br i1 %16, label %17, label %21

17:                                               ; preds = %13
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = load i64, ptr %18, align 8, !tbaa !9
  %20 = mul i64 %19, 2
  store i64 %20, ptr %18, align 8, !tbaa !9
  br label %25

21:                                               ; preds = %13
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = load i64, ptr %22, align 8, !tbaa !9
  %24 = add i64 %23, 33554432
  store i64 %24, ptr %22, align 8, !tbaa !9
  br label %25

25:                                               ; preds = %21, %17
  br label %26

26:                                               ; preds = %25, %11
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = load i64, ptr %27, align 8, !tbaa !9
  %29 = call noalias ptr @malloc(i64 noundef %28) #5
  store ptr %29, ptr %7, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %39, %26
  %31 = load i64, ptr %8, align 8, !tbaa !9
  %32 = load i64, ptr %5, align 8, !tbaa !9
  %33 = icmp ult i64 %31, %32
  br i1 %33, label %34, label %37

34:                                               ; preds = %30
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = icmp ne ptr %35, null
  br label %37

37:                                               ; preds = %34, %30
  %38 = phi i1 [ false, %30 ], [ %36, %34 ]
  br i1 %38, label %39, label %50

39:                                               ; preds = %37
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = load ptr, ptr %40, align 8, !tbaa !5
  %42 = load i64, ptr %8, align 8, !tbaa !9
  %43 = getelementptr inbounds i8, ptr %41, i64 %42
  %44 = load i8, ptr %43, align 1, !tbaa !11
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = load i64, ptr %8, align 8, !tbaa !9
  %47 = getelementptr inbounds i8, ptr %45, i64 %46
  store i8 %44, ptr %47, align 1, !tbaa !11
  %48 = load i64, ptr %8, align 8, !tbaa !9
  %49 = add i64 %48, 1
  store i64 %49, ptr %8, align 8, !tbaa !9
  br label %30, !llvm.loop !12

50:                                               ; preds = %37
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = load ptr, ptr %51, align 8, !tbaa !5
  call void @free(ptr noundef %52) #4
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %53, ptr %54, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret void
}

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

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

attributes #0 = { 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 = { nounwind allocsize(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 "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 }
attributes #5 = { nounwind allocsize(0) }

!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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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: nounwind uwtable
define dso_local void @ft_realloc(ptr nocapture noundef %0, i64 noundef %1, ptr nocapture noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq i64 %1, 0
  br i1 %4, label %12, label %5

5:                                                ; preds = %3
  %6 = load i64, ptr %2, align 8, !tbaa !5
  %7 = icmp ult i64 %6, 33554433
  br i1 %7, label %8, label %10

8:                                                ; preds = %5
  %9 = shl nuw nsw i64 %6, 1
  br label %12

10:                                               ; preds = %5
  %11 = add i64 %6, 33554432
  br label %12

12:                                               ; preds = %3, %8, %10
  %.sink = phi i64 [ %9, %8 ], [ %11, %10 ], [ 128, %3 ]
  store i64 %.sink, ptr %2, align 8, !tbaa !5
  %13 = tail call noalias ptr @malloc(i64 noundef %.sink) #3
  %14 = icmp ne ptr %13, null
  %15 = icmp ne i64 %1, 0
  %16 = and i1 %14, %15
  %.pre = load ptr, ptr %0, align 8, !tbaa !9
  br i1 %16, label %iter.check, label %._crit_edge

iter.check:                                       ; preds = %12
  %.pre19 = ptrtoint ptr %.pre to i64
  %17 = ptrtoint ptr %13 to i64
  %min.iters.check = icmp ult i64 %1, 8
  %18 = sub i64 %17, %.pre19
  %diff.check = icmp ult i64 %18, 32
  %or.cond = select i1 %min.iters.check, i1 true, i1 %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.check20 = icmp ult i64 %1, 32
  br i1 %min.iters.check20, label %vec.epilog.ph, label %vector.ph

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

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %19 = getelementptr inbounds i8, ptr %.pre, i64 %index
  %20 = getelementptr inbounds i8, ptr %19, i64 16
  %wide.load = load <16 x i8>, ptr %19, align 1, !tbaa !11
  %wide.load21 = load <16 x i8>, ptr %20, align 1, !tbaa !11
  %21 = getelementptr inbounds i8, ptr %13, i64 %index
  %22 = getelementptr inbounds i8, ptr %21, i64 16
  store <16 x i8> %wide.load, ptr %21, align 1, !tbaa !11
  store <16 x i8> %wide.load21, ptr %22, align 1, !tbaa !11
  %index.next = add nuw i64 %index, 32
  %23 = icmp eq i64 %index.next, %n.vec
  br i1 %23, label %middle.block, label %vector.body, !llvm.loop !12

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

vec.epilog.iter.check:                            ; preds = %middle.block
  %n.vec.remaining = and i64 %1, 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

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.vec23 = and i64 %1, -8
  br label %vec.epilog.vector.body

vec.epilog.vector.body:                           ; preds = %vec.epilog.vector.body, %vec.epilog.ph
  %index24 = phi i64 [ %vec.epilog.resume.val, %vec.epilog.ph ], [ %index.next26, %vec.epilog.vector.body ]
  %24 = getelementptr inbounds i8, ptr %.pre, i64 %index24
  %wide.load25 = load <8 x i8>, ptr %24, align 1, !tbaa !11
  %25 = getelementptr inbounds i8, ptr %13, i64 %index24
  store <8 x i8> %wide.load25, ptr %25, align 1, !tbaa !11
  %index.next26 = add nuw i64 %index24, 8
  %26 = icmp eq i64 %index.next26, %n.vec23
  br i1 %26, label %vec.epilog.middle.block, label %vec.epilog.vector.body, !llvm.loop !16

vec.epilog.middle.block:                          ; preds = %vec.epilog.vector.body
  %cmp.n27 = icmp eq i64 %n.vec23, %1
  br i1 %cmp.n27, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %vec.epilog.middle.block, %iter.check, %vec.epilog.iter.check
  %.018.ph = phi i64 [ 0, %iter.check ], [ %n.vec, %vec.epilog.iter.check ], [ %n.vec23, %vec.epilog.middle.block ]
  %xtraiter = and i64 %1, 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
  %.018.prol = phi i64 [ %30, %.lr.ph.prol ], [ %.018.ph, %.lr.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader ]
  %27 = getelementptr inbounds i8, ptr %.pre, i64 %.018.prol
  %28 = load i8, ptr %27, align 1, !tbaa !11
  %29 = getelementptr inbounds i8, ptr %13, i64 %.018.prol
  store i8 %28, ptr %29, align 1, !tbaa !11
  %30 = add nuw i64 %.018.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 !17

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader
  %.018.unr = phi i64 [ %.018.ph, %.lr.ph.preheader ], [ %30, %.lr.ph.prol ]
  %31 = sub i64 %.018.ph, %1
  %32 = icmp ugt i64 %31, -4
  br i1 %32, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %.018 = phi i64 [ %48, %.lr.ph ], [ %.018.unr, %.lr.ph.prol.loopexit ]
  %33 = getelementptr inbounds i8, ptr %.pre, i64 %.018
  %34 = load i8, ptr %33, align 1, !tbaa !11
  %35 = getelementptr inbounds i8, ptr %13, i64 %.018
  store i8 %34, ptr %35, align 1, !tbaa !11
  %36 = add nuw i64 %.018, 1
  %37 = getelementptr inbounds i8, ptr %.pre, i64 %36
  %38 = load i8, ptr %37, align 1, !tbaa !11
  %39 = getelementptr inbounds i8, ptr %13, i64 %36
  store i8 %38, ptr %39, align 1, !tbaa !11
  %40 = add nuw i64 %.018, 2
  %41 = getelementptr inbounds i8, ptr %.pre, i64 %40
  %42 = load i8, ptr %41, align 1, !tbaa !11
  %43 = getelementptr inbounds i8, ptr %13, i64 %40
  store i8 %42, ptr %43, align 1, !tbaa !11
  %44 = add nuw i64 %.018, 3
  %45 = getelementptr inbounds i8, ptr %.pre, i64 %44
  %46 = load i8, ptr %45, align 1, !tbaa !11
  %47 = getelementptr inbounds i8, ptr %13, i64 %44
  store i8 %46, ptr %47, align 1, !tbaa !11
  %48 = add nuw i64 %.018, 4
  %exitcond.not.3 = icmp eq i64 %48, %1
  br i1 %exitcond.not.3, label %._crit_edge, label %.lr.ph, !llvm.loop !19

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %middle.block, %vec.epilog.middle.block, %12
  tail call void @free(ptr noundef %.pre) #4
  store ptr %13, ptr %0, align 8, !tbaa !9
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

attributes #0 = { 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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 allocsize(0) }
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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13, !14, !15}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!"llvm.loop.isvectorized", i32 1}
!15 = !{!"llvm.loop.unroll.runtime.disable"}
!16 = distinct !{!16, !13, !14, !15}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.unroll.disable"}
!19 = distinct !{!19, !13, !14}


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