#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 */
char **realloc(char **, int);
void _extend(char **io_items[], int *io_count) {
  char **new_items = realloc(*io_items, sizeof(char *) * (*io_count + 1));
  if (!new_items)
    return;
  *io_items = new_items;
  new_items[*io_count] = NULL;
  *io_count += 1;
}


x86 assembly (clang, -O0):
<_extend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   1030 <realloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1151 <_extend+0x41>
jmp    117a <_extend+0x6a>
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq (%rcx),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_extend>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    (%rdi),%rdi
mov    (%rsi),%eax
lea    0x8(,%rax,8),%esi
call   1030 <realloc@plt>
test   %rax,%rax
je     1143 <_extend+0x33>
mov    %rax,(%r14)
movslq (%rbx),%rcx
movq   $0x0,(%rax,%rcx,8)
lea    0x1(%rcx),%eax
mov    %eax,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @_extend(i8*** %0, i32* %1) {
%3 = alloca i8***
%4 = alloca i32*
%5 = alloca i8**
store i8*** %0, i8**** %3
store i32* %1, i32** %4
%6 = load i8***, i8**** %3
%7 = load i8**, i8*** %6
%8 = load i32*, i32** %4
%9 = load i32, i32* %8
%10 = add nsw i32 %9, 1
%11 = sext i32 %10 to i64
%12 = mul i64 8, %11
%13 = trunc i64 %12 to i32
%14 = call i8** @realloc(i8** %7, i32 %13)
store i8** %14, i8*** %5
%15 = load i8**, i8*** %5
%16 = icmp ne i8** %15, null
br i1 %16, label %18, label %17
17: ; preds = %2
br label %29
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = load i8***, i8**** %3
store i8** %19, i8*** %20
%21 = load i8**, i8*** %5
%22 = load i32*, i32** %4
%23 = load i32, i32* %22
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %21, i64 %24
store i8* null, i8** %25
%26 = load i32*, i32** %4
%27 = load i32, i32* %26
%28 = add nsw i32 %27, 1
store i32 %28, i32* %26
br label %29
29: ; preds = %18, %17
ret void
}

LLVM IR (-O2):
define void @_extend(i8*** nocapture %0, i32* nocapture %1) {
%3 = load i8**, i8*** %0
%4 = load i32, i32* %1
%5 = shl i32 %4, 3
%6 = add i32 %5, 8
%7 = tail call i8** @realloc(i8** %3, i32 %6)
%8 = icmp eq i8** %7, null
br i1 %8, label %14, label %9
9: ; preds = %2
store i8** %7, i8*** %0
%10 = load i32, i32* %1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8*, i8** %7, i64 %11
store i8* null, i8** %12
%13 = add nsw i32 %10, 1
store i32 %13, i32* %1
br label %14
14: ; preds = %2, %9
ret void
}