#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 */
struct rule_message_t {
  int dummy;
};
typedef int ssize_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct rule_message_t **realloc(struct rule_message_t **, int);
int /*<<< orphan*/ stderr;
struct rule_message_t **add_to_matches(struct rule_message_t *matches[],
                                       ssize_t *matches_reserved_length,
                                       struct rule_message_t *message,
                                       ssize_t *index_last_written_to) {
  *index_last_written_to = *index_last_written_to + 1;
  if (*index_last_written_to + 1 > *matches_reserved_length) {
    struct rule_message_t **temp;
    temp = realloc(matches, sizeof(struct rule_message_t *) *
                                (*matches_reserved_length + 20));
    if (temp == NULL) {
      fprintf(stderr, "Couldn't reallocate matches\n");
      exit(EXIT_FAILURE);
    }
    *matches_reserved_length = *matches_reserved_length + 20;
    matches = temp;
  }
  matches[*index_last_written_to] = message;
  return matches;
}


x86 assembly (clang, -O0):
<add_to_matches>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jle    11cf <add_to_matches+0x9f>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
add    $0x14,%eax
cltq
shl    $0x3,%rax
mov    %eax,%esi
call   1040 <realloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b8 <add_to_matches+0x88>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
lea    0xe5b(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x14,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%rdx
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movslq (%rcx),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_to_matches>:
push   %r15
push   %r14
push   %rbx
mov    %rcx,%rbx
mov    %rdx,%r14
mov    (%rcx),%edx
lea    0x1(%rdx),%eax
mov    %eax,(%rcx)
add    $0x2,%edx
mov    (%rsi),%ecx
cmp    %ecx,%edx
jle    1168 <add_to_matches+0x38>
mov    %rsi,%r15
lea    0xa0(,%rcx,8),%esi
call   1040 <realloc@plt>
test   %rax,%rax
je     1177 <add_to_matches+0x47>
mov    %rax,%rdi
addl   $0x14,(%r15)
mov    (%rbx),%eax
cltq
mov    %r14,(%rdi,%rax,8)
mov    %rdi,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
lea    0xe79(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.rule_message_t = type { i32 }
@stderr = global i32 0
@.str = [29 x i8] c"Couldn't reallocate matches\0A\00"
@EXIT_FAILURE = global i32 0
define %struct.rule_message_t** @add_to_matches(%struct.rule_message_t** %0, i32* %1, %struct.rule_message_t* %2, i32* %3) {
%5 = alloca %struct.rule_message_t**
%6 = alloca i32*
%7 = alloca %struct.rule_message_t*
%8 = alloca i32*
%9 = alloca %struct.rule_message_t**
store %struct.rule_message_t** %0, %struct.rule_message_t*** %5
store i32* %1, i32** %6
store %struct.rule_message_t* %2, %struct.rule_message_t** %7
store i32* %3, i32** %8
%10 = load i32*, i32** %8
%11 = load i32, i32* %10
%12 = add nsw i32 %11, 1
%13 = load i32*, i32** %8
store i32 %12, i32* %13
%14 = load i32*, i32** %8
%15 = load i32, i32* %14
%16 = add nsw i32 %15, 1
%17 = load i32*, i32** %6
%18 = load i32, i32* %17
%19 = icmp sgt i32 %16, %18
br i1 %19, label %20, label %42
20: ; preds = %4
%21 = load %struct.rule_message_t**, %struct.rule_message_t*** %5
%22 = load i32*, i32** %6
%23 = load i32, i32* %22
%24 = add nsw i32 %23, 20
%25 = sext i32 %24 to i64
%26 = mul i64 8, %25
%27 = trunc i64 %26 to i32
%28 = call %struct.rule_message_t** @realloc(%struct.rule_message_t** %21, i32 %27)
store %struct.rule_message_t** %28, %struct.rule_message_t*** %9
%29 = load %struct.rule_message_t**, %struct.rule_message_t*** %9
%30 = icmp eq %struct.rule_message_t** %29, null
br i1 %30, label %31, label %36
31: ; preds = %20
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %20
%37 = load i32*, i32** %6
%38 = load i32, i32* %37
%39 = add nsw i32 %38, 20
%40 = load i32*, i32** %6
store i32 %39, i32* %40
%41 = load %struct.rule_message_t**, %struct.rule_message_t*** %9
store %struct.rule_message_t** %41, %struct.rule_message_t*** %5
br label %42
42: ; preds = %36, %4
%43 = load %struct.rule_message_t*, %struct.rule_message_t** %7
%44 = load %struct.rule_message_t**, %struct.rule_message_t*** %5
%45 = load i32*, i32** %8
%46 = load i32, i32* %45
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds %struct.rule_message_t*, %struct.rule_message_t** %44, i64 %47
store %struct.rule_message_t* %43, %struct.rule_message_t** %48
%49 = load %struct.rule_message_t**, %struct.rule_message_t*** %5
ret %struct.rule_message_t** %49
}

LLVM IR (-O2):
%struct.rule_message_t = type { i32 }
@stderr = global i32 0
@.str = [29 x i8] c"Couldn't reallocate matches\0A\00"
@EXIT_FAILURE = global i32 0
define %struct.rule_message_t** @add_to_matches(%struct.rule_message_t** %0, i32* nocapture %1, %struct.rule_message_t* %2, i32* nocapture %3) {
%5 = load i32, i32* %3
%6 = add nsw i32 %5, 1
store i32 %6, i32* %3
%7 = add nsw i32 %5, 2
%8 = load i32, i32* %1
%9 = icmp sgt i32 %7, %8
br i1 %9, label %10, label %24
10: ; preds = %4
%11 = shl i32 %8, 3
%12 = add i32 %11, 160
%13 = tail call %struct.rule_message_t** @realloc(%struct.rule_message_t** %0, i32 %12)
%14 = icmp eq %struct.rule_message_t** %13, null
br i1 %14, label %15, label %20
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = tail call i32 @exit(i32 %18)
unreachable
20: ; preds = %10
%21 = load i32, i32* %1
%22 = add nsw i32 %21, 20
store i32 %22, i32* %1
%23 = load i32, i32* %3
br label %24
24: ; preds = %20, %4
%25 = phi i32 [ %23, %20 ], [ %6, %4 ]
%26 = phi %struct.rule_message_t** [ %13, %20 ], [ %0, %4 ]
%27 = sext i32 %25 to i64
%28 = getelementptr inbounds %struct.rule_message_t*, %struct.rule_message_t** %26, i64 %27
store %struct.rule_message_t* %2, %struct.rule_message_t** %28
ret %struct.rule_message_t** %26
}