#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*/ memcpy(char *, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned char);
void escape_json_attr(const char *buf, char *out) {
  char *o = out;
  const char *b;
  for (b = buf; *b; ++b) {
    unsigned char c = *b;
    switch (c) {
    case '"':
      memcpy(o, "\\\"", ((sizeof("\\\"") / sizeof("\\\""[0])) - 1));
      o += ((sizeof("\\\"") / sizeof("\\\""[0])) - 1);
      break;
    case '\\':
      memcpy(o, "\\\\", ((sizeof("\\\\") / sizeof("\\\\"[0])) - 1));
      o += ((sizeof("\\\\") / sizeof("\\\\"[0])) - 1);
      break;
    case '/':
      memcpy(o, "\\/", ((sizeof("\\/") / sizeof("\\/"[0])) - 1));
      o += ((sizeof("\\/") / sizeof("\\/"[0])) - 1);
      break;
    case '\t':
      memcpy(o, "\\t", ((sizeof("\\t") / sizeof("\\t"[0])) - 1));
      o += ((sizeof("\\t") / sizeof("\\t"[0])) - 1);
      break;
    case '\n':
      memcpy(o, "\\n", ((sizeof("\\n") / sizeof("\\n"[0])) - 1));
      o += ((sizeof("\\n") / sizeof("\\n"[0])) - 1);
      break;
    default:
      if ((c < 0x20) || (c == 0x7f)) {
        snprintf(o, 7, "\\u%04x", c);
        o += 6;
      } else {
        *o++ = c;
      }
      break;
    }
  }
  *o = '\0';
}


x86 assembly (clang, -O0):
<escape_json_attr>:
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    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     12e0 <escape_json_attr+0x1c0>
mov    -0x20(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x21(%rbp)
movzbl -0x21(%rbp),%eax
mov    %eax,-0x28(%rbp)
sub    $0x9,%eax
je     1221 <escape_json_attr+0x101>
jmp    116b <escape_json_attr+0x4b>
mov    -0x28(%rbp),%eax
sub    $0xa,%eax
je     1247 <escape_json_attr+0x127>
jmp    117c <escape_json_attr+0x5c>
mov    -0x28(%rbp),%eax
sub    $0x22,%eax
je     11af <escape_json_attr+0x8f>
jmp    118d <escape_json_attr+0x6d>
mov    -0x28(%rbp),%eax
sub    $0x2f,%eax
je     11fb <escape_json_attr+0xdb>
jmp    119e <escape_json_attr+0x7e>
mov    -0x28(%rbp),%eax
sub    $0x5c,%eax
je     11d5 <escape_json_attr+0xb5>
jmp    126d <escape_json_attr+0x14d>
mov    -0x18(%rbp),%rdi
lea    0xe46(%rip),%rsi
mov    $0x2,%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
jmp    12ca <escape_json_attr+0x1aa>
mov    -0x18(%rbp),%rdi
lea    0xe23(%rip),%rsi
mov    $0x2,%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
jmp    12ca <escape_json_attr+0x1aa>
mov    -0x18(%rbp),%rdi
lea    0xe00(%rip),%rsi
mov    $0x2,%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
jmp    12ca <escape_json_attr+0x1aa>
mov    -0x18(%rbp),%rdi
lea    0xddd(%rip),%rsi
mov    $0x2,%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
jmp    12ca <escape_json_attr+0x1aa>
mov    -0x18(%rbp),%rdi
lea    0xdba(%rip),%rsi
mov    $0x2,%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
jmp    12ca <escape_json_attr+0x1aa>
movzbl -0x21(%rbp),%eax
cmp    $0x20,%eax
jl     1287 <escape_json_attr+0x167>
movzbl -0x21(%rbp),%eax
cmp    $0x7f,%eax
jne    12b1 <escape_json_attr+0x191>
mov    -0x18(%rbp),%rdi
mov    $0x7,%esi
lea    0xd78(%rip),%rdx
movzbl -0x21(%rbp),%ecx
call   1030 <snprintf@plt>
mov    -0x18(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x18(%rbp)
jmp    12c5 <escape_json_attr+0x1a5>
mov    -0x21(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    12ca <escape_json_attr+0x1aa>
jmp    12cf <escape_json_attr+0x1af>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1140 <escape_json_attr+0x20>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<escape_json_attr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xec8(%rip),%r13
lea    0xf8d(%rip),%rbp
lea    0xf7a(%rip),%r12
lea    0xf79(%rip),%r15
jmp    1167 <escape_json_attr+0x47>
mov    %r14,%rdi
mov    %r12,%rsi
mov    $0x2,%edx
call   1040 <memcpy@plt>
add    $0x2,%r14
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x2f,%rax
ja     1190 <escape_json_attr+0x70>
movslq 0x0(%r13,%rax,4),%rcx
add    %r13,%rcx
jmp    *%rcx
mov    %r14,%rdi
lea    0xf45(%rip),%rsi
jmp    1155 <escape_json_attr+0x35>
cs nopw 0x0(%rax,%rax,1)
cmp    $0x5c,%al
jne    11a0 <escape_json_attr+0x80>
mov    %r14,%rdi
lea    0xf25(%rip),%rsi
jmp    1155 <escape_json_attr+0x35>
cmp    $0x20,%al
jb     11c5 <escape_json_attr+0xa5>
cmp    $0x7f,%al
je     11c5 <escape_json_attr+0xa5>
mov    %al,(%r14)
add    $0x1,%r14
add    $0x1,%rbx
jmp    1167 <escape_json_attr+0x47>
mov    %r14,%rdi
mov    %rbp,%rsi
jmp    1155 <escape_json_attr+0x35>
mov    %r14,%rdi
mov    %r15,%rsi
jmp    1155 <escape_json_attr+0x35>
movzbl %al,%ecx
mov    %r14,%rdi
mov    $0x7,%esi
lea    0xef8(%rip),%rdx
call   1030 <snprintf@plt>
add    $0x6,%r14
add    $0x1,%rbx
jmp    1167 <escape_json_attr+0x47>
movb   $0x0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\\\22\00"
@.str.1 = [3 x i8] c"\\\\\00"
@.str.2 = [3 x i8] c"\\/\00"
@.str.3 = [3 x i8] c"\\t\00"
@.str.4 = [3 x i8] c"\\n\00"
@.str.5 = [7 x i8] c"\\u%04x\00"
define void @escape_json_attr(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%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** %5
%9 = load i8*, i8** %3
store i8* %9, i8** %6
br label %10
10: ; preds = %64, %2
%11 = load i8*, i8** %6
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
br i1 %13, label %14, label %67
14: ; preds = %10
%15 = load i8*, i8** %6
%16 = load i8, i8* %15
store i8 %16, i8* %7
%17 = load i8, i8* %7
%18 = zext i8 %17 to i32
switch i32 %18, label %44 [
i32 34, label %19
i32 92, label %24
i32 47, label %29
i32 9, label %34
i32 10, label %39
]
19: ; preds = %14
%20 = load i8*, i8** %5
%21 = call i32 @memcpy(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%22 = load i8*, i8** %5
%23 = getelementptr inbounds i8, i8* %22, i64 2
store i8* %23, i8** %5
br label %63
24: ; preds = %14
%25 = load i8*, i8** %5
%26 = call i32 @memcpy(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i64 2
store i8* %28, i8** %5
br label %63
29: ; preds = %14
%30 = load i8*, i8** %5
%31 = call i32 @memcpy(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%32 = load i8*, i8** %5
%33 = getelementptr inbounds i8, i8* %32, i64 2
store i8* %33, i8** %5
br label %63
34: ; preds = %14
%35 = load i8*, i8** %5
%36 = call i32 @memcpy(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2)
%37 = load i8*, i8** %5
%38 = getelementptr inbounds i8, i8* %37, i64 2
store i8* %38, i8** %5
br label %63
39: ; preds = %14
%40 = load i8*, i8** %5
%41 = call i32 @memcpy(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 2)
%42 = load i8*, i8** %5
%43 = getelementptr inbounds i8, i8* %42, i64 2
store i8* %43, i8** %5
br label %63
44: ; preds = %14
%45 = load i8, i8* %7
%46 = zext i8 %45 to i32
%47 = icmp slt i32 %46, 32
br i1 %47, label %52, label %48
48: ; preds = %44
%49 = load i8, i8* %7
%50 = zext i8 %49 to i32
%51 = icmp eq i32 %50, 127
br i1 %51, label %52, label %58
52: ; preds = %48, %44
%53 = load i8*, i8** %5
%54 = load i8, i8* %7
%55 = call i32 @snprintf(i8* %53, i32 7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8 zeroext %54)
%56 = load i8*, i8** %5
%57 = getelementptr inbounds i8, i8* %56, i64 6
store i8* %57, i8** %5
br label %62
58: ; preds = %48
%59 = load i8, i8* %7
%60 = load i8*, i8** %5
%61 = getelementptr inbounds i8, i8* %60, i32 1
store i8* %61, i8** %5
store i8 %59, i8* %60
br label %62
62: ; preds = %58, %52
br label %63
63: ; preds = %62, %39, %34, %29, %24, %19
br label %64
64: ; preds = %63
%65 = load i8*, i8** %6
%66 = getelementptr inbounds i8, i8* %65, i32 1
store i8* %66, i8** %6
br label %10
67: ; preds = %10
%68 = load i8*, i8** %5
store i8 0, i8* %68
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"\\\22\00"
@.str.1 = [3 x i8] c"\\\\\00"
@.str.2 = [3 x i8] c"\\/\00"
@.str.3 = [3 x i8] c"\\t\00"
@.str.4 = [3 x i8] c"\\n\00"
@.str.5 = [7 x i8] c"\\u%04x\00"
define void @escape_json_attr(i8* nocapture %0, i8* %1) {
br label %3
3: ; preds = %31, %2
%4 = phi i8* [ %0, %2 ], [ %33, %31 ]
%5 = phi i8* [ %1, %2 ], [ %32, %31 ]
%6 = load i8, i8* %4
switch i8 %6, label %22 [
i8 0, label %34
i8 34, label %7
i8 92, label %10
i8 47, label %13
i8 9, label %16
i8 10, label %19
]
7: ; preds = %3
%8 = tail call i32 @memcpy(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%9 = getelementptr inbounds i8, i8* %5, i64 2
br label %31
10: ; preds = %3
%11 = tail call i32 @memcpy(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%12 = getelementptr inbounds i8, i8* %5, i64 2
br label %31
13: ; preds = %3
%14 = tail call i32 @memcpy(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%15 = getelementptr inbounds i8, i8* %5, i64 2
br label %31
16: ; preds = %3
%17 = tail call i32 @memcpy(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2)
%18 = getelementptr inbounds i8, i8* %5, i64 2
br label %31
19: ; preds = %3
%20 = tail call i32 @memcpy(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 2)
%21 = getelementptr inbounds i8, i8* %5, i64 2
br label %31
22: ; preds = %3
%23 = icmp ult i8 %6, 32
%24 = icmp eq i8 %6, 127
%25 = or i1 %23, %24
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = tail call i32 @snprintf(i8* %5, i32 7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8 zeroext %6)
%28 = getelementptr inbounds i8, i8* %5, i64 6
br label %31
29: ; preds = %22
%30 = getelementptr inbounds i8, i8* %5, i64 1
store i8 %6, i8* %5
br label %31
31: ; preds = %26, %29, %19, %16, %13, %10, %7
%32 = phi i8* [ %28, %26 ], [ %30, %29 ], [ %21, %19 ], [ %18, %16 ], [ %15, %13 ], [ %12, %10 ], [ %9, %7 ]
%33 = getelementptr inbounds i8, i8* %4, i64 1
br label %3
34: ; preds = %3
store i8 0, i8* %5
ret void
}