#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 find(char const *, char const *, int);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int /*<<< orphan*/ printf(char *);
int strlen(char const *);
char *get_between(const char *buf, int maxlen, const char *f, const char *t) {
  int a = find(f, buf, maxlen);
  if (a < 0)
    return NULL;
  int new_start = a + strlen(f);
  if (new_start >= maxlen)
    return NULL;
  int b = find(t, &buf[new_start], maxlen - new_start);
  if (b < 0)
    return NULL;
  char *tmp = malloc(b + 1);
  if (!tmp) {
    printf("out of memory\n");
    return NULL;
  }
  tmp[b] = '\0';
  memcpy(&tmp[0], &buf[new_start], b);
  return tmp;
}


x86 assembly (clang, -O0):
<get_between>:
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    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1060 <find@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1191 <get_between+0x41>
movq   $0x0,-0x8(%rbp)
jmp    1255 <get_between+0x105>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     11c3 <get_between+0x73>
movq   $0x0,-0x8(%rbp)
jmp    1255 <get_between+0x105>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x30(%rbp),%rax
add    %rax,%rsi
mov    -0x14(%rbp),%edx
sub    -0x30(%rbp),%edx
call   1060 <find@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    11f7 <get_between+0xa7>
movq   $0x0,-0x8(%rbp)
jmp    1255 <get_between+0x105>
mov    -0x34(%rbp),%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    122a <get_between+0xda>
lea    0xde8(%rip),%rdi
call   1040 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1255 <get_between+0x105>
mov    -0x40(%rbp),%rax
movslq -0x34(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x30(%rbp),%rax
add    %rax,%rsi
mov    -0x34(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_between>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r15
mov    %rdx,%rbx
mov    %esi,%r12d
mov    %rdi,%r14
mov    %rdx,%rdi
mov    %r14,%rsi
mov    %r12d,%edx
call   1060 <find@plt>
test   %eax,%eax
js     11d9 <get_between+0x89>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
add    %ebp,%eax
cmp    %r12d,%eax
jge    11d9 <get_between+0x89>
movslq %eax,%rcx
add    %rcx,%r14
sub    %eax,%r12d
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12d,%edx
call   1060 <find@plt>
test   %eax,%eax
js     11d9 <get_between+0x89>
mov    %eax,%r15d
lea    0x1(%r15),%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     11cd <get_between+0x7d>
mov    %rax,%rbx
mov    %r15d,%eax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1050 <memcpy@plt>
jmp    11db <get_between+0x8b>
lea    0xe2c(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"out of memory\0A\00"
define i8* @get_between(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%14 = load i8*, i8** %8
%15 = load i8*, i8** %6
%16 = load i32, i32* %7
%17 = call i32 @find(i8* %14, i8* %15, i32 %16)
store i32 %17, i32* %10
%18 = load i32, i32* %10
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %4
store i8* null, i8** %5
br label %65
21: ; preds = %4
%22 = load i32, i32* %10
%23 = load i8*, i8** %8
%24 = call i32 @strlen(i8* %23)
%25 = add nsw i32 %22, %24
store i32 %25, i32* %11
%26 = load i32, i32* %11
%27 = load i32, i32* %7
%28 = icmp sge i32 %26, %27
br i1 %28, label %29, label %30
29: ; preds = %21
store i8* null, i8** %5
br label %65
30: ; preds = %21
%31 = load i8*, i8** %9
%32 = load i8*, i8** %6
%33 = load i32, i32* %11
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i32, i32* %7
%37 = load i32, i32* %11
%38 = sub nsw i32 %36, %37
%39 = call i32 @find(i8* %31, i8* %35, i32 %38)
store i32 %39, i32* %12
%40 = load i32, i32* %12
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %30
store i8* null, i8** %5
br label %65
43: ; preds = %30
%44 = load i32, i32* %12
%45 = add nsw i32 %44, 1
%46 = call i8* @malloc(i32 %45)
store i8* %46, i8** %13
%47 = load i8*, i8** %13
%48 = icmp ne i8* %47, null
br i1 %48, label %51, label %49
49: ; preds = %43
%50 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %5
br label %65
51: ; preds = %43
%52 = load i8*, i8** %13
%53 = load i32, i32* %12
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %52, i64 %54
store i8 0, i8* %55
%56 = load i8*, i8** %13
%57 = getelementptr inbounds i8, i8* %56, i64 0
%58 = load i8*, i8** %6
%59 = load i32, i32* %11
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %58, i64 %60
%62 = load i32, i32* %12
%63 = call i32 @memcpy(i8* %57, i8* %61, i32 %62)
%64 = load i8*, i8** %13
store i8* %64, i8** %5
br label %65
65: ; preds = %51, %49, %42, %29, %20
%66 = load i8*, i8** %5
ret i8* %66
}

LLVM IR (-O2):
@str = [14 x i8] c"out of memory\00"
define i8* @get_between(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = tail call i32 @find(i8* %2, i8* %0, i32 %1)
%6 = icmp slt i32 %5, 0
br i1 %6, label %27, label %7
7: ; preds = %4
%8 = tail call i32 @strlen(i8* %2)
%9 = add nsw i32 %8, %5
%10 = icmp slt i32 %9, %1
br i1 %10, label %11, label %27
11: ; preds = %7
%12 = sext i32 %9 to i64
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = sub nsw i32 %1, %9
%15 = tail call i32 @find(i8* %3, i8* %13, i32 %14)
%16 = icmp slt i32 %15, 0
br i1 %16, label %27, label %17
17: ; preds = %11
%18 = add nuw nsw i32 %15, 1
%19 = tail call i8* @malloc(i32 %18)
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %27
23: ; preds = %17
%24 = zext i32 %15 to i64
%25 = getelementptr inbounds i8, i8* %19, i64 %24
store i8 0, i8* %25
%26 = tail call i32 @memcpy(i8* %19, i8* %13, i32 %15)
br label %27
27: ; preds = %7, %21, %23, %11, %4
%28 = phi i8* [ null, %4 ], [ null, %7 ], [ null, %11 ], [ %19, %23 ], [ null, %21 ]
ret i8* %28
}