#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
void *ft_memalloc(size_t);
int /*<<< orphan*/ ft_memdel(void **);
int /*<<< orphan*/ ft_memmove(void *, void *, size_t);
void *ft_memreallocf(void *ptr, size_t new_size, size_t old_size) {
  void *newbuf;
  if (!(newbuf = ft_memalloc(new_size))) {
    ft_memdel(&ptr);
    return (NULL);
  }
  if (!ptr)
    return (newbuf);
  ft_memmove(newbuf, ptr, old_size);
  ft_memdel(&ptr);
  return (newbuf);
}


x86 assembly (clang, -O0):
<ft_memreallocf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <ft_memalloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1171 <ft_memreallocf+0x41>
lea    -0x10(%rbp),%rdi
call   1030 <ft_memdel@plt>
movq   $0x0,-0x8(%rbp)
jmp    11ab <ft_memreallocf+0x7b>
cmpq   $0x0,-0x10(%rbp)
jne    1189 <ft_memreallocf+0x59>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ab <ft_memreallocf+0x7b>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <ft_memmove@plt>
lea    -0x10(%rbp),%rdi
call   1030 <ft_memdel@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_memreallocf>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rdi,%r15
mov    %rdi,0x8(%rsp)
mov    %rsi,%rdi
call   1050 <ft_memalloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1167 <ft_memreallocf+0x37>
test   %r15,%r15
je     1171 <ft_memreallocf+0x41>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1040 <ft_memmove@plt>
lea    0x8(%rsp),%rdi
call   1030 <ft_memdel@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @ft_memreallocf(i8* %0, i64 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
store i8* %0, i8** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
%9 = load i64, i64* %6
%10 = call i8* @ft_memalloc(i64 %9)
store i8* %10, i8** %8
%11 = icmp ne i8* %10, null
br i1 %11, label %14, label %12
12: ; preds = %3
%13 = call i32 @ft_memdel(i8** %5)
store i8* null, i8** %4
br label %26
14: ; preds = %3
%15 = load i8*, i8** %5
%16 = icmp ne i8* %15, null
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = load i8*, i8** %8
store i8* %18, i8** %4
br label %26
19: ; preds = %14
%20 = load i8*, i8** %8
%21 = load i8*, i8** %5
%22 = load i64, i64* %7
%23 = call i32 @ft_memmove(i8* %20, i8* %21, i64 %22)
%24 = call i32 @ft_memdel(i8** %5)
%25 = load i8*, i8** %8
store i8* %25, i8** %4
br label %26
26: ; preds = %19, %17, %12
%27 = load i8*, i8** %4
ret i8* %27
}

LLVM IR (-O2):
define i8* @ft_memreallocf(i8* %0, i64 %1, i64 %2) {
%4 = alloca i8*
store i8* %0, i8** %4
%5 = tail call i8* @ft_memalloc(i64 %1)
%6 = icmp eq i8* %5, null
br i1 %6, label %11, label %7
7: ; preds = %3
%8 = icmp eq i8* %0, null
br i1 %8, label %13, label %9
9: ; preds = %7
%10 = tail call i32 @ft_memmove(i8* %5, i8* %0, i64 %2)
br label %11
11: ; preds = %3, %9
%12 = call i32 @ft_memdel(i8** %4)
br label %13
13: ; preds = %11, %7
ret i8* %5
}