#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*/ strcpy(char *, char *);
void XML_Escape(char *buffer, size_t size, const char *string) {
  int i;
  for (i = 7; i < size && *string != 0; i++, string++) {
    switch (*string) {
    case '<':
      strcpy(buffer, "&lt;");
      buffer += 4;
      break;
    case '>':
      strcpy(buffer, "&gt;");
      buffer += 4;
      break;
    case '&':
      strcpy(buffer, "&amp;");
      buffer += 5;
      break;
    case '"':
      strcpy(buffer, "&quot;");
      buffer += 6;
      break;
    case '\'':
      strcpy(buffer, "&apos;");
      buffer += 6;
      break;
    default:
      if (*string >= ' ') {
        *buffer = *string;
        buffer++;
      }
    }
  }
  *buffer = 0;
}


x86 assembly (clang, -O0):
<XML_Escape>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x7,-0x1c(%rbp)
movslq -0x1c(%rbp),%rcx
xor    %eax,%eax
cmp    -0x10(%rbp),%rcx
mov    %al,-0x1d(%rbp)
jae    114e <XML_Escape+0x3e>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    115e <XML_Escape+0x4e>
jmp    127c <XML_Escape+0x16c>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffffde,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x1c,%eax
ja     1230 <XML_Escape+0x120>
mov    -0x28(%rbp),%rax
lea    0xe7e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%rdi
lea    0xede(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x8(%rbp)
jmp    125d <XML_Escape+0x14d>
mov    -0x8(%rbp),%rdi
lea    0xec2(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x8(%rbp)
jmp    125d <XML_Escape+0x14d>
mov    -0x8(%rbp),%rdi
lea    0xea6(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x8(%rbp)
jmp    125d <XML_Escape+0x14d>
mov    -0x8(%rbp),%rdi
lea    0xe8b(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x8(%rbp)
jmp    125d <XML_Escape+0x14d>
mov    -0x8(%rbp),%rdi
lea    0xe71(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x8(%rbp)
jmp    125d <XML_Escape+0x14d>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jl     1258 <XML_Escape+0x148>
mov    -0x18(%rbp),%rax
mov    (%rax),%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    125d <XML_Escape+0x14d>
jmp    1262 <XML_Escape+0x152>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    112b <XML_Escape+0x1b>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<XML_Escape>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
cmp    $0x8,%rsi
jb     11c4 <XML_Escape+0xb4>
mov    %rdx,%r14
mov    %rsi,%r15
add    $0xfffffffffffffff9,%r15
xor    %ebp,%ebp
lea    0xec5(%rip),%r12
lea    0xf37(%rip),%r13
jmp    1160 <XML_Escape+0x50>
mov    %rbx,%rdi
lea    0xf36(%rip),%rsi
call   1030 <strcpy@plt>
add    $0x6,%rbx
add    $0x1,%rbp
cmp    %rbp,%r15
je     11c4 <XML_Escape+0xb4>
movsbl (%r14,%rbp,1),%eax
test   %eax,%eax
je     11c4 <XML_Escape+0xb4>
lea    -0x22(%rax),%ecx
cmp    $0x1c,%ecx
ja     118f <XML_Escape+0x7f>
movslq (%r12,%rcx,4),%rcx
add    %r12,%rcx
jmp    *%rcx
mov    %rbx,%rdi
lea    0xefa(%rip),%rsi
call   1030 <strcpy@plt>
add    $0x5,%rbx
jmp    1157 <XML_Escape+0x47>
cmp    $0x20,%al
jl     1157 <XML_Escape+0x47>
mov    %al,(%rbx)
add    $0x1,%rbx
jmp    1157 <XML_Escape+0x47>
mov    %rbx,%rdi
lea    0xee6(%rip),%rsi
jmp    114e <XML_Escape+0x3e>
mov    %rbx,%rdi
lea    0xec3(%rip),%rsi
jmp    11b9 <XML_Escape+0xa9>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1030 <strcpy@plt>
add    $0x4,%rbx
jmp    1157 <XML_Escape+0x47>
movb   $0x0,(%rbx)
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 = [5 x i8] c"&gt;\00"
@.str.2 = [6 x i8] c"&amp;\00"
@.str.3 = [7 x i8] c"&quot;\00"
@.str.4 = [7 x i8] c"&apos;\00"
define void @XML_Escape(i8* %0, i64 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
store i8* %2, i8** %6
store i32 7, i32* %7
br label %8
8: ; preds = %62, %3
%9 = load i32, i32* %7
%10 = sext i32 %9 to i64
%11 = load i64, i64* %5
%12 = icmp ult i64 %10, %11
br i1 %12, label %13, label %18
13: ; preds = %8
%14 = load i8*, i8** %6
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br label %18
18: ; preds = %13, %8
%19 = phi i1 [ false, %8 ], [ %17, %13 ]
br i1 %19, label %20, label %67
20: ; preds = %18
%21 = load i8*, i8** %6
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
switch i32 %23, label %49 [
i32 60, label %24
i32 62, label %29
i32 38, label %34
i32 34, label %39
i32 39, label %44
]
24: ; preds = %20
%25 = load i8*, i8** %4
%26 = call i32 @strcpy(i8* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%27 = load i8*, i8** %4
%28 = getelementptr inbounds i8, i8* %27, i64 4
store i8* %28, i8** %4
br label %61
29: ; preds = %20
%30 = load i8*, i8** %4
%31 = call i32 @strcpy(i8* %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%32 = load i8*, i8** %4
%33 = getelementptr inbounds i8, i8* %32, i64 4
store i8* %33, i8** %4
br label %61
34: ; preds = %20
%35 = load i8*, i8** %4
%36 = call i32 @strcpy(i8* %35, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%37 = load i8*, i8** %4
%38 = getelementptr inbounds i8, i8* %37, i64 5
store i8* %38, i8** %4
br label %61
39: ; preds = %20
%40 = load i8*, i8** %4
%41 = call i32 @strcpy(i8* %40, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%42 = load i8*, i8** %4
%43 = getelementptr inbounds i8, i8* %42, i64 6
store i8* %43, i8** %4
br label %61
44: ; preds = %20
%45 = load i8*, i8** %4
%46 = call i32 @strcpy(i8* %45, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%47 = load i8*, i8** %4
%48 = getelementptr inbounds i8, i8* %47, i64 6
store i8* %48, i8** %4
br label %61
49: ; preds = %20
%50 = load i8*, i8** %6
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp sge i32 %52, 32
br i1 %53, label %54, label %60
54: ; preds = %49
%55 = load i8*, i8** %6
%56 = load i8, i8* %55
%57 = load i8*, i8** %4
store i8 %56, i8* %57
%58 = load i8*, i8** %4
%59 = getelementptr inbounds i8, i8* %58, i32 1
store i8* %59, i8** %4
br label %60
60: ; preds = %54, %49
br label %61
61: ; preds = %60, %44, %39, %34, %29, %24
br label %62
62: ; preds = %61
%63 = load i32, i32* %7
%64 = add nsw i32 %63, 1
store i32 %64, i32* %7
%65 = load i8*, i8** %6
%66 = getelementptr inbounds i8, i8* %65, i32 1
store i8* %66, i8** %6
br label %8
67: ; preds = %18
%68 = load i8*, i8** %4
store i8 0, i8* %68
ret void
}

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