#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*/ memcmp(char *, char *, int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int SDF_xml_encode_data(char *s, int len, char *t) {
  char *tt = t;
  while (len > 0) {
    switch (*s) {
    case '<': {
      (void)memcpy(t, ("&lt;"), sizeof("&lt;") - 1);
      t += sizeof("&lt;") - 1;
    } break;
    case '>': {
      (void)memcpy(t, ("&gt;"), sizeof("&gt;") - 1);
      t += sizeof("&gt;") - 1;
    } break;
    case '&': {
      if (memcmp(s, ("&lt;"), sizeof("&lt;") - 1) == 0) {
        *t++ = *s;
        break;
      }
    }
      {
        if (memcmp(s, ("&gt;"), sizeof("&gt;") - 1) == 0) {
          *t++ = *s;
          break;
        }
      }
      {
        if (memcmp(s, ("&amp;"), sizeof("&amp;") - 1) == 0) {
          *t++ = *s;
          break;
        }
      }
      {
        if (memcmp(s, ("&apos;"), sizeof("&apos;") - 1) == 0) {
          *t++ = *s;
          break;
        }
      }
      {
        if (memcmp(s, ("&quot;"), sizeof("&quot;") - 1) == 0) {
          *t++ = *s;
          break;
        }
      }
      {
        (void)memcpy(t, ("&amp;"), sizeof("&amp;") - 1);
        t += sizeof("&amp;") - 1;
      }
      break;
    case '\'': {
      (void)memcpy(t, ("&apos;"), sizeof("&apos;") - 1);
      t += sizeof("&apos;") - 1;
    } break;
    case '"': {
      (void)memcpy(t, ("&quot;"), sizeof("&quot;") - 1);
      t += sizeof("&quot;") - 1;
    } break;
    default:
      *t++ = *s;
      break;
    }
    ++s;
    --len;
  }
  *t = '\0';
  return (int)(t - tt);
}


x86 assembly (clang, -O0):
<SDF_xml_encode_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    1383 <SDF_xml_encode_data+0x263>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffffde,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x1c,%eax
ja     1352 <SDF_xml_encode_data+0x232>
mov    -0x28(%rbp),%rax
lea    0xe97(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x18(%rbp),%rdi
lea    0xef7(%rip),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
jmp    1369 <SDF_xml_encode_data+0x249>
mov    -0x18(%rbp),%rdi
lea    0xed6(%rip),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
jmp    1369 <SDF_xml_encode_data+0x249>
mov    -0x8(%rbp),%rdi
lea    0xeab(%rip),%rsi
mov    $0x4,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%eax
jne    11f8 <SDF_xml_encode_data+0xd8>
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    1369 <SDF_xml_encode_data+0x249>
mov    -0x8(%rbp),%rdi
lea    0xe76(%rip),%rsi
mov    $0x4,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%eax
jne    1232 <SDF_xml_encode_data+0x112>
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    1369 <SDF_xml_encode_data+0x249>
mov    -0x8(%rbp),%rdi
lea    0xe41(%rip),%rsi
mov    $0x5,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%eax
jne    126c <SDF_xml_encode_data+0x14c>
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    1369 <SDF_xml_encode_data+0x249>
mov    -0x8(%rbp),%rdi
lea    0xe0d(%rip),%rsi
mov    $0x6,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%eax
jne    12a6 <SDF_xml_encode_data+0x186>
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    1369 <SDF_xml_encode_data+0x249>
mov    -0x8(%rbp),%rdi
lea    0xdda(%rip),%rsi
mov    $0x6,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%eax
jne    12e0 <SDF_xml_encode_data+0x1c0>
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    1369 <SDF_xml_encode_data+0x249>
mov    -0x18(%rbp),%rdi
lea    0xd93(%rip),%rsi
mov    $0x5,%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x18(%rbp)
jmp    1369 <SDF_xml_encode_data+0x249>
mov    -0x18(%rbp),%rdi
lea    0xd73(%rip),%rsi
mov    $0x6,%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x18(%rbp)
jmp    1369 <SDF_xml_encode_data+0x249>
mov    -0x18(%rbp),%rdi
lea    0xd54(%rip),%rsi
mov    $0x6,%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x18(%rbp)
jmp    1369 <SDF_xml_encode_data+0x249>
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    113b <SDF_xml_encode_data+0x1b>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SDF_xml_encode_data>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rdx,%r15
test   %esi,%esi
jle    1271 <SDF_xml_encode_data+0x151>
mov    %esi,%ebp
mov    %rdi,%rbx
add    $0x1,%ebp
lea    0xeb8(%rip),%r12
lea    0xf25(%rip),%r13
mov    %r14,%r15
jmp    117c <SDF_xml_encode_data+0x5c>
mov    %r15,%rdi
lea    0xf26(%rip),%rsi
mov    $0x6,%edx
call   1040 <memcpy@plt>
add    $0x6,%r15
add    $0x1,%rbx
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
jle    1271 <SDF_xml_encode_data+0x151>
movsbl (%rbx),%eax
lea    -0x22(%rax),%ecx
cmp    $0x1c,%ecx
ja     119c <SDF_xml_encode_data+0x7c>
movslq (%r12,%rcx,4),%rcx
add    %r12,%rcx
jmp    *%rcx
mov    %r15,%rdi
lea    0xef1(%rip),%rsi
jmp    115e <SDF_xml_encode_data+0x3e>
mov    %al,(%r15)
jmp    1268 <SDF_xml_encode_data+0x148>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x4,%edx
call   1030 <memcmp@plt>
test   %eax,%eax
je     1262 <SDF_xml_encode_data+0x142>
mov    %rbx,%rdi
lea    0xeb3(%rip),%rsi
mov    $0x4,%edx
call   1030 <memcmp@plt>
test   %eax,%eax
je     1262 <SDF_xml_encode_data+0x142>
mov    %rbx,%rdi
lea    0xe9c(%rip),%rsi
mov    $0x5,%edx
call   1030 <memcmp@plt>
test   %eax,%eax
je     1262 <SDF_xml_encode_data+0x142>
mov    %rbx,%rdi
lea    0xe8a(%rip),%rsi
mov    $0x6,%edx
call   1030 <memcmp@plt>
test   %eax,%eax
je     1262 <SDF_xml_encode_data+0x142>
mov    %rbx,%rdi
lea    0xe79(%rip),%rsi
mov    $0x6,%edx
call   1030 <memcmp@plt>
test   %eax,%eax
je     1262 <SDF_xml_encode_data+0x142>
mov    %r15,%rdi
lea    0xe54(%rip),%rsi
mov    $0x5,%edx
call   1040 <memcpy@plt>
add    $0x5,%r15
jmp    116c <SDF_xml_encode_data+0x4c>
mov    %r15,%rdi
mov    %r13,%rsi
jmp    124f <SDF_xml_encode_data+0x12f>
mov    %r15,%rdi
lea    0xe2a(%rip),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
add    $0x4,%r15
jmp    116c <SDF_xml_encode_data+0x4c>
movzbl (%rbx),%eax
mov    %al,(%r15)
add    $0x1,%r15
jmp    116c <SDF_xml_encode_data+0x4c>
movb   $0x0,(%r15)
sub    %r14d,%r15d
mov    %r15d,%eax
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"&apos;\00"
@.str.4 = [7 x i8] c"&quot;\00"
define i32 @SDF_xml_encode_data(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%8 = load i8*, i8** %6
store i8* %8, i8** %7
br label %9
9: ; preds = %91, %3
%10 = load i32, i32* %5
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %96
12: ; preds = %9
%13 = load i8*, i8** %4
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
switch i32 %15, label %86 [
i32 60, label %16
i32 62, label %21
i32 38, label %26
i32 39, label %76
i32 34, label %81
]
16: ; preds = %12
%17 = load i8*, i8** %6
%18 = call i32 @memcpy(i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%19 = load i8*, i8** %6
%20 = getelementptr inbounds i8, i8* %19, i64 4
store i8* %20, i8** %6
br label %91
21: ; preds = %12
%22 = load i8*, i8** %6
%23 = call i32 @memcpy(i8* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%24 = load i8*, i8** %6
%25 = getelementptr inbounds i8, i8* %24, i64 4
store i8* %25, i8** %6
br label %91
26: ; preds = %12
%27 = load i8*, i8** %4
%28 = call i32 @memcmp(i8* %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %26
%31 = load i8*, i8** %4
%32 = load i8, i8* %31
%33 = load i8*, i8** %6
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %6
store i8 %32, i8* %33
br label %91
35: ; preds = %26
%36 = load i8*, i8** %4
%37 = call i32 @memcmp(i8* %36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %44
39: ; preds = %35
%40 = load i8*, i8** %4
%41 = load i8, i8* %40
%42 = load i8*, i8** %6
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %6
store i8 %41, i8* %42
br label %91
44: ; preds = %35
%45 = load i8*, i8** %4
%46 = call i32 @memcmp(i8* %45, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %53
48: ; preds = %44
%49 = load i8*, i8** %4
%50 = load i8, i8* %49
%51 = load i8*, i8** %6
%52 = getelementptr inbounds i8, i8* %51, i32 1
store i8* %52, i8** %6
store i8 %50, i8* %51
br label %91
53: ; preds = %44
%54 = load i8*, i8** %4
%55 = call i32 @memcmp(i8* %54, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 6)
%56 = icmp eq i32 %55, 0
br i1 %56, label %57, label %62
57: ; preds = %53
%58 = load i8*, i8** %4
%59 = load i8, i8* %58
%60 = load i8*, i8** %6
%61 = getelementptr inbounds i8, i8* %60, i32 1
store i8* %61, i8** %6
store i8 %59, i8* %60
br label %91
62: ; preds = %53
%63 = load i8*, i8** %4
%64 = call i32 @memcmp(i8* %63, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 6)
%65 = icmp eq i32 %64, 0
br i1 %65, label %66, label %71
66: ; preds = %62
%67 = load i8*, i8** %4
%68 = load i8, i8* %67
%69 = load i8*, i8** %6
%70 = getelementptr inbounds i8, i8* %69, i32 1
store i8* %70, i8** %6
store i8 %68, i8* %69
br label %91
71: ; preds = %62
%72 = load i8*, i8** %6
%73 = call i32 @memcpy(i8* %72, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%74 = load i8*, i8** %6
%75 = getelementptr inbounds i8, i8* %74, i64 5
store i8* %75, i8** %6
br label %91
76: ; preds = %12
%77 = load i8*, i8** %6
%78 = call i32 @memcpy(i8* %77, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 6)
%79 = load i8*, i8** %6
%80 = getelementptr inbounds i8, i8* %79, i64 6
store i8* %80, i8** %6
br label %91
81: ; preds = %12
%82 = load i8*, i8** %6
%83 = call i32 @memcpy(i8* %82, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 6)
%84 = load i8*, i8** %6
%85 = getelementptr inbounds i8, i8* %84, i64 6
store i8* %85, i8** %6
br label %91
86: ; preds = %12
%87 = load i8*, i8** %4
%88 = load i8, i8* %87
%89 = load i8*, i8** %6
%90 = getelementptr inbounds i8, i8* %89, i32 1
store i8* %90, i8** %6
store i8 %88, i8* %89
br label %91
91: ; preds = %86, %81, %76, %71, %66, %57, %48, %39, %30, %21, %16
%92 = load i8*, i8** %4
%93 = getelementptr inbounds i8, i8* %92, i32 1
store i8* %93, i8** %4
%94 = load i32, i32* %5
%95 = add nsw i32 %94, -1
store i32 %95, i32* %5
br label %9
96: ; preds = %9
%97 = load i8*, i8** %6
store i8 0, i8* %97
%98 = load i8*, i8** %6
%99 = load i8*, i8** %7
%100 = ptrtoint i8* %98 to i64
%101 = ptrtoint i8* %99 to i64
%102 = sub i64 %100, %101
%103 = trunc i64 %102 to i32
ret i32 %103
}

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"&apos;\00"
@.str.4 = [7 x i8] c"&quot;\00"
define i32 @SDF_xml_encode_data(i8* %0, i32 %1, i8* %2) {
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %63
5: ; preds = %3, %58
%6 = phi i8* [ %60, %58 ], [ %0, %3 ]
%7 = phi i8* [ %59, %58 ], [ %2, %3 ]
%8 = phi i32 [ %61, %58 ], [ %1, %3 ]
%9 = load i8, i8* %6
%10 = sext i8 %9 to i32
switch i32 %10, label %56 [
i32 60, label %11
i32 62, label %14
i32 38, label %17
i32 39, label %50
i32 34, label %53
]
11: ; preds = %5
%12 = tail call i32 @memcpy(i8* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%13 = getelementptr inbounds i8, i8* %7, i64 4
br label %58
14: ; preds = %5
%15 = tail call i32 @memcpy(i8* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%16 = getelementptr inbounds i8, i8* %7, i64 4
br label %58
17: ; preds = %5
%18 = tail call i32 @memcmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i8, i8* %6
%22 = getelementptr inbounds i8, i8* %7, i64 1
store i8 %21, i8* %7
br label %58
23: ; preds = %17
%24 = tail call i32 @memcmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i8, i8* %6
%28 = getelementptr inbounds i8, i8* %7, i64 1
store i8 %27, i8* %7
br label %58
29: ; preds = %23
%30 = tail call i32 @memcmp(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = load i8, i8* %6
%34 = getelementptr inbounds i8, i8* %7, i64 1
store i8 %33, i8* %7
br label %58
35: ; preds = %29
%36 = tail call i32 @memcmp(i8* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 6)
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %35
%39 = load i8, i8* %6
%40 = getelementptr inbounds i8, i8* %7, i64 1
store i8 %39, i8* %7
br label %58
41: ; preds = %35
%42 = tail call i32 @memcmp(i8* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 6)
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %41
%45 = load i8, i8* %6
%46 = getelementptr inbounds i8, i8* %7, i64 1
store i8 %45, i8* %7
br label %58
47: ; preds = %41
%48 = tail call i32 @memcpy(i8* %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%49 = getelementptr inbounds i8, i8* %7, i64 5
br label %58
50: ; preds = %5
%51 = tail call i32 @memcpy(i8* %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 6)
%52 = getelementptr inbounds i8, i8* %7, i64 6
br label %58
53: ; preds = %5
%54 = tail call i32 @memcpy(i8* %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 6)
%55 = getelementptr inbounds i8, i8* %7, i64 6
br label %58
56: ; preds = %5
%57 = getelementptr inbounds i8, i8* %7, i64 1
store i8 %9, i8* %7
br label %58
58: ; preds = %56, %53, %50, %47, %44, %38, %32, %26, %20, %14, %11
%59 = phi i8* [ %57, %56 ], [ %55, %53 ], [ %52, %50 ], [ %22, %20 ], [ %28, %26 ], [ %34, %32 ], [ %40, %38 ], [ %46, %44 ], [ %49, %47 ], [ %16, %14 ], [ %13, %11 ]
%60 = getelementptr inbounds i8, i8* %6, i64 1
%61 = add nsw i32 %8, -1
%62 = icmp sgt i32 %8, 1
br i1 %62, label %5, label %63
63: ; preds = %58, %3
%64 = phi i8* [ %2, %3 ], [ %59, %58 ]
store i8 0, i8* %64
%65 = ptrtoint i8* %64 to i64
%66 = ptrtoint i8* %2 to i64
%67 = sub i64 %65, %66
%68 = trunc i64 %67 to i32
ret i32 %68
}