#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_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
void *realloc(char **, size_t);
char **grow(char **entries, size_t num, size_t *max) {
  if (num >= *max) {
    void *t;
    *max = 2 * (*max + 1);
    t = realloc(entries, *max * sizeof *entries);
    if (!t) {
      perror("realloc");
      exit(EXIT_FAILURE);
    }
    entries = t;
  }
  return entries;
}


x86 assembly (clang, -O0):
<grow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%rax
jb     11b0 <grow+0x80>
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
shl    $0x1,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
shl    $0x3,%rsi
call   1030 <realloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a8 <grow+0x78>
lea    0xe6b(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grow>:
push   %rax
mov    (%rdx),%rax
cmp    %rsi,%rax
ja     115c <grow+0x2c>
lea    (%rax,%rax,1),%rcx
add    %rax,%rax
add    $0x2,%rax
mov    %rax,(%rdx)
lea    0x10(,%rcx,8),%rsi
call   1030 <realloc@plt>
test   %rax,%rax
je     1161 <grow+0x31>
mov    %rax,%rdi
mov    %rdi,%rax
pop    %rcx
ret
lea    0xe98(%rip),%rdi
call   1040 <perror@plt>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"realloc\00"
@EXIT_FAILURE = global i32 0
define i8** @grow(i8** %0, i64 %1, i64* %2) {
%4 = alloca i8**
%5 = alloca i64
%6 = alloca i64*
%7 = alloca i8*
store i8** %0, i8*** %4
store i64 %1, i64* %5
store i64* %2, i64** %6
%8 = load i64, i64* %5
%9 = load i64*, i64** %6
%10 = load i64, i64* %9
%11 = icmp uge i64 %8, %10
br i1 %11, label %12, label %32
12: ; preds = %3
%13 = load i64*, i64** %6
%14 = load i64, i64* %13
%15 = add i64 %14, 1
%16 = mul i64 2, %15
%17 = load i64*, i64** %6
store i64 %16, i64* %17
%18 = load i8**, i8*** %4
%19 = load i64*, i64** %6
%20 = load i64, i64* %19
%21 = mul i64 %20, 8
%22 = call i8* @realloc(i8** %18, i64 %21)
store i8* %22, i8** %7
%23 = load i8*, i8** %7
%24 = icmp ne i8* %23, null
br i1 %24, label %29, label %25
25: ; preds = %12
%26 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %12
%30 = load i8*, i8** %7
%31 = bitcast i8* %30 to i8**
store i8** %31, i8*** %4
br label %32
32: ; preds = %29, %3
%33 = load i8**, i8*** %4
ret i8** %33
}

LLVM IR (-O2):
@.str = [8 x i8] c"realloc\00"
@EXIT_FAILURE = global i32 0
define i8** @grow(i8** %0, i64 %1, i64* nocapture %2) {
%4 = load i64, i64* %2
%5 = icmp ugt i64 %4, %1
br i1 %5, label %18, label %6
6: ; preds = %3
%7 = shl i64 %4, 1
%8 = add i64 %7, 2
store i64 %8, i64* %2
%9 = shl i64 %8, 3
%10 = tail call i8* @realloc(i8** %0, i64 %9)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %6
%13 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %6
%17 = bitcast i8* %10 to i8**
br label %18
18: ; preds = %16, %3
%19 = phi i8** [ %17, %16 ], [ %0, %3 ]
ret i8** %19
}