#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);
scalar_t__ strlen(char const *);
int ILibXmlEscape(char *outdata, const char *indata) {
  int i = 0;
  int inlen;
  char *out;
  out = outdata;
  inlen = (int)strlen(indata);
  for (i = 0; i < inlen; i++) {
    if (indata[i] == '"') {
      memcpy(out, "&quot;", 6);
      out = out + 6;
    } else if (indata[i] == '\'') {
      memcpy(out, "&apos;", 6);
      out = out + 6;
    } else if (indata[i] == '<') {
      memcpy(out, "&lt;", 4);
      out = out + 4;
    } else if (indata[i] == '>') {
      memcpy(out, "&gt;", 4);
      out = out + 4;
    } else if (indata[i] == '&') {
      memcpy(out, "&amp;", 5);
      out = out + 5;
    } else {
      out[0] = indata[i];
      out++;
    }
  }
  out[0] = 0;
  return (int)(out - outdata);
}


x86 assembly (clang, -O0):
<ILibXmlEscape>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    12c9 <ILibXmlEscape+0x1a9>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x22,%eax
jne    1199 <ILibXmlEscape+0x79>
mov    -0x20(%rbp),%rdi
lea    0xe82(%rip),%rsi
mov    $0x6,%edx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x20(%rbp)
jmp    12b6 <ILibXmlEscape+0x196>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x27,%eax
jne    11d4 <ILibXmlEscape+0xb4>
mov    -0x20(%rbp),%rdi
lea    0xe4e(%rip),%rsi
mov    $0x6,%edx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x20(%rbp)
jmp    12b1 <ILibXmlEscape+0x191>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3c,%eax
jne    120f <ILibXmlEscape+0xef>
mov    -0x20(%rbp),%rdi
lea    0xe1a(%rip),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x20(%rbp)
jmp    12ac <ILibXmlEscape+0x18c>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3e,%eax
jne    124a <ILibXmlEscape+0x12a>
mov    -0x20(%rbp),%rdi
lea    0xde4(%rip),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x20(%rbp)
jmp    12a7 <ILibXmlEscape+0x187>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x26,%eax
jne    1285 <ILibXmlEscape+0x165>
mov    -0x20(%rbp),%rdi
lea    0xdae(%rip),%rsi
mov    $0x5,%edx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x20(%rbp)
jmp    12a2 <ILibXmlEscape+0x182>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    12a7 <ILibXmlEscape+0x187>
jmp    12ac <ILibXmlEscape+0x18c>
jmp    12b1 <ILibXmlEscape+0x191>
jmp    12b6 <ILibXmlEscape+0x196>
jmp    12bb <ILibXmlEscape+0x19b>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1152 <ILibXmlEscape+0x32>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ILibXmlEscape>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %r14,%rbx
test   %eax,%eax
jle    11eb <ILibXmlEscape+0xcb>
mov    %eax,%ebp
xor    %r12d,%r12d
lea    0xeb0(%rip),%r13
mov    %r14,%rbx
jmp    117a <ILibXmlEscape+0x5a>
mov    %rbx,%rdi
lea    0xf15(%rip),%rsi
mov    $0x6,%edx
call   1040 <memcpy@plt>
mov    $0x6,%eax
add    %rax,%rbx
add    $0x1,%r12
cmp    %r12,%rbp
je     11eb <ILibXmlEscape+0xcb>
movzbl (%r15,%r12,1),%eax
lea    -0x22(%rax),%ecx
cmp    $0x1c,%cl
ja     11af <ILibXmlEscape+0x8f>
movzbl %cl,%ecx
movslq 0x0(%r13,%rcx,4),%rcx
add    %r13,%rcx
jmp    *%rcx
mov    %rbx,%rdi
lea    0xeee(%rip),%rsi
mov    $0x5,%edx
call   1040 <memcpy@plt>
mov    $0x5,%eax
jmp    116e <ILibXmlEscape+0x4e>
mov    %al,(%rbx)
mov    $0x1,%eax
jmp    116e <ILibXmlEscape+0x4e>
mov    %rbx,%rdi
lea    0xeb9(%rip),%rsi
jmp    115f <ILibXmlEscape+0x3f>
mov    %rbx,%rdi
lea    0xeb4(%rip),%rsi
jmp    11da <ILibXmlEscape+0xba>
mov    %rbx,%rdi
lea    0xead(%rip),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    $0x4,%eax
jmp    116e <ILibXmlEscape+0x4e>
movb   $0x0,(%rbx)
sub    %r14d,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"&quot;\00"
@.str.1 = [7 x i8] c"&apos;\00"
@.str.2 = [5 x i8] c"&lt;\00"
@.str.3 = [5 x i8] c"&gt;\00"
@.str.4 = [6 x i8] c"&amp;\00"
define i32 @ILibXmlEscape(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %5
%8 = load i8*, i8** %3
store i8* %8, i8** %7
%9 = load i8*, i8** %4
%10 = call i64 @strlen(i8* %9)
%11 = trunc i64 %10 to i32
store i32 %11, i32* %6
store i32 0, i32* %5
br label %12
12: ; preds = %96, %2
%13 = load i32, i32* %5
%14 = load i32, i32* %6
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %99
16: ; preds = %12
%17 = load i8*, i8** %4
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 34
br i1 %23, label %24, label %29
24: ; preds = %16
%25 = load i8*, i8** %7
%26 = call i32 @memcpy(i8* %25, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%27 = load i8*, i8** %7
%28 = getelementptr inbounds i8, i8* %27, i64 6
store i8* %28, i8** %7
br label %95
29: ; preds = %16
%30 = load i8*, i8** %4
%31 = load i32, i32* %5
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 39
br i1 %36, label %37, label %42
37: ; preds = %29
%38 = load i8*, i8** %7
%39 = call i32 @memcpy(i8* %38, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 6)
%40 = load i8*, i8** %7
%41 = getelementptr inbounds i8, i8* %40, i64 6
store i8* %41, i8** %7
br label %94
42: ; preds = %29
%43 = load i8*, i8** %4
%44 = load i32, i32* %5
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 60
br i1 %49, label %50, label %55
50: ; preds = %42
%51 = load i8*, i8** %7
%52 = call i32 @memcpy(i8* %51, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%53 = load i8*, i8** %7
%54 = getelementptr inbounds i8, i8* %53, i64 4
store i8* %54, i8** %7
br label %93
55: ; preds = %42
%56 = load i8*, i8** %4
%57 = load i32, i32* %5
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = icmp eq i32 %61, 62
br i1 %62, label %63, label %68
63: ; preds = %55
%64 = load i8*, i8** %7
%65 = call i32 @memcpy(i8* %64, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%66 = load i8*, i8** %7
%67 = getelementptr inbounds i8, i8* %66, i64 4
store i8* %67, i8** %7
br label %92
68: ; preds = %55
%69 = load i8*, i8** %4
%70 = load i32, i32* %5
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8, i8* %69, i64 %71
%73 = load i8, i8* %72
%74 = sext i8 %73 to i32
%75 = icmp eq i32 %74, 38
br i1 %75, label %76, label %81
76: ; preds = %68
%77 = load i8*, i8** %7
%78 = call i32 @memcpy(i8* %77, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 5)
%79 = load i8*, i8** %7
%80 = getelementptr inbounds i8, i8* %79, i64 5
store i8* %80, i8** %7
br label %91
81: ; preds = %68
%82 = load i8*, i8** %4
%83 = load i32, i32* %5
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i8, i8* %82, i64 %84
%86 = load i8, i8* %85
%87 = load i8*, i8** %7
%88 = getelementptr inbounds i8, i8* %87, i64 0
store i8 %86, i8* %88
%89 = load i8*, i8** %7
%90 = getelementptr inbounds i8, i8* %89, i32 1
store i8* %90, i8** %7
br label %91
91: ; preds = %81, %76
br label %92
92: ; preds = %91, %63
br label %93
93: ; preds = %92, %50
br label %94
94: ; preds = %93, %37
br label %95
95: ; preds = %94, %24
br label %96
96: ; preds = %95
%97 = load i32, i32* %5
%98 = add nsw i32 %97, 1
store i32 %98, i32* %5
br label %12
99: ; preds = %12
%100 = load i8*, i8** %7
%101 = getelementptr inbounds i8, i8* %100, i64 0
store i8 0, i8* %101
%102 = load i8*, i8** %7
%103 = load i8*, i8** %3
%104 = ptrtoint i8* %102 to i64
%105 = ptrtoint i8* %103 to i64
%106 = sub i64 %104, %105
%107 = trunc i64 %106 to i32
ret i32 %107
}

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