#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_memrealloc(void *ptr, size_t new_size) {
  void *newbuf;
  if (!(newbuf = ft_memalloc(new_size)))
    return (NULL);
  if (!ptr)
    return (newbuf);
  ft_memmove(newbuf, ptr, new_size);
  ft_memdel(&ptr);
  return (newbuf);
}


x86 assembly (clang, -O0):
<ft_memrealloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <ft_memalloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1164 <ft_memrealloc+0x34>
movq   $0x0,-0x8(%rbp)
jmp    119e <ft_memrealloc+0x6e>
cmpq   $0x0,-0x10(%rbp)
jne    117c <ft_memrealloc+0x4c>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    119e <ft_memrealloc+0x6e>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <ft_memmove@plt>
lea    -0x10(%rbp),%rdi
call   1030 <ft_memdel@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

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

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

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