#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_xml_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, "&lt;", ((sizeof("&lt;") / sizeof("&lt;"[0])) - 1));
      o += ((sizeof("&lt;") / sizeof("&lt;"[0])) - 1);
      break;
    case '&':
      memcpy(o, "&amp;", ((sizeof("&amp;") / sizeof("&amp;"[0])) - 1));
      o += ((sizeof("&amp;") / sizeof("&amp;"[0])) - 1);
      break;
    case '>':
      memcpy(o, "&gt;", ((sizeof("&gt;") / sizeof("&gt;"[0])) - 1));
      o += ((sizeof("&gt;") / sizeof("&gt;"[0])) - 1);
      break;
    case '\'':
      memcpy(o, "&apos;", ((sizeof("&apos;") / sizeof("&apos;"[0])) - 1));
      o += ((sizeof("&apos;") / sizeof("&apos;"[0])) - 1);
      break;
    case '"':
      memcpy(o, "&quot;", ((sizeof("&quot;") / sizeof("&quot;"[0])) - 1));
      o += ((sizeof("&quot;") / sizeof("&quot;"[0])) - 1);
      break;
    default:
      if (((c < 0x20) && (c != 0x09) && (c != 0x0a)) || (c == 0x7f)) {
        snprintf(o, 7, "&#x%02x;", c);
        o += 6;
      } else {
        *o++ = c;
      }
      break;
    }
  }
  *o = '\0';
}


x86 assembly (clang, -O0):
<escape_xml_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     12cb <escape_xml_attr+0x1ab>
mov    -0x20(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x21(%rbp)
movzbl -0x21(%rbp),%eax
add    $0xffffffde,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x1c,%eax
ja     123e <escape_xml_attr+0x11e>
mov    -0x30(%rbp),%rax
lea    0xe89(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x18(%rbp),%rdi
lea    0xee9(%rip),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
jmp    12b5 <escape_xml_attr+0x195>
mov    -0x18(%rbp),%rdi
lea    0xec8(%rip),%rsi
mov    $0x5,%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x18(%rbp)
jmp    12b5 <escape_xml_attr+0x195>
mov    -0x18(%rbp),%rdi
lea    0xea8(%rip),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
jmp    12b5 <escape_xml_attr+0x195>
mov    -0x18(%rbp),%rdi
lea    0xe87(%rip),%rsi
mov    $0x6,%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x18(%rbp)
jmp    12b5 <escape_xml_attr+0x195>
mov    -0x18(%rbp),%rdi
lea    0xe68(%rip),%rsi
mov    $0x6,%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x18(%rbp)
jmp    12b5 <escape_xml_attr+0x195>
movzbl -0x21(%rbp),%eax
cmp    $0x20,%eax
jge    1265 <escape_xml_attr+0x145>
movzbl -0x21(%rbp),%eax
cmp    $0x9,%eax
je     1265 <escape_xml_attr+0x145>
movzbl -0x21(%rbp),%eax
cmp    $0xa,%eax
jne    1272 <escape_xml_attr+0x152>
movzbl -0x21(%rbp),%eax
cmp    $0x7f,%eax
jne    129c <escape_xml_attr+0x17c>
mov    -0x18(%rbp),%rdi
mov    $0x7,%esi
lea    0xe10(%rip),%rdx
movzbl -0x21(%rbp),%ecx
call   1030 <snprintf@plt>
mov    -0x18(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x18(%rbp)
jmp    12b0 <escape_xml_attr+0x190>
mov    -0x21(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    12b5 <escape_xml_attr+0x195>
jmp    12ba <escape_xml_attr+0x19a>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1140 <escape_xml_attr+0x20>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<escape_xml_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    0xf45(%rip),%rbp
lea    0xf2e(%rip),%r15
lea    0xf32(%rip),%r12
jmp    1170 <escape_xml_attr+0x50>
mov    %r14,%rdi
lea    0xf20(%rip),%rsi
mov    $0x5,%edx
call   1040 <memcpy@plt>
add    $0x5,%r14
add    $0x1,%rbx
nopl   0x0(%rax,%rax,1)
movzbl (%rbx),%eax
lea    -0x22(%rax),%ecx
cmp    $0x1c,%cl
ja     11c8 <escape_xml_attr+0xa8>
movzbl %cl,%ecx
movslq 0x0(%r13,%rcx,4),%rcx
add    %r13,%rcx
jmp    *%rcx
mov    %r14,%rdi
lea    0xef9(%rip),%rsi
jmp    119a <escape_xml_attr+0x7a>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    $0x6,%edx
call   1040 <memcpy@plt>
jmp    1206 <escape_xml_attr+0xe6>
mov    %r14,%rdi
mov    %r15,%rsi
jmp    11b4 <escape_xml_attr+0x94>
mov    %r14,%rdi
mov    %r12,%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
add    $0x4,%r14
add    $0x1,%rbx
jmp    1170 <escape_xml_attr+0x50>
test   %al,%al
je     1213 <escape_xml_attr+0xf3>
cmp    $0x20,%al
setb   %cl
lea    -0xb(%rax),%edx
cmp    $0xfe,%dl
setb   %dl
cmp    $0x7f,%al
je     11ef <escape_xml_attr+0xcf>
and    %dl,%cl
jne    11ef <escape_xml_attr+0xcf>
mov    %al,(%r14)
add    $0x1,%r14
add    $0x1,%rbx
jmp    1170 <escape_xml_attr+0x50>
movzbl %al,%ecx
mov    %r14,%rdi
mov    $0x7,%esi
lea    0xe91(%rip),%rdx
call   1030 <snprintf@plt>
add    $0x6,%r14
add    $0x1,%rbx
jmp    1170 <escape_xml_attr+0x50>
movb   $0x0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"&lt;\00"
@.str.1 = [6 x i8] c"&amp;\00"
@.str.2 = [5 x i8] c"&gt;\00"
@.str.3 = [7 x i8] c"&apos;\00"
@.str.4 = [7 x i8] c"&quot;\00"
@.str.5 = [9 x i8] c"&#x%02x;\00"
define void @escape_xml_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 = %72, %2
%11 = load i8*, i8** %6
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
br i1 %13, label %14, label %75
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 60, label %19
i32 38, label %24
i32 62, label %29
i32 39, label %34
i32 34, label %39
]
19: ; preds = %14
%20 = load i8*, i8** %5
%21 = call i32 @memcpy(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%22 = load i8*, i8** %5
%23 = getelementptr inbounds i8, i8* %22, i64 4
store i8* %23, i8** %5
br label %71
24: ; preds = %14
%25 = load i8*, i8** %5
%26 = call i32 @memcpy(i8* %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i64 5
store i8* %28, i8** %5
br label %71
29: ; preds = %14
%30 = load i8*, i8** %5
%31 = call i32 @memcpy(i8* %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%32 = load i8*, i8** %5
%33 = getelementptr inbounds i8, i8* %32, i64 4
store i8* %33, i8** %5
br label %71
34: ; preds = %14
%35 = load i8*, i8** %5
%36 = call i32 @memcpy(i8* %35, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 6)
%37 = load i8*, i8** %5
%38 = getelementptr inbounds i8, i8* %37, i64 6
store i8* %38, i8** %5
br label %71
39: ; preds = %14
%40 = load i8*, i8** %5
%41 = call i32 @memcpy(i8* %40, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 6)
%42 = load i8*, i8** %5
%43 = getelementptr inbounds i8, i8* %42, i64 6
store i8* %43, i8** %5
br label %71
44: ; preds = %14
%45 = load i8, i8* %7
%46 = zext i8 %45 to i32
%47 = icmp slt i32 %46, 32
br i1 %47, label %48, label %56
48: ; preds = %44
%49 = load i8, i8* %7
%50 = zext i8 %49 to i32
%51 = icmp ne i32 %50, 9
br i1 %51, label %52, label %56
52: ; preds = %48
%53 = load i8, i8* %7
%54 = zext i8 %53 to i32
%55 = icmp ne i32 %54, 10
br i1 %55, label %60, label %56
56: ; preds = %52, %48, %44
%57 = load i8, i8* %7
%58 = zext i8 %57 to i32
%59 = icmp eq i32 %58, 127
br i1 %59, label %60, label %66
60: ; preds = %56, %52
%61 = load i8*, i8** %5
%62 = load i8, i8* %7
%63 = call i32 @snprintf(i8* %61, i32 7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8 zeroext %62)
%64 = load i8*, i8** %5
%65 = getelementptr inbounds i8, i8* %64, i64 6
store i8* %65, i8** %5
br label %70
66: ; preds = %56
%67 = load i8, i8* %7
%68 = load i8*, i8** %5
%69 = getelementptr inbounds i8, i8* %68, i32 1
store i8* %69, i8** %5
store i8 %67, i8* %68
br label %70
70: ; preds = %66, %60
br label %71
71: ; preds = %70, %39, %34, %29, %24, %19
br label %72
72: ; preds = %71
%73 = load i8*, i8** %6
%74 = getelementptr inbounds i8, i8* %73, i32 1
store i8* %74, i8** %6
br label %10
75: ; preds = %10
%76 = load i8*, i8** %5
store i8 0, i8* %76
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"&lt;\00"
@.str.1 = [6 x i8] c"&amp;\00"
@.str.2 = [5 x i8] c"&gt;\00"
@.str.3 = [7 x i8] c"&apos;\00"
@.str.4 = [7 x i8] c"&quot;\00"
@.str.5 = [9 x i8] c"&#x%02x;\00"
define void @escape_xml_attr(i8* nocapture %0, i8* %1) {
br label %3
3: ; preds = %34, %2
%4 = phi i8* [ %0, %2 ], [ %36, %34 ]
%5 = phi i8* [ %1, %2 ], [ %35, %34 ]
%6 = load i8, i8* %4
switch i8 %6, label %22 [
i8 0, label %37
i8 60, label %7
i8 38, label %10
i8 62, label %13
i8 39, label %16
i8 34, label %19
]
7: ; preds = %3
%8 = tail call i32 @memcpy(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%9 = getelementptr inbounds i8, i8* %5, i64 4
br label %34
10: ; preds = %3
%11 = tail call i32 @memcpy(i8* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%12 = getelementptr inbounds i8, i8* %5, i64 5
br label %34
13: ; preds = %3
%14 = tail call i32 @memcpy(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%15 = getelementptr inbounds i8, i8* %5, i64 4
br label %34
16: ; preds = %3
%17 = tail call i32 @memcpy(i8* %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 6)
%18 = getelementptr inbounds i8, i8* %5, i64 6
br label %34
19: ; preds = %3
%20 = tail call i32 @memcpy(i8* %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 6)
%21 = getelementptr inbounds i8, i8* %5, i64 6
br label %34
22: ; preds = %3
%23 = icmp ult i8 %6, 32
%24 = add i8 %6, -11
%25 = icmp ult i8 %24, -2
%26 = and i1 %23, %25
%27 = icmp eq i8 %6, 127
%28 = or i1 %27, %26
br i1 %28, label %29, label %32
29: ; preds = %22
%30 = tail call i32 @snprintf(i8* %5, i32 7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8 zeroext %6)
%31 = getelementptr inbounds i8, i8* %5, i64 6
br label %34
32: ; preds = %22
%33 = getelementptr inbounds i8, i8* %5, i64 1
store i8 %6, i8* %5
br label %34
34: ; preds = %29, %32, %19, %16, %13, %10, %7
%35 = phi i8* [ %31, %29 ], [ %33, %32 ], [ %21, %19 ], [ %18, %16 ], [ %15, %13 ], [ %12, %10 ], [ %9, %7 ]
%36 = getelementptr inbounds i8, i8* %4, i64 1
br label %3
37: ; preds = %3
store i8 0, i8* %5
ret void
}