#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 /*<<< orphan*/ buf;

/* Variables and functions */
scalar_t__ strncmp(char const *, char *, int);
char *firetalk_htmlclean(const char *str) {
  static char buf[2048];
  int i, b = 0;
  for (i = 0; (str[i] != 0) && (b < sizeof(buf) - 1); i++)
    if ((strncmp((str + i), ("&gt;"), sizeof("&gt;") - 1)) == 0) {
      buf[b++] = '>';
      i += sizeof("&gt;") - 2;
    } else if ((strncmp((str + i), ("&lt;"), sizeof("&lt;") - 1)) == 0) {
      buf[b++] = '<';
      i += sizeof("&lt;") - 2;
    } else if ((strncmp((str + i), ("&quot;"), sizeof("&quot;") - 1)) == 0) {
      buf[b++] = '"';
      i += sizeof("&quot;") - 2;
    } else if ((strncmp((str + i), ("&nbsp;"), sizeof("&nbsp;") - 1)) == 0) {
      buf[b++] = ' ';
      i += sizeof("&nbsp;") - 2;
    } else if ((strncmp((str + i), ("&amp;"), sizeof("&amp;") - 1)) == 0) {
      buf[b++] = '&';
      i += sizeof("&amp;") - 2;
    } else
      buf[b++] = str[i];
  buf[b] = 0;
  return (buf);
}


x86 assembly (clang, -O0):
<firetalk_htmlclean>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x11(%rbp)
je     1154 <firetalk_htmlclean+0x44>
movslq -0x10(%rbp),%rax
cmp    $0x7ff,%rax
setb   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1164 <firetalk_htmlclean+0x54>
jmp    1339 <firetalk_htmlclean+0x229>
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
add    %rax,%rdi
lea    0xe8a(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11b3 <firetalk_htmlclean+0xa3>
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x10(%rbp)
movslq %eax,%rcx
lea    0x2ea1(%rip),%rax
movb   $0x3e,(%rax,%rcx,1)
movslq -0xc(%rbp),%rax
add    $0x3,%rax
mov    %eax,-0xc(%rbp)
jmp    1326 <firetalk_htmlclean+0x216>
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
add    %rax,%rdi
lea    0xe40(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1202 <firetalk_htmlclean+0xf2>
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x10(%rbp)
movslq %eax,%rcx
lea    0x2e52(%rip),%rax
movb   $0x3c,(%rax,%rcx,1)
movslq -0xc(%rbp),%rax
add    $0x3,%rax
mov    %eax,-0xc(%rbp)
jmp    1321 <firetalk_htmlclean+0x211>
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
add    %rax,%rdi
lea    0xdf6(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1251 <firetalk_htmlclean+0x141>
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x10(%rbp)
movslq %eax,%rcx
lea    0x2e03(%rip),%rax
movb   $0x22,(%rax,%rcx,1)
movslq -0xc(%rbp),%rax
add    $0x5,%rax
mov    %eax,-0xc(%rbp)
jmp    131c <firetalk_htmlclean+0x20c>
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
add    %rax,%rdi
lea    0xdae(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    12a0 <firetalk_htmlclean+0x190>
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x10(%rbp)
movslq %eax,%rcx
lea    0x2db4(%rip),%rax
movb   $0x20,(%rax,%rcx,1)
movslq -0xc(%rbp),%rax
add    $0x5,%rax
mov    %eax,-0xc(%rbp)
jmp    1317 <firetalk_htmlclean+0x207>
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
add    %rax,%rdi
lea    0xd66(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    12ef <firetalk_htmlclean+0x1df>
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x10(%rbp)
movslq %eax,%rcx
lea    0x2d65(%rip),%rax
movb   $0x26,(%rax,%rcx,1)
movslq -0xc(%rbp),%rax
add    $0x4,%rax
mov    %eax,-0xc(%rbp)
jmp    1312 <firetalk_htmlclean+0x202>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x10(%rbp)
movslq %eax,%rcx
lea    0x2d31(%rip),%rax
mov    %dl,(%rax,%rcx,1)
jmp    1317 <firetalk_htmlclean+0x207>
jmp    131c <firetalk_htmlclean+0x20c>
jmp    1321 <firetalk_htmlclean+0x211>
jmp    1326 <firetalk_htmlclean+0x216>
jmp    132b <firetalk_htmlclean+0x21b>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    112a <firetalk_htmlclean+0x1a>
movslq -0x10(%rbp),%rcx
lea    0x2cfc(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2cf1(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<firetalk_htmlclean>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %r13d,%r13d
cmpb   $0x0,(%rdi)
je     1240 <firetalk_htmlclean+0x130>
mov    %rdi,%rbp
lea    0xecf(%rip),%r14
lea    0x2f08(%rip),%r12
xor    %r15d,%r15d
mov    %rdi,%rbx
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11d0 <firetalk_htmlclean+0xc0>
mov    %rbx,%rdi
lea    0xea6(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11e0 <firetalk_htmlclean+0xd0>
mov    %rbx,%rdi
lea    0xe92(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11eb <firetalk_htmlclean+0xdb>
mov    %rbx,%rdi
lea    0xe80(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11f6 <firetalk_htmlclean+0xe6>
mov    %rbx,%rdi
lea    0xe6e(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1201 <firetalk_htmlclean+0xf1>
movzbl (%rbx),%eax
mov    %al,(%r15,%r12,1)
jmp    1210 <firetalk_htmlclean+0x100>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movb   $0x3e,(%r15,%r12,1)
add    $0x3,%r13d
jmp    1210 <firetalk_htmlclean+0x100>
nopl   0x0(%rax,%rax,1)
movb   $0x3c,(%r15,%r12,1)
add    $0x3,%r13d
jmp    1210 <firetalk_htmlclean+0x100>
movb   $0x22,(%r15,%r12,1)
add    $0x5,%r13d
jmp    1210 <firetalk_htmlclean+0x100>
movb   $0x20,(%r15,%r12,1)
add    $0x5,%r13d
jmp    1210 <firetalk_htmlclean+0x100>
movb   $0x26,(%r15,%r12,1)
add    $0x4,%r13d
nopw   0x0(%rax,%rax,1)
lea    0x1(%r15),%rcx
movslq %r13d,%r13
cmpb   $0x0,0x1(%rbp,%r13,1)
je     1242 <firetalk_htmlclean+0x132>
lea    0x1(,%r13,1),%rbx
add    %rbp,%rbx
add    $0x1,%r13
cmp    $0x7fe,%r15
mov    %rcx,%r15
jb     1140 <firetalk_htmlclean+0x30>
jmp    1242 <firetalk_htmlclean+0x132>
xor    %ecx,%ecx
lea    0x2df7(%rip),%rax
movb   $0x0,(%rcx,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@firetalk_htmlclean.buf = internal global [2048 x i8] zeroinitializer
@.str = [5 x i8] c"&gt;\00"
@.str.1 = [5 x i8] c"&lt;\00"
@.str.2 = [7 x i8] c"&quot;\00"
@.str.3 = [7 x i8] c"&nbsp;\00"
@.str.4 = [6 x i8] c"&amp;\00"
define i8* @firetalk_htmlclean(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %52, label %4
4: ; preds = %1, %40
%5 = phi i64 [ %42, %40 ], [ 0, %1 ]
%6 = phi i8* [ %45, %40 ], [ %0, %1 ]
%7 = phi i32 [ %43, %40 ], [ 0, %1 ]
%8 = tail call i64 @strncmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %4
%11 = getelementptr inbounds [2048 x i8], [2048 x i8]* @firetalk_htmlclean.buf, i64 0, i64 %5
store i8 62, i8* %11
%12 = add i32 %7, 3
br label %40
13: ; preds = %4
%14 = tail call i64 @strncmp(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = getelementptr inbounds [2048 x i8], [2048 x i8]* @firetalk_htmlclean.buf, i64 0, i64 %5
store i8 60, i8* %17
%18 = add i32 %7, 3
br label %40
19: ; preds = %13
%20 = tail call i64 @strncmp(i8* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 6)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = getelementptr inbounds [2048 x i8], [2048 x i8]* @firetalk_htmlclean.buf, i64 0, i64 %5
store i8 34, i8* %23
%24 = add i32 %7, 5
br label %40
25: ; preds = %19
%26 = tail call i64 @strncmp(i8* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 6)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = getelementptr inbounds [2048 x i8], [2048 x i8]* @firetalk_htmlclean.buf, i64 0, i64 %5
store i8 32, i8* %29
%30 = add i32 %7, 5
br label %40
31: ; preds = %25
%32 = tail call i64 @strncmp(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 5)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %31
%35 = getelementptr inbounds [2048 x i8], [2048 x i8]* @firetalk_htmlclean.buf, i64 0, i64 %5
store i8 38, i8* %35
%36 = add i32 %7, 4
br label %40
37: ; preds = %31
%38 = load i8, i8* %6
%39 = getelementptr inbounds [2048 x i8], [2048 x i8]* @firetalk_htmlclean.buf, i64 0, i64 %5
store i8 %38, i8* %39
br label %40
40: ; preds = %10, %22, %34, %37, %28, %16
%41 = phi i32 [ %12, %10 ], [ %18, %16 ], [ %24, %22 ], [ %30, %28 ], [ %36, %34 ], [ %7, %37 ]
%42 = add nuw nsw i64 %5, 1
%43 = add nsw i32 %41, 1
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %0, i64 %44
%46 = load i8, i8* %45
%47 = icmp ne i8 %46, 0
%48 = icmp ult i64 %5, 2046
%49 = select i1 %47, i1 %48, i1 false
br i1 %49, label %4, label %50
50: ; preds = %40
%51 = and i64 %42, 4294967295
br label %52
52: ; preds = %50, %1
%53 = phi i64 [ 0, %1 ], [ %51, %50 ]
%54 = getelementptr inbounds [2048 x i8], [2048 x i8]* @firetalk_htmlclean.buf, i64 0, i64 %53
store i8 0, i8* %54
ret i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @firetalk_htmlclean.buf, i64 0, i64 0)
}