#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 tinyrl {
  int dummy;
};

/* Variables and functions */
char **realloc(char **, size_t);
char *strdup(char const *);
scalar_t__ strncmp(char const *, char const *, unsigned int);
char *tinyrl_get_line(struct tinyrl const *);
unsigned int tinyrl_get_point(struct tinyrl const *);
char **tinyrl_add_match(const struct tinyrl *this, unsigned start,
                        char **matches, const char *match) {
  const char *line;
  unsigned end;
  size_t len;
  char **m;
  line = tinyrl_get_line(this);
  end = tinyrl_get_point(this);
  if (strncmp(match, line + start, end - start) != 0)
    return matches;
  len = 0;
  if (matches)
    for (m = matches; *m; m++)
      len++;
  matches = realloc(matches, (len + 2) * sizeof(*matches));
  matches[len] = strdup(match);
  matches[len + 1] = NULL;
  return matches;
}


x86 assembly (clang, -O0):
<tinyrl_add_match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <tinyrl_get_line@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <tinyrl_get_point@plt>
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x14(%rbp),%eax
add    %rax,%rsi
mov    -0x34(%rbp),%edx
sub    -0x14(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     11b0 <tinyrl_add_match+0x60>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1245 <tinyrl_add_match+0xf5>
movq   $0x0,-0x40(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11fb <tinyrl_add_match+0xab>
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
cmpq   $0x0,(%rax)
je     11f6 <tinyrl_add_match+0xa6>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    -0x48(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x48(%rbp)
jmp    11cb <tinyrl_add_match+0x7b>
jmp    11fb <tinyrl_add_match+0xab>
mov    -0x20(%rbp),%rdi
mov    -0x40(%rbp),%rsi
add    $0x2,%rsi
shl    $0x3,%rsi
call   1060 <realloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
mov    -0x40(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
mov    -0x40(%rbp),%rcx
movq   $0x0,0x8(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tinyrl_add_match>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %esi,%r15d
mov    %rdi,%rbp
call   1050 <tinyrl_get_line@plt>
mov    %rax,%r12
mov    %rbp,%rdi
call   1040 <tinyrl_get_point@plt>
mov    %r15d,%esi
add    %r12,%rsi
sub    %r15d,%eax
mov    %r14,%rdi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11db <tinyrl_add_match+0x8b>
test   %rbx,%rbx
je     11b1 <tinyrl_add_match+0x61>
cmpq   $0x0,(%rbx)
je     11b1 <tinyrl_add_match+0x61>
xor    %eax,%eax
nopl   0x0(%rax)
lea    0x1(%rax),%rbp
cmpq   $0x0,0x8(%rbx,%rax,8)
mov    %rbp,%rax
jne    11a0 <tinyrl_add_match+0x50>
jmp    11b3 <tinyrl_add_match+0x63>
xor    %ebp,%ebp
lea    0x10(,%rbp,8),%rsi
mov    %rbx,%rdi
call   1060 <realloc@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1070 <strdup@plt>
mov    %rax,(%rbx,%rbp,8)
movq   $0x0,0x8(%rbx,%rbp,8)
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tinyrl = type { i32 }
define i8** @tinyrl_add_match(%struct.tinyrl* %0, i32 %1, i8** %2, i8* %3) {
%5 = alloca i8**
%6 = alloca %struct.tinyrl*
%7 = alloca i32
%8 = alloca i8**
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i64
%13 = alloca i8**
store %struct.tinyrl* %0, %struct.tinyrl** %6
store i32 %1, i32* %7
store i8** %2, i8*** %8
store i8* %3, i8** %9
%14 = load %struct.tinyrl*, %struct.tinyrl** %6
%15 = call i8* @tinyrl_get_line(%struct.tinyrl* %14)
store i8* %15, i8** %10
%16 = load %struct.tinyrl*, %struct.tinyrl** %6
%17 = call i32 @tinyrl_get_point(%struct.tinyrl* %16)
store i32 %17, i32* %11
%18 = load i8*, i8** %9
%19 = load i8*, i8** %10
%20 = load i32, i32* %7
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i32, i32* %11
%24 = load i32, i32* %7
%25 = sub i32 %23, %24
%26 = call i64 @strncmp(i8* %18, i8* %22, i32 %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %4
%29 = load i8**, i8*** %8
store i8** %29, i8*** %5
br label %62
30: ; preds = %4
store i64 0, i64* %12
%31 = load i8**, i8*** %8
%32 = icmp ne i8** %31, null
br i1 %32, label %33, label %46
33: ; preds = %30
%34 = load i8**, i8*** %8
store i8** %34, i8*** %13
br label %35
35: ; preds = %42, %33
%36 = load i8**, i8*** %13
%37 = load i8*, i8** %36
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %45
39: ; preds = %35
%40 = load i64, i64* %12
%41 = add i64 %40, 1
store i64 %41, i64* %12
br label %42
42: ; preds = %39
%43 = load i8**, i8*** %13
%44 = getelementptr inbounds i8*, i8** %43, i32 1
store i8** %44, i8*** %13
br label %35
45: ; preds = %35
br label %46
46: ; preds = %45, %30
%47 = load i8**, i8*** %8
%48 = load i64, i64* %12
%49 = add i64 %48, 2
%50 = mul i64 %49, 8
%51 = call i8** @realloc(i8** %47, i64 %50)
store i8** %51, i8*** %8
%52 = load i8*, i8** %9
%53 = call i8* @strdup(i8* %52)
%54 = load i8**, i8*** %8
%55 = load i64, i64* %12
%56 = getelementptr inbounds i8*, i8** %54, i64 %55
store i8* %53, i8** %56
%57 = load i8**, i8*** %8
%58 = load i64, i64* %12
%59 = add i64 %58, 1
%60 = getelementptr inbounds i8*, i8** %57, i64 %59
store i8* null, i8** %60
%61 = load i8**, i8*** %8
store i8** %61, i8*** %5
br label %62
62: ; preds = %46, %28
%63 = load i8**, i8*** %5
ret i8** %63
}

LLVM IR (-O2):
%struct.tinyrl = type { i32 }
define i8** @tinyrl_add_match(%struct.tinyrl* %0, i32 %1, i8** %2, i8* %3) {
%5 = tail call i8* @tinyrl_get_line(%struct.tinyrl* %0)
%6 = tail call i32 @tinyrl_get_point(%struct.tinyrl* %0)
%7 = zext i32 %1 to i64
%8 = getelementptr inbounds i8, i8* %5, i64 %7
%9 = sub i32 %6, %1
%10 = tail call i64 @strncmp(i8* %3, i8* %8, i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %33
12: ; preds = %4
%13 = icmp eq i8** %2, null
br i1 %13, label %24, label %14
14: ; preds = %12
%15 = load i8*, i8** %2
%16 = icmp eq i8* %15, null
br i1 %16, label %24, label %17
17: ; preds = %14, %17
%18 = phi i8** [ %21, %17 ], [ %2, %14 ]
%19 = phi i64 [ %20, %17 ], [ 0, %14 ]
%20 = add i64 %19, 1
%21 = getelementptr inbounds i8*, i8** %18, i64 1
%22 = load i8*, i8** %21
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %17
24: ; preds = %17, %14, %12
%25 = phi i64 [ 0, %12 ], [ 0, %14 ], [ %20, %17 ]
%26 = shl i64 %25, 3
%27 = add i64 %26, 16
%28 = tail call i8** @realloc(i8** %2, i64 %27)
%29 = tail call i8* @strdup(i8* %3)
%30 = getelementptr inbounds i8*, i8** %28, i64 %25
store i8* %29, i8** %30
%31 = add i64 %25, 1
%32 = getelementptr inbounds i8*, i8** %28, i64 %31
store i8* null, i8** %32
br label %33
33: ; preds = %4, %24
%34 = phi i8** [ %28, %24 ], [ %2, %4 ]
ret i8** %34
}