#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*/ sprintf(unsigned char *, char *, unsigned char);
int /*<<< orphan*/ strcpy(unsigned char *, char *);
int /*<<< orphan*/ strncpy(unsigned char *, unsigned char *, int);
int txt2html(unsigned char *src, long srclen, unsigned char *dst, long dstlen) {
  int si, di, substrlen;
  unsigned char *substr;
  unsigned char tmpstr[7];
  unsigned char *lt = "&lt;";
  unsigned char *gt = "&gt;";
  unsigned char *amp = "&amp;";
  unsigned char *nl = "<BR>\n";
  di = 0;
  si = 0;
  if (dstlen < 0 + 0 + 1)
    goto term;
  strcpy(dst, "");
  dst += 0;
  di += 0;
  for (; si < srclen && di < dstlen; si++, src++) {
    if (*src >= 160) {
      substrlen = 6;
      sprintf(tmpstr, "&#%d;", *src);
      substr = tmpstr;
    } else
      switch (*src) {
      case '<':
        substrlen = 4;
        substr = lt;
        break;
      case '>':
        substrlen = 4;
        substr = gt;
        break;
      case '&':
        substrlen = 5;
        substr = amp;
        break;
      case '\n':
        substrlen = 5;
        substr = nl;
        break;
      default:
        substrlen = 1;
        substr = src;
      }
    if (substrlen + di <= dstlen - 0 - 1) {
      strncpy(dst, substr, substrlen);
      dst += substrlen;
      di += substrlen;
    } else {
      break;
    }
  }
  strcpy(dst, "");
  dst += 0;
  di += 0;
term:
  if (si < srclen) {
    return -si;
  } else {
    return di;
  }
}


x86 assembly (clang, -O0):
<txt2html>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
lea    0xeb1(%rip),%rax
mov    %rax,-0x50(%rbp)
lea    0xeab(%rip),%rax
mov    %rax,-0x58(%rbp)
lea    0xea5(%rip),%rax
mov    %rax,-0x60(%rbp)
lea    0xea0(%rip),%rax
mov    %rax,-0x68(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpq   $0x1,-0x28(%rbp)
jge    1192 <txt2html+0x62>
jmp    1361 <txt2html+0x231>
mov    -0x20(%rbp),%rdi
lea    0xe78(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%eax
add    $0x0,%eax
mov    %eax,-0x30(%rbp)
movslq -0x2c(%rbp),%rcx
xor    %eax,%eax
cmp    -0x18(%rbp),%rcx
mov    %al,-0x69(%rbp)
jge    11d4 <txt2html+0xa4>
movslq -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
setl   %al
mov    %al,-0x69(%rbp)
mov    -0x69(%rbp),%al
test   $0x1,%al
jne    11e4 <txt2html+0xb4>
jmp    1340 <txt2html+0x210>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
cmp    $0xa0,%eax
jl     1221 <txt2html+0xf1>
movl   $0x6,-0x34(%rbp)
lea    -0x47(%rbp),%rdi
mov    -0x10(%rbp),%rax
lea    0xe0a(%rip),%rsi
movzbl (%rax),%edx
call   1050 <sprintf@plt>
lea    -0x47(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    12d0 <txt2html+0x1a0>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
mov    %eax,-0x70(%rbp)
sub    $0xa,%eax
je     12a8 <txt2html+0x178>
jmp    1239 <txt2html+0x109>
mov    -0x70(%rbp),%eax
sub    $0x26,%eax
je     1294 <txt2html+0x164>
jmp    124a <txt2html+0x11a>
mov    -0x70(%rbp),%eax
sub    $0x3c,%eax
je     126c <txt2html+0x13c>
jmp    125b <txt2html+0x12b>
mov    -0x70(%rbp),%eax
sub    $0x3e,%eax
je     1280 <txt2html+0x150>
jmp    12bc <txt2html+0x18c>
movl   $0x4,-0x34(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    12cb <txt2html+0x19b>
movl   $0x4,-0x34(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    12cb <txt2html+0x19b>
movl   $0x5,-0x34(%rbp)
mov    -0x60(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    12cb <txt2html+0x19b>
movl   $0x5,-0x34(%rbp)
mov    -0x68(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    12cb <txt2html+0x19b>
movl   $0x1,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    12d0 <txt2html+0x1a0>
mov    -0x34(%rbp),%eax
add    -0x30(%rbp),%eax
cltq
mov    -0x28(%rbp),%rcx
sub    $0x0,%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jg     131c <txt2html+0x1ec>
mov    -0x20(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x34(%rbp),%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x34(%rbp),%eax
add    -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    1321 <txt2html+0x1f1>
jmp    1340 <txt2html+0x210>
jmp    1326 <txt2html+0x1f6>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11b3 <txt2html+0x83>
mov    -0x20(%rbp),%rdi
lea    0xcca(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%eax
add    $0x0,%eax
mov    %eax,-0x30(%rbp)
movslq -0x2c(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    137c <txt2html+0x24c>
xor    %eax,%eax
sub    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1382 <txt2html+0x252>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<txt2html>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbp
mov    %rdi,0x8(%rsp)
test   %rcx,%rcx
jle    1243 <txt2html+0x113>
mov    %rcx,%r12
mov    %rdx,%r15
lea    0xeb9(%rip),%rsi
mov    %rdx,%rdi
call   1040 <strcpy@plt>
test   %rbp,%rbp
jle    124a <txt2html+0x11a>
xor    %ebx,%ebx
xor    %r13d,%r13d
mov    %rbp,(%rsp)
cs nopw 0x0(%rax,%rax,1)
mov    0x8(%rsp),%rax
movzbl (%rax,%rbx,1),%eax
cmp    $0xa0,%al
jb     11e0 <txt2html+0xb0>
movzbl %al,%edx
lea    0x11(%rsp),%r14
mov    %r14,%rdi
lea    0xe77(%rip),%rsi
call   1050 <sprintf@plt>
mov    $0x6,%ebp
mov    %r14,%rsi
lea    0x0(%rbp,%r13,1),%r14d
cmp    %r12,%r14
jge    1251 <txt2html+0x121>
mov    %r15,%rdi
mov    %ebp,%edx
call   1030 <strncpy@plt>
mov    %ebp,%eax
add    %rax,%r15
add    $0x1,%rbx
mov    %r14d,%r13d
mov    (%rsp),%rbp
cmp    %rbp,%rbx
jl     1180 <txt2html+0x50>
jmp    1258 <txt2html+0x128>
nopl   0x0(%rax,%rax,1)
cmp    $0x3b,%al
jg     1200 <txt2html+0xd0>
cmp    $0xa,%al
je     1216 <txt2html+0xe6>
cmp    $0x26,%al
jne    1230 <txt2html+0x100>
mov    $0x5,%ebp
lea    0xe12(%rip),%rsi
jmp    11ac <txt2html+0x7c>
nopw   0x0(%rax,%rax,1)
mov    $0x4,%ebp
cmp    $0x3c,%al
je     1224 <txt2html+0xf4>
cmp    $0x3e,%al
jne    1230 <txt2html+0x100>
lea    0xdf1(%rip),%rsi
jmp    11ac <txt2html+0x7c>
mov    $0x5,%ebp
lea    0xdee(%rip),%rsi
jmp    11ac <txt2html+0x7c>
lea    0xdd5(%rip),%rsi
jmp    11ac <txt2html+0x7c>
mov    0x8(%rsp),%rax
lea    (%rax,%rbx,1),%rsi
mov    $0x1,%ebp
jmp    11ac <txt2html+0x7c>
xor    %r14d,%r14d
xor    %ebx,%ebx
jmp    1267 <txt2html+0x137>
xor    %r14d,%r14d
xor    %ebx,%ebx
jmp    1258 <txt2html+0x128>
mov    %r13d,%r14d
mov    (%rsp),%rbp
lea    0xdb6(%rip),%rsi
mov    %r15,%rdi
call   1040 <strcpy@plt>
mov    %ebx,%eax
neg    %ebx
cmp    %rbp,%rax
cmovge %r14d,%ebx
mov    %ebx,%eax
add    $0x18,%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 = [6 x i8] c"<BR>\0A\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [6 x i8] c"&#%d;\00"
define i32 @txt2html(i8* %0, i64 %1, i8* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
%14 = alloca [7 x i8]
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i8*
%18 = alloca i8*
store i8* %0, i8** %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i64 %3, i64* %9
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %15
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %16
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8** %17
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8** %18
store i32 0, i32* %11
store i32 0, i32* %10
%19 = load i64, i64* %9
%20 = icmp slt i64 %19, 1
br i1 %20, label %21, label %22
21: ; preds = %4
br label %102
22: ; preds = %4
%23 = load i8*, i8** %8
%24 = call i32 @strcpy(i8* %23, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
%25 = load i8*, i8** %8
%26 = getelementptr inbounds i8, i8* %25, i64 0
store i8* %26, i8** %8
%27 = load i32, i32* %11
%28 = add nsw i32 %27, 0
store i32 %28, i32* %11
br label %29
29: ; preds = %90, %22
%30 = load i32, i32* %10
%31 = sext i32 %30 to i64
%32 = load i64, i64* %7
%33 = icmp slt i64 %31, %32
br i1 %33, label %34, label %39
34: ; preds = %29
%35 = load i32, i32* %11
%36 = sext i32 %35 to i64
%37 = load i64, i64* %9
%38 = icmp slt i64 %36, %37
br label %39
39: ; preds = %34, %29
%40 = phi i1 [ false, %29 ], [ %38, %34 ]
br i1 %40, label %41, label %95
41: ; preds = %39
%42 = load i8*, i8** %6
%43 = load i8, i8* %42
%44 = zext i8 %43 to i32
%45 = icmp sge i32 %44, 160
br i1 %45, label %46, label %52
46: ; preds = %41
store i32 6, i32* %12
%47 = getelementptr inbounds [7 x i8], [7 x i8]* %14, i64 0, i64 0
%48 = load i8*, i8** %6
%49 = load i8, i8* %48
%50 = call i32 @sprintf(i8* %47, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8 zeroext %49)
%51 = getelementptr inbounds [7 x i8], [7 x i8]* %14, i64 0, i64 0
store i8* %51, i8** %13
br label %67
52: ; preds = %41
%53 = load i8*, i8** %6
%54 = load i8, i8* %53
%55 = zext i8 %54 to i32
switch i32 %55, label %64 [
i32 60, label %56
i32 62, label %58
i32 38, label %60
i32 10, label %62
]
56: ; preds = %52
store i32 4, i32* %12
%57 = load i8*, i8** %15
store i8* %57, i8** %13
br label %66
58: ; preds = %52
store i32 4, i32* %12
%59 = load i8*, i8** %16
store i8* %59, i8** %13
br label %66
60: ; preds = %52
store i32 5, i32* %12
%61 = load i8*, i8** %17
store i8* %61, i8** %13
br label %66
62: ; preds = %52
store i32 5, i32* %12
%63 = load i8*, i8** %18
store i8* %63, i8** %13
br label %66
64: ; preds = %52
store i32 1, i32* %12
%65 = load i8*, i8** %6
store i8* %65, i8** %13
br label %66
66: ; preds = %64, %62, %60, %58, %56
br label %67
67: ; preds = %66, %46
%68 = load i32, i32* %12
%69 = load i32, i32* %11
%70 = add nsw i32 %68, %69
%71 = sext i32 %70 to i64
%72 = load i64, i64* %9
%73 = sub nsw i64 %72, 0
%74 = sub nsw i64 %73, 1
%75 = icmp sle i64 %71, %74
br i1 %75, label %76, label %88
76: ; preds = %67
%77 = load i8*, i8** %8
%78 = load i8*, i8** %13
%79 = load i32, i32* %12
%80 = call i32 @strncpy(i8* %77, i8* %78, i32 %79)
%81 = load i32, i32* %12
%82 = load i8*, i8** %8
%83 = sext i32 %81 to i64
%84 = getelementptr inbounds i8, i8* %82, i64 %83
store i8* %84, i8** %8
%85 = load i32, i32* %12
%86 = load i32, i32* %11
%87 = add nsw i32 %86, %85
store i32 %87, i32* %11
br label %89
88: ; preds = %67
br label %95
89: ; preds = %76
br label %90
90: ; preds = %89
%91 = load i32, i32* %10
%92 = add nsw i32 %91, 1
store i32 %92, i32* %10
%93 = load i8*, i8** %6
%94 = getelementptr inbounds i8, i8* %93, i32 1
store i8* %94, i8** %6
br label %29
95: ; preds = %88, %39
%96 = load i8*, i8** %8
%97 = call i32 @strcpy(i8* %96, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
%98 = load i8*, i8** %8
%99 = getelementptr inbounds i8, i8* %98, i64 0
store i8* %99, i8** %8
%100 = load i32, i32* %11
%101 = add nsw i32 %100, 0
store i32 %101, i32* %11
br label %102
102: ; preds = %95, %21
%103 = load i32, i32* %10
%104 = sext i32 %103 to i64
%105 = load i64, i64* %7
%106 = icmp slt i64 %104, %105
br i1 %106, label %107, label %110
107: ; preds = %102
%108 = load i32, i32* %10
%109 = sub nsw i32 0, %108
store i32 %109, i32* %5
br label %112
110: ; preds = %102
%111 = load i32, i32* %11
store i32 %111, i32* %5
br label %112
112: ; preds = %110, %107
%113 = load i32, i32* %5
ret i32 %113
}

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 = [6 x i8] c"<BR>\0A\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [6 x i8] c"&#%d;\00"
define i32 @txt2html(i8* %0, i64 %1, i8* %2, i64 %3) {
%5 = alloca [7 x i8]
%6 = getelementptr inbounds [7 x i8], [7 x i8]* %5, i64 0, i64 0
%7 = icmp slt i64 %3, 1
br i1 %7, label %48, label %8
8: ; preds = %4
%9 = tail call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
%10 = icmp sgt i64 %1, 0
br i1 %10, label %11, label %43
11: ; preds = %8, %31
%12 = phi i64 [ %35, %31 ], [ 0, %8 ]
%13 = phi i8* [ %36, %31 ], [ %0, %8 ]
%14 = phi i8* [ %34, %31 ], [ %2, %8 ]
%15 = phi i32 [ %28, %31 ], [ 0, %8 ]
%16 = load i8, i8* %13
%17 = icmp ugt i8 %16, -97
br i1 %17, label %18, label %20
18: ; preds = %11
%19 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8 zeroext %16)
br label %25
20: ; preds = %11
switch i8 %16, label %24 [
i8 60, label %25
i8 62, label %21
i8 38, label %22
i8 10, label %23
]
21: ; preds = %20
br label %25
22: ; preds = %20
br label %25
23: ; preds = %20
br label %25
24: ; preds = %20
br label %25
25: ; preds = %20, %21, %22, %23, %24, %18
%26 = phi i32 [ 6, %18 ], [ 1, %24 ], [ 5, %23 ], [ 5, %22 ], [ 4, %21 ], [ 4, %20 ]
%27 = phi i8* [ %6, %18 ], [ %13, %24 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), %23 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), %22 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %21 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %20 ]
%28 = add nuw nsw i32 %26, %15
%29 = zext i32 %28 to i64
%30 = icmp slt i64 %29, %3
br i1 %30, label %31, label %38
31: ; preds = %25
%32 = call i32 @strncpy(i8* %14, i8* %27, i32 %26)
%33 = zext i32 %26 to i64
%34 = getelementptr inbounds i8, i8* %14, i64 %33
%35 = add nuw nsw i64 %12, 1
%36 = getelementptr inbounds i8, i8* %13, i64 1
%37 = icmp slt i64 %35, %1
br i1 %37, label %11, label %38
38: ; preds = %25, %31
%39 = phi i32 [ %28, %31 ], [ %15, %25 ]
%40 = phi i64 [ %35, %31 ], [ %12, %25 ]
%41 = phi i8* [ %34, %31 ], [ %14, %25 ]
%42 = trunc i64 %40 to i32
br label %43
43: ; preds = %38, %8
%44 = phi i32 [ 0, %8 ], [ %39, %38 ]
%45 = phi i32 [ 0, %8 ], [ %42, %38 ]
%46 = phi i8* [ %2, %8 ], [ %41, %38 ]
%47 = call i32 @strcpy(i8* %46, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
br label %48
48: ; preds = %4, %43
%49 = phi i32 [ 0, %4 ], [ %44, %43 ]
%50 = phi i32 [ 0, %4 ], [ %45, %43 ]
%51 = zext i32 %50 to i64
%52 = icmp slt i64 %51, %1
%53 = sub nsw i32 0, %50
%54 = select i1 %52, i32 %53, i32 %49
ret i32 %54
}