#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 */

/* Variables and functions */
int readcmd();
int main() {
  int st;
  int ok;
  int p;
  int cmd;
  st = 0;
  ok = 0;
  cmd = readcmd();
  while (1) {
    switch (st) {
    case 0:
      if (cmd == 177) {
        st = 1;
      } else {
        st = 2;
      }
      break;
    case 1:
      if (cmd == 177) {
        st = 3;
        cmd = readcmd();
      } else {
        st = 0;
      }
      break;
    case 2:
      if (cmd != 177) {
        cmd = 79;
        st = 4;
        p = cmd;
        while (1) {
          if (p <= 0) {
            goto L1;
          } else {
            --p;
          }
        }
      L1:
        if (p < 0) {
          goto ERROR;
        }
      } else {
        goto ERROR;
      }
      break;
    case 3:
      if (cmd == 78) {
        st = 4;
        ok = 1;
      } else {
        st = 0;
        cmd = readcmd();
      }
      break;
    case 4:
      if (ok) {
        if (cmd != 78) {
          goto ERROR;
        }
      } else {
        if (cmd != 79) {
          goto ERROR;
        }
      }
      goto cont;
    }
  }
cont:
  p = cmd;
  while (1) {
    if (p <= 0) {
      goto L2;
    } else {
      --p;
    }
  }
L2:
  if (p > 0) {
    goto ERROR;
  }
  return (0);
ERROR:
  return (-1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1030 <readcmd@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    %rax,-0x20(%rbp)
sub    $0x4,%rax
ja     1276 <main+0x166>
mov    -0x20(%rbp),%rax
lea    0xead(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
cmpl   $0xb1,-0x14(%rbp)
jne    1175 <main+0x65>
movl   $0x1,-0x8(%rbp)
jmp    117c <main+0x6c>
movl   $0x2,-0x8(%rbp)
jmp    1276 <main+0x166>
cmpl   $0xb1,-0x14(%rbp)
jne    11a4 <main+0x94>
movl   $0x3,-0x8(%rbp)
mov    $0x0,%al
call   1030 <readcmd@plt>
mov    %eax,-0x14(%rbp)
jmp    11ab <main+0x9b>
movl   $0x0,-0x8(%rbp)
jmp    1276 <main+0x166>
cmpl   $0xb1,-0x14(%rbp)
je     1202 <main+0xf2>
movl   $0x4f,-0x14(%rbp)
movl   $0x4,-0x8(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jg     11e0 <main+0xd0>
jmp    11ee <main+0xde>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    11d1 <main+0xc1>
cmpl   $0x0,-0x10(%rbp)
jge    11fd <main+0xed>
jmp    12b9 <main+0x1a9>
jmp    1207 <main+0xf7>
jmp    12b9 <main+0x1a9>
jmp    1276 <main+0x166>
cmpl   $0x4e,-0x14(%rbp)
jne    1229 <main+0x119>
movl   $0x4,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
jmp    123a <main+0x12a>
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1030 <readcmd@plt>
mov    %eax,-0x14(%rbp)
jmp    1276 <main+0x166>
cmpl   $0x0,-0xc(%rbp)
je     125d <main+0x14d>
cmpl   $0x4e,-0x14(%rbp)
je     1258 <main+0x148>
jmp    12b9 <main+0x1a9>
jmp    1271 <main+0x161>
cmpl   $0x4f,-0x14(%rbp)
je     126c <main+0x15c>
jmp    12b9 <main+0x1a9>
jmp    1271 <main+0x161>
jmp    127b <main+0x16b>
jmp    1137 <main+0x27>
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jg     1290 <main+0x180>
jmp    129e <main+0x18e>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1281 <main+0x171>
cmpl   $0x0,-0x10(%rbp)
jle    12ad <main+0x19d>
jmp    12b9 <main+0x1a9>
movl   $0x0,-0x4(%rbp)
jmp    12c0 <main+0x1b0>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
call   1030 <readcmd@plt>
mov    $0x1,%r14b
lea    0xedb(%rip),%rbx
xor    %ebp,%ebp
xor    %edx,%edx
cmp    $0xb1,%eax
sete   %dl
mov    $0x2,%ecx
sub    %edx,%ecx
nopl   0x0(%rax,%rax,1)
cmp    $0x4,%ebp
ja     1140 <main+0x30>
mov    %ebp,%edx
movslq (%rbx,%rdx,4),%rdx
add    %rbx,%rdx
jmp    *%rdx
mov    %ecx,%ebp
jmp    1140 <main+0x30>
xor    %ebp,%ebp
cmp    $0xb1,%eax
jne    1140 <main+0x30>
xor    %eax,%eax
call   1030 <readcmd@plt>
mov    $0x3,%ebp
jmp    1127 <main+0x17>
nopl   0x0(%rax,%rax,1)
mov    $0x4,%ebp
cmp    $0xb1,%eax
mov    $0x4f,%eax
jne    1127 <main+0x17>
jmp    11d2 <main+0xc2>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %ebp,%ebp
cmp    $0x4e,%eax
je     11a0 <main+0x90>
xor    %eax,%eax
call   1030 <readcmd@plt>
jmp    1127 <main+0x17>
mov    $0x4e,%eax
mov    $0x4,%ebp
xor    %r14d,%r14d
jmp    1127 <main+0x17>
mov    $0xffffffff,%ecx
test   $0x1,%r14b
je     11c4 <main+0xb4>
cmp    $0x4f,%eax
je     11c9 <main+0xb9>
jmp    11cb <main+0xbb>
cmp    $0x4e,%eax
jne    11cb <main+0xbb>
xor    %ecx,%ecx
mov    %ecx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    $0xffffffff,%ecx
jmp    11cb <main+0xbb>

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
%6 = call i32 (...) @readcmd()
store i32 %6, i32* %5
br label %7
7: ; preds = %0, %63
%8 = load i32, i32* %2
switch i32 %8, label %63 [
i32 0, label %9
i32 1, label %15
i32 2, label %22
i32 3, label %42
i32 4, label %49
]
9: ; preds = %7
%10 = load i32, i32* %5
%11 = icmp eq i32 %10, 177
br i1 %11, label %12, label %13
12: ; preds = %9
store i32 1, i32* %2
br label %14
13: ; preds = %9
store i32 2, i32* %2
br label %14
14: ; preds = %13, %12
br label %63
15: ; preds = %7
%16 = load i32, i32* %5
%17 = icmp eq i32 %16, 177
br i1 %17, label %18, label %20
18: ; preds = %15
store i32 3, i32* %2
%19 = call i32 (...) @readcmd()
store i32 %19, i32* %5
br label %21
20: ; preds = %15
store i32 0, i32* %2
br label %21
21: ; preds = %20, %18
br label %63
22: ; preds = %7
%23 = load i32, i32* %5
%24 = icmp ne i32 %23, 177
br i1 %24, label %25, label %40
25: ; preds = %22
store i32 79, i32* %5
store i32 4, i32* %2
%26 = load i32, i32* %5
store i32 %26, i32* %4
br label %27
27: ; preds = %25, %34
%28 = load i32, i32* %4
%29 = icmp sle i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %27
br label %35
31: ; preds = %27
%32 = load i32, i32* %4
%33 = add nsw i32 %32, -1
store i32 %33, i32* %4
br label %34
34: ; preds = %31
br label %27
35: ; preds = %30
%36 = load i32, i32* %4
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %35
br label %79
39: ; preds = %35
br label %41
40: ; preds = %22
br label %79
41: ; preds = %39
br label %63
42: ; preds = %7
%43 = load i32, i32* %5
%44 = icmp eq i32 %43, 78
br i1 %44, label %45, label %46
45: ; preds = %42
store i32 4, i32* %2
store i32 1, i32* %3
br label %48
46: ; preds = %42
store i32 0, i32* %2
%47 = call i32 (...) @readcmd()
store i32 %47, i32* %5
br label %48
48: ; preds = %46, %45
br label %63
49: ; preds = %7
%50 = load i32, i32* %3
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %57
52: ; preds = %49
%53 = load i32, i32* %5
%54 = icmp ne i32 %53, 78
br i1 %54, label %55, label %56
55: ; preds = %52
br label %79
56: ; preds = %52
br label %62
57: ; preds = %49
%58 = load i32, i32* %5
%59 = icmp ne i32 %58, 79
br i1 %59, label %60, label %61
60: ; preds = %57
br label %79
61: ; preds = %57
br label %62
62: ; preds = %61, %56
br label %64
63: ; preds = %7, %48, %41, %21, %14
br label %7
64: ; preds = %62
%65 = load i32, i32* %5
store i32 %65, i32* %4
br label %66
66: ; preds = %64, %73
%67 = load i32, i32* %4
%68 = icmp sle i32 %67, 0
br i1 %68, label %69, label %70
69: ; preds = %66
br label %74
70: ; preds = %66
%71 = load i32, i32* %4
%72 = add nsw i32 %71, -1
store i32 %72, i32* %4
br label %73
73: ; preds = %70
br label %66
74: ; preds = %69
%75 = load i32, i32* %4
%76 = icmp sgt i32 %75, 0
br i1 %76, label %77, label %78
77: ; preds = %74
br label %79
78: ; preds = %74
store i32 0, i32* %1
br label %80
79: ; preds = %77, %60, %55, %40, %38
store i32 -1, i32* %1
br label %80
80: ; preds = %79, %78
%81 = load i32, i32* %1
ret i32 %81
}

LLVM IR (-O2):
define i32 @main() {
%1 = tail call i32 (...) @readcmd()
br label %2
2: ; preds = %25, %0
%3 = phi i32 [ 0, %0 ], [ 4, %25 ]
%4 = phi i1 [ true, %0 ], [ false, %25 ]
%5 = phi i32 [ %1, %0 ], [ 78, %25 ]
br label %6
6: ; preds = %22, %2
%7 = phi i32 [ %3, %2 ], [ %23, %22 ]
%8 = phi i32 [ %5, %2 ], [ %24, %22 ]
%9 = icmp eq i32 %8, 177
%10 = icmp eq i32 %8, 177
%11 = select i1 %10, i32 1, i32 2
br label %12
12: ; preds = %15, %6
%13 = phi i32 [ %7, %6 ], [ %16, %15 ]
br label %14
14: ; preds = %12, %14
switch i32 %13, label %14 [
i32 0, label %15
i32 1, label %17
i32 2, label %20
i32 3, label %25
i32 4, label %29
]
15: ; preds = %14, %17
%16 = phi i32 [ 0, %17 ], [ %11, %14 ]
br label %12
17: ; preds = %14
br i1 %9, label %18, label %15
18: ; preds = %17
%19 = tail call i32 (...) @readcmd()
br label %22
20: ; preds = %14
%21 = icmp eq i32 %8, 177
br i1 %21, label %35, label %22
22: ; preds = %20, %18, %27
%23 = phi i32 [ 0, %27 ], [ 3, %18 ], [ 4, %20 ]
%24 = phi i32 [ %28, %27 ], [ %19, %18 ], [ 79, %20 ]
br label %6
25: ; preds = %14
%26 = icmp eq i32 %8, 78
br i1 %26, label %2, label %27
27: ; preds = %25
%28 = tail call i32 (...) @readcmd()
br label %22
29: ; preds = %14
br i1 %4, label %32, label %30
30: ; preds = %29
%31 = icmp eq i32 %8, 78
br i1 %31, label %34, label %35
32: ; preds = %29
%33 = icmp eq i32 %8, 79
br i1 %33, label %34, label %35
34: ; preds = %30, %32
br label %35
35: ; preds = %20, %34, %30, %32
%36 = phi i32 [ -1, %32 ], [ -1, %30 ], [ 0, %34 ], [ -1, %20 ]
ret i32 %36
}