#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 alloc_vector_memory(char **, unsigned int *, unsigned int, unsigned int);
unsigned int round_next_p_two(unsigned int);
int vector_expand(char **data, unsigned int *size, unsigned int *capacity,
                  unsigned int data_size, unsigned int expanded_size) {
  if (*size + expanded_size > *capacity) {
    unsigned int new_capacity = round_next_p_two(*capacity + expanded_size);
    return alloc_vector_memory(data, capacity, data_size, new_capacity);
  }
  return 0;
}


x86 assembly (clang, -O0):
<vector_expand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
add    -0x28(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%eax
jbe    117c <vector_expand+0x5c>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
add    -0x28(%rbp),%edi
call   1040 <round_next_p_two@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x2c(%rbp),%ecx
call   1030 <alloc_vector_memory@plt>
mov    %eax,-0x4(%rbp)
jmp    1183 <vector_expand+0x63>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vector_expand>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbp
mov    (%rsi),%eax
add    %r8d,%eax
mov    (%rdx),%edi
cmp    %edi,%eax
jbe    1154 <vector_expand+0x34>
mov    %ecx,%r14d
mov    %rdx,%rbx
add    %r8d,%edi
call   1040 <round_next_p_two@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
mov    %eax,%ecx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <alloc_vector_memory@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @vector_expand(i8** %0, i32* nocapture %1, i32* %2, i32 %3, i32 %4) {
%6 = load i32, i32* %1
%7 = add i32 %6, %4
%8 = load i32, i32* %2
%9 = icmp ugt i32 %7, %8
br i1 %9, label %10, label %14
10: ; preds = %5
%11 = add i32 %8, %4
%12 = tail call i32 @round_next_p_two(i32 %11)
%13 = tail call i32 @alloc_vector_memory(i8** %0, i32* %2, i32 %3, i32 %12)
br label %14
14: ; preds = %5, %10
%15 = phi i32 [ %13, %10 ], [ 0, %5 ]
ret i32 %15
}