#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 */
scalar_t__ ar_has_char(char *, char);
int /*<<< orphan*/ memmove(char *, char *, scalar_t__);
scalar_t__ strlen(char *);
char *g_p_escape_once(char *input, char *match) {
  char *ptr = input;
  int c = 0;
  while (0x0 != ptr[0]) {
    if (ptr[0] == 0x5C && (0x0 != ptr[1] && 0 == ar_has_char(match, ptr[1]))) {
      memmove(ptr, &ptr[1], strlen(&ptr[1]) + 1);
      c++;
    }
    ptr++;
    c++;
  }
  return input;
}


x86 assembly (clang, -O0):
<g_p_escape_once>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
je     11f9 <g_p_escape_once+0xc9>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    11df <g_p_escape_once+0xaf>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
je     11df <g_p_escape_once+0xaf>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%esi
call   1040 <ar_has_char@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    11df <g_p_escape_once+0xaf>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1050 <memmove@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114f <g_p_escape_once+0x1f>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<g_p_escape_once>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
lea    0x1(%rdi),%rbx
jmp    1158 <g_p_escape_once+0x28>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
test   %al,%al
je     1194 <g_p_escape_once+0x64>
add    $0x1,%rbx
movzbl -0x1(%rbx),%eax
cmp    $0x5c,%al
jne    1150 <g_p_escape_once+0x20>
movzbl (%rbx),%eax
test   %al,%al
je     1154 <g_p_escape_once+0x24>
movsbl %al,%esi
mov    %r15,%rdi
call   1040 <ar_has_char@plt>
test   %rax,%rax
jne    1154 <g_p_escape_once+0x24>
lea    -0x1(%rbx),%r12
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <memmove@plt>
jmp    1154 <g_p_escape_once+0x24>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @g_p_escape_once(i8* returned %0, i8* %1) {
br label %3
3: ; preds = %17, %2
%4 = phi i8* [ %0, %2 ], [ %18, %17 ]
%5 = load i8, i8* %4
switch i8 %5, label %17 [
i8 0, label %19
i8 92, label %6
]
6: ; preds = %3
%7 = getelementptr inbounds i8, i8* %4, i64 1
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 0
br i1 %9, label %17, label %10
10: ; preds = %6
%11 = tail call i64 @ar_has_char(i8* %1, i8 signext %8)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = tail call i64 @strlen(i8* %7)
%15 = add nsw i64 %14, 1
%16 = tail call i32 @memmove(i8* %4, i8* %7, i64 %15)
br label %17
17: ; preds = %3, %13, %10, %6
%18 = getelementptr inbounds i8, i8* %4, i64 1
br label %3
19: ; preds = %3
ret i8* %0
}