#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__ strchr(char *, int);
void MwQuotecpy(char *p, char *q, char *b) {
  int c;
  while ((c = *q++)) {
    if (strchr(b, c))
      *p++ = '\\';
    *p++ = c;
  }
  *p = '\0';
}


x86 assembly (clang, -O0):
<MwQuotecpy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%eax
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     1185 <MwQuotecpy+0x75>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     116a <MwQuotecpy+0x5a>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x5c,(%rax)
mov    -0x1c(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
jmp    1124 <MwQuotecpy+0x14>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MwQuotecpy>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    (%rsi),%bpl
test   %bpl,%bpl
je     115e <MwQuotecpy+0x4e>
mov    %rdx,%r14
mov    %rsi,%r15
add    $0x1,%r15
jmp    1144 <MwQuotecpy+0x34>
xchg   %ax,%ax
mov    %bpl,(%rbx)
add    $0x1,%rbx
movzbl (%r15),%ebp
add    $0x1,%r15
test   %bpl,%bpl
je     115e <MwQuotecpy+0x4e>
movsbl %bpl,%esi
mov    %r14,%rdi
call   1030 <strchr@plt>
test   %rax,%rax
je     1130 <MwQuotecpy+0x20>
movb   $0x5c,(%rbx)
add    $0x1,%rbx
jmp    1130 <MwQuotecpy+0x20>
movb   $0x0,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @MwQuotecpy(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
br label %8
8: ; preds = %22, %3
%9 = load i8*, i8** %5
%10 = getelementptr inbounds i8, i8* %9, i32 1
store i8* %10, i8** %5
%11 = load i8, i8* %9
%12 = sext i8 %11 to i32
store i32 %12, i32* %7
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %27
14: ; preds = %8
%15 = load i8*, i8** %6
%16 = load i32, i32* %7
%17 = call i64 @strchr(i8* %15, i32 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %4
store i8 92, i8* %20
br label %22
22: ; preds = %19, %14
%23 = load i32, i32* %7
%24 = trunc i32 %23 to i8
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %4
store i8 %24, i8* %25
br label %8
27: ; preds = %8
%28 = load i8*, i8** %4
store i8 0, i8* %28
ret void
}

LLVM IR (-O2):
define void @MwQuotecpy(i8* nocapture writeonly %0, i8* nocapture %1, i8* %2) {
%4 = load i8, i8* %1
%5 = icmp eq i8 %4, 0
br i1 %5, label %21, label %6
6: ; preds = %3, %16
%7 = phi i8 [ %19, %16 ], [ %4, %3 ]
%8 = phi i8* [ %10, %16 ], [ %1, %3 ]
%9 = phi i8* [ %18, %16 ], [ %0, %3 ]
%10 = getelementptr inbounds i8, i8* %8, i64 1
%11 = sext i8 %7 to i32
%12 = tail call i64 @strchr(i8* %2, i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %6
%15 = getelementptr inbounds i8, i8* %9, i64 1
store i8 92, i8* %9
br label %16
16: ; preds = %14, %6
%17 = phi i8* [ %15, %14 ], [ %9, %6 ]
%18 = getelementptr inbounds i8, i8* %17, i64 1
store i8 %7, i8* %17
%19 = load i8, i8* %10
%20 = icmp eq i8 %19, 0
br i1 %20, label %21, label %6
21: ; preds = %16, %3
%22 = phi i8* [ %0, %3 ], [ %18, %16 ]
store i8 0, i8* %22
ret void
}