#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 */
int /*<<< orphan*/ memmove(void *, void *, int /*<<< orphan*/);
int /*<<< orphan*/ mt_free(void *);
int /*<<< orphan*/ mt_get_buf_size(void *);
void *mt_malloc(size_t, char *, char *, int);
void *mt_realloc(void *addr, size_t size, char *callfunc, char *file,
                 int line) {
  void *buf;
  buf = mt_malloc(size, callfunc, file, line);
  if (buf) {
    memmove(buf, addr, mt_get_buf_size(addr));
    mt_free(addr);
  }
  return buf;
}


x86 assembly (clang, -O0):
<mt_realloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
call   1060 <mt_malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11b0 <mt_realloc+0x70>
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <mt_get_buf_size@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1050 <memmove@plt>
mov    -0x8(%rbp),%rdi
call   1040 <mt_free@plt>
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mt_realloc>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    %rcx,%rdx
mov    %r8d,%ecx
call   1060 <mt_malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     117d <mt_realloc+0x3d>
mov    %r14,%rdi
call   1030 <mt_get_buf_size@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1050 <memmove@plt>
mov    %r14,%rdi
call   1040 <mt_free@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i8* @mt_realloc(i8* %0, i64 %1, i8* %2, i8* %3, i32 %4) {
%6 = tail call i8* @mt_malloc(i64 %1, i8* %2, i8* %3, i32 %4)
%7 = icmp eq i8* %6, null
br i1 %7, label %12, label %8
8: ; preds = %5
%9 = tail call i32 @mt_get_buf_size(i8* %0)
%10 = tail call i32 @memmove(i8* %6, i8* %0, i32 %9)
%11 = tail call i32 @mt_free(i8* %0)
br label %12
12: ; preds = %8, %5
ret i8* %6
}