#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*/ free(void *);
void *malloc(size_t);
int /*<<< orphan*/ memcpy(void *, void *, size_t);
void *RKMem_Realloc_Func(void *data, size_t newsize, size_t oldsize,
                         int NULLonError0No1Yes) {
  void *newdata;
  newdata = malloc(newsize);
  if (newdata != NULL) {
    memcpy(newdata, data, oldsize);
    free(data);
    return newdata;
  } else {
    if (NULLonError0No1Yes) {
      free(data);
      return NULL;
    } else {
      return data;
    }
  }
}


x86 assembly (clang, -O0):
<RKMem_Realloc_Func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1186 <RKMem_Realloc_Func+0x56>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ae <RKMem_Realloc_Func+0x7e>
cmpl   $0x0,-0x24(%rbp)
je     11a6 <RKMem_Realloc_Func+0x76>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    11ae <RKMem_Realloc_Func+0x7e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RKMem_Realloc_Func>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebp
mov    %rdx,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1050 <malloc@plt>
test   %rax,%rax
je     115f <RKMem_Realloc_Func+0x2f>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <memcpy@plt>
jmp    1165 <RKMem_Realloc_Func+0x35>
test   %ebp,%ebp
je     1170 <RKMem_Realloc_Func+0x40>
xor    %ebx,%ebx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @RKMem_Realloc_Func(i8* %0, i64 %1, i64 %2, i32 %3) {
%5 = tail call i8* @malloc(i64 %1)
%6 = icmp eq i8* %5, null
br i1 %6, label %9, label %7
7: ; preds = %4
%8 = tail call i32 @memcpy(i8* %5, i8* %0, i64 %2)
br label %11
9: ; preds = %4
%10 = icmp eq i32 %3, 0
br i1 %10, label %14, label %11
11: ; preds = %9, %7
%12 = phi i8* [ %5, %7 ], [ null, %9 ]
%13 = tail call i32 @free(i8* %0)
br label %14
14: ; preds = %11, %9
%15 = phi i8* [ %0, %9 ], [ %12, %11 ]
ret i8* %15
}