#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 */
char *allocstr(char *);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ strcat(char *, char *);
char *ASCII_to_html(char *s) {
  char buffer[1024];
  char *b;
  b = buffer;
  memset(buffer, '\0', 1024);
  while (*s != '\0') {
    if (((*s) & 0x80) == 0) {
      switch (*s) {
      case '>':
        strcat(buffer, "&gt;");
        b += 4;
        break;
      case '<':
        strcat(buffer, "&lt;");
        b += 4;
        break;
      case '&':
        strcat(buffer, "&amp;");
        b += 5;
        break;
      case '"':
        strcat(buffer, "&quot;");
        b += 6;
        break;
      default:
        *b = *s;
        b++;
      }
    }
    s++;
  }
  *b = '\0';
  return allocstr(buffer);
}


x86 assembly (clang, -O0):
<ASCII_to_html>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x418(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1030 <memset@plt>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1297 <ASCII_to_html+0x167>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
and    $0x80,%eax
cmp    $0x0,%eax
jne    1286 <ASCII_to_html+0x156>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffffde,%eax
mov    %eax,%ecx
mov    %rcx,-0x420(%rbp)
sub    $0x1c,%eax
ja     1260 <ASCII_to_html+0x130>
mov    -0x420(%rbp),%rax
lea    0xe51(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    -0x410(%rbp),%rdi
lea    0xeae(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x418(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x418(%rbp)
jmp    1281 <ASCII_to_html+0x151>
lea    -0x410(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x418(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x418(%rbp)
jmp    1281 <ASCII_to_html+0x151>
lea    -0x410(%rbp),%rdi
lea    0xe64(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x418(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x418(%rbp)
jmp    1281 <ASCII_to_html+0x151>
lea    -0x410(%rbp),%rdi
lea    0xe40(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x418(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x418(%rbp)
jmp    1281 <ASCII_to_html+0x151>
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x418(%rbp),%rax
mov    %cl,(%rax)
mov    -0x418(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x418(%rbp)
jmp    1286 <ASCII_to_html+0x156>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1160 <ASCII_to_html+0x30>
mov    -0x418(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x410(%rbp),%rdi
call   1040 <allocstr@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ASCII_to_html>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rdi,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1030 <memset@plt>
mov    (%rbx),%al
test   %al,%al
je     11ef <ASCII_to_html+0xbf>
mov    %rsp,%r15
add    $0x1,%rbx
lea    0xe92(%rip),%r13
lea    0xf04(%rip),%rbp
lea    0xef8(%rip),%r12
mov    %r15,%r14
jmp    119b <ASCII_to_html+0x6b>
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <strcat@plt>
add    $0x4,%r14
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     11ef <ASCII_to_html+0xbf>
test   $0x80,%al
jne    1190 <ASCII_to_html+0x60>
movsbl %al,%ecx
add    $0xffffffde,%ecx
cmp    $0x1c,%ecx
ja     11c9 <ASCII_to_html+0x99>
movslq 0x0(%r13,%rcx,4),%rcx
add    %r13,%rcx
jmp    *%rcx
mov    %r15,%rdi
lea    0xec6(%rip),%rsi
call   1050 <strcat@plt>
add    $0x6,%r14
jmp    1190 <ASCII_to_html+0x60>
mov    %al,(%r14)
add    $0x1,%r14
jmp    1190 <ASCII_to_html+0x60>
mov    %r15,%rdi
lea    0xea2(%rip),%rsi
call   1050 <strcat@plt>
add    $0x5,%r14
jmp    1190 <ASCII_to_html+0x60>
mov    %r15,%rdi
mov    %rbp,%rsi
jmp    1187 <ASCII_to_html+0x57>
movb   $0x0,(%r14)
mov    %rsp,%rdi
call   1040 <allocstr@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c"&gt;\00"
@.str.1 = [5 x i8] c"&lt;\00"
@.str.2 = [6 x i8] c"&amp;\00"
@.str.3 = [7 x i8] c"&quot;\00"
define i8* @ASCII_to_html(i8* nocapture %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = call i32 @memset(i8* %3, i8 signext 0, i32 1024)
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %34, label %7
7: ; preds = %1, %29
%8 = phi i8 [ %32, %29 ], [ %5, %1 ]
%9 = phi i8* [ %30, %29 ], [ %3, %1 ]
%10 = phi i8* [ %31, %29 ], [ %0, %1 ]
%11 = sext i8 %8 to i32
%12 = and i32 %11, 128
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %29
14: ; preds = %7
switch i32 %11, label %27 [
i32 62, label %15
i32 60, label %18
i32 38, label %21
i32 34, label %24
]
15: ; preds = %14
%16 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%17 = getelementptr inbounds i8, i8* %9, i64 4
br label %29
18: ; preds = %14
%19 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%20 = getelementptr inbounds i8, i8* %9, i64 4
br label %29
21: ; preds = %14
%22 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%23 = getelementptr inbounds i8, i8* %9, i64 5
br label %29
24: ; preds = %14
%25 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%26 = getelementptr inbounds i8, i8* %9, i64 6
br label %29
27: ; preds = %14
store i8 %8, i8* %9
%28 = getelementptr inbounds i8, i8* %9, i64 1
br label %29
29: ; preds = %15, %18, %21, %24, %27, %7
%30 = phi i8* [ %28, %27 ], [ %26, %24 ], [ %23, %21 ], [ %20, %18 ], [ %17, %15 ], [ %9, %7 ]
%31 = getelementptr inbounds i8, i8* %10, i64 1
%32 = load i8, i8* %31
%33 = icmp eq i8 %32, 0
br i1 %33, label %34, label %7
34: ; preds = %29, %1
%35 = phi i8* [ %3, %1 ], [ %30, %29 ]
store i8 0, i8* %35
%36 = call i8* @allocstr(i8* %3)
ret i8* %36
}