#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*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
void html_encode(FILE *fd, char *s) {
  for (; *s; s++) {
    switch (*s) {
    case '<':
      fputs("&lt;", fd);
      break;
    case '>':
      fputs("&gt;", fd);
      break;
    case '&':
      fputs("&amp;", fd);
      break;
    case '"':
      fputs("&quot;", fd);
      break;
    default:
      fputc(*s, fd);
      break;
    }
  }
}


x86 assembly (clang, -O0):
<html_encode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     11e6 <html_encode+0xc6>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffffde,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x1c,%eax
ja     11be <html_encode+0x9e>
mov    -0x18(%rbp),%rax
lea    0xe9f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%rsi
lea    0xeff(%rip),%rdi
call   1030 <fputs@plt>
jmp    11d0 <html_encode+0xb0>
mov    -0x8(%rbp),%rsi
lea    0xeef(%rip),%rdi
call   1030 <fputs@plt>
jmp    11d0 <html_encode+0xb0>
mov    -0x8(%rbp),%rsi
lea    0xedf(%rip),%rdi
call   1030 <fputs@plt>
jmp    11d0 <html_encode+0xb0>
mov    -0x8(%rbp),%rsi
lea    0xed0(%rip),%rdi
call   1030 <fputs@plt>
jmp    11d0 <html_encode+0xb0>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1040 <fputc@plt>
jmp    11d5 <html_encode+0xb5>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1130 <html_encode+0x10>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<html_encode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    (%rsi),%al
test   %al,%al
je     11df <html_encode+0xbf>
mov    %rsi,%rbx
mov    %rdi,%r14
add    $0x1,%rbx
lea    0xeba(%rip),%r15
lea    0xf31(%rip),%r12
lea    0xf20(%rip),%r13
lea    0xf1e(%rip),%rbp
jmp    1180 <html_encode+0x60>
nopl   (%rax)
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r13,%rdi
mov    %r14,%rcx
call   1040 <fwrite@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     11df <html_encode+0xbf>
movsbl %al,%edi
lea    -0x22(%rdi),%eax
cmp    $0x1c,%eax
ja     11b0 <html_encode+0x90>
movslq (%r15,%rax,4),%rax
add    %r15,%rax
jmp    *%rax
mov    $0x6,%esi
mov    $0x1,%edx
lea    0xedf(%rip),%rdi
jmp    116d <html_encode+0x4d>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rsi
call   1030 <fputc@plt>
jmp    1175 <html_encode+0x55>
nopw   0x0(%rax,%rax,1)
mov    $0x5,%esi
mov    $0x1,%edx
mov    %r12,%rdi
jmp    116d <html_encode+0x4d>
nop
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbp,%rdi
jmp    116d <html_encode+0x4d>
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 void @html_encode(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 = %31, %2
%6 = load i8*, i8** %4
%7 = load i8, i8* %6
%8 = icmp ne i8 %7, 0
br i1 %8, label %9, label %34
9: ; preds = %5
%10 = load i8*, i8** %4
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
switch i32 %12, label %25 [
i32 60, label %13
i32 62, label %16
i32 38, label %19
i32 34, label %22
]
13: ; preds = %9
%14 = load i32*, i32** %3
%15 = call i32 @fputs(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %14)
br label %30
16: ; preds = %9
%17 = load i32*, i32** %3
%18 = call i32 @fputs(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %17)
br label %30
19: ; preds = %9
%20 = load i32*, i32** %3
%21 = call i32 @fputs(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %20)
br label %30
22: ; preds = %9
%23 = load i32*, i32** %3
%24 = call i32 @fputs(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32* %23)
br label %30
25: ; preds = %9
%26 = load i8*, i8** %4
%27 = load i8, i8* %26
%28 = load i32*, i32** %3
%29 = call i32 @fputc(i8 signext %27, i32* %28)
br label %30
30: ; preds = %25, %22, %19, %16, %13
br label %31
31: ; preds = %30
%32 = load i8*, i8** %4
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %4
br label %5
34: ; preds = %5
ret void
}

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 void @html_encode(i32* nocapture %0, i8* nocapture %1) {
%3 = load i8, i8* %1
%4 = icmp eq i8 %3, 0
br i1 %4, label %23, label %5
5: ; preds = %2, %19
%6 = phi i8 [ %21, %19 ], [ %3, %2 ]
%7 = phi i8* [ %20, %19 ], [ %1, %2 ]
%8 = sext i8 %6 to i32
switch i32 %8, label %17 [
i32 60, label %9
i32 62, label %11
i32 38, label %13
i32 34, label %15
]
9: ; preds = %5
%10 = tail call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 4, i64 1, i32* %0)
br label %19
11: ; preds = %5
%12 = tail call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i64 4, i64 1, i32* %0)
br label %19
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 %19
15: ; preds = %5
%16 = tail call i64 @fwrite(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i64 6, i64 1, i32* %0)
br label %19
17: ; preds = %5
%18 = tail call i32 @fputc(i8 signext %6, i32* %0)
br label %19
19: ; preds = %9, %11, %13, %15, %17
%20 = getelementptr inbounds i8, i8* %7, i64 1
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %5
23: ; preds = %19, %2
ret void
}