#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 */
char *malloc(int);
size_t strlen(char *);
char *strstr(char *, char *);
char *getBetweenTags(char *haystack, char *start, char *stop) {
  char *tmp = strstr(haystack, start);
  int i, c = strlen(tmp) - strlen(strstr(haystack, stop)) - strlen(start);
  char *newstr;
  newstr = malloc(c + 1);
  for (i = 0; i < c; i++)
    newstr[i] = tmp[i + strlen(start)];
  return newstr;
}


x86 assembly (clang, -O0):
<getBetweenTags>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edi
add    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    1200 <getBetweenTags+0xd0>
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
movslq -0x24(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x50(%rbp),%rcx
mov    %rax,%rdx
mov    -0x48(%rbp),%rax
add    %rdx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x30(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11b1 <getBetweenTags+0x81>
mov    -0x30(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getBetweenTags>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r13
mov    %rsi,%r12
mov    %rdi,%rbx
call   1060 <strstr@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1030 <strlen@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %r13,%rsi
call   1060 <strstr@plt>
mov    %rax,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %rax,%r13
add    %rax,%rbx
mov    %r15d,%ebp
sub    %ebx,%ebp
lea    0x1(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,%r12
test   %ebp,%ebp
jle    11b9 <getBetweenTags+0x79>
add    %r13,%r14
not    %ebx
add    %ebx,%r15d
add    $0x1,%r15
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <memcpy@plt>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @getBetweenTags(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%11 = load i8*, i8** %4
%12 = load i8*, i8** %5
%13 = call i8* @strstr(i8* %11, i8* %12)
store i8* %13, i8** %7
%14 = load i8*, i8** %7
%15 = call i64 @strlen(i8* %14)
%16 = load i8*, i8** %4
%17 = load i8*, i8** %6
%18 = call i8* @strstr(i8* %16, i8* %17)
%19 = call i64 @strlen(i8* %18)
%20 = sub i64 %15, %19
%21 = load i8*, i8** %5
%22 = call i64 @strlen(i8* %21)
%23 = sub i64 %20, %22
%24 = trunc i64 %23 to i32
store i32 %24, i32* %9
%25 = load i32, i32* %9
%26 = add nsw i32 %25, 1
%27 = call i8* @malloc(i32 %26)
store i8* %27, i8** %10
store i32 0, i32* %8
br label %28
28: ; preds = %45, %3
%29 = load i32, i32* %8
%30 = load i32, i32* %9
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %48
32: ; preds = %28
%33 = load i8*, i8** %7
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = load i8*, i8** %5
%37 = call i64 @strlen(i8* %36)
%38 = add i64 %35, %37
%39 = getelementptr inbounds i8, i8* %33, i64 %38
%40 = load i8, i8* %39
%41 = load i8*, i8** %10
%42 = load i32, i32* %8
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
store i8 %40, i8* %44
br label %45
45: ; preds = %32
%46 = load i32, i32* %8
%47 = add nsw i32 %46, 1
store i32 %47, i32* %8
br label %28
48: ; preds = %28
%49 = load i8*, i8** %10
ret i8* %49
}

LLVM IR (-O2):
define noalias i8* @getBetweenTags(i8* %0, i8* nocapture %1, i8* nocapture %2) {
%4 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1)
%5 = tail call i64 @strlen(i8* dereferenceable(1) %4)
%6 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %2)
%7 = tail call i64 @strlen(i8* dereferenceable(1) %6)
%8 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%9 = add i64 %7, %8
%10 = sub i64 %5, %9
%11 = trunc i64 %10 to i32
%12 = add nsw i32 %11, 1
%13 = tail call i8* @malloc(i32 %12)
%14 = icmp sgt i32 %11, 0
br i1 %14, label %15, label %21
15: ; preds = %3
%16 = getelementptr i8, i8* %4, i64 %8
%17 = xor i64 %9, -1
%18 = add i64 %5, %17
%19 = and i64 %18, 4294967295
%20 = add nuw nsw i64 %19, 1
br label %21
21: ; preds = %15, %3
ret i8* %13
}