#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*/ fputs(char *, int /*<<< orphan*/);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ slurp(char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stdout;
void read_file(char *vfilename, char *filename, FILE *fp) {
  int ich;
  int state;
  state = 0;
  while ((ich = getc(fp)) != EOF) {
    switch (state) {
    case 0:
      if (ich == '<') {
        state = 1;
        continue;
      }
      break;
    case 1:
      if (ich == '!') {
        state = 2;
        continue;
      } else {
        state = 0;
        putchar('<');
      }
      break;
    case 2:
      if (ich == '-') {
        state = 3;
        continue;
      } else {
        state = 0;
        (void)fputs("<!", stdout);
      }
      break;
    case 3:
      if (ich == '-') {
        state = 4;
        continue;
      } else {
        state = 0;
        (void)fputs("<!-", stdout);
      }
      break;
    case 4:
      if (ich == '#') {
        slurp(vfilename, filename, fp);
        state = 0;
        continue;
      } else {
        state = 0;
        (void)fputs("<!--", stdout);
      }
      break;
    }
    putchar((char)ich);
  }
}


x86 assembly (clang, -O0):
<read_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <getc@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e7a(%rip),%rcx
cmp    (%rcx),%eax
je     12a8 <read_file+0x168>
mov    -0x20(%rbp),%eax
mov    %rax,-0x28(%rbp)
sub    $0x4,%rax
ja     1298 <read_file+0x158>
mov    -0x28(%rbp),%rax
lea    0xe6e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
cmpl   $0x3c,-0x1c(%rbp)
jne    11b1 <read_file+0x71>
movl   $0x1,-0x20(%rbp)
jmp    115b <read_file+0x1b>
jmp    1298 <read_file+0x158>
cmpl   $0x21,-0x1c(%rbp)
jne    11cc <read_file+0x8c>
movl   $0x2,-0x20(%rbp)
jmp    115b <read_file+0x1b>
movl   $0x0,-0x20(%rbp)
mov    $0x3c,%edi
call   1030 <putchar@plt>
jmp    1298 <read_file+0x158>
cmpl   $0x2d,-0x1c(%rbp)
jne    11f8 <read_file+0xb8>
movl   $0x3,-0x20(%rbp)
jmp    115b <read_file+0x1b>
movl   $0x0,-0x20(%rbp)
mov    0x2dd2(%rip),%rax
mov    (%rax),%esi
lea    0xe05(%rip),%rdi
call   1050 <fputs@plt>
jmp    1298 <read_file+0x158>
cmpl   $0x2d,-0x1c(%rbp)
jne    122f <read_file+0xef>
movl   $0x4,-0x20(%rbp)
jmp    115b <read_file+0x1b>
movl   $0x0,-0x20(%rbp)
mov    0x2d9b(%rip),%rax
mov    (%rax),%esi
lea    0xdd1(%rip),%rdi
call   1050 <fputs@plt>
jmp    1298 <read_file+0x158>
cmpl   $0x23,-0x1c(%rbp)
jne    1277 <read_file+0x137>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <slurp@plt>
movl   $0x0,-0x20(%rbp)
jmp    115b <read_file+0x1b>
movl   $0x0,-0x20(%rbp)
mov    0x2d53(%rip),%rax
mov    (%rax),%esi
lea    0xd8d(%rip),%rdi
call   1050 <fputs@plt>
jmp    1298 <read_file+0x158>
mov    -0x1c(%rbp),%eax
movsbl %al,%edi
call   1030 <putchar@plt>
jmp    115b <read_file+0x1b>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%rbx
mov    %rsi,0x10(%rsp)
mov    %rdi,0x8(%rsp)
mov    %rdx,%rdi
call   1060 <getc@plt>
mov    0x2e7e(%rip),%r13
cmp    0x0(%r13),%eax
jne    117f <read_file+0x3f>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%r12d
xor    %r15d,%r15d
lea    0xe74(%rip),%rbp
jmp    11c6 <read_file+0x86>
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
lea    0xe7d(%rip),%rdi
call   1050 <fputs@plt>
xor    %r15d,%r15d
movsbl %r12b,%edi
call   1030 <putchar@plt>
mov    %r15d,%r14d
mov    %rbx,%rdi
call   1060 <getc@plt>
mov    %eax,%r12d
mov    %r14d,%r15d
cmp    0x0(%r13),%eax
je     1170 <read_file+0x30>
cmp    $0x4,%r15d
ja     11a6 <read_file+0x66>
mov    %r15d,%eax
movslq 0x0(%rbp,%rax,4),%rax
add    %rbp,%rax
jmp    *%rax
xor    %r15d,%r15d
mov    $0x1,%r14d
cmp    $0x3c,%r12d
jne    11a6 <read_file+0x66>
jmp    11b2 <read_file+0x72>
mov    $0x2,%r14d
cmp    $0x21,%r12d
je     11b2 <read_file+0x72>
mov    $0x3c,%edi
call   1030 <putchar@plt>
jmp    11a3 <read_file+0x63>
mov    $0x3,%r14d
cmp    $0x2d,%r12d
je     11b2 <read_file+0x72>
mov    0x2dc3(%rip),%rax
mov    (%rax),%esi
lea    0xdf6(%rip),%rdi
jmp    119e <read_file+0x5e>
mov    $0x4,%r14d
cmp    $0x2d,%r12d
je     11b2 <read_file+0x72>
mov    0x2da2(%rip),%rax
mov    (%rax),%esi
lea    0xdd8(%rip),%rdi
jmp    119e <read_file+0x5e>
cmp    $0x23,%r12d
jne    118e <read_file+0x4e>
mov    0x8(%rsp),%rdi
mov    0x10(%rsp),%rsi
mov    %rbx,%rdx
call   1040 <slurp@plt>
xor    %r14d,%r14d
jmp    11b2 <read_file+0x72>

LLVM IR (-O0):
@EOF = global i32 0
@.str = [3 x i8] c"<!\00"
@stdout = global i32 0
@.str.1 = [4 x i8] c"<!-\00"
@.str.2 = [5 x i8] c"<!--\00"
define void @read_file(i8* %0, i8* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32* %2, i32** %6
store i32 0, i32* %8
br label %9
9: ; preds = %56, %47, %39, %31, %24, %19, %3
%10 = load i32*, i32** %6
%11 = call i32 @getc(i32* %10)
store i32 %11, i32* %7
%12 = load i32, i32* @EOF
%13 = icmp ne i32 %11, %12
br i1 %13, label %14, label %60
14: ; preds = %9
%15 = load i32, i32* %8
switch i32 %15, label %56 [
i32 0, label %16
i32 1, label %21
i32 2, label %28
i32 3, label %36
i32 4, label %44
]
16: ; preds = %14
%17 = load i32, i32* %7
%18 = icmp eq i32 %17, 60
br i1 %18, label %19, label %20
19: ; preds = %16
store i32 1, i32* %8
br label %9
20: ; preds = %16
br label %56
21: ; preds = %14
%22 = load i32, i32* %7
%23 = icmp eq i32 %22, 33
br i1 %23, label %24, label %25
24: ; preds = %21
store i32 2, i32* %8
br label %9
25: ; preds = %21
store i32 0, i32* %8
%26 = call i32 @putchar(i8 signext 60)
br label %27
27: ; preds = %25
br label %56
28: ; preds = %14
%29 = load i32, i32* %7
%30 = icmp eq i32 %29, 45
br i1 %30, label %31, label %32
31: ; preds = %28
store i32 3, i32* %8
br label %9
32: ; preds = %28
store i32 0, i32* %8
%33 = load i32, i32* @stdout
%34 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %32
br label %56
36: ; preds = %14
%37 = load i32, i32* %7
%38 = icmp eq i32 %37, 45
br i1 %38, label %39, label %40
39: ; preds = %36
store i32 4, i32* %8
br label %9
40: ; preds = %36
store i32 0, i32* %8
%41 = load i32, i32* @stdout
%42 = call i32 @fputs(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %41)
br label %43
43: ; preds = %40
br label %56
44: ; preds = %14
%45 = load i32, i32* %7
%46 = icmp eq i32 %45, 35
br i1 %46, label %47, label %52
47: ; preds = %44
%48 = load i8*, i8** %4
%49 = load i8*, i8** %5
%50 = load i32*, i32** %6
%51 = call i32 @slurp(i8* %48, i8* %49, i32* %50)
store i32 0, i32* %8
br label %9
52: ; preds = %44
store i32 0, i32* %8
%53 = load i32, i32* @stdout
%54 = call i32 @fputs(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %53)
br label %55
55: ; preds = %52
br label %56
56: ; preds = %14, %55, %43, %35, %27, %20
%57 = load i32, i32* %7
%58 = trunc i32 %57 to i8
%59 = call i32 @putchar(i8 signext %58)
br label %9
60: ; preds = %9
ret void
}

LLVM IR (-O2):
@EOF = global i32 0
@.str = [3 x i8] c"<!\00"
@stdout = global i32 0
@.str.1 = [4 x i8] c"<!-\00"
@.str.2 = [5 x i8] c"<!--\00"
define void @read_file(i8* %0, i8* %1, i32* %2) {
%4 = tail call i32 @getc(i32* %2)
%5 = load i32, i32* @EOF
%6 = icmp eq i32 %4, %5
br i1 %6, label %42, label %7
7: ; preds = %3, %30
%8 = phi i32 [ %32, %30 ], [ %4, %3 ]
%9 = phi i32 [ %31, %30 ], [ 0, %3 ]
switch i32 %9, label %38 [
i32 0, label %10
i32 1, label %12
i32 2, label %16
i32 3, label %21
i32 4, label %26
]
10: ; preds = %7
%11 = icmp eq i32 %8, 60
br i1 %11, label %30, label %38
12: ; preds = %7
%13 = icmp eq i32 %8, 33
br i1 %13, label %30, label %14
14: ; preds = %12
%15 = tail call i32 @putchar(i8 signext 60)
br label %38
16: ; preds = %7
%17 = icmp eq i32 %8, 45
br i1 %17, label %30, label %18
18: ; preds = %16
%19 = load i32, i32* @stdout
%20 = tail call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %19)
br label %38
21: ; preds = %7
%22 = icmp eq i32 %8, 45
br i1 %22, label %30, label %23
23: ; preds = %21
%24 = load i32, i32* @stdout
%25 = tail call i32 @fputs(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %24)
br label %38
26: ; preds = %7
%27 = icmp eq i32 %8, 35
br i1 %27, label %28, label %35
28: ; preds = %26
%29 = tail call i32 @slurp(i8* %0, i8* %1, i32* %2)
br label %30
30: ; preds = %28, %38, %10, %12, %16, %21
%31 = phi i32 [ %39, %38 ], [ 0, %28 ], [ 1, %10 ], [ 2, %12 ], [ 3, %16 ], [ 4, %21 ]
%32 = tail call i32 @getc(i32* %2)
%33 = load i32, i32* @EOF
%34 = icmp eq i32 %32, %33
br i1 %34, label %42, label %7
35: ; preds = %26
%36 = load i32, i32* @stdout
%37 = tail call i32 @fputs(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %36)
br label %38
38: ; preds = %10, %7, %35, %23, %18, %14
%39 = phi i32 [ %9, %7 ], [ 0, %35 ], [ 0, %23 ], [ 0, %18 ], [ 0, %14 ], [ 0, %10 ]
%40 = trunc i32 %8 to i8
%41 = tail call i32 @putchar(i8 signext %40)
br label %30
42: ; preds = %30, %3
ret void
}