#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*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void escape_string(char *string, char c) {
  int i;
  char d;
  int inescape = 0;
  char tmpstring[1024];
  char *p = tmpstring;
  memset(tmpstring, 0, 1024);
  for (i = 0; i < strlen(string); i++) {
    d = string[i];
    if ((inescape) && (d == c)) {
      inescape = 0;
      continue;
    }
    *p = d;
    p++;
    if (d == c)
      inescape = 1;
  }
  strcpy(string, tmpstring);
}


x86 assembly (clang, -O0):
<escape_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movl   $0x0,-0x18(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x428(%rbp)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x42c(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x42c(%rbp),%eax
cmp    %ecx,%eax
jge    1212 <escape_string+0xe2>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x11(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11ca <escape_string+0x9a>
movsbl -0x11(%rbp),%eax
movsbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
jne    11ca <escape_string+0x9a>
movl   $0x0,-0x18(%rbp)
jmp    1204 <escape_string+0xd4>
mov    -0x11(%rbp),%cl
mov    -0x428(%rbp),%rax
mov    %cl,(%rax)
mov    -0x428(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x428(%rbp)
movsbl -0x11(%rbp),%eax
movsbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
jne    11ff <escape_string+0xcf>
movl   $0x1,-0x18(%rbp)
jmp    1204 <escape_string+0xd4>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1174 <escape_string+0x44>
mov    -0x8(%rbp),%rdi
lea    -0x420(%rbp),%rsi
call   1030 <strcpy@plt>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<escape_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %esi,%r14d
mov    %rdi,%r13
mov    %rsp,%r12
xor    %ebx,%ebx
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    %r13,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11b0 <escape_string+0x80>
xor    %ebp,%ebp
jmp    119c <escape_string+0x6c>
nopl   0x0(%rax,%rax,1)
mov    %al,(%r12)
add    $0x1,%r12
cmp    %r14b,%al
mov    $0x1,%eax
cmove  %eax,%ebx
mov    %ebx,%r15d
add    $0x1,%rbp
mov    %r13,%rdi
call   1040 <strlen@plt>
cltq
mov    %r15d,%ebx
cmp    %rax,%rbp
jge    11b0 <escape_string+0x80>
movzbl 0x0(%r13,%rbp,1),%eax
test   %ebx,%ebx
je     1170 <escape_string+0x40>
xor    %r15d,%r15d
cmp    %r14b,%al
je     1186 <escape_string+0x56>
jmp    1170 <escape_string+0x40>
mov    %rsp,%rsi
mov    %r13,%rdi
call   1030 <strcpy@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @escape_string(i8* %0, i8 signext %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 1024)
%6 = call i32 @strlen(i8* %0)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %27
8: ; preds = %2, %20
%9 = phi i64 [ %23, %20 ], [ 0, %2 ]
%10 = phi i8* [ %22, %20 ], [ %4, %2 ]
%11 = phi i32 [ %21, %20 ], [ 0, %2 ]
%12 = getelementptr inbounds i8, i8* %0, i64 %9
%13 = load i8, i8* %12
%14 = icmp ne i32 %11, 0
%15 = icmp eq i8 %13, %1
%16 = select i1 %14, i1 %15, i1 false
br i1 %16, label %20, label %17
17: ; preds = %8
store i8 %13, i8* %10
%18 = getelementptr inbounds i8, i8* %10, i64 1
%19 = select i1 %15, i32 1, i32 %11
br label %20
20: ; preds = %17, %8
%21 = phi i32 [ 0, %8 ], [ %19, %17 ]
%22 = phi i8* [ %10, %8 ], [ %18, %17 ]
%23 = add nuw nsw i64 %9, 1
%24 = call i32 @strlen(i8* %0)
%25 = sext i32 %24 to i64
%26 = icmp slt i64 %23, %25
br i1 %26, label %8, label %27
27: ; preds = %20, %2
%28 = call i32 @strcpy(i8* %0, i8* %4)
ret void
}