#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 */
typedef int uint8_t;
typedef int /*<<< orphan*/ replacements;

/* Variables and functions */
int /*<<< orphan*/ strcpy(char *, char const *);
int /*<<< orphan*/ strlen(char const *);
scalar_t__ strncasecmp(char *, char const *, int const);
void convert(char *s) {
  char *sIn = s;
  char *sOut = s;
  do {
    while (*sIn != '&' && *sIn != '\0') {
      *sOut = *sIn;
      sIn++;
      sOut++;
    }
    if (*sIn == '&') {
      static const struct {
        const char *token;
        const uint8_t len;
        const char *substitution;
      } replacements[] = {{"&quot;", 6, "\""},
                          {"&apos;", 6, "'"},
                          {"&amp;", 5, "&"},
                          {"&lt;", 4, "<"},
                          {"&gt;", 4, ">"}};
      uint8_t t;
      for (t = 0; t < (sizeof(replacements) / sizeof(replacements[0])); t++) {
        if (strncasecmp(sIn, replacements[t].token, replacements[t].len) == 0) {
          break;
        }
      }
      if (t < (sizeof(replacements) / sizeof(replacements[0]))) {
        sIn += replacements[t].len;
        strcpy(sOut, replacements[t].substitution);
        sOut += strlen(replacements[t].substitution);
      } else {
        *sOut = *sIn;
        sIn++;
        sOut++;
      }
    }
  } while (*sIn != '\0');
  *sOut = '\0';
}


x86 assembly (clang, -O0):
<convert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    1151 <convert+0x21>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x26,%ecx
mov    %al,-0x1d(%rbp)
je     1176 <convert+0x46>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1186 <convert+0x56>
jmp    11af <convert+0x7f>
mov    -0x10(%rbp),%rax
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1151 <convert+0x21>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x26,%eax
jne    12d2 <convert+0x1a2>
movl   $0x0,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    $0x5,%rax
jae    1229 <convert+0xf9>
mov    -0x10(%rbp),%rdi
movslq -0x1c(%rbp),%rcx
lea    0x2bbd(%rip),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%rsi
movslq -0x1c(%rbp),%rcx
lea    0x2ba8(%rip),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
mov    0x8(%rax),%edx
call   1050 <strncasecmp@plt>
cmp    $0x0,%rax
jne    1216 <convert+0xe6>
jmp    1229 <convert+0xf9>
jmp    121b <convert+0xeb>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11c6 <convert+0x96>
movslq -0x1c(%rbp),%rax
cmp    $0x5,%rax
jae    12a9 <convert+0x179>
movslq -0x1c(%rbp),%rcx
lea    0x2b5e(%rip),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
mov    0x8(%rax),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rdi
movslq -0x1c(%rbp),%rcx
lea    0x2b37(%rip),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
mov    0x10(%rax),%rsi
call   1030 <strcpy@plt>
movslq -0x1c(%rbp),%rcx
lea    0x2b1c(%rip),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
mov    0x10(%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    12cd <convert+0x19d>
mov    -0x10(%rbp),%rax
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    12d2 <convert+0x1a2>
jmp    12d7 <convert+0x1a7>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    114c <convert+0x1c>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r13
lea    0xebb(%rip),%r14
lea    0x2c54(%rip),%r12
lea    0xeb6(%rip),%r15
mov    %rdi,%rbx
cs nopw 0x0(%rax,%rax,1)
movzbl 0x0(%r13),%eax
cmp    $0x26,%al
je     1180 <convert+0x50>
test   %al,%al
je     126f <convert+0x13f>
mov    %al,(%rbx)
add    $0x1,%r13
add    $0x1,%rbx
jmp    1160 <convert+0x30>
nopl   (%rax)
mov    %r13,%rdi
mov    %r14,%rsi
mov    $0x6,%edx
call   1050 <strncasecmp@plt>
mov    $0x6,%ebp
test   %rax,%rax
je     1208 <convert+0xd8>
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0x6,%edx
call   1050 <strncasecmp@plt>
test   %rax,%rax
je     120c <convert+0xdc>
mov    %r13,%rdi
lea    0xe59(%rip),%rsi
mov    $0x5,%edx
call   1050 <strncasecmp@plt>
test   %rax,%rax
je     1213 <convert+0xe3>
mov    %r13,%rdi
lea    0xe48(%rip),%rsi
mov    $0x4,%edx
call   1050 <strncasecmp@plt>
test   %rax,%rax
je     121f <convert+0xef>
mov    %r13,%rdi
lea    0xe36(%rip),%rsi
mov    $0x4,%edx
call   1050 <strncasecmp@plt>
test   %rax,%rax
je     122b <convert+0xfb>
movb   $0x26,(%rbx)
add    $0x1,%r13
mov    $0x1,%eax
jmp    1261 <convert+0x131>
xor    %eax,%eax
jmp    1240 <convert+0x110>
mov    $0x1,%eax
jmp    1240 <convert+0x110>
mov    $0x5,%ebp
mov    $0x2,%eax
jmp    1240 <convert+0x110>
mov    $0x4,%ebp
mov    $0x3,%eax
jmp    1240 <convert+0x110>
mov    $0x4,%eax
mov    $0x4,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
add    %rbp,%r13
lea    (%rax,%rax,2),%rax
mov    0x10(%r12,%rax,8),%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
cltq
add    %rax,%rbx
cmpb   $0x0,0x0(%r13)
jne    1160 <convert+0x30>
movb   $0x0,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.anon = type { i8*, i32, i8* }
@convert.replacements = internal unnamed_addr constant [5 x %struct.anon] [%struct.anon { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i32 6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i32 0, i32 0) }, %struct.anon { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i32 0, i32 0), i32 6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i32 0, i32 0) }, %struct.anon { i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i32 0, i32 0), i32 5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i32 0, i32 0) }, %struct.anon { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i32 0, i32 0), i32 4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i32 0, i32 0) }, %struct.anon { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i32 0, i32 0), i32 4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i32 0, i32 0) }]
@.str = [7 x i8] c"&quot;\00"
@.str.1 = [2 x i8] c"\22\00"
@.str.2 = [7 x i8] c"&apos;\00"
@.str.3 = [2 x i8] c"'\00"
@.str.4 = [6 x i8] c"&amp;\00"
@.str.5 = [2 x i8] c"&\00"
@.str.6 = [5 x i8] c"&lt;\00"
@.str.7 = [2 x i8] c"<\00"
@.str.8 = [5 x i8] c"&gt;\00"
@.str.9 = [2 x i8] c">\00"
define void @convert(i8* %0) {
br label %2
2: ; preds = %12, %1
%3 = phi i8* [ %0, %1 ], [ %13, %12 ]
%4 = phi i8* [ %0, %1 ], [ %14, %12 ]
%5 = load i8, i8* %3
switch i8 %5, label %9 [
i8 38, label %6
i8 0, label %44
]
6: ; preds = %2
%7 = tail call i64 @strncasecmp(i8* %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %29, label %15
9: ; preds = %2
store i8 %5, i8* %4
%10 = getelementptr inbounds i8, i8* %3, i64 1
%11 = getelementptr inbounds i8, i8* %4, i64 1
br label %12
12: ; preds = %9, %38
%13 = phi i8* [ %10, %9 ], [ %40, %38 ]
%14 = phi i8* [ %11, %9 ], [ %41, %38 ]
br label %2
15: ; preds = %6
%16 = tail call i64 @strncasecmp(i8* %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 6)
%17 = icmp eq i64 %16, 0
br i1 %17, label %29, label %18
18: ; preds = %15
%19 = tail call i64 @strncasecmp(i8* %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 5)
%20 = icmp eq i64 %19, 0
br i1 %20, label %29, label %21
21: ; preds = %18
%22 = tail call i64 @strncasecmp(i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 4)
%23 = icmp eq i64 %22, 0
br i1 %23, label %29, label %24
24: ; preds = %21
%25 = tail call i64 @strncasecmp(i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i32 4)
%26 = icmp eq i64 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %24
store i8 38, i8* %4
%28 = getelementptr inbounds i8, i8* %3, i64 1
br label %38
29: ; preds = %24, %21, %18, %15, %6
%30 = phi i64 [ 0, %6 ], [ 1, %15 ], [ 2, %18 ], [ 3, %21 ], [ 4, %24 ]
%31 = phi i64 [ 6, %6 ], [ 6, %15 ], [ 5, %18 ], [ 4, %21 ], [ 4, %24 ]
%32 = getelementptr inbounds i8, i8* %3, i64 %31
%33 = getelementptr inbounds [5 x %struct.anon], [5 x %struct.anon]* @convert.replacements, i64 0, i64 %30, i32 2
%34 = load i8*, i8** %33
%35 = tail call i32 @strcpy(i8* %4, i8* %34)
%36 = tail call i32 @strlen(i8* %34)
%37 = sext i32 %36 to i64
br label %38
38: ; preds = %29, %27
%39 = phi i64 [ %37, %29 ], [ 1, %27 ]
%40 = phi i8* [ %32, %29 ], [ %28, %27 ]
%41 = getelementptr inbounds i8, i8* %4, i64 %39
%42 = load i8, i8* %40
%43 = icmp eq i8 %42, 0
br i1 %43, label %44, label %12
44: ; preds = %38, %2
%45 = phi i8* [ %4, %2 ], [ %41, %38 ]
store i8 0, i8* %45
ret void
}