#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 */
char *malloc(int);
int strlen(char const *);
char *mpd_sanitizeArg(const char *arg) {
  size_t i;
  char *ret;
  register const char *c;
  register char *rc;
  ret = malloc(strlen(arg) * 2 + 1);
  c = arg;
  rc = ret;
  for (i = strlen(arg) + 1; i != 0; --i) {
    if (*c == '"' || *c == '\\')
      *rc++ = '\\';
    *(rc++) = *(c++);
  }
  return ret;
}


x86 assembly (clang, -O0):
<mpd_sanitizeArg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
shl    $0x1,%edi
add    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11d8 <mpd_sanitizeArg+0xb8>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
je     1193 <mpd_sanitizeArg+0x73>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    11a5 <mpd_sanitizeArg+0x85>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x5c,(%rax)
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    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1168 <mpd_sanitizeArg+0x48>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mpd_sanitizeArg>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
lea    (%rax,%rax,1),%edi
add    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
inc    %ecx
je     11ec <mpd_sanitizeArg+0xcc>
movslq %ecx,%rsi
test   $0x1,%sil
jne    1161 <mpd_sanitizeArg+0x41>
mov    %r14,%rdx
test   %eax,%eax
jne    118f <mpd_sanitizeArg+0x6f>
jmp    11ec <mpd_sanitizeArg+0xcc>
mov    (%rbx),%cl
cmp    $0x5c,%cl
je     1170 <mpd_sanitizeArg+0x50>
mov    %r14,%rdx
cmp    $0x22,%cl
jne    117d <mpd_sanitizeArg+0x5d>
mov    %r14,%rdx
add    $0x1,%rdx
movb   $0x5c,(%r14)
mov    (%rbx),%cl
add    $0x1,%rbx
mov    %cl,(%rdx)
add    $0x1,%rdx
add    $0xffffffffffffffff,%rsi
test   %eax,%eax
je     11ec <mpd_sanitizeArg+0xcc>
xor    %eax,%eax
jmp    11bc <mpd_sanitizeArg+0x9c>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movb   $0x5c,0x1(%rdx)
add    $0x2,%rdx
movzbl 0x1(%rbx,%rax,1),%ecx
mov    %cl,(%rdx)
add    $0x1,%rdx
add    $0x2,%rax
cmp    %rax,%rsi
je     11ec <mpd_sanitizeArg+0xcc>
movzbl (%rbx,%rax,1),%ecx
cmp    $0x5c,%cl
je     11ca <mpd_sanitizeArg+0xaa>
cmp    $0x22,%cl
jne    11d5 <mpd_sanitizeArg+0xb5>
movb   $0x5c,(%rdx)
add    $0x1,%rdx
movzbl (%rbx,%rax,1),%ecx
mov    %cl,(%rdx)
movzbl 0x1(%rbx,%rax,1),%ecx
cmp    $0x5c,%cl
je     11a0 <mpd_sanitizeArg+0x80>
cmp    $0x22,%cl
je     11a0 <mpd_sanitizeArg+0x80>
add    $0x1,%rdx
jmp    11ad <mpd_sanitizeArg+0x8d>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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