#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 *, size_t);
size_t strlen(char *);
char *strstr(char *, char *);
char *strtok(char *, char *);
char *substract_names(char *str_a, char *str_b) {
  size_t firstLen = strlen(str_a);
  size_t secondLen = strlen(str_b);
  char *token = strtok(str_b, " ");
  while (token) {
    size_t length = strlen(token);
    char *substr = strstr(str_a, token);
    while (substr) {
      size_t index = substr - str_a;
      memmove(&str_a[index], &str_a[index + length + 1], firstLen - index);
      substr = strstr(str_a, token);
    }
    token = strtok(NULL, " ");
  }
  return str_a;
}


x86 assembly (clang, -O0):
<substract_names>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe8b(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1218 <substract_names+0xd8>
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11ff <substract_names+0xbf>
mov    -0x38(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
add    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x40(%rbp),%rax
add    -0x30(%rbp),%rax
add    $0x1,%rax
add    %rax,%rsi
mov    -0x18(%rbp),%rdx
sub    -0x40(%rbp),%rdx
call   1040 <memmove@plt>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x38(%rbp)
jmp    11a7 <substract_names+0x67>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdf6(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x28(%rbp)
jmp    117e <substract_names+0x3e>
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<substract_names>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %rax,%r14
lea    0xea0(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strtok@plt>
test   %rax,%rax
je     11f0 <substract_names+0xb0>
mov    %rax,%r12
lea    0xe85(%rip),%r15
jmp    1192 <substract_names+0x52>
nopl   (%rax)
xor    %edi,%edi
mov    %r15,%rsi
call   1050 <strtok@plt>
mov    %rax,%r12
test   %rax,%rax
je     11f0 <substract_names+0xb0>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <strstr@plt>
test   %rax,%rax
je     1180 <substract_names+0x40>
mov    %rax,%rbp
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %rax,%r13
add    $0x1,%r13
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbp,%rax
sub    %rbx,%rax
lea    (%rax,%r13,1),%rsi
add    %rbx,%rsi
mov    %r14,%rdx
sub    %rax,%rdx
mov    %rbp,%rdi
call   1040 <memmove@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <strstr@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    11c0 <substract_names+0x80>
jmp    1180 <substract_names+0x40>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define i8* @substract_names(i8* returned %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = tail call i8* @strtok(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %29, label %6
6: ; preds = %2
%7 = ptrtoint i8* %0 to i64
br label %8
8: ; preds = %6, %26
%9 = phi i8* [ %4, %6 ], [ %27, %26 ]
%10 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* %9)
%11 = icmp eq i8* %10, null
br i1 %11, label %26, label %12
12: ; preds = %8
%13 = tail call i64 @strlen(i8* %9)
%14 = add i64 %13, 1
br label %15
15: ; preds = %12, %15
%16 = phi i8* [ %10, %12 ], [ %24, %15 ]
%17 = ptrtoint i8* %16 to i64
%18 = sub i64 %17, %7
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = add i64 %14, %18
%21 = getelementptr inbounds i8, i8* %0, i64 %20
%22 = sub i64 %3, %18
%23 = tail call i32 @memmove(i8* %19, i8* %21, i64 %22)
%24 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* %9)
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %15
26: ; preds = %15, %8
%27 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %8
29: ; preds = %26, %2
ret i8* %0
}