#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*/ abort();
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
int *realloc(int *, int);
int *resizeArray(int *data, int newsz, int oldsz) {
  data = realloc(data, newsz * sizeof(int));
  if (data == NULL)
    abort();
  if (newsz > oldsz)
    memset(data + oldsz, 0, sizeof(int) * (newsz - oldsz));
  return data;
}


x86 assembly (clang, -O0):
<resizeArray>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%esi
call   1050 <realloc@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    116b <resizeArray+0x3b>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jle    119b <resizeArray+0x6b>
mov    -0x8(%rbp),%rdi
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0xc(%rbp),%eax
sub    -0x10(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resizeArray>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %esi,%ebx
lea    0x0(,%rbx,4),%esi
call   1050 <realloc@plt>
test   %rax,%rax
je     116b <resizeArray+0x3b>
mov    %rax,%r14
sub    %ebp,%ebx
jle    1163 <resizeArray+0x33>
movslq %ebp,%rax
lea    (%r14,%rax,4),%rdi
shl    $0x2,%ebx
xor    %esi,%esi
mov    %ebx,%edx
call   1040 <memset@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %eax,%eax
call   1030 <abort@plt>

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

LLVM IR (-O2):
define i32* @resizeArray(i32* %0, i32 %1, i32 %2) {
%4 = shl i32 %1, 2
%5 = tail call i32* @realloc(i32* %0, i32 %4)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 (...) @abort()
unreachable
9: ; preds = %3
%10 = icmp sgt i32 %1, %2
br i1 %10, label %11, label %17
11: ; preds = %9
%12 = sext i32 %2 to i64
%13 = getelementptr inbounds i32, i32* %5, i64 %12
%14 = sub nsw i32 %1, %2
%15 = shl i32 %14, 2
%16 = tail call i32 @memset(i32* %13, i32 0, i32 %15)
br label %17
17: ; preds = %11, %9
ret i32* %5
}