#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*/ strcpy(char *, char *);
long strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
void find_store_substring(char *src, char *cmp, char *dest) {
  char *pos;
  char *pos2;
  if ((pos = strstr(src, cmp)) != NULL) {
    if ((pos2 = strstr(pos, " ")) != NULL) {
      strncpy(dest, pos + strlen(cmp), pos2 - pos - strlen(cmp));
      dest[pos2 - pos - strlen(cmp)] = '\0';
    } else {
      strcpy(dest, pos + strlen(cmp));
    }
  }
}


x86 assembly (clang, -O0):
<find_store_substring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     124a <find_store_substring+0x10a>
mov    -0x20(%rbp),%rdi
lea    0xe86(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     121c <find_store_substring+0xdc>
mov    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x38(%rbp),%rcx
mov    %rax,%rdx
mov    -0x30(%rbp),%rax
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1245 <find_store_substring+0x105>
mov    -0x18(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x68(%rbp),%rsi
mov    -0x60(%rbp),%rdi
add    %rax,%rsi
call   1040 <strcpy@plt>
jmp    124a <find_store_substring+0x10a>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_store_substring>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
call   1070 <strstr@plt>
test   %rax,%rax
je     11ac <find_store_substring+0x5c>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x20,%esi
call   1060 <strchr@plt>
mov    %rax,%r12
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    (%rbx,%rax,1),%rsi
test   %r12,%r12
je     11b8 <find_store_substring+0x68>
sub    %rbx,%r12
mov    %r12d,%edx
sub    %eax,%edx
mov    %r14,%rdi
call   1030 <strncpy@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
sub    %rax,%r12
movb   $0x0,(%r14,%r12,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <strcpy@plt>

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
define void @find_store_substring(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%9 = load i8*, i8** %4
%10 = load i8*, i8** %5
%11 = call i8* @strstr(i8* %9, i8* %10)
store i8* %11, i8** %7
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %51
13: ; preds = %3
%14 = load i8*, i8** %7
%15 = call i8* @strstr(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %15, i8** %8
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %43
17: ; preds = %13
%18 = load i8*, i8** %6
%19 = load i8*, i8** %7
%20 = load i8*, i8** %5
%21 = call i64 @strlen(i8* %20)
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8*, i8** %8
%24 = load i8*, i8** %7
%25 = ptrtoint i8* %23 to i64
%26 = ptrtoint i8* %24 to i64
%27 = sub i64 %25, %26
%28 = load i8*, i8** %5
%29 = call i64 @strlen(i8* %28)
%30 = sub nsw i64 %27, %29
%31 = trunc i64 %30 to i32
%32 = call i32 @strncpy(i8* %18, i8* %22, i32 %31)
%33 = load i8*, i8** %6
%34 = load i8*, i8** %8
%35 = load i8*, i8** %7
%36 = ptrtoint i8* %34 to i64
%37 = ptrtoint i8* %35 to i64
%38 = sub i64 %36, %37
%39 = load i8*, i8** %5
%40 = call i64 @strlen(i8* %39)
%41 = sub nsw i64 %38, %40
%42 = getelementptr inbounds i8, i8* %33, i64 %41
store i8 0, i8* %42
br label %50
43: ; preds = %13
%44 = load i8*, i8** %6
%45 = load i8*, i8** %7
%46 = load i8*, i8** %5
%47 = call i64 @strlen(i8* %46)
%48 = getelementptr inbounds i8, i8* %45, i64 %47
%49 = call i32 @strcpy(i8* %44, i8* %48)
br label %50
50: ; preds = %43, %17
br label %51
51: ; preds = %50, %3
ret void
}

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