#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 EOF;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int tolower(int);
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/ *);
int entity_ref(FILE *stream) {
  int ret = 0, c = tolower(getc(stream));
  switch (c) {
  case 'a':
    c = tolower(getc(stream));
    if (c == 'p')
      ret = 39;
    else if (c == 'm')
      ret = '&';
    else {
      fprintf(stderr, "&a %c\n", (char)c);
      fprintf(stderr, "Unknown entity reference!\n");
      exit(EXIT_FAILURE);
    }
    break;
  case 'q':
    ret = '"';
    break;
  case 'l':
    ret = '<';
    break;
  case 'g':
    ret = '>';
    break;
  default:
    ungetc(c, stream);
    return ret;
  }
  while (EOF != c && ';' != c)
    c = getc(stream);
  return ret;
}


x86 assembly (clang, -O0):
<entity_ref>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,%edi
call   1040 <tolower@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0xffffff9f,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x10,%eax
ja     124e <entity_ref+0xfe>
mov    -0x20(%rbp),%rax
lea    0xe6a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,%edi
call   1040 <tolower@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x70,-0x18(%rbp)
jne    11c8 <entity_ref+0x78>
movl   $0x27,-0x14(%rbp)
jmp    1225 <entity_ref+0xd5>
cmpl   $0x6d,-0x18(%rbp)
jne    11de <entity_ref+0x8e>
movl   $0x26,-0x14(%rbp)
jmp    1220 <entity_ref+0xd0>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%eax
movsbl %al,%edx
lea    0xe50(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
lea    0xe40(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
jmp    1225 <entity_ref+0xd5>
jmp    1265 <entity_ref+0x115>
movl   $0x22,-0x14(%rbp)
jmp    1265 <entity_ref+0x115>
movl   $0x3c,-0x14(%rbp)
jmp    1265 <entity_ref+0x115>
movl   $0x3e,-0x14(%rbp)
jmp    1265 <entity_ref+0x115>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <ungetc@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12b6 <entity_ref+0x166>
jmp    126a <entity_ref+0x11a>
mov    0x2d77(%rip),%rax
mov    (%rax),%ecx
xor    %eax,%eax
cmp    -0x18(%rbp),%ecx
mov    %al,-0x21(%rbp)
je     128f <entity_ref+0x13f>
mov    $0x3b,%eax
cmp    -0x18(%rbp),%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    129f <entity_ref+0x14f>
jmp    12b0 <entity_ref+0x160>
mov    -0x10(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x18(%rbp)
jmp    126a <entity_ref+0x11a>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<entity_ref>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1070 <getc@plt>
mov    %eax,%edi
call   1040 <tolower@plt>
mov    %eax,%ecx
add    $0xffffff9f,%ecx
cmp    $0x10,%ecx
ja     11b7 <entity_ref+0x67>
mov    $0x22,%r14d
lea    0xe86(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
mov    %rbx,%rdi
call   1070 <getc@plt>
mov    %eax,%edi
call   1040 <tolower@plt>
mov    $0x27,%r14d
cmp    $0x70,%eax
je     11cc <entity_ref+0x7c>
cmp    $0x6d,%eax
jne    11fa <entity_ref+0xaa>
mov    $0x6d,%eax
mov    $0x26,%r14d
jmp    11cc <entity_ref+0x7c>
mov    $0x3e,%r14d
jmp    11cc <entity_ref+0x7c>
mov    %eax,%edi
mov    %rbx,%rsi
call   1050 <ungetc@plt>
xor    %r14d,%r14d
jmp    11f2 <entity_ref+0xa2>
mov    $0x3c,%r14d
mov    0x2e15(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    %eax,0x0(%rbp)
je     11f2 <entity_ref+0xa2>
mov    %rbx,%rdi
call   1070 <getc@plt>
cmp    $0x3b,%eax
jne    11e0 <entity_ref+0x90>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2dd7(%rip),%rbx
mov    (%rbx),%edi
movsbl %al,%edx
lea    0xe37(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe2e(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [7 x i8] c"&a %c\0A\00"
@.str.1 = [27 x i8] c"Unknown entity reference!\0A\00"
@EXIT_FAILURE = global i32 0
@EOF = global i32 0
define i32 @entity_ref(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
store i32 0, i32* %4
%6 = load i32*, i32** %3
%7 = call i32 @getc(i32* %6)
%8 = call i32 @tolower(i32 %7)
store i32 %8, i32* %5
%9 = load i32, i32* %5
switch i32 %9, label %36 [
i32 97, label %10
i32 113, label %33
i32 108, label %34
i32 103, label %35
]
10: ; preds = %1
%11 = load i32*, i32** %3
%12 = call i32 @getc(i32* %11)
%13 = call i32 @tolower(i32 %12)
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = icmp eq i32 %14, 112
br i1 %15, label %16, label %17
16: ; preds = %10
store i32 39, i32* %4
br label %32
17: ; preds = %10
%18 = load i32, i32* %5
%19 = icmp eq i32 %18, 109
br i1 %19, label %20, label %21
20: ; preds = %17
store i32 38, i32* %4
br label %31
21: ; preds = %17
%22 = load i32, i32* @stderr
%23 = load i32, i32* %5
%24 = trunc i32 %23 to i8
%25 = sext i8 %24 to i32
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %25)
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %20
br label %32
32: ; preds = %31, %16
br label %41
33: ; preds = %1
store i32 34, i32* %4
br label %41
34: ; preds = %1
store i32 60, i32* %4
br label %41
35: ; preds = %1
store i32 62, i32* %4
br label %41
36: ; preds = %1
%37 = load i32, i32* %5
%38 = load i32*, i32** %3
%39 = call i32 @ungetc(i32 %37, i32* %38)
%40 = load i32, i32* %4
store i32 %40, i32* %2
br label %56
41: ; preds = %35, %34, %33, %32
br label %42
42: ; preds = %51, %41
%43 = load i32, i32* @EOF
%44 = load i32, i32* %5
%45 = icmp ne i32 %43, %44
br i1 %45, label %46, label %49
46: ; preds = %42
%47 = load i32, i32* %5
%48 = icmp ne i32 59, %47
br label %49
49: ; preds = %46, %42
%50 = phi i1 [ false, %42 ], [ %48, %46 ]
br i1 %50, label %51, label %54
51: ; preds = %49
%52 = load i32*, i32** %3
%53 = call i32 @getc(i32* %52)
store i32 %53, i32* %5
br label %42
54: ; preds = %49
%55 = load i32, i32* %4
store i32 %55, i32* %2
br label %56
56: ; preds = %54, %36
%57 = load i32, i32* %2
ret i32 %57
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [7 x i8] c"&a %c\0A\00"
@.str.1 = [27 x i8] c"Unknown entity reference!\0A\00"
@EXIT_FAILURE = global i32 0
@EOF = global i32 0
define i32 @entity_ref(i32* nocapture %0) {
%2 = tail call i32 @getc(i32* %0)
%3 = tail call i32 @tolower(i32 %2)
switch i32 %3, label %19 [
i32 97, label %4
i32 113, label %21
i32 108, label %17
i32 103, label %18
]
4: ; preds = %1
%5 = tail call i32 @getc(i32* %0)
%6 = tail call i32 @tolower(i32 %5)
switch i32 %6, label %8 [
i32 112, label %21
i32 109, label %7
]
7: ; preds = %4
br label %21
8: ; preds = %4
%9 = load i32, i32* @stderr
%10 = shl i32 %6, 24
%11 = ashr exact i32 %10, 24
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %1
br label %21
18: ; preds = %1
br label %21
19: ; preds = %1
%20 = tail call i32 @ungetc(i32 %3, i32* %0)
br label %32
21: ; preds = %1, %4, %7, %18, %17
%22 = phi i32 [ 62, %18 ], [ 60, %17 ], [ 38, %7 ], [ 39, %4 ], [ 34, %1 ]
%23 = phi i32 [ %3, %18 ], [ %3, %17 ], [ 109, %7 ], [ %6, %4 ], [ %3, %1 ]
%24 = load i32, i32* @EOF
%25 = icmp eq i32 %24, %23
br i1 %25, label %32, label %26
26: ; preds = %21, %26
%27 = tail call i32 @getc(i32* %0)
%28 = load i32, i32* @EOF
%29 = icmp ne i32 %28, %27
%30 = icmp ne i32 %27, 59
%31 = and i1 %30, %29
br i1 %31, label %26, label %32
32: ; preds = %26, %21, %19
%33 = phi i32 [ 0, %19 ], [ %22, %21 ], [ %22, %26 ]
ret i32 %33
}