#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(char *, char *, ...);
char *str2html(const char *src) {
  static char buf[2048];
  char *dst;
  for (dst = buf; *src; ++src) {
    if (*src < ' ') {
      sprintf(dst, "&#%d;", *src);
    } else
      switch (*src) {
      case '"':
        sprintf(dst, "&quot;");
        break;
      case '&':
        sprintf(dst, "&amp;");
        break;
      case '<':
        sprintf(dst, "&lt;");
        break;
      case '>':
        sprintf(dst, "&gt;");
        break;
      default:
        *dst++ = *src;
        continue;
      }
    while (*dst)
      ++dst;
  }
  *dst = '\0';
  return buf;
}


x86 assembly (clang, -O0):
<str2html>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0x2f1d(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1245 <str2html+0x135>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jge    1162 <str2html+0x52>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
movsbl (%rax),%edx
lea    0xf1e(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    120c <str2html+0xfc>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffffde,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x1c,%eax
ja     11eb <str2html+0xdb>
mov    -0x18(%rbp),%rax
lea    0xe7a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
lea    0xee0(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1207 <str2html+0xf7>
mov    -0x10(%rbp),%rdi
lea    0xed0(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1207 <str2html+0xf7>
mov    -0x10(%rbp),%rdi
lea    0xebf(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1207 <str2html+0xf7>
mov    -0x10(%rbp),%rdi
lea    0xead(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1207 <str2html+0xf7>
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    1234 <str2html+0x124>
jmp    120c <str2html+0xfc>
jmp    1211 <str2html+0x101>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     122f <str2html+0x11f>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1211 <str2html+0x101>
jmp    1234 <str2html+0x124>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1127 <str2html+0x17>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
lea    0x2ded(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2html>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    (%rdi),%al
test   %al,%al
je     11d6 <str2html+0xc6>
mov    %rdi,%r15
lea    0x2f14(%rip),%rbx
lea    0xf41(%rip),%r14
lea    0xec6(%rip),%r12
jmp    1160 <str2html+0x50>
mov    %al,(%rbx)
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x1(%r15),%al
add    $0x1,%r15
test   %al,%al
je     11dd <str2html+0xcd>
movsbl %al,%edx
cmp    $0x1f,%dl
jg     1190 <str2html+0x80>
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <sprintf@plt>
add    $0xffffffffffffffff,%rbx
mov    %rbx,%rax
nopl   0x0(%rax)
lea    0x1(%rax),%rbx
cmpb   $0x0,0x1(%rax)
mov    %rbx,%rax
jne    1180 <str2html+0x70>
jmp    1150 <str2html+0x40>
nop
add    $0xffffffde,%edx
cmp    $0x1c,%edx
ja     113c <str2html+0x2c>
movslq (%r12,%rdx,4),%rcx
add    %r12,%rcx
jmp    *%rcx
movl   $0x3b746f,0x3(%rbx)
movl   $0x6f757126,(%rbx)
jmp    1175 <str2html+0x65>
movw   $0x3b,0x4(%rbx)
movl   $0x706d6126,(%rbx)
jmp    1175 <str2html+0x65>
movb   $0x0,0x4(%rbx)
movl   $0x3b746c26,(%rbx)
jmp    1175 <str2html+0x65>
movb   $0x0,0x4(%rbx)
movl   $0x3b746726,(%rbx)
jmp    1175 <str2html+0x65>
lea    0x2e63(%rip),%rbx
movb   $0x0,(%rbx)
lea    0x2e59(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@str2html.buf = internal global [2048 x i8] zeroinitializer
@.str = [6 x i8] c"&#%d;\00"
@.str.1 = [7 x i8] c"&quot;\00"
@.str.2 = [6 x i8] c"&amp;\00"
@.str.3 = [5 x i8] c"&lt;\00"
@.str.4 = [5 x i8] c"&gt;\00"
define i8* @str2html(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %30, label %4
4: ; preds = %1, %25
%5 = phi i8 [ %28, %25 ], [ %2, %1 ]
%6 = phi i8* [ %26, %25 ], [ getelementptr inbounds ([2048 x i8], [2048 x i8]* @str2html.buf, i64 0, i64 0), %1 ]
%7 = phi i8* [ %27, %25 ], [ %0, %1 ]
%8 = sext i8 %5 to i32
%9 = icmp slt i8 %5, 32
br i1 %9, label %10, label %13
10: ; preds = %4
%11 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %6, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %12
12: ; preds = %14, %15, %16, %17, %10
br label %20
13: ; preds = %4
switch i32 %8, label %18 [
i32 34, label %14
i32 38, label %15
i32 60, label %16
i32 62, label %17
]
14: ; preds = %13
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(7) %6, i8* align 1 dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i64 7, i1 false)
br label %12
15: ; preds = %13
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(6) %6, i8* align 1 dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i64 6, i1 false)
br label %12
16: ; preds = %13
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(5) %6, i8* align 1 dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 5, i1 false)
br label %12
17: ; preds = %13
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(5) %6, i8* align 1 dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i64 5, i1 false)
br label %12
18: ; preds = %13
%19 = getelementptr inbounds i8, i8* %6, i64 1
store i8 %5, i8* %6
br label %25
20: ; preds = %12, %20
%21 = phi i8* [ %24, %20 ], [ %6, %12 ]
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 0
%24 = getelementptr inbounds i8, i8* %21, i64 1
br i1 %23, label %25, label %20
25: ; preds = %20, %18
%26 = phi i8* [ %19, %18 ], [ %21, %20 ]
%27 = getelementptr inbounds i8, i8* %7, i64 1
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 0
br i1 %29, label %30, label %4
30: ; preds = %25, %1
%31 = phi i8* [ getelementptr inbounds ([2048 x i8], [2048 x i8]* @str2html.buf, i64 0, i64 0), %1 ], [ %26, %25 ]
store i8 0, i8* %31
ret i8* getelementptr inbounds ([2048 x i8], [2048 x i8]* @str2html.buf, i64 0, i64 0)
}