#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);
int strlen(char const *);
char *strstr(char *, char const *);
void remove_path_string(char *p, const char *str) {
  char *p_ptr = p;
  size_t str_len = strlen(str) - 1;
  size_t p_len = strlen(p);
  while (p_ptr = strstr(p, str)) {
    memmove(p_ptr, p_ptr + str_len, p_len - (size_t)(p_ptr - p));
    p[p_len - (str_len)] = 0;
    p_len -= str_len;
  }
}


x86 assembly (clang, -O0):
<remove_path_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
cltq
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11cb <remove_path_string+0x9b>
mov    -0x18(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
sub    %rax,%rdx
call   1040 <memmove@plt>
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x28(%rbp)
jmp    1169 <remove_path_string+0x39>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_path_string>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r12
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1030 <strlen@plt>
mov    %eax,%r15d
mov    %r12,%rdi
mov    %r14,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     11ab <remove_path_string+0x7b>
add    $0xffffffff,%ebp
movslq %ebp,%rbp
movslq %r15d,%rbx
mov    %r12,%r15
sub    %rbp,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    (%rax,%rbp,1),%rsi
lea    (%r12,%rbx,1),%rdx
sub    %rax,%rdx
mov    %rax,%rdi
call   1040 <memmove@plt>
movb   $0x0,(%r15,%rbx,1)
sub    %rbp,%rbx
mov    %r12,%rdi
mov    %r14,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
jne    1180 <remove_path_string+0x50>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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