#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*/ memset(char *, int /*<<< orphan*/, size_t);
void *realloc(void *, size_t);
int /*<<< orphan*/ warn_err();
void *remalloczero(void *ptr, size_t oldsize, size_t newsize) {
  void *p = ((void *)0);
  if (newsize != 0) {
    p = realloc(ptr, newsize);
    if (p == ((void *)0)) {
      warn_err();
      return ((void *)0);
    }
    if (newsize > oldsize)
      memset((char *)p + oldsize, 0, newsize - oldsize);
  }
  return p;
}


x86 assembly (clang, -O0):
<remalloczero>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11b1 <remalloczero+0x81>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <realloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1187 <remalloczero+0x57>
mov    $0x0,%al
call   1050 <warn_err@plt>
movq   $0x0,-0x8(%rbp)
jmp    11b9 <remalloczero+0x89>
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jbe    11ac <remalloczero+0x7c>
mov    -0x28(%rbp),%rdi
add    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
sub    -0x18(%rbp),%rdx
xor    %esi,%esi
call   1030 <memset@plt>
jmp    11b1 <remalloczero+0x81>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remalloczero>:
push   %r15
push   %r14
push   %rbx
test   %rdx,%rdx
je     1167 <remalloczero+0x37>
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdx,%rsi
call   1040 <realloc@plt>
test   %rax,%rax
je     116c <remalloczero+0x3c>
mov    %rax,%r14
sub    %r15,%rbx
jbe    1176 <remalloczero+0x46>
mov    %r14,%rdi
add    %r15,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1030 <memset@plt>
jmp    1176 <remalloczero+0x46>
xor    %r14d,%r14d
jmp    1176 <remalloczero+0x46>
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <warn_err@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @remalloczero(i8* %0, i64 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
store i8* %0, i8** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
store i8* null, i8** %8
%9 = load i64, i64* %7
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %32
11: ; preds = %3
%12 = load i8*, i8** %5
%13 = load i64, i64* %7
%14 = call i8* @realloc(i8* %12, i64 %13)
store i8* %14, i8** %8
%15 = load i8*, i8** %8
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = call i32 (...) @warn_err()
store i8* null, i8** %4
br label %34
19: ; preds = %11
%20 = load i64, i64* %7
%21 = load i64, i64* %6
%22 = icmp ugt i64 %20, %21
br i1 %22, label %23, label %31
23: ; preds = %19
%24 = load i8*, i8** %8
%25 = load i64, i64* %6
%26 = getelementptr inbounds i8, i8* %24, i64 %25
%27 = load i64, i64* %7
%28 = load i64, i64* %6
%29 = sub i64 %27, %28
%30 = call i32 @memset(i8* %26, i32 0, i64 %29)
br label %31
31: ; preds = %23, %19
br label %32
32: ; preds = %31, %3
%33 = load i8*, i8** %8
store i8* %33, i8** %4
br label %34
34: ; preds = %32, %17
%35 = load i8*, i8** %4
ret i8* %35
}

LLVM IR (-O2):
define i8* @remalloczero(i8* nocapture %0, i64 %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %16, label %5
5: ; preds = %3
%6 = tail call i8* @realloc(i8* %0, i64 %2)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 (...) @warn_err()
br label %16
10: ; preds = %5
%11 = icmp ugt i64 %2, %1
br i1 %11, label %12, label %16
12: ; preds = %10
%13 = getelementptr inbounds i8, i8* %6, i64 %1
%14 = sub i64 %2, %1
%15 = tail call i32 @memset(i8* %13, i32 0, i64 %14)
br label %16
16: ; preds = %3, %12, %10, %8
%17 = phi i8* [ null, %8 ], [ %6, %12 ], [ %6, %10 ], [ null, %3 ]
ret i8* %17
}