#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 const, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
void print_attr_val_xml_encode(FILE *out, const char *word) {
  const char *ptr;
  for (ptr = word; ptr[0]; ++ptr) {
    switch (ptr[0]) {
    case '<':
      fputs("&lt;", out);
      break;
    case '>':
      fputs("&gt;", out);
      break;
    case '&':
      fputs("&amp;", out);
      break;
    case '\"':
      fputs("&quot;", out);
      break;
    default:
      fputc(ptr[0], out);
      break;
    }
  }
}


x86 assembly (clang, -O0):
<print_attr_val_xml_encode>:
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    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     11ee <print_attr_val_xml_encode+0xce>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffffde,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x1c,%eax
ja     11c6 <print_attr_val_xml_encode+0xa6>
mov    -0x20(%rbp),%rax
lea    0xe97(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%rsi
lea    0xef7(%rip),%rdi
call   1030 <fputs@plt>
jmp    11d8 <print_attr_val_xml_encode+0xb8>
mov    -0x8(%rbp),%rsi
lea    0xee7(%rip),%rdi
call   1030 <fputs@plt>
jmp    11d8 <print_attr_val_xml_encode+0xb8>
mov    -0x8(%rbp),%rsi
lea    0xed7(%rip),%rdi
call   1030 <fputs@plt>
jmp    11d8 <print_attr_val_xml_encode+0xb8>
mov    -0x8(%rbp),%rsi
lea    0xec8(%rip),%rdi
call   1030 <fputs@plt>
jmp    11d8 <print_attr_val_xml_encode+0xb8>
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1040 <fputc@plt>
jmp    11dd <print_attr_val_xml_encode+0xbd>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1138 <print_attr_val_xml_encode+0x18>
add    $0x20,%rsp
pop    %rbp
ret

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