#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*/ strcpyn(char *, size_t, char *);
int /*<<< orphan*/ strlen(char *);
char *escape_html(char *buf, size_t buflen, const char *in) {
  char *out = buf;
  while (*in) {
    if (*in == '<') {
      strcpyn(out, buflen, "&lt;");
      out += strlen(out);
    } else if (*in == '>') {
      strcpyn(out, buflen, "&gt;");
      out += strlen(out);
    } else if (*in == '&') {
      strcpyn(out, buflen, "&amp;");
      out += strlen(out);
    } else if (*in == '"') {
      strcpyn(out, buflen, "&quot;");
      out += strlen(out);
    } else {
      *out++ = *in;
    }
    in++;
  }
  *out++ = '\0';
  return buf;
}


x86 assembly (clang, -O0):
<escape_html>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     1288 <escape_html+0x168>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3c,%eax
jne    118b <escape_html+0x6b>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xe98(%rip),%rdx
call   1040 <strcpyn@plt>
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
jmp    1277 <escape_html+0x157>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3e,%eax
jne    11cd <escape_html+0xad>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xe5b(%rip),%rdx
call   1040 <strcpyn@plt>
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
jmp    1272 <escape_html+0x152>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x26,%eax
jne    120f <escape_html+0xef>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xe1e(%rip),%rdx
call   1040 <strcpyn@plt>
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
jmp    126d <escape_html+0x14d>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
jne    1251 <escape_html+0x131>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    0xde2(%rip),%rdx
call   1040 <strcpyn@plt>
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
jmp    1268 <escape_html+0x148>
mov    -0x18(%rbp),%rax
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
jmp    126d <escape_html+0x14d>
jmp    1272 <escape_html+0x152>
jmp    1277 <escape_html+0x157>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    113c <escape_html+0x1c>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<escape_html>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r12
lea    0xec5(%rip),%r13
lea    0xf32(%rip),%rbp
lea    0xf30(%rip),%r14
mov    %rdi,(%rsp)
jmp    116e <escape_html+0x4e>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
call   1040 <strcpyn@plt>
mov    %r12,%rdi
call   1030 <strlen@plt>
cltq
add    %rax,%r12
add    $0x1,%rbx
movzbl (%rbx),%eax
lea    -0x22(%rax),%ecx
cmp    $0x1c,%cl
ja     11af <escape_html+0x8f>
movzbl %cl,%ecx
movslq 0x0(%r13,%rcx,4),%rcx
add    %r13,%rcx
jmp    *%rcx
mov    %r12,%rdi
mov    %r15,%rsi
lea    0xef1(%rip),%rdx
jmp    1158 <escape_html+0x38>
mov    %r12,%rdi
mov    %r15,%rsi
lea    0xedc(%rip),%rdx
jmp    1158 <escape_html+0x38>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
jmp    1158 <escape_html+0x38>
test   %al,%al
je     11c1 <escape_html+0xa1>
mov    %al,(%r12)
add    $0x1,%r12
add    $0x1,%rbx
jmp    116e <escape_html+0x4e>
movb   $0x0,(%r12)
mov    (%rsp),%rax
add    $0x8,%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 = [7 x i8] c"&quot;\00"
define i8* @escape_html(i8* %0, i64 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
store i8* %2, i8** %6
%8 = load i8*, i8** %4
store i8* %8, i8** %7
br label %9
9: ; preds = %77, %3
%10 = load i8*, i8** %6
%11 = load i8, i8* %10
%12 = icmp ne i8 %11, 0
br i1 %12, label %13, label %80
13: ; preds = %9
%14 = load i8*, i8** %6
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 60
br i1 %17, label %18, label %27
18: ; preds = %13
%19 = load i8*, i8** %7
%20 = load i64, i64* %5
%21 = call i32 @strcpyn(i8* %19, i64 %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%22 = load i8*, i8** %7
%23 = call i32 @strlen(i8* %22)
%24 = load i8*, i8** %7
%25 = sext i32 %23 to i64
%26 = getelementptr inbounds i8, i8* %24, i64 %25
store i8* %26, i8** %7
br label %77
27: ; preds = %13
%28 = load i8*, i8** %6
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 62
br i1 %31, label %32, label %41
32: ; preds = %27
%33 = load i8*, i8** %7
%34 = load i64, i64* %5
%35 = call i32 @strcpyn(i8* %33, i64 %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%36 = load i8*, i8** %7
%37 = call i32 @strlen(i8* %36)
%38 = load i8*, i8** %7
%39 = sext i32 %37 to i64
%40 = getelementptr inbounds i8, i8* %38, i64 %39
store i8* %40, i8** %7
br label %76
41: ; preds = %27
%42 = load i8*, i8** %6
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 38
br i1 %45, label %46, label %55
46: ; preds = %41
%47 = load i8*, i8** %7
%48 = load i64, i64* %5
%49 = call i32 @strcpyn(i8* %47, i64 %48, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%50 = load i8*, i8** %7
%51 = call i32 @strlen(i8* %50)
%52 = load i8*, i8** %7
%53 = sext i32 %51 to i64
%54 = getelementptr inbounds i8, i8* %52, i64 %53
store i8* %54, i8** %7
br label %75
55: ; preds = %41
%56 = load i8*, i8** %6
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = icmp eq i32 %58, 34
br i1 %59, label %60, label %69
60: ; preds = %55
%61 = load i8*, i8** %7
%62 = load i64, i64* %5
%63 = call i32 @strcpyn(i8* %61, i64 %62, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%64 = load i8*, i8** %7
%65 = call i32 @strlen(i8* %64)
%66 = load i8*, i8** %7
%67 = sext i32 %65 to i64
%68 = getelementptr inbounds i8, i8* %66, i64 %67
store i8* %68, i8** %7
br label %74
69: ; preds = %55
%70 = load i8*, i8** %6
%71 = load i8, i8* %70
%72 = load i8*, i8** %7
%73 = getelementptr inbounds i8, i8* %72, i32 1
store i8* %73, i8** %7
store i8 %71, i8* %72
br label %74
74: ; preds = %69, %60
br label %75
75: ; preds = %74, %46
br label %76
76: ; preds = %75, %32
br label %77
77: ; preds = %76, %18
%78 = load i8*, i8** %6
%79 = getelementptr inbounds i8, i8* %78, i32 1
store i8* %79, i8** %6
br label %9
80: ; preds = %9
%81 = load i8*, i8** %7
%82 = getelementptr inbounds i8, i8* %81, i32 1
store i8* %82, i8** %7
store i8 0, i8* %81
%83 = load i8*, i8** %4
ret i8* %83
}

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 = [7 x i8] c"&quot;\00"
define i8* @escape_html(i8* returned %0, i64 %1, i8* nocapture %2) {
br label %4
4: ; preds = %30, %3
%5 = phi i8* [ %2, %3 ], [ %32, %30 ]
%6 = phi i8* [ %0, %3 ], [ %31, %30 ]
%7 = load i8, i8* %5
switch i8 %7, label %28 [
i8 0, label %33
i8 60, label %8
i8 62, label %13
i8 38, label %18
i8 34, label %23
]
8: ; preds = %4
%9 = tail call i32 @strcpyn(i8* %6, i64 %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @strlen(i8* %6)
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %6, i64 %11
br label %30
13: ; preds = %4
%14 = tail call i32 @strcpyn(i8* %6, i64 %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i32 @strlen(i8* %6)
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %6, i64 %16
br label %30
18: ; preds = %4
%19 = tail call i32 @strcpyn(i8* %6, i64 %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%20 = tail call i32 @strlen(i8* %6)
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %6, i64 %21
br label %30
23: ; preds = %4
%24 = tail call i32 @strcpyn(i8* %6, i64 %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%25 = tail call i32 @strlen(i8* %6)
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %6, i64 %26
br label %30
28: ; preds = %4
%29 = getelementptr inbounds i8, i8* %6, i64 1
store i8 %7, i8* %6
br label %30
30: ; preds = %13, %23, %28, %18, %8
%31 = phi i8* [ %12, %8 ], [ %17, %13 ], [ %22, %18 ], [ %27, %23 ], [ %29, %28 ]
%32 = getelementptr inbounds i8, i8* %5, i64 1
br label %4
33: ; preds = %4
store i8 0, i8* %6
ret i8* %0
}