#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*/ memcpy(void *, void *, int);
int /*<<< orphan*/ zzfree(void *, int);
void *zzmalloc(int);
void *zzrealloc(void *p, int old_len, int new_len) {
  void *tmp = zzmalloc(new_len);
  if (!tmp) {
    return 0;
  }
  int t = old_len;
  if (old_len > new_len) {
    t = old_len;
  }
  memcpy(tmp, p, t);
  if (p) {
    zzfree(p, old_len);
  }
  return tmp;
}


x86 assembly (clang, -O0):
<zzrealloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <zzmalloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1166 <zzrealloc+0x36>
movq   $0x0,-0x8(%rbp)
jmp    11ad <zzrealloc+0x7d>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jle    117e <zzrealloc+0x4e>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <memcpy@plt>
cmpq   $0x0,-0x10(%rbp)
je     11a5 <zzrealloc+0x75>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <zzfree@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zzrealloc>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbp
mov    %edx,%edi
call   1030 <zzmalloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1167 <zzrealloc+0x37>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r14d,%edx
call   1040 <memcpy@plt>
test   %rbp,%rbp
je     1167 <zzrealloc+0x37>
mov    %rbp,%rdi
mov    %r14d,%esi
call   1050 <zzfree@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @zzrealloc(i8* %0, i32 %1, i32 %2) {
%4 = tail call i8* @zzmalloc(i32 %2)
%5 = icmp eq i8* %4, null
br i1 %5, label %11, label %6
6: ; preds = %3
%7 = tail call i32 @memcpy(i8* %4, i8* %0, i32 %1)
%8 = icmp eq i8* %0, null
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = tail call i32 @zzfree(i8* %0, i32 %1)
br label %11
11: ; preds = %6, %9, %3
ret i8* %4
}