#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*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strncat(char *, char *, int);
void mcparmprinter_string(char *f, void *vptr) {
  char **v = (char **)vptr;
  char *p;
  if (!*v) {
    *f = '\0';
    return;
  }
  strcpy(f, "");
  for (p = *v; *p != '\0'; p++) {
    switch (*p) {
    case '\n':
      strcat(f, "\\n");
      break;
    case '\r':
      strcat(f, "\\r");
      break;
    case '"':
      strcat(f, "\\\"");
      break;
    case '\\':
      strcat(f, "\\\\");
      break;
    default:
      strncat(f, p, 1);
    }
  }
}


x86 assembly (clang, -O0):
<mcparmprinter_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1162 <mcparmprinter_string+0x32>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
jmp    1254 <mcparmprinter_string+0x124>
mov    -0x8(%rbp),%rdi
lea    0xe9b(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1254 <mcparmprinter_string+0x124>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x24(%rbp)
sub    $0xa,%eax
je     11d8 <mcparmprinter_string+0xa8>
jmp    11a5 <mcparmprinter_string+0x75>
mov    -0x24(%rbp),%eax
sub    $0xd,%eax
je     11ed <mcparmprinter_string+0xbd>
jmp    11b6 <mcparmprinter_string+0x86>
mov    -0x24(%rbp),%eax
sub    $0x22,%eax
je     1202 <mcparmprinter_string+0xd2>
jmp    11c7 <mcparmprinter_string+0x97>
mov    -0x24(%rbp),%eax
sub    $0x5c,%eax
je     1217 <mcparmprinter_string+0xe7>
jmp    122c <mcparmprinter_string+0xfc>
mov    -0x8(%rbp),%rdi
lea    0xe1d(%rip),%rsi
call   1050 <strcat@plt>
jmp    123e <mcparmprinter_string+0x10e>
mov    -0x8(%rbp),%rdi
lea    0xe0b(%rip),%rsi
call   1050 <strcat@plt>
jmp    123e <mcparmprinter_string+0x10e>
mov    -0x8(%rbp),%rdi
lea    0xdf9(%rip),%rsi
call   1050 <strcat@plt>
jmp    123e <mcparmprinter_string+0x10e>
mov    -0x8(%rbp),%rdi
lea    0xde7(%rip),%rsi
call   1050 <strcat@plt>
jmp    123e <mcparmprinter_string+0x10e>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x1,%edx
call   1040 <strncat@plt>
jmp    1243 <mcparmprinter_string+0x113>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    117d <mcparmprinter_string+0x4d>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mcparmprinter_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
cmpq   $0x0,(%rsi)
je     120d <mcparmprinter_string+0xdd>
mov    %rsi,%rbx
lea    0xeb6(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    (%rbx),%rbx
mov    (%rbx),%al
test   %al,%al
je     1211 <mcparmprinter_string+0xe1>
lea    0xe92(%rip),%r15
lea    0xe8e(%rip),%r12
lea    0xe8a(%rip),%r13
lea    0xe86(%rip),%rbp
jmp    11ac <mcparmprinter_string+0x7c>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <strncat@plt>
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1211 <mcparmprinter_string+0xe1>
movsbl %al,%eax
cmp    $0x21,%eax
jg     11d0 <mcparmprinter_string+0xa0>
cmp    $0xa,%eax
je     11f0 <mcparmprinter_string+0xc0>
cmp    $0xd,%eax
jne    1190 <mcparmprinter_string+0x60>
mov    %r14,%rdi
mov    %r12,%rsi
call   1050 <strcat@plt>
jmp    11a0 <mcparmprinter_string+0x70>
nopl   0x0(%rax,%rax,1)
cmp    $0x22,%eax
je     1200 <mcparmprinter_string+0xd0>
cmp    $0x5c,%eax
jne    1190 <mcparmprinter_string+0x60>
mov    %r14,%rdi
mov    %rbp,%rsi
call   1050 <strcat@plt>
jmp    11a0 <mcparmprinter_string+0x70>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <strcat@plt>
jmp    11a0 <mcparmprinter_string+0x70>
nopl   (%rax)
mov    %r14,%rdi
mov    %r13,%rsi
call   1050 <strcat@plt>
jmp    11a0 <mcparmprinter_string+0x70>
movb   $0x0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c"\\n\00"
@.str.2 = [3 x i8] c"\\r\00"
@.str.3 = [3 x i8] c"\\\22\00"
@.str.4 = [3 x i8] c"\\\\\00"
define void @mcparmprinter_string(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = bitcast i8* %7 to i8**
store i8** %8, i8*** %5
%9 = load i8**, i8*** %5
%10 = load i8*, i8** %9
%11 = icmp ne i8* %10, null
br i1 %11, label %14, label %12
12: ; preds = %2
%13 = load i8*, i8** %3
store i8 0, i8* %13
br label %48
14: ; preds = %2
%15 = load i8*, i8** %3
%16 = call i32 @strcpy(i8* %15, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%17 = load i8**, i8*** %5
%18 = load i8*, i8** %17
store i8* %18, i8** %6
br label %19
19: ; preds = %45, %14
%20 = load i8*, i8** %6
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %48
24: ; preds = %19
%25 = load i8*, i8** %6
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
switch i32 %27, label %40 [
i32 10, label %28
i32 13, label %31
i32 34, label %34
i32 92, label %37
]
28: ; preds = %24
%29 = load i8*, i8** %3
%30 = call i32 @strcat(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %44
31: ; preds = %24
%32 = load i8*, i8** %3
%33 = call i32 @strcat(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %44
34: ; preds = %24
%35 = load i8*, i8** %3
%36 = call i32 @strcat(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %44
37: ; preds = %24
%38 = load i8*, i8** %3
%39 = call i32 @strcat(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %44
40: ; preds = %24
%41 = load i8*, i8** %3
%42 = load i8*, i8** %6
%43 = call i32 @strncat(i8* %41, i8* %42, i32 1)
br label %44
44: ; preds = %40, %37, %34, %31, %28
br label %45
45: ; preds = %44
%46 = load i8*, i8** %6
%47 = getelementptr inbounds i8, i8* %46, i32 1
store i8* %47, i8** %6
br label %19
48: ; preds = %12, %19
ret void
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c"\\n\00"
@.str.2 = [3 x i8] c"\\r\00"
@.str.3 = [3 x i8] c"\\\22\00"
@.str.4 = [3 x i8] c"\\\\\00"
define void @mcparmprinter_string(i8* %0, i8* nocapture %1) {
%3 = bitcast i8* %1 to i8**
%4 = load i8*, i8** %3
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %7
6: ; preds = %2
store i8 0, i8* %0
br label %30
7: ; preds = %2
%8 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%9 = load i8*, i8** %3
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 0
br i1 %11, label %30, label %12
12: ; preds = %7, %26
%13 = phi i8 [ %28, %26 ], [ %10, %7 ]
%14 = phi i8* [ %27, %26 ], [ %9, %7 ]
%15 = sext i8 %13 to i32
switch i32 %15, label %24 [
i32 10, label %16
i32 13, label %18
i32 34, label %20
i32 92, label %22
]
16: ; preds = %12
%17 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %26
18: ; preds = %12
%19 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %26
20: ; preds = %12
%21 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %26
22: ; preds = %12
%23 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %26
24: ; preds = %12
%25 = tail call i32 @strncat(i8* %0, i8* %14, i32 1)
br label %26
26: ; preds = %16, %18, %20, %22, %24
%27 = getelementptr inbounds i8, i8* %14, i64 1
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 0
br i1 %29, label %30, label %12
30: ; preds = %26, %7, %6
ret void
}