#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(int);
int /*<<< orphan*/ printf(char *, char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
void strBetween(char *instr, char *outstr, char *start, char *end) {
  char *s;
  char *f;
  s = strstr(instr, start);
  if (s == NULL) {
    printf("Fail: Couldn't find start '%s' in '%s' (strBetween)\n", start,
           instr);
    exit(1);
  }
  f = strstr(instr, end);
  if (f == NULL) {
    printf("Fail: Couldn't find end '%s' in '%s' (strBetween)\n", start, instr);
    exit(1);
  }
  strncpy(outstr, s + strlen(start), f - (s + strlen(start)));
  if (outstr[f - (s + strlen(start)) - 1] == '\r')
    outstr[f - (s + strlen(start)) - 1] = 0;
  outstr[f - (s + strlen(start))] = 0;
}


x86 assembly (clang, -O0):
<strBetween>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a5 <strBetween+0x55>
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    0xe6a(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <strstr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11df <strBetween+0x8f>
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    0xe65(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x70(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x58(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x68(%rbp),%rcx
mov    -0x60(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    %eax,%edx
mov    -0x50(%rbp),%rax
movslq %edx,%rdx
add    %rdx,%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x48(%rbp),%rdx
mov    -0x40(%rbp),%rcx
mov    %eax,%esi
mov    -0x38(%rbp),%rax
movslq %esi,%rsi
add    %rsi,%rdx
sub    %rdx,%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xd,%eax
jne    12d2 <strBetween+0x182>
mov    -0x10(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x88(%rbp),%rdx
mov    -0x80(%rbp),%rcx
mov    %eax,%esi
mov    -0x78(%rbp),%rax
movslq %esi,%rsi
add    %rsi,%rdx
sub    %rdx,%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xa0(%rbp),%rdx
mov    -0x98(%rbp),%rcx
mov    %eax,%esi
mov    -0x90(%rbp),%rax
movslq %esi,%rsi
add    %rsi,%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strBetween>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r12
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r13
mov    %rdx,%rsi
call   1070 <strstr@plt>
test   %rax,%rax
je     1210 <strBetween+0xc0>
mov    %rax,%rbp
mov    %r13,%rdi
mov    %r12,%rsi
call   1070 <strstr@plt>
test   %rax,%rax
je     1219 <strBetween+0xc9>
mov    %rax,%r12
mov    %r15,%rdi
call   1040 <strlen@plt>
movslq %eax,%rbx
add    %rbp,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
add    %ebp,%eax
mov    %r12d,%edx
sub    %eax,%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strncpy@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
add    %rbp,%rax
not    %rax
add    %r12,%rax
cmpb   $0xd,(%r14,%rax,1)
jne    11ec <strBetween+0x9c>
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
add    %rbp,%rax
not    %rax
add    %r12,%rax
movb   $0x0,(%r14,%rax,1)
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
add    %rax,%rbp
sub    %rbp,%r12
movb   $0x0,(%r14,%r12,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xde9(%rip),%rdi
jmp    1220 <strBetween+0xd0>
lea    0xe15(%rip),%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1050 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [53 x i8] c"Fail: Couldn't find start '%s' in '%s' (strBetween)\0A\00"
@.str.1 = [51 x i8] c"Fail: Couldn't find end '%s' in '%s' (strBetween)\0A\00"
define void @strBetween(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%11 = load i8*, i8** %5
%12 = load i8*, i8** %7
%13 = call i8* @strstr(i8* %11, i8* %12)
store i8* %13, i8** %9
%14 = load i8*, i8** %9
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %21
16: ; preds = %4
%17 = load i8*, i8** %7
%18 = load i8*, i8** %5
%19 = call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8* %17, i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %4
%22 = load i8*, i8** %5
%23 = load i8*, i8** %8
%24 = call i8* @strstr(i8* %22, i8* %23)
store i8* %24, i8** %10
%25 = load i8*, i8** %10
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %32
27: ; preds = %21
%28 = load i8*, i8** %7
%29 = load i8*, i8** %5
%30 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i8* %28, i8* %29)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %21
%33 = load i8*, i8** %6
%34 = load i8*, i8** %9
%35 = load i8*, i8** %7
%36 = call i32 @strlen(i8* %35)
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %34, i64 %37
%39 = load i8*, i8** %10
%40 = load i8*, i8** %9
%41 = load i8*, i8** %7
%42 = call i32 @strlen(i8* %41)
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %40, i64 %43
%45 = ptrtoint i8* %39 to i64
%46 = ptrtoint i8* %44 to i64
%47 = sub i64 %45, %46
%48 = trunc i64 %47 to i32
%49 = call i32 @strncpy(i8* %33, i8* %38, i32 %48)
%50 = load i8*, i8** %6
%51 = load i8*, i8** %10
%52 = load i8*, i8** %9
%53 = load i8*, i8** %7
%54 = call i32 @strlen(i8* %53)
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %52, i64 %55
%57 = ptrtoint i8* %51 to i64
%58 = ptrtoint i8* %56 to i64
%59 = sub i64 %57, %58
%60 = sub nsw i64 %59, 1
%61 = getelementptr inbounds i8, i8* %50, i64 %60
%62 = load i8, i8* %61
%63 = sext i8 %62 to i32
%64 = icmp eq i32 %63, 13
br i1 %64, label %65, label %78
65: ; preds = %32
%66 = load i8*, i8** %6
%67 = load i8*, i8** %10
%68 = load i8*, i8** %9
%69 = load i8*, i8** %7
%70 = call i32 @strlen(i8* %69)
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8, i8* %68, i64 %71
%73 = ptrtoint i8* %67 to i64
%74 = ptrtoint i8* %72 to i64
%75 = sub i64 %73, %74
%76 = sub nsw i64 %75, 1
%77 = getelementptr inbounds i8, i8* %66, i64 %76
store i8 0, i8* %77
br label %78
78: ; preds = %65, %32
%79 = load i8*, i8** %6
%80 = load i8*, i8** %10
%81 = load i8*, i8** %9
%82 = load i8*, i8** %7
%83 = call i32 @strlen(i8* %82)
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i8, i8* %81, i64 %84
%86 = ptrtoint i8* %80 to i64
%87 = ptrtoint i8* %85 to i64
%88 = sub i64 %86, %87
%89 = getelementptr inbounds i8, i8* %79, i64 %88
store i8 0, i8* %89
ret void
}

LLVM IR (-O2):
@.str = [53 x i8] c"Fail: Couldn't find start '%s' in '%s' (strBetween)\0A\00"
@.str.1 = [51 x i8] c"Fail: Couldn't find end '%s' in '%s' (strBetween)\0A\00"
define void @strBetween(i8* %0, i8* %1, i8* %2, i8* nocapture %3) {
%5 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %2)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = tail call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i8* %2, i8* %0)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %4
%11 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) %3)
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = tail call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* %0)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %10
%17 = tail call i32 @strlen(i8* %2)
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %5, i64 %18
%20 = tail call i32 @strlen(i8* %2)
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %5, i64 %21
%23 = ptrtoint i8* %11 to i64
%24 = ptrtoint i8* %22 to i64
%25 = sub i64 %23, %24
%26 = trunc i64 %25 to i32
%27 = tail call i32 @strncpy(i8* %1, i8* %19, i32 %26)
%28 = tail call i32 @strlen(i8* %2)
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %5, i64 %29
%31 = ptrtoint i8* %30 to i64
%32 = xor i64 %31, -1
%33 = add i64 %32, %23
%34 = getelementptr inbounds i8, i8* %1, i64 %33
%35 = load i8, i8* %34
%36 = icmp eq i8 %35, 13
br i1 %36, label %37, label %45
37: ; preds = %16
%38 = tail call i32 @strlen(i8* %2)
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %5, i64 %39
%41 = ptrtoint i8* %40 to i64
%42 = xor i64 %41, -1
%43 = add i64 %42, %23
%44 = getelementptr inbounds i8, i8* %1, i64 %43
store i8 0, i8* %44
br label %45
45: ; preds = %37, %16
%46 = tail call i32 @strlen(i8* %2)
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %5, i64 %47
%49 = ptrtoint i8* %48 to i64
%50 = sub i64 %23, %49
%51 = getelementptr inbounds i8, i8* %1, i64 %50
store i8 0, i8* %51
ret void
}