#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 *malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char const *);
char *mangle_htmlescape(const char *in) {
  char *out, *tmp;
  int outlen;
  const char *s;
  outlen = strlen(in);
  for (s = in; *s; s++) {
    char c = *s;
    switch (c) {
    case '<':
    case '>':
      outlen += 3;
      break;
    case '&':
      outlen += 4;
      break;
    case '"':
      outlen += 5;
      break;
    }
  }
  out = malloc(outlen + 1);
  if (!out)
    return NULL;
  for (s = in, tmp = out; *s; s++, tmp++) {
    unsigned char c = *s;
    switch (c) {
    case '<':
      strcpy(tmp, "&lt;");
      tmp += 3;
      break;
    case '>':
      strcpy(tmp, "&gt;");
      tmp += 3;
      break;
    case '&':
      strcpy(tmp, "&amp;");
      tmp += 4;
      break;
    case '"':
      strcpy(tmp, "&quot;");
      tmp += 5;
      break;
    default:
      *tmp = c;
      break;
    }
  }
  *tmp = '\0';
  return out;
}


x86 assembly (clang, -O0):
<mangle_htmlescape>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmpb   $0x0,(%rax)
je     11cb <mangle_htmlescape+0x9b>
mov    -0x30(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x31(%rbp)
movsbl -0x31(%rbp),%eax
add    $0xffffffde,%eax
mov    %eax,%ecx
mov    %rcx,-0x40(%rbp)
sub    $0x1c,%eax
ja     11b5 <mangle_htmlescape+0x85>
mov    -0x40(%rbp),%rax
lea    0xeed(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x24(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x24(%rbp)
jmp    11b5 <mangle_htmlescape+0x85>
mov    -0x24(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x24(%rbp)
jmp    11b5 <mangle_htmlescape+0x85>
mov    -0x24(%rbp),%eax
add    $0x5,%eax
mov    %eax,-0x24(%rbp)
jmp    11ba <mangle_htmlescape+0x8a>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1150 <mangle_htmlescape+0x20>
mov    -0x24(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f2 <mangle_htmlescape+0xc2>
movq   $0x0,-0x8(%rbp)
jmp    1300 <mangle_htmlescape+0x1d0>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%rax
cmpb   $0x0,(%rax)
je     12f1 <mangle_htmlescape+0x1c1>
mov    -0x30(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x32(%rbp)
movzbl -0x32(%rbp),%eax
add    $0xffffffde,%eax
mov    %eax,%ecx
mov    %rcx,-0x48(%rbp)
sub    $0x1c,%eax
ja     12c6 <mangle_htmlescape+0x196>
mov    -0x48(%rbp),%rax
lea    0xdc7(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x20(%rbp),%rdi
lea    0xe9b(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x20(%rbp)
jmp    12cf <mangle_htmlescape+0x19f>
mov    -0x20(%rbp),%rdi
lea    0xe7f(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x20(%rbp)
jmp    12cf <mangle_htmlescape+0x19f>
mov    -0x20(%rbp),%rdi
lea    0xe63(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x20(%rbp)
jmp    12cf <mangle_htmlescape+0x19f>
mov    -0x20(%rbp),%rdi
lea    0xe48(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x20(%rbp)
jmp    12cf <mangle_htmlescape+0x19f>
mov    -0x32(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
jmp    12d4 <mangle_htmlescape+0x1a4>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1202 <mangle_htmlescape+0xd2>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mangle_htmlescape>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    (%rbx),%r15b
test   %r15b,%r15b
je     11a5 <mangle_htmlescape+0x75>
lea    0x1(%rbx),%rcx
lea    0xeaa(%rip),%rsi
mov    %r15d,%edx
jmp    117b <mangle_htmlescape+0x4b>
nopl   0x0(%rax,%rax,1)
add    $0x5,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%rcx),%edx
add    $0x1,%rcx
test   %dl,%dl
je     11a5 <mangle_htmlescape+0x75>
movsbl %dl,%edx
add    $0xffffffde,%edx
cmp    $0x1c,%edx
ja     1170 <mangle_htmlescape+0x40>
movslq (%rsi,%rdx,4),%rdx
add    %rsi,%rdx
jmp    *%rdx
add    $0x3,%eax
jmp    1170 <mangle_htmlescape+0x40>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x4,%eax
jmp    1170 <mangle_htmlescape+0x40>
add    $0x1,%eax
mov    %eax,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     1250 <mangle_htmlescape+0x120>
add    $0x1,%rbx
lea    0xeb1(%rip),%r12
lea    0xf1e(%rip),%r13
lea    0xf1c(%rip),%rbp
mov    %rax,(%rsp)
mov    %rax,%r14
jmp    11fc <mangle_htmlescape+0xcc>
mov    %r14,%rdi
lea    0xf14(%rip),%rsi
call   1030 <strcpy@plt>
add    $0x5,%r14
nopl   (%rax)
add    $0x1,%r14
movzbl (%rbx),%r15d
add    $0x1,%rbx
lea    -0x22(%r15),%eax
cmp    $0x1c,%al
ja     123e <mangle_htmlescape+0x10e>
movzbl %al,%eax
movslq (%r12,%rax,4),%rax
add    %r12,%rax
jmp    *%rax
mov    %r14,%rdi
lea    0xed8(%rip),%rsi
call   1030 <strcpy@plt>
add    $0x4,%r14
jmp    11f0 <mangle_htmlescape+0xc0>
mov    %r14,%rdi
mov    %r13,%rsi
jmp    1233 <mangle_htmlescape+0x103>
mov    %r14,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
add    $0x3,%r14
jmp    11f0 <mangle_htmlescape+0xc0>
test   %r15b,%r15b
je     1248 <mangle_htmlescape+0x118>
mov    %r15b,(%r14)
jmp    11f0 <mangle_htmlescape+0xc0>
movb   $0x0,(%r14)
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* @mangle_htmlescape(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8
%9 = alloca i8
store i8* %0, i8** %3
%10 = load i8*, i8** %3
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %6
%12 = load i8*, i8** %3
store i8* %12, i8** %7
br label %13
13: ; preds = %32, %1
%14 = load i8*, i8** %7
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
br i1 %16, label %17, label %35
17: ; preds = %13
%18 = load i8*, i8** %7
%19 = load i8, i8* %18
store i8 %19, i8* %8
%20 = load i8, i8* %8
%21 = sext i8 %20 to i32
switch i32 %21, label %31 [
i32 60, label %22
i32 62, label %22
i32 38, label %25
i32 34, label %28
]
22: ; preds = %17, %17
%23 = load i32, i32* %6
%24 = add nsw i32 %23, 3
store i32 %24, i32* %6
br label %31
25: ; preds = %17
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 4
store i32 %27, i32* %6
br label %31
28: ; preds = %17
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 5
store i32 %30, i32* %6
br label %31
31: ; preds = %17, %28, %25, %22
br label %32
32: ; preds = %31
%33 = load i8*, i8** %7
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %7
br label %13
35: ; preds = %13
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
%38 = call i8* @malloc(i32 %37)
store i8* %38, i8** %4
%39 = load i8*, i8** %4
%40 = icmp ne i8* %39, null
br i1 %40, label %42, label %41
41: ; preds = %35
store i8* null, i8** %2
br label %86
42: ; preds = %35
%43 = load i8*, i8** %3
store i8* %43, i8** %7
%44 = load i8*, i8** %4
store i8* %44, i8** %5
br label %45
45: ; preds = %78, %42
%46 = load i8*, i8** %7
%47 = load i8, i8* %46
%48 = icmp ne i8 %47, 0
br i1 %48, label %49, label %83
49: ; preds = %45
%50 = load i8*, i8** %7
%51 = load i8, i8* %50
store i8 %51, i8* %9
%52 = load i8, i8* %9
%53 = zext i8 %52 to i32
switch i32 %53, label %74 [
i32 60, label %54
i32 62, label %59
i32 38, label %64
i32 34, label %69
]
54: ; preds = %49
%55 = load i8*, i8** %5
%56 = call i32 @strcpy(i8* %55, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%57 = load i8*, i8** %5
%58 = getelementptr inbounds i8, i8* %57, i64 3
store i8* %58, i8** %5
br label %77
59: ; preds = %49
%60 = load i8*, i8** %5
%61 = call i32 @strcpy(i8* %60, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%62 = load i8*, i8** %5
%63 = getelementptr inbounds i8, i8* %62, i64 3
store i8* %63, i8** %5
br label %77
64: ; preds = %49
%65 = load i8*, i8** %5
%66 = call i32 @strcpy(i8* %65, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%67 = load i8*, i8** %5
%68 = getelementptr inbounds i8, i8* %67, i64 4
store i8* %68, i8** %5
br label %77
69: ; preds = %49
%70 = load i8*, i8** %5
%71 = call i32 @strcpy(i8* %70, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%72 = load i8*, i8** %5
%73 = getelementptr inbounds i8, i8* %72, i64 5
store i8* %73, i8** %5
br label %77
74: ; preds = %49
%75 = load i8, i8* %9
%76 = load i8*, i8** %5
store i8 %75, i8* %76
br label %77
77: ; preds = %74, %69, %64, %59, %54
br label %78
78: ; preds = %77
%79 = load i8*, i8** %7
%80 = getelementptr inbounds i8, i8* %79, i32 1
store i8* %80, i8** %7
%81 = load i8*, i8** %5
%82 = getelementptr inbounds i8, i8* %81, i32 1
store i8* %82, i8** %5
br label %45
83: ; preds = %45
%84 = load i8*, i8** %5
store i8 0, i8* %84
%85 = load i8*, i8** %4
store i8* %85, i8** %2
br label %86
86: ; preds = %83, %41
%87 = load i8*, i8** %2
ret i8* %87
}

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* @mangle_htmlescape(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %21, label %5
5: ; preds = %1, %16
%6 = phi i8 [ %19, %16 ], [ %3, %1 ]
%7 = phi i8* [ %18, %16 ], [ %0, %1 ]
%8 = phi i32 [ %17, %16 ], [ %2, %1 ]
%9 = sext i8 %6 to i32
switch i32 %9, label %16 [
i32 60, label %10
i32 62, label %10
i32 38, label %12
i32 34, label %14
]
10: ; preds = %5, %5
%11 = add nsw i32 %8, 3
br label %16
12: ; preds = %5
%13 = add nsw i32 %8, 4
br label %16
14: ; preds = %5
%15 = add nsw i32 %8, 5
br label %16
16: ; preds = %5, %14, %12, %10
%17 = phi i32 [ %8, %5 ], [ %15, %14 ], [ %13, %12 ], [ %11, %10 ]
%18 = getelementptr inbounds i8, i8* %7, i64 1
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 0
br i1 %20, label %21, label %5
21: ; preds = %16, %1
%22 = phi i32 [ %2, %1 ], [ %17, %16 ]
%23 = add nsw i32 %22, 1
%24 = tail call i8* @malloc(i32 %23)
%25 = icmp eq i8* %24, null
br i1 %25, label %49, label %26
26: ; preds = %21, %43
%27 = phi i8 [ %47, %43 ], [ %3, %21 ]
%28 = phi i8* [ %45, %43 ], [ %0, %21 ]
%29 = phi i8* [ %46, %43 ], [ %24, %21 ]
switch i8 %27, label %42 [
i8 0, label %48
i8 60, label %30
i8 62, label %33
i8 38, label %36
i8 34, label %39
]
30: ; preds = %26
%31 = tail call i32 @strcpy(i8* %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%32 = getelementptr inbounds i8, i8* %29, i64 3
br label %43
33: ; preds = %26
%34 = tail call i32 @strcpy(i8* %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%35 = getelementptr inbounds i8, i8* %29, i64 3
br label %43
36: ; preds = %26
%37 = tail call i32 @strcpy(i8* %29, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%38 = getelementptr inbounds i8, i8* %29, i64 4
br label %43
39: ; preds = %26
%40 = tail call i32 @strcpy(i8* %29, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%41 = getelementptr inbounds i8, i8* %29, i64 5
br label %43
42: ; preds = %26
store i8 %27, i8* %29
br label %43
43: ; preds = %42, %39, %36, %33, %30
%44 = phi i8* [ %29, %42 ], [ %41, %39 ], [ %38, %36 ], [ %35, %33 ], [ %32, %30 ]
%45 = getelementptr inbounds i8, i8* %28, i64 1
%46 = getelementptr inbounds i8, i8* %44, i64 1
%47 = load i8, i8* %45
br label %26
48: ; preds = %26
store i8 0, i8* %29
br label %49
49: ; preds = %21, %48
ret i8* %24
}