#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
void clean_output(FILE *fp, char *s) {
  while (*s) {
    switch (*s) {
    case '\'':
      fprintf(fp, "&#39;");
      break;
    case '"':
      fprintf(fp, "&#34;");
      break;
    case '&':
      fprintf(fp, "&amp;");
      break;
    case '<':
      fprintf(fp, "&lt;");
      break;
    case '>':
      fprintf(fp, "&gt;");
      break;
    case ' ':
      fprintf(fp, "&nbsp;");
      break;
    default:
      fputc(*s, fp);
      break;
    }
    s++;
  }
}


x86 assembly (clang, -O0):
<clean_output>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     120b <clean_output+0xeb>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffffe0,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x1e,%eax
ja     11e8 <clean_output+0xc8>
mov    -0x18(%rbp),%rax
lea    0xe9f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%rdi
lea    0xf07(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11fa <clean_output+0xda>
mov    -0x8(%rbp),%rdi
lea    0xef8(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11fa <clean_output+0xda>
mov    -0x8(%rbp),%rdi
lea    0xee9(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11fa <clean_output+0xda>
mov    -0x8(%rbp),%rdi
lea    0xeda(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11fa <clean_output+0xda>
mov    -0x8(%rbp),%rdi
lea    0xeca(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11fa <clean_output+0xda>
mov    -0x8(%rbp),%rdi
lea    0xeba(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11fa <clean_output+0xda>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1030 <fputc@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1130 <clean_output+0x10>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clean_output>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    (%rsi),%al
test   %al,%al
je     11fc <clean_output+0xdc>
mov    %rsi,%rbx
mov    %rdi,%r14
add    $0x1,%rbx
lea    0xeba(%rip),%r13
lea    0xf2f(%rip),%rbp
lea    0xf3a(%rip),%r15
lea    0xf38(%rip),%r12
jmp    1183 <clean_output+0x63>
mov    $0x5,%esi
mov    $0x1,%edx
mov    %rbp,%rdi
nopw   0x0(%rax,%rax,1)
mov    %r14,%rcx
call   1040 <fwrite@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     11fc <clean_output+0xdc>
movsbl %al,%edi
lea    -0x20(%rdi),%eax
cmp    $0x1e,%eax
ja     11ab <clean_output+0x8b>
movslq 0x0(%r13,%rax,4),%rax
add    %r13,%rax
jmp    *%rax
mov    $0x6,%esi
mov    $0x1,%edx
lea    0xeef(%rip),%rdi
jmp    1170 <clean_output+0x50>
mov    %r14,%rsi
call   1030 <fputc@plt>
jmp    1178 <clean_output+0x58>
mov    $0x5,%esi
mov    $0x1,%edx
lea    0xebc(%rip),%rdi
jmp    1170 <clean_output+0x50>
mov    $0x5,%esi
mov    $0x1,%edx
lea    0xeaf(%rip),%rdi
jmp    1170 <clean_output+0x50>
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r15,%rdi
jmp    1170 <clean_output+0x50>
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r12,%rdi
jmp    1170 <clean_output+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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