#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 */
char EOF;
int /*<<< orphan*/ accept();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ printf(char *, ...);
int q0(char);
int q1(char);
int q2(char);
int q3(char);
int /*<<< orphan*/ reject();
int main() {
  const char *filename = "Q1Acc.txt";
  FILE *file = fopen(filename, "r");
  if (file == NULL)
    exit(0);
  int state = 0;
  char str;
  while ((str = fgetc(file)) != EOF) {
    printf("C: %c\n", str);
    switch (state) {
    case 0:
      state = q0(str);
      break;
    case 1:
      state = q1(str);
      break;
    case 2:
      state = q2(str);
      break;
    case 3:
      state = q3(str);
      break;
    case -2:
      printf("Error\n");
      break;
    default:
      printf("hello\n");
      break;
    }
  }
  switch (state) {
  case 0:
    accept();
    break;
  case 3:
    accept();
    break;
  default:
    reject();
    break;
  }
  fclose(file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe52(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe4d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f0 <main+0x40>
xor    %edi,%edi
call   10d0 <exit@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <fgetc@plt>
mov    %al,-0x1d(%rbp)
movsbl %al,%eax
mov    0x2ddb(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     12bd <main+0x10d>
movsbl -0x1d(%rbp),%esi
lea    0xe01(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x5,%eax
ja     12aa <main+0xfa>
mov    -0x28(%rbp),%rax
lea    0xdb6(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movsbl -0x1d(%rbp),%edi
call   10b0 <q0@plt>
mov    %eax,-0x1c(%rbp)
jmp    12b8 <main+0x108>
movsbl -0x1d(%rbp),%edi
call   1060 <q1@plt>
mov    %eax,-0x1c(%rbp)
jmp    12b8 <main+0x108>
movsbl -0x1d(%rbp),%edi
call   10c0 <q2@plt>
mov    %eax,-0x1c(%rbp)
jmp    12b8 <main+0x108>
movsbl -0x1d(%rbp),%edi
call   1080 <q3@plt>
mov    %eax,-0x1c(%rbp)
jmp    12b8 <main+0x108>
lea    0xd8d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12b8 <main+0x108>
lea    0xd81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11f7 <main+0x47>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
test   %eax,%eax
je     12e1 <main+0x131>
jmp    12d0 <main+0x120>
mov    -0x2c(%rbp),%eax
sub    $0x3,%eax
je     12ed <main+0x13d>
jmp    12f9 <main+0x149>
mov    $0x0,%al
call   10a0 <accept@plt>
jmp    1300 <main+0x150>
mov    $0x0,%al
call   10a0 <accept@plt>
jmp    1300 <main+0x150>
mov    $0x0,%al
call   1050 <reject@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe46(%rip),%rdi
lea    0xe54(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     12be <main+0xfe>
mov    %rax,%r13
mov    %rax,%rdi
call   1080 <fgetc@plt>
mov    0x2def(%rip),%r15
cmp    (%r15),%al
je     1295 <main+0xd5>
lea    0xe19(%rip),%r14
lea    0xdf0(%rip),%r12
xor    %ebx,%ebx
jmp    122d <main+0x6d>
lea    0xe14(%rip),%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
call   1080 <fgetc@plt>
cmp    (%r15),%al
je     128c <main+0xcc>
movsbl %al,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x2(%rbx),%eax
cmp    $0x5,%eax
ja     1214 <main+0x54>
movslq (%r12,%rax,4),%rax
add    %r12,%rax
jmp    *%rax
lea    0xdd5(%rip),%rdi
call   1030 <puts@plt>
mov    $0xfffffffe,%ebx
jmp    1220 <main+0x60>
mov    %ebp,%edi
call   1070 <q1@plt>
mov    %eax,%ebx
jmp    1220 <main+0x60>
mov    %ebp,%edi
call   10c0 <q0@plt>
mov    %eax,%ebx
jmp    1220 <main+0x60>
mov    %ebp,%edi
call   10d0 <q2@plt>
mov    %eax,%ebx
jmp    1220 <main+0x60>
mov    %ebp,%edi
call   1090 <q3@plt>
mov    %eax,%ebx
jmp    1220 <main+0x60>
cmp    $0x3,%ebx
je     1295 <main+0xd5>
test   %ebx,%ebx
jne    12b5 <main+0xf5>
xor    %eax,%eax
call   10b0 <accept@plt>
mov    %r13,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   1060 <reject@plt>
jmp    129c <main+0xdc>
xor    %edi,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"Q1Acc.txt\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.2 = [7 x i8] c"C: %c\0A\00"
@.str.3 = [7 x i8] c"Error\0A\00"
@.str.4 = [7 x i8] c"hello\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i8
store i32 0, i32* %1
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %2
%6 = load i8*, i8** %2
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %3
%8 = load i32*, i32** %3
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @exit(i32 0)
unreachable
12: ; preds = %0
store i32 0, i32* %4
br label %13
13: ; preds = %41, %12
%14 = load i32*, i32** %3
%15 = call signext i8 @fgetc(i32* %14)
store i8 %15, i8* %5
%16 = sext i8 %15 to i32
%17 = load i8, i8* @EOF
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %16, %18
br i1 %19, label %20, label %42
20: ; preds = %13
%21 = load i8, i8* %5
%22 = sext i8 %21 to i32
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %22)
%24 = load i32, i32* %4
switch i32 %24, label %39 [
i32 0, label %25
i32 1, label %28
i32 2, label %31
i32 3, label %34
i32 -2, label %37
]
25: ; preds = %20
%26 = load i8, i8* %5
%27 = call i32 @q0(i8 signext %26)
store i32 %27, i32* %4
br label %41
28: ; preds = %20
%29 = load i8, i8* %5
%30 = call i32 @q1(i8 signext %29)
store i32 %30, i32* %4
br label %41
31: ; preds = %20
%32 = load i8, i8* %5
%33 = call i32 @q2(i8 signext %32)
store i32 %33, i32* %4
br label %41
34: ; preds = %20
%35 = load i8, i8* %5
%36 = call i32 @q3(i8 signext %35)
store i32 %36, i32* %4
br label %41
37: ; preds = %20
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %41
39: ; preds = %20
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %41
41: ; preds = %39, %37, %34, %31, %28, %25
br label %13
42: ; preds = %13
%43 = load i32, i32* %4
switch i32 %43, label %48 [
i32 0, label %44
i32 3, label %46
]
44: ; preds = %42
%45 = call i32 (...) @accept()
br label %50
46: ; preds = %42
%47 = call i32 (...) @accept()
br label %50
48: ; preds = %42
%49 = call i32 (...) @reject()
br label %50
50: ; preds = %48, %46, %44
%51 = load i32*, i32** %3
%52 = call i32 @fclose(i32* %51)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"Q1Acc.txt\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i8 0
@.str.2 = [7 x i8] c"C: %c\0A\00"
@str = [6 x i8] c"Error\00"
@str.5 = [6 x i8] c"hello\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %7, label %3
3: ; preds = %0
%4 = tail call signext i8 @fgetc(i32* %1)
%5 = load i8, i8* @EOF
%6 = icmp eq i8 %4, %5
br i1 %6, label %32, label %9
7: ; preds = %0
%8 = tail call i32 @exit(i32 0)
unreachable
9: ; preds = %3, %26
%10 = phi i8 [ %28, %26 ], [ %4, %3 ]
%11 = phi i32 [ %27, %26 ], [ 0, %3 ]
%12 = sext i8 %10 to i32
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %12)
switch i32 %11, label %24 [
i32 0, label %14
i32 1, label %16
i32 2, label %18
i32 3, label %20
i32 -2, label %22
]
14: ; preds = %9
%15 = tail call i32 @q0(i8 signext %10)
br label %26
16: ; preds = %9
%17 = tail call i32 @q1(i8 signext %10)
br label %26
18: ; preds = %9
%19 = tail call i32 @q2(i8 signext %10)
br label %26
20: ; preds = %9
%21 = tail call i32 @q3(i8 signext %10)
br label %26
22: ; preds = %9
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
br label %26
24: ; preds = %9
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.5, i64 0, i64 0))
br label %26
26: ; preds = %24, %22, %20, %18, %16, %14
%27 = phi i32 [ %11, %24 ], [ -2, %22 ], [ %21, %20 ], [ %19, %18 ], [ %17, %16 ], [ %15, %14 ]
%28 = tail call signext i8 @fgetc(i32* %1)
%29 = load i8, i8* @EOF
%30 = icmp eq i8 %28, %29
br i1 %30, label %31, label %9
31: ; preds = %26
switch i32 %27, label %36 [
i32 0, label %32
i32 3, label %34
]
32: ; preds = %3, %31
%33 = tail call i32 (...) @accept()
br label %38
34: ; preds = %31
%35 = tail call i32 (...) @accept()
br label %38
36: ; preds = %31
%37 = tail call i32 (...) @reject()
br label %38
38: ; preds = %36, %34, %32
%39 = tail call i32 @fclose(i32* %1)
ret i32 0
}