#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ append_char(unsigned char **, int *, int *,
                               unsigned char const);
int /*<<< orphan*/ append_string(unsigned char **, int *, int *, ...);
int /*<<< orphan*/ snprintf(unsigned char *, int, char *, unsigned char const);
void append_string_quoted(unsigned char **p_t, int *p_a, int *p_u,
                          const unsigned char *s) {
  unsigned char buf[16];
  if (!s || !*s)
    return;
  for (; *s; ++s) {
    switch (*s) {
    case '\t':
      append_string(p_t, p_a, p_u, "\\t");
      break;
    case '\r':
      append_string(p_t, p_a, p_u, "\\r");
      break;
    case '\n':
      append_string(p_t, p_a, p_u, "\\n");
      break;
    case '\'':
      append_string(p_t, p_a, p_u, "\\\'");
      break;
    case '\"':
      append_string(p_t, p_a, p_u, "\\\"");
      break;
    case '\\':
      append_string(p_t, p_a, p_u, "\\\\");
      break;
    default:
      if (*s < ' ' || *s == 0177) {
        snprintf(buf, sizeof(buf), "\\%03o", *s);
        append_string(p_t, p_a, p_u, buf);
      } else {
        append_char(p_t, p_a, p_u, *s);
      }
      break;
    }
  }
}


x86 assembly (clang, -O0):
<append_string_quoted>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1160 <append_string_quoted+0x30>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1165 <append_string_quoted+0x35>
jmp    1329 <append_string_quoted+0x1f9>
jmp    116a <append_string_quoted+0x3a>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     1329 <append_string_quoted+0x1f9>
mov    -0x20(%rbp),%rax
movzbl (%rax),%eax
mov    %eax,-0x34(%rbp)
sub    $0x9,%eax
je     11e4 <append_string_quoted+0xb4>
jmp    118f <append_string_quoted+0x5f>
mov    -0x34(%rbp),%eax
sub    $0xa,%eax
je     1222 <append_string_quoted+0xf2>
jmp    11a0 <append_string_quoted+0x70>
mov    -0x34(%rbp),%eax
sub    $0xd,%eax
je     1203 <append_string_quoted+0xd3>
jmp    11b1 <append_string_quoted+0x81>
mov    -0x34(%rbp),%eax
sub    $0x22,%eax
je     1260 <append_string_quoted+0x130>
jmp    11c2 <append_string_quoted+0x92>
mov    -0x34(%rbp),%eax
sub    $0x27,%eax
je     1241 <append_string_quoted+0x111>
jmp    11d3 <append_string_quoted+0xa3>
mov    -0x34(%rbp),%eax
sub    $0x5c,%eax
je     127f <append_string_quoted+0x14f>
jmp    129e <append_string_quoted+0x16e>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe09(%rip),%rcx
mov    $0x0,%al
call   1030 <append_string@plt>
jmp    1313 <append_string_quoted+0x1e3>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xded(%rip),%rcx
mov    $0x0,%al
call   1030 <append_string@plt>
jmp    1313 <append_string_quoted+0x1e3>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xdd1(%rip),%rcx
mov    $0x0,%al
call   1030 <append_string@plt>
jmp    1313 <append_string_quoted+0x1e3>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xdb5(%rip),%rcx
mov    $0x0,%al
call   1030 <append_string@plt>
jmp    1313 <append_string_quoted+0x1e3>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xd99(%rip),%rcx
mov    $0x0,%al
call   1030 <append_string@plt>
jmp    1313 <append_string_quoted+0x1e3>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xd7d(%rip),%rcx
mov    $0x0,%al
call   1030 <append_string@plt>
jmp    1313 <append_string_quoted+0x1e3>
mov    -0x20(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x20,%eax
jl     12be <append_string_quoted+0x18e>
mov    -0x20(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x7f,%eax
jne    12f6 <append_string_quoted+0x1c6>
lea    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    $0x10,%esi
lea    0xd40(%rip),%rdx
movzbl (%rax),%ecx
call   1040 <snprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    -0x30(%rbp),%rcx
mov    $0x0,%al
call   1030 <append_string@plt>
jmp    130e <append_string_quoted+0x1de>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rax
movzbl (%rax),%ecx
call   1050 <append_char@plt>
jmp    1313 <append_string_quoted+0x1e3>
jmp    1318 <append_string_quoted+0x1e8>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    116a <append_string_quoted+0x3a>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<append_string_quoted>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %rcx,%rcx
je     124f <append_string_quoted+0x11f>
mov    %rcx,%rbx
mov    (%rcx),%al
test   %al,%al
je     124f <append_string_quoted+0x11f>
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
add    $0x1,%rbx
mov    %rsp,%rbp
lea    0xe95(%rip),%r13
jmp    118e <append_string_quoted+0x5e>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
lea    0xf23(%rip),%rcx
nopl   (%rax)
xor    %eax,%eax
call   1030 <append_string@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
movzbl %al,%ecx
cmp    $0x27,%cl
ja     11c0 <append_string_quoted+0x90>
movslq 0x0(%r13,%rcx,4),%rdx
add    %r13,%rdx
jmp    *%rdx
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
lea    0xef6(%rip),%rcx
jmp    1180 <append_string_quoted+0x50>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    $0x5c,%al
jne    11d6 <append_string_quoted+0xa6>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
lea    0xedb(%rip),%rcx
jmp    1180 <append_string_quoted+0x50>
cmp    $0x20,%al
jb     122a <append_string_quoted+0xfa>
cmp    $0x7f,%al
je     122a <append_string_quoted+0xfa>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1050 <append_char@plt>
jmp    1187 <append_string_quoted+0x57>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
lea    0xea5(%rip),%rcx
jmp    1180 <append_string_quoted+0x50>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
lea    0xe9c(%rip),%rcx
jmp    1180 <append_string_quoted+0x50>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
lea    0xe84(%rip),%rcx
jmp    1180 <append_string_quoted+0x50>
mov    %rbp,%rdi
mov    $0x10,%esi
lea    0xe79(%rip),%rdx
call   1040 <snprintf@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %rbp,%rcx
jmp    1180 <append_string_quoted+0x50>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\\t\00"
@.str.1 = [3 x i8] c"\\r\00"
@.str.2 = [3 x i8] c"\\n\00"
@.str.3 = [3 x i8] c"\\'\00"
@.str.4 = [3 x i8] c"\\\22\00"
@.str.5 = [3 x i8] c"\\\\\00"
@.str.6 = [6 x i8] c"\\%03o\00"
define void @append_string_quoted(i8** %0, i32* %1, i32* %2, i8* %3) {
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca [16 x i8]
store i8** %0, i8*** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i8* %3, i8** %8
%10 = load i8*, i8** %8
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %4
%13 = load i8*, i8** %8
%14 = load i8, i8* %13
%15 = icmp ne i8 %14, 0
br i1 %15, label %17, label %16
16: ; preds = %12, %4
br label %88
17: ; preds = %12
br label %18
18: ; preds = %85, %17
%19 = load i8*, i8** %8
%20 = load i8, i8* %19
%21 = icmp ne i8 %20, 0
br i1 %21, label %22, label %88
22: ; preds = %18
%23 = load i8*, i8** %8
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
switch i32 %25, label %56 [
i32 9, label %26
i32 13, label %31
i32 10, label %36
i32 39, label %41
i32 34, label %46
i32 92, label %51
]
26: ; preds = %22
%27 = load i8**, i8*** %5
%28 = load i32*, i32** %6
%29 = load i32*, i32** %7
%30 = call i32 (i8**, i32*, i32*, ...) @append_string(i8** %27, i32* %28, i32* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %84
31: ; preds = %22
%32 = load i8**, i8*** %5
%33 = load i32*, i32** %6
%34 = load i32*, i32** %7
%35 = call i32 (i8**, i32*, i32*, ...) @append_string(i8** %32, i32* %33, i32* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %84
36: ; preds = %22
%37 = load i8**, i8*** %5
%38 = load i32*, i32** %6
%39 = load i32*, i32** %7
%40 = call i32 (i8**, i32*, i32*, ...) @append_string(i8** %37, i32* %38, i32* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %84
41: ; preds = %22
%42 = load i8**, i8*** %5
%43 = load i32*, i32** %6
%44 = load i32*, i32** %7
%45 = call i32 (i8**, i32*, i32*, ...) @append_string(i8** %42, i32* %43, i32* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %84
46: ; preds = %22
%47 = load i8**, i8*** %5
%48 = load i32*, i32** %6
%49 = load i32*, i32** %7
%50 = call i32 (i8**, i32*, i32*, ...) @append_string(i8** %47, i32* %48, i32* %49, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %84
51: ; preds = %22
%52 = load i8**, i8*** %5
%53 = load i32*, i32** %6
%54 = load i32*, i32** %7
%55 = call i32 (i8**, i32*, i32*, ...) @append_string(i8** %52, i32* %53, i32* %54, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %84
56: ; preds = %22
%57 = load i8*, i8** %8
%58 = load i8, i8* %57
%59 = zext i8 %58 to i32
%60 = icmp slt i32 %59, 32
br i1 %60, label %66, label %61
61: ; preds = %56
%62 = load i8*, i8** %8
%63 = load i8, i8* %62
%64 = zext i8 %63 to i32
%65 = icmp eq i32 %64, 127
br i1 %65, label %66, label %76
66: ; preds = %61, %56
%67 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%68 = load i8*, i8** %8
%69 = load i8, i8* %68
%70 = call i32 @snprintf(i8* %67, i32 16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8 zeroext %69)
%71 = load i8**, i8*** %5
%72 = load i32*, i32** %6
%73 = load i32*, i32** %7
%74 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%75 = call i32 (i8**, i32*, i32*, ...) @append_string(i8** %71, i32* %72, i32* %73, i8* %74)
br label %83
76: ; preds = %61
%77 = load i8**, i8*** %5
%78 = load i32*, i32** %6
%79 = load i32*, i32** %7
%80 = load i8*, i8** %8
%81 = load i8, i8* %80
%82 = call i32 @append_char(i8** %77, i32* %78, i32* %79, i8 zeroext %81)
br label %83
83: ; preds = %76, %66
br label %84
84: ; preds = %83, %51, %46, %41, %36, %31, %26
br label %85
85: ; preds = %84
%86 = load i8*, i8** %8
%87 = getelementptr inbounds i8, i8* %86, i32 1
store i8* %87, i8** %8
br label %18
88: ; preds = %16, %18
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"\\t\00"
@.str.1 = [3 x i8] c"\\r\00"
@.str.2 = [3 x i8] c"\\n\00"
@.str.3 = [3 x i8] c"\\'\00"
@.str.4 = [3 x i8] c"\\\22\00"
@.str.5 = [3 x i8] c"\\\\\00"
@.str.6 = [6 x i8] c"\\%03o\00"
define void @append_string_quoted(i8** %0, i32* %1, i32* %2, i8* %3) {
%5 = alloca [16 x i8]
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%7 = icmp eq i8* %3, null
br i1 %7, label %38, label %8
8: ; preds = %4
%9 = load i8, i8* %3
%10 = icmp eq i8 %9, 0
br i1 %10, label %38, label %11
11: ; preds = %8, %35
%12 = phi i8 [ %37, %35 ], [ %9, %8 ]
%13 = phi i8* [ %36, %35 ], [ %3, %8 ]
switch i8 %12, label %26 [
i8 0, label %38
i8 9, label %14
i8 13, label %16
i8 10, label %18
i8 39, label %20
i8 34, label %22
i8 92, label %24
]
14: ; preds = %11
%15 = call i32 (i8**, i32*, i32*, ...) @append_string(i8** %0, i32* %1, i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %35
16: ; preds = %11
%17 = call i32 (i8**, i32*, i32*, ...) @append_string(i8** %0, i32* %1, i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %35
18: ; preds = %11
%19 = call i32 (i8**, i32*, i32*, ...) @append_string(i8** %0, i32* %1, i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %35
20: ; preds = %11
%21 = call i32 (i8**, i32*, i32*, ...) @append_string(i8** %0, i32* %1, i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %35
22: ; preds = %11
%23 = call i32 (i8**, i32*, i32*, ...) @append_string(i8** %0, i32* %1, i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %35
24: ; preds = %11
%25 = call i32 (i8**, i32*, i32*, ...) @append_string(i8** %0, i32* %1, i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %35
26: ; preds = %11
%27 = icmp ult i8 %12, 32
%28 = icmp eq i8 %12, 127
%29 = or i1 %27, %28
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = call i32 @snprintf(i8* %6, i32 16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8 zeroext %12)
%32 = call i32 (i8**, i32*, i32*, ...) @append_string(i8** %0, i32* %1, i32* %2, i8* %6)
br label %35
33: ; preds = %26
%34 = call i32 @append_char(i8** %0, i32* %1, i32* %2, i8 zeroext %12)
br label %35
35: ; preds = %14, %16, %18, %20, %22, %24, %33, %30
%36 = getelementptr inbounds i8, i8* %13, i64 1
%37 = load i8, i8* %36
br label %11
38: ; preds = %11, %4, %8
ret void
}