#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 *dyad_realloc(char *, int);
void vec_expand(char **data, int *length, int *capacity, int memsz) {
  if (*length + 1 > *capacity) {
    if (*capacity == 0) {
      *capacity = 1;
    } else {
      *capacity <<= 1;
    }
    *data = dyad_realloc(*data, *capacity * memsz);
  }
}


x86 assembly (clang, -O0):
<vec_expand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jle    1183 <vec_expand+0x73>
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jne    1158 <vec_expand+0x48>
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
jmp    1163 <vec_expand+0x53>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
shl    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
imul   -0x1c(%rbp),%esi
call   1030 <dyad_realloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vec_expand>:
push   %rbx
mov    (%rdx),%eax
cmp    %eax,(%rsi)
jl     1137 <vec_expand+0x27>
mov    %rdi,%rbx
lea    (%rax,%rax,1),%edi
test   %eax,%eax
mov    $0x1,%esi
cmovne %edi,%esi
mov    %esi,(%rdx)
mov    (%rbx),%rdi
imul   %ecx,%esi
call   1030 <dyad_realloc@plt>
mov    %rax,(%rbx)
pop    %rbx
ret

LLVM IR (-O0):
define void @vec_expand(i8** %0, i32* %1, i32* %2, i32 %3) {
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
store i8** %0, i8*** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i32 %3, i32* %8
%9 = load i32*, i32** %6
%10 = load i32, i32* %9
%11 = add nsw i32 %10, 1
%12 = load i32*, i32** %7
%13 = load i32, i32* %12
%14 = icmp sgt i32 %11, %13
br i1 %14, label %15, label %34
15: ; preds = %4
%16 = load i32*, i32** %7
%17 = load i32, i32* %16
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = load i32*, i32** %7
store i32 1, i32* %20
br label %25
21: ; preds = %15
%22 = load i32*, i32** %7
%23 = load i32, i32* %22
%24 = shl i32 %23, 1
store i32 %24, i32* %22
br label %25
25: ; preds = %21, %19
%26 = load i8**, i8*** %5
%27 = load i8*, i8** %26
%28 = load i32*, i32** %7
%29 = load i32, i32* %28
%30 = load i32, i32* %8
%31 = mul nsw i32 %29, %30
%32 = call i8* @dyad_realloc(i8* %27, i32 %31)
%33 = load i8**, i8*** %5
store i8* %32, i8** %33
br label %34
34: ; preds = %25, %4
ret void
}

LLVM IR (-O2):
define void @vec_expand(i8** nocapture %0, i32* nocapture %1, i32* nocapture %2, i32 %3) {
%5 = load i32, i32* %1
%6 = load i32, i32* %2
%7 = icmp slt i32 %5, %6
br i1 %7, label %15, label %8
8: ; preds = %4
%9 = icmp eq i32 %6, 0
%10 = shl i32 %6, 1
%11 = select i1 %9, i32 1, i32 %10
store i32 %11, i32* %2
%12 = load i8*, i8** %0
%13 = mul nsw i32 %11, %3
%14 = tail call i8* @dyad_realloc(i8* %12, i32 %13)
store i8* %14, i8** %0
br label %15
15: ; preds = %8, %4
ret void
}