#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, size_t);
scalar_t__ realloc(char *, size_t);
int /*<<< orphan*/ stderr;
void *resizebytes(void *old, size_t oldsize, size_t newsize) {
  void *ret;
  if (newsize < 1)
    newsize = 1;
  if (oldsize < 1)
    oldsize = 1;
  ret = (void *)realloc((char *)old, newsize);
  if (newsize > oldsize && ret)
    memset(((char *)ret) + oldsize, 0, newsize - oldsize);
  if (!ret)
    fprintf(stderr, "ERROR: resizebytes() failed -- out of memory");
  return (ret);
}


x86 assembly (clang, -O0):
<resizebytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x1,-0x18(%rbp)
jae    1157 <resizebytes+0x27>
movq   $0x1,-0x18(%rbp)
cmpq   $0x1,-0x10(%rbp)
jae    116a <resizebytes+0x3a>
movq   $0x1,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <realloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jbe    11ab <resizebytes+0x7b>
cmpq   $0x0,-0x20(%rbp)
je     11ab <resizebytes+0x7b>
mov    -0x20(%rbp),%rdi
add    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
sub    -0x10(%rbp),%rdx
xor    %esi,%esi
call   1030 <memset@plt>
cmpq   $0x0,-0x20(%rbp)
jne    11cb <resizebytes+0x9b>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
lea    0xe3a(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resizebytes>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
test   %rdx,%rdx
mov    $0x1,%eax
cmove  %rax,%r15
mov    %rsi,%rbx
test   %rsi,%rsi
cmove  %rax,%rbx
mov    %r15,%rsi
call   1050 <realloc@plt>
mov    %rax,%r14
sub    %rbx,%r15
jbe    1173 <resizebytes+0x43>
test   %r14,%r14
je     1173 <resizebytes+0x43>
add    %r14,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r15,%rdx
call   1030 <memset@plt>
test   %r14,%r14
jne    118d <resizebytes+0x5d>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
lea    0xe78(%rip),%rsi
call   1040 <fprintf@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [45 x i8] c"ERROR: resizebytes() failed -- out of memory\00"
define i8* @resizebytes(i8* %0, i64 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%8 = load i64, i64* %6
%9 = icmp ult i64 %8, 1
br i1 %9, label %10, label %11
10: ; preds = %3
store i64 1, i64* %6
br label %11
11: ; preds = %10, %3
%12 = load i64, i64* %5
%13 = icmp ult i64 %12, 1
br i1 %13, label %14, label %15
14: ; preds = %11
store i64 1, i64* %5
br label %15
15: ; preds = %14, %11
%16 = load i8*, i8** %4
%17 = load i64, i64* %6
%18 = call i64 @realloc(i8* %16, i64 %17)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %7
%20 = load i64, i64* %6
%21 = load i64, i64* %5
%22 = icmp ugt i64 %20, %21
br i1 %22, label %23, label %34
23: ; preds = %15
%24 = load i8*, i8** %7
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %34
26: ; preds = %23
%27 = load i8*, i8** %7
%28 = load i64, i64* %5
%29 = getelementptr inbounds i8, i8* %27, i64 %28
%30 = load i64, i64* %6
%31 = load i64, i64* %5
%32 = sub i64 %30, %31
%33 = call i32 @memset(i8* %29, i32 0, i64 %32)
br label %34
34: ; preds = %26, %23, %15
%35 = load i8*, i8** %7
%36 = icmp ne i8* %35, null
br i1 %36, label %40, label %37
37: ; preds = %34
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
br label %40
40: ; preds = %37, %34
%41 = load i8*, i8** %7
ret i8* %41
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [45 x i8] c"ERROR: resizebytes() failed -- out of memory\00"
define i8* @resizebytes(i8* %0, i64 %1, i64 %2) {
%4 = icmp eq i64 %2, 0
%5 = select i1 %4, i64 1, i64 %2
%6 = icmp eq i64 %1, 0
%7 = select i1 %6, i64 1, i64 %1
%8 = tail call i64 @realloc(i8* %0, i64 %5)
%9 = inttoptr i64 %8 to i8*
%10 = icmp ugt i64 %5, %7
%11 = icmp ne i64 %8, 0
%12 = select i1 %10, i1 %11, i1 false
br i1 %12, label %13, label %17
13: ; preds = %3
%14 = getelementptr inbounds i8, i8* %9, i64 %7
%15 = sub i64 %5, %7
%16 = tail call i32 @memset(i8* %14, i32 0, i64 %15)
br label %17
17: ; preds = %13, %3
br i1 %11, label %21, label %18
18: ; preds = %17
%19 = load i32, i32* @stderr
%20 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %18, %17
ret i8* %9
}