#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*/ ENOMEM;
int /*<<< orphan*/ _sizeof_flexarr(size_t *, size_t, size_t, size_t);
int /*<<< orphan*/ errno;
void *realloc(void *, size_t);
void *_realloc_flexarr(void *p, size_t sz0, size_t cnt, size_t sz1) {
  size_t sz;
  if (!_sizeof_flexarr(&sz, sz0, cnt, sz1)) {
    errno = ENOMEM;
    return NULL;
  }
  return realloc(p, sz);
}


x86 assembly (clang, -O0):
<_realloc_flexarr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    -0x30(%rbp),%rdi
call   1030 <_sizeof_flexarr@plt>
cmp    $0x0,%eax
jne    1175 <_realloc_flexarr+0x55>
mov    0x2e83(%rip),%rax
mov    (%rax),%ecx
mov    0x2e72(%rip),%rax
mov    %ecx,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    1186 <_realloc_flexarr+0x66>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1040 <realloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_realloc_flexarr>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rdi
call   1030 <_sizeof_flexarr@plt>
test   %eax,%eax
je     1145 <_realloc_flexarr+0x25>
mov    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <realloc@plt>
jmp    1159 <_realloc_flexarr+0x39>
mov    0x2e94(%rip),%rax
mov    (%rax),%eax
mov    0x2e83(%rip),%rcx
mov    %eax,(%rcx)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@ENOMEM = global i32 0
@errno = global i32 0
define i8* @_realloc_flexarr(i8* %0, i64 %1, i64 %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
store i8* %0, i8** %6
store i64 %1, i64* %7
store i64 %2, i64* %8
store i64 %3, i64* %9
%11 = load i64, i64* %7
%12 = load i64, i64* %8
%13 = load i64, i64* %9
%14 = call i32 @_sizeof_flexarr(i64* %10, i64 %11, i64 %12, i64 %13)
%15 = icmp ne i32 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %4
%17 = load i32, i32* @ENOMEM
store i32 %17, i32* @errno
store i8* null, i8** %5
br label %22
18: ; preds = %4
%19 = load i8*, i8** %6
%20 = load i64, i64* %10
%21 = call i8* @realloc(i8* %19, i64 %20)
store i8* %21, i8** %5
br label %22
22: ; preds = %18, %16
%23 = load i8*, i8** %5
ret i8* %23
}

LLVM IR (-O2):
@ENOMEM = global i32 0
@errno = global i32 0
define noalias i8* @_realloc_flexarr(i8* nocapture %0, i64 %1, i64 %2, i64 %3) {
%5 = alloca i64
%6 = bitcast i64* %5 to i8*
%7 = call i32 @_sizeof_flexarr(i64* %5, i64 %1, i64 %2, i64 %3)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = load i32, i32* @ENOMEM
store i32 %10, i32* @errno
br label %14
11: ; preds = %4
%12 = load i64, i64* %5
%13 = call i8* @realloc(i8* %0, i64 %12)
br label %14
14: ; preds = %11, %9
%15 = phi i8* [ %13, %11 ], [ null, %9 ]
ret i8* %15
}