#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*/ exit(int);
int /*<<< orphan*/ memset(void **, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
void **realloc(void **, int);
void array_resize(void **data, int size, int *data_size) {
  void **items = realloc(data, sizeof(void *) * size);
  if (!items) {
    printf("eror on realloc array\n");
    exit(1);
  }
  memset(items + *data_size, 0, size - *data_size);
  *data_size = size;
}


x86 assembly (clang, -O0):
<array_resize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%esi
call   1050 <realloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118b <array_resize+0x4b>
lea    0xe84(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq (%rax),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0xc(%rbp),%edx
mov    -0x18(%rbp),%rax
sub    (%rax),%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0xc(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<array_resize>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%ebx
lea    0x0(,%rbx,8),%esi
call   1050 <realloc@plt>
test   %rax,%rax
je     1177 <array_resize+0x37>
movslq (%r14),%rcx
lea    (%rax,%rcx,8),%rdi
mov    %ebx,%edx
sub    %ecx,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    %ebx,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe82(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"eror on realloc array\0A\00"
define void @array_resize(i8** %0, i32 %1, i32* %2) {
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8**
store i8** %0, i8*** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%8 = load i8**, i8*** %4
%9 = load i32, i32* %5
%10 = sext i32 %9 to i64
%11 = mul i64 8, %10
%12 = trunc i64 %11 to i32
%13 = call i8** @realloc(i8** %8, i32 %12)
store i8** %13, i8*** %7
%14 = load i8**, i8*** %7
%15 = icmp ne i8** %14, null
br i1 %15, label %19, label %16
16: ; preds = %3
%17 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %3
%20 = load i8**, i8*** %7
%21 = load i32*, i32** %6
%22 = load i32, i32* %21
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8*, i8** %20, i64 %23
%25 = load i32, i32* %5
%26 = load i32*, i32** %6
%27 = load i32, i32* %26
%28 = sub nsw i32 %25, %27
%29 = call i32 @memset(i8** %24, i32 0, i32 %28)
%30 = load i32, i32* %5
%31 = load i32*, i32** %6
store i32 %30, i32* %31
ret void
}

LLVM IR (-O2):
@str = [22 x i8] c"eror on realloc array\00"
define void @array_resize(i8** %0, i32 %1, i32* nocapture %2) {
%4 = shl i32 %1, 3
%5 = tail call i8** @realloc(i8** %0, i32 %4)
%6 = icmp eq i8** %5, null
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %3
%11 = load i32, i32* %2
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8*, i8** %5, i64 %12
%14 = sub nsw i32 %1, %11
%15 = tail call i32 @memset(i8** %13, i32 0, i32 %14)
store i32 %1, i32* %2
ret void
}