#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*/ memmove(char *, char const *, size_t);
size_t strlen(char const *);
char *strstr(char const *, char const *);
char *strstrmove(char *whither, const char *whence, const char *restrict str) {
  const char *stop = str == NULL ? NULL : strstr(whence, str);
  size_t n = stop == NULL ? strlen(whence) : (size_t)(stop - whence);
  char *r = stop == NULL ? NULL : (whither + n);
  memmove(whither, whence, n);
  whither[n] = 0;
  return r;
}


x86 assembly (clang, -O0):
<strstrmove>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    115a <strstrmove+0x2a>
xor    %eax,%eax
mov    %rax,-0x38(%rbp)
jmp    116b <strstrmove+0x3b>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1190 <strstrmove+0x60>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x40(%rbp)
jmp    119f <strstrmove+0x6f>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11bd <strstrmove+0x8d>
xor    %eax,%eax
mov    %rax,-0x48(%rbp)
jmp    11c9 <strstrmove+0x99>
mov    -0x8(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <memmove@plt>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strstrmove>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
test   %rdx,%rdx
je     115f <strstrmove+0x2f>
mov    %r15,%rdi
mov    %rdx,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     115f <strstrmove+0x2f>
mov    %rax,%rbx
sub    %r15,%rbx
lea    (%r14,%rbx,1),%r12
jmp    116d <strstrmove+0x3d>
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbx
xor    %r12d,%r12d
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1040 <memmove@plt>
movb   $0x0,(%r14,%rbx,1)
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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