#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*/ strcat(char *, char *);
scalar_t__ strlen(char const *);
void make_html_friendly(unsigned char *string, char *html_version) {
  int i, len, html_pos;
  html_pos = 0;
  html_version[html_pos] = '\0';
  len = (int)strlen((const char *)(string));
  for (i = 0; i < len; i++) {
    switch (string[i]) {
    case '>':
      strcat(html_version, "&gt;");
      html_pos += 4;
      break;
    case '<':
      strcat(html_version, "&lt;");
      html_pos += 4;
      break;
    case '&':
      strcat(html_version, "&amp;");
      html_pos += 5;
      break;
    case '"':
      strcat(html_version, "&quot;");
      html_pos += 6;
      break;
    case '\'':
      strcat(html_version, "&apos;");
      html_pos += 6;
      break;
    default:
      html_version[html_pos] = string[i];
      html_pos++;
      html_version[html_pos] = '\0';
      break;
    }
  }
}


x86 assembly (clang, -O0):
<make_html_friendly>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1268 <make_html_friendly+0x148>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
add    $0xffffffde,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x1c,%eax
ja     122a <make_html_friendly+0x10a>
mov    -0x28(%rbp),%rax
lea    0xe75(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
lea    0xed5(%rip),%rsi
call   1040 <strcat@plt>
mov    -0x1c(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x1c(%rbp)
jmp    1255 <make_html_friendly+0x135>
mov    -0x10(%rbp),%rdi
lea    0xebc(%rip),%rsi
call   1040 <strcat@plt>
mov    -0x1c(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x1c(%rbp)
jmp    1255 <make_html_friendly+0x135>
mov    -0x10(%rbp),%rdi
lea    0xea3(%rip),%rsi
call   1040 <strcat@plt>
mov    -0x1c(%rbp),%eax
add    $0x5,%eax
mov    %eax,-0x1c(%rbp)
jmp    1255 <make_html_friendly+0x135>
mov    -0x10(%rbp),%rdi
lea    0xe8b(%rip),%rsi
call   1040 <strcat@plt>
mov    -0x1c(%rbp),%eax
add    $0x6,%eax
mov    %eax,-0x1c(%rbp)
jmp    1255 <make_html_friendly+0x135>
mov    -0x10(%rbp),%rdi
lea    0xe74(%rip),%rsi
call   1040 <strcat@plt>
mov    -0x1c(%rbp),%eax
add    $0x6,%eax
mov    %eax,-0x1c(%rbp)
jmp    1255 <make_html_friendly+0x135>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    125a <make_html_friendly+0x13a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1156 <make_html_friendly+0x36>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_html_friendly>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
movb   $0x0,(%rsi)
call   1030 <strlen@plt>
test   %eax,%eax
jle    11de <make_html_friendly+0xbe>
mov    %eax,%r12d
xor    %r13d,%r13d
lea    0xeb2(%rip),%rbp
xor    %r15d,%r15d
jmp    116f <make_html_friendly+0x4f>
mov    %rbx,%rdi
lea    0xf27(%rip),%rsi
call   1040 <strcat@plt>
add    $0x6,%r15d
add    $0x1,%r13
cmp    %r13,%r12
je     11de <make_html_friendly+0xbe>
movzbl (%r14,%r13,1),%eax
lea    -0x22(%rax),%ecx
cmp    $0x1c,%cl
ja     119e <make_html_friendly+0x7e>
movzbl %cl,%ecx
movslq 0x0(%rbp,%rcx,4),%rcx
add    %rbp,%rcx
jmp    *%rcx
mov    %rbx,%rdi
lea    0xeeb(%rip),%rsi
call   1040 <strcat@plt>
add    $0x5,%r15d
jmp    1166 <make_html_friendly+0x46>
movslq %r15d,%r15
mov    %al,(%rbx,%r15,1)
movb   $0x0,0x1(%rbx,%r15,1)
add    $0x1,%r15
jmp    1166 <make_html_friendly+0x46>
mov    %rbx,%rdi
lea    0xed0(%rip),%rsi
jmp    115d <make_html_friendly+0x3d>
mov    %rbx,%rdi
lea    0xeb2(%rip),%rsi
jmp    11d3 <make_html_friendly+0xb3>
mov    %rbx,%rdi
lea    0xea1(%rip),%rsi
call   1040 <strcat@plt>
add    $0x4,%r15d
jmp    1166 <make_html_friendly+0x46>
add    $0x8,%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"
@.str.4 = [7 x i8] c"&apos;\00"
define void @make_html_friendly(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %7
%8 = load i8*, i8** %4
%9 = load i32, i32* %7
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %8, i64 %10
store i8 0, i8* %11
%12 = load i8*, i8** %3
%13 = call i64 @strlen(i8* %12)
%14 = trunc i64 %13 to i32
store i32 %14, i32* %6
store i32 0, i32* %5
br label %15
15: ; preds = %68, %2
%16 = load i32, i32* %5
%17 = load i32, i32* %6
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %71
19: ; preds = %15
%20 = load i8*, i8** %3
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
switch i32 %25, label %51 [
i32 62, label %26
i32 60, label %31
i32 38, label %36
i32 34, label %41
i32 39, label %46
]
26: ; preds = %19
%27 = load i8*, i8** %4
%28 = call i32 @strcat(i8* %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 4
store i32 %30, i32* %7
br label %67
31: ; preds = %19
%32 = load i8*, i8** %4
%33 = call i32 @strcat(i8* %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%34 = load i32, i32* %7
%35 = add nsw i32 %34, 4
store i32 %35, i32* %7
br label %67
36: ; preds = %19
%37 = load i8*, i8** %4
%38 = call i32 @strcat(i8* %37, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 5
store i32 %40, i32* %7
br label %67
41: ; preds = %19
%42 = load i8*, i8** %4
%43 = call i32 @strcat(i8* %42, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 6
store i32 %45, i32* %7
br label %67
46: ; preds = %19
%47 = load i8*, i8** %4
%48 = call i32 @strcat(i8* %47, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%49 = load i32, i32* %7
%50 = add nsw i32 %49, 6
store i32 %50, i32* %7
br label %67
51: ; preds = %19
%52 = load i8*, i8** %3
%53 = load i32, i32* %5
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %52, i64 %54
%56 = load i8, i8* %55
%57 = load i8*, i8** %4
%58 = load i32, i32* %7
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %57, i64 %59
store i8 %56, i8* %60
%61 = load i32, i32* %7
%62 = add nsw i32 %61, 1
store i32 %62, i32* %7
%63 = load i8*, i8** %4
%64 = load i32, i32* %7
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %63, i64 %65
store i8 0, i8* %66
br label %67
67: ; preds = %51, %46, %41, %36, %31, %26
br label %68
68: ; preds = %67
%69 = load i32, i32* %5
%70 = add nsw i32 %69, 1
store i32 %70, i32* %5
br label %15
71: ; preds = %15
ret void
}

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"
@.str.4 = [7 x i8] c"&apos;\00"
define void @make_html_friendly(i8* nocapture %0, i8* %1) {
store i8 0, i8* %1
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = trunc i64 %3 to i32
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %38
6: ; preds = %2
%7 = and i64 %3, 4294967295
br label %8
8: ; preds = %6, %34
%9 = phi i64 [ 0, %6 ], [ %36, %34 ]
%10 = phi i32 [ 0, %6 ], [ %35, %34 ]
%11 = getelementptr inbounds i8, i8* %0, i64 %9
%12 = load i8, i8* %11
switch i8 %12, label %28 [
i8 62, label %13
i8 60, label %16
i8 38, label %19
i8 34, label %22
i8 39, label %25
]
13: ; preds = %8
%14 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%15 = add nsw i32 %10, 4
br label %34
16: ; preds = %8
%17 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%18 = add nsw i32 %10, 4
br label %34
19: ; preds = %8
%20 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%21 = add nsw i32 %10, 5
br label %34
22: ; preds = %8
%23 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%24 = add nsw i32 %10, 6
br label %34
25: ; preds = %8
%26 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%27 = add nsw i32 %10, 6
br label %34
28: ; preds = %8
%29 = sext i32 %10 to i64
%30 = getelementptr inbounds i8, i8* %1, i64 %29
store i8 %12, i8* %30
%31 = add nsw i32 %10, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %1, i64 %32
store i8 0, i8* %33
br label %34
34: ; preds = %13, %16, %19, %22, %25, %28
%35 = phi i32 [ %31, %28 ], [ %27, %25 ], [ %24, %22 ], [ %21, %19 ], [ %18, %16 ], [ %15, %13 ]
%36 = add nuw nsw i64 %9, 1
%37 = icmp eq i64 %36, %7
br i1 %37, label %38, label %8
38: ; preds = %34, %2
ret void
}