#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 strlen(char const *);
void mpd_sanitizeArg_st(char *dest, const char *arg) {
  size_t i;
  register const char *c;
  register char *rc;
  c = arg;
  rc = dest;
  for (i = strlen(arg) + 1; i != 0; --i) {
    if (*c == '"' || *c == '\\') {
      *rc = '\\';
      rc++;
    }
    *(rc++) = *(c++);
  }
  *rc = '\0';
}


x86 assembly (clang, -O0):
<mpd_sanitizeArg_st>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11b3 <mpd_sanitizeArg_st+0xa3>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
je     116d <mpd_sanitizeArg_st+0x5d>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    1180 <mpd_sanitizeArg_st+0x70>
mov    -0x28(%rbp),%rax
movb   $0x5c,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%cl
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1142 <mpd_sanitizeArg_st+0x32>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mpd_sanitizeArg_st>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
inc    %ecx
je     11c0 <mpd_sanitizeArg_st+0xb0>
movslq %ecx,%rcx
test   $0x1,%cl
je     1159 <mpd_sanitizeArg_st+0x49>
mov    (%r14),%dl
cmp    $0x5c,%dl
je     1141 <mpd_sanitizeArg_st+0x31>
cmp    $0x22,%dl
jne    114b <mpd_sanitizeArg_st+0x3b>
movb   $0x5c,(%rbx)
add    $0x1,%rbx
mov    (%r14),%dl
add    $0x1,%r14
mov    %dl,(%rbx)
add    $0x1,%rbx
add    $0xffffffffffffffff,%rcx
test   %eax,%eax
je     11c0 <mpd_sanitizeArg_st+0xb0>
xor    %eax,%eax
jmp    118d <mpd_sanitizeArg_st+0x7d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movb   $0x5c,0x1(%rbx)
add    $0x2,%rbx
movzbl 0x1(%r14,%rax,1),%edx
mov    %dl,(%rbx)
add    $0x1,%rbx
add    $0x2,%rax
cmp    %rax,%rcx
je     11c0 <mpd_sanitizeArg_st+0xb0>
movzbl (%r14,%rax,1),%edx
cmp    $0x5c,%dl
je     119c <mpd_sanitizeArg_st+0x8c>
cmp    $0x22,%dl
jne    11a8 <mpd_sanitizeArg_st+0x98>
movb   $0x5c,(%rbx)
add    $0x1,%rbx
movzbl (%r14,%rax,1),%edx
mov    %dl,(%rbx)
movzbl 0x1(%r14,%rax,1),%edx
cmp    $0x5c,%dl
je     1170 <mpd_sanitizeArg_st+0x60>
cmp    $0x22,%dl
je     1170 <mpd_sanitizeArg_st+0x60>
add    $0x1,%rbx
jmp    117e <mpd_sanitizeArg_st+0x6e>
movb   $0x0,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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