#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*/ strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char const *, char const *);
char *strextract(const char input_str[], char output_str[],
                 const char search_start[], const char search_end[]) {
  if (input_str == NULL)
    return NULL;
  char *begin, *end = NULL;
  if ((begin = strstr(input_str, search_start))) {
    begin += strlen(search_start);
    if ((end = strstr(begin, search_end))) {
      strncpy(output_str, begin, end - begin);
      output_str[end - begin] = '\0';
    }
  }
  return end;
}


x86 assembly (clang, -O0):
<strextract>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1160 <strextract+0x30>
movq   $0x0,-0x8(%rbp)
jmp    11f1 <strextract+0xc1>
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     11e9 <strextract+0xb9>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     11e4 <strextract+0xb4>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    -0x30(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11e9 <strextract+0xb9>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strextract>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     1191 <strextract+0x61>
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdx,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     1191 <strextract+0x61>
mov    %rax,%rbx
mov    %r12,%rdi
call   1040 <strlen@plt>
cltq
add    %rax,%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     1191 <strextract+0x61>
mov    %rax,%r15
mov    %rax,%r12
sub    %rbx,%r12
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%r14,%r12,1)
jmp    1194 <strextract+0x64>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @strextract(i8* %0, i8* %1, i8* %2, i8* nocapture %3) {
%5 = icmp eq i8* %0, null
br i1 %5, label %22, label %6
6: ; preds = %4
%7 = tail call i8* @strstr(i8* %0, i8* dereferenceable(1) %2)
%8 = icmp eq i8* %7, null
br i1 %8, label %22, label %9
9: ; preds = %6
%10 = tail call i32 @strlen(i8* %2)
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %7, i64 %11
%13 = tail call i8* @strstr(i8* %12, i8* dereferenceable(1) %3)
%14 = icmp eq i8* %13, null
br i1 %14, label %22, label %15
15: ; preds = %9
%16 = ptrtoint i8* %13 to i64
%17 = ptrtoint i8* %12 to i64
%18 = sub i64 %16, %17
%19 = trunc i64 %18 to i32
%20 = tail call i32 @strncpy(i8* %1, i8* %12, i32 %19)
%21 = getelementptr inbounds i8, i8* %1, i64 %18
store i8 0, i8* %21
br label %22
22: ; preds = %6, %15, %9, %4
%23 = phi i8* [ null, %4 ], [ %13, %15 ], [ null, %9 ], [ null, %6 ]
ret i8* %23
}