#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*/ memcpy(char *, char *, int);
char *htmlspecialchars(char *in, char *out) {
  char *o = out;
  while (*in) {
    switch (*in) {
    case '&':
      memcpy(o, "&amp;", 5);
      o += 5;
      break;
      ;
    case '<':
      memcpy(o, "&lt;", 4);
      o += 4;
      break;
      ;
    case '>':
      memcpy(o, "&gt;", 4);
      o += 4;
      break;
      ;
    case '"':
      memcpy(o, "&quot;", 6);
      o += 6;
      break;
      ;
    default:
      *o++ = *in;
      break;
    }
    in++;
  }
  *o = 0;
  return out;
}


x86 assembly (clang, -O0):
<htmlspecialchars>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1222 <htmlspecialchars+0x112>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffffde,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x1c,%eax
ja     11fa <htmlspecialchars+0xea>
mov    -0x20(%rbp),%rax
lea    0xea7(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x18(%rbp),%rdi
lea    0xf07(%rip),%rsi
mov    $0x5,%edx
call   1030 <memcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x18(%rbp)
jmp    1211 <htmlspecialchars+0x101>
mov    -0x18(%rbp),%rdi
lea    0xee7(%rip),%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
jmp    1211 <htmlspecialchars+0x101>
mov    -0x18(%rbp),%rdi
lea    0xec6(%rip),%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
jmp    1211 <htmlspecialchars+0x101>
mov    -0x18(%rbp),%rdi
lea    0xea5(%rip),%rsi
mov    $0x6,%edx
call   1030 <memcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x18(%rbp)
jmp    1211 <htmlspecialchars+0x101>
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1128 <htmlspecialchars+0x18>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<htmlspecialchars>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    (%rdi),%al
mov    %rsi,%r13
test   %al,%al
je     11e9 <htmlspecialchars+0xd9>
mov    %rdi,%rbx
add    $0x1,%rbx
lea    0xec7(%rip),%r12
lea    0xf3a(%rip),%rbp
lea    0xf38(%rip),%r15
mov    %r14,%r13
jmp    116b <htmlspecialchars+0x5b>
nopl   0x0(%rax)
mov    %al,0x0(%r13)
add    $0x1,%r13
nopl   0x0(%rax,%rax,1)
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     11e9 <htmlspecialchars+0xd9>
movsbl %al,%ecx
add    $0xffffffde,%ecx
cmp    $0x1c,%ecx
ja     1150 <htmlspecialchars+0x40>
movslq (%r12,%rcx,4),%rcx
add    %r12,%rcx
jmp    *%rcx
mov    %r13,%rdi
lea    0xefb(%rip),%rsi
mov    $0x6,%edx
call   1030 <memcpy@plt>
add    $0x6,%r13
jmp    1160 <htmlspecialchars+0x50>
nopl   0x0(%rax)
mov    %r13,%rdi
lea    0xeca(%rip),%rsi
mov    $0x5,%edx
call   1030 <memcpy@plt>
add    $0x5,%r13
jmp    1160 <htmlspecialchars+0x50>
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %rbp,%rsi
jmp    11d6 <htmlspecialchars+0xc6>
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0x4,%edx
call   1030 <memcpy@plt>
add    $0x4,%r13
jmp    1160 <htmlspecialchars+0x50>
movb   $0x0,0x0(%r13)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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