#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 gchbuf();
int /*<<< orphan*/ pushback(int);
int trigraph() {
  int c;
  int q_count;
  if ((c = gchbuf()) == '?') {
    if ((c = gchbuf()) == '?') {
      q_count = 0;
      for (;;) {
        switch ((int)(c = gchbuf())) {
        case '=':
          c = '#';
          break;
        case '(':
          c = '[';
          break;
        case '/':
          c = '\\';
          break;
        case ')':
          c = ']';
          break;
        case '\'':
          c = '^';
          break;
        case '<':
          c = '{';
          break;
        case '!':
          c = '|';
          break;
        case '>':
          c = '}';
          break;
        case '-':
          c = '~';
          break;
        case '?':
          q_count++;
          continue;
        default:
          pushback(c);
          pushback('?');
          c = '?';
          break;
        }
        if (q_count > 0) {
          pushback(c);
          while (q_count-- > 1)
            pushback('?');
          c = '?';
        }
        break;
      }
    } else {
      pushback(c);
      c = '?';
    }
  }
  return (c);
}


x86 assembly (clang, -O0):
<trigraph>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <gchbuf@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x3f,%eax
jne    1272 <trigraph+0x152>
mov    $0x0,%al
call   1030 <gchbuf@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x3f,%eax
jne    125e <trigraph+0x13e>
movl   $0x0,-0x8(%rbp)
xor    %eax,%eax
call   1030 <gchbuf@plt>
mov    %eax,-0x4(%rbp)
add    $0xffffffdf,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x1e,%eax
ja     11ff <trigraph+0xdf>
mov    -0x10(%rbp),%rax
lea    0xe84(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x23,-0x4(%rbp)
jmp    1218 <trigraph+0xf8>
movl   $0x5b,-0x4(%rbp)
jmp    1218 <trigraph+0xf8>
movl   $0x5c,-0x4(%rbp)
jmp    1218 <trigraph+0xf8>
movl   $0x5d,-0x4(%rbp)
jmp    1218 <trigraph+0xf8>
movl   $0x5e,-0x4(%rbp)
jmp    1218 <trigraph+0xf8>
movl   $0x7b,-0x4(%rbp)
jmp    1218 <trigraph+0xf8>
movl   $0x7c,-0x4(%rbp)
jmp    1218 <trigraph+0xf8>
movl   $0x7d,-0x4(%rbp)
jmp    1218 <trigraph+0xf8>
movl   $0x7e,-0x4(%rbp)
jmp    1218 <trigraph+0xf8>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1155 <trigraph+0x35>
mov    -0x4(%rbp),%edi
call   1040 <pushback@plt>
mov    $0x3f,%edi
call   1040 <pushback@plt>
movl   $0x3f,-0x4(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    1254 <trigraph+0x134>
mov    -0x4(%rbp),%edi
call   1040 <pushback@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x1,%eax
jle    124d <trigraph+0x12d>
mov    $0x3f,%edi
call   1040 <pushback@plt>
jmp    122a <trigraph+0x10a>
movl   $0x3f,-0x4(%rbp)
jmp    1259 <trigraph+0x139>
jmp    126d <trigraph+0x14d>
mov    -0x4(%rbp),%edi
call   1040 <pushback@plt>
movl   $0x3f,-0x4(%rbp)
jmp    1272 <trigraph+0x152>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trigraph>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <gchbuf@plt>
mov    %eax,%ebx
cmp    $0x3f,%eax
jne    1202 <trigraph+0xe2>
xor    %eax,%eax
call   1030 <gchbuf@plt>
cmp    $0x3f,%eax
jne    1157 <trigraph+0x37>
mov    $0x1,%ebp
xor    %eax,%eax
call   1030 <gchbuf@plt>
cmp    $0x3f,%eax
jne    1168 <trigraph+0x48>
add    $0x1,%ebp
jmp    1146 <trigraph+0x26>
mov    %eax,%edi
call   1040 <pushback@plt>
mov    $0x3f,%ebx
jmp    1202 <trigraph+0xe2>
lea    -0x21(%rax),%ecx
cmp    $0x1d,%ecx
ja     1187 <trigraph+0x67>
lea    0xe89(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
mov    $0x7c,%ebx
jmp    11d5 <trigraph+0xb5>
mov    %eax,%edi
call   1040 <pushback@plt>
mov    $0x3f,%ebx
mov    $0x3f,%edi
call   1040 <pushback@plt>
jmp    11d5 <trigraph+0xb5>
mov    $0x5e,%ebx
jmp    11d5 <trigraph+0xb5>
mov    $0x5b,%ebx
jmp    11d5 <trigraph+0xb5>
mov    $0x5d,%ebx
jmp    11d5 <trigraph+0xb5>
mov    $0x7e,%ebx
jmp    11d5 <trigraph+0xb5>
mov    $0x5c,%ebx
jmp    11d5 <trigraph+0xb5>
mov    $0x7b,%ebx
jmp    11d5 <trigraph+0xb5>
mov    $0x23,%ebx
jmp    11d5 <trigraph+0xb5>
mov    $0x7d,%ebx
cmp    $0x1,%ebp
je     1202 <trigraph+0xe2>
mov    %ebx,%edi
call   1040 <pushback@plt>
mov    $0x3f,%ebx
cmp    $0x2,%ebp
je     1202 <trigraph+0xe2>
mov    $0x3f,%ebx
mov    $0x3f,%edi
call   1040 <pushback@plt>
add    $0xffffffff,%ebp
cmp    $0x2,%ebp
jg     11f0 <trigraph+0xd0>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @trigraph() {
%1 = alloca i32
%2 = alloca i32
%3 = call i32 (...) @gchbuf()
store i32 %3, i32* %1
%4 = icmp eq i32 %3, 63
br i1 %4, label %5, label %46
5: ; preds = %0
%6 = call i32 (...) @gchbuf()
store i32 %6, i32* %1
%7 = icmp eq i32 %6, 63
br i1 %7, label %8, label %42
8: ; preds = %5
store i32 0, i32* %2
br label %9
9: ; preds = %20, %8
%10 = call i32 (...) @gchbuf()
store i32 %10, i32* %1
switch i32 %10, label %23 [
i32 61, label %11
i32 40, label %12
i32 47, label %13
i32 41, label %14
i32 39, label %15
i32 60, label %16
i32 33, label %17
i32 62, label %18
i32 45, label %19
i32 63, label %20
]
11: ; preds = %9
store i32 35, i32* %1
br label %27
12: ; preds = %9
store i32 91, i32* %1
br label %27
13: ; preds = %9
store i32 92, i32* %1
br label %27
14: ; preds = %9
store i32 93, i32* %1
br label %27
15: ; preds = %9
store i32 94, i32* %1
br label %27
16: ; preds = %9
store i32 123, i32* %1
br label %27
17: ; preds = %9
store i32 124, i32* %1
br label %27
18: ; preds = %9
store i32 125, i32* %1
br label %27
19: ; preds = %9
store i32 126, i32* %1
br label %27
20: ; preds = %9
%21 = load i32, i32* %2
%22 = add nsw i32 %21, 1
store i32 %22, i32* %2
br label %9
23: ; preds = %9
%24 = load i32, i32* %1
%25 = call i32 @pushback(i32 %24)
%26 = call i32 @pushback(i32 63)
store i32 63, i32* %1
br label %27
27: ; preds = %23, %19, %18, %17, %16, %15, %14, %13, %12, %11
%28 = load i32, i32* %2
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %40
30: ; preds = %27
%31 = load i32, i32* %1
%32 = call i32 @pushback(i32 %31)
br label %33
33: ; preds = %37, %30
%34 = load i32, i32* %2
%35 = add nsw i32 %34, -1
store i32 %35, i32* %2
%36 = icmp sgt i32 %34, 1
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = call i32 @pushback(i32 63)
br label %33
39: ; preds = %33
store i32 63, i32* %1
br label %40
40: ; preds = %39, %27
br label %41
41: ; preds = %40
br label %45
42: ; preds = %5
%43 = load i32, i32* %1
%44 = call i32 @pushback(i32 %43)
store i32 63, i32* %1
br label %45
45: ; preds = %42, %41
br label %46
46: ; preds = %45, %0
%47 = load i32, i32* %1
ret i32 %47
}

LLVM IR (-O2):
define i32 @trigraph() {
%1 = tail call i32 (...) @gchbuf()
%2 = icmp eq i32 %1, 63
br i1 %2, label %3, label %35
3: ; preds = %0
%4 = tail call i32 (...) @gchbuf()
%5 = icmp eq i32 %4, 63
br i1 %5, label %6, label %33
6: ; preds = %3, %12
%7 = phi i32 [ %13, %12 ], [ 0, %3 ]
%8 = tail call i32 (...) @gchbuf()
switch i32 %8, label %14 [
i32 61, label %17
i32 40, label %18
i32 47, label %19
i32 41, label %20
i32 39, label %21
i32 60, label %22
i32 33, label %9
i32 62, label %10
i32 45, label %11
i32 63, label %12
]
9: ; preds = %6
br label %22
10: ; preds = %6
br label %22
11: ; preds = %6
br label %22
12: ; preds = %6
%13 = add nuw nsw i32 %7, 1
br label %6
14: ; preds = %6
%15 = tail call i32 @pushback(i32 %8)
%16 = tail call i32 @pushback(i32 63)
br label %22
17: ; preds = %6
br label %22
18: ; preds = %6
br label %22
19: ; preds = %6
br label %22
20: ; preds = %6
br label %22
21: ; preds = %6
br label %22
22: ; preds = %6, %21, %20, %19, %18, %17, %14, %11, %10, %9
%23 = phi i32 [ 63, %14 ], [ 126, %11 ], [ 125, %10 ], [ 124, %9 ], [ 35, %17 ], [ 91, %18 ], [ 92, %19 ], [ 93, %20 ], [ 94, %21 ], [ 123, %6 ]
%24 = icmp eq i32 %7, 0
br i1 %24, label %35, label %25
25: ; preds = %22
%26 = tail call i32 @pushback(i32 %23)
%27 = icmp eq i32 %7, 1
br i1 %27, label %35, label %28
28: ; preds = %25, %28
%29 = phi i32 [ %30, %28 ], [ %7, %25 ]
%30 = add nsw i32 %29, -1
%31 = tail call i32 @pushback(i32 63)
%32 = icmp sgt i32 %29, 2
br i1 %32, label %28, label %35
33: ; preds = %3
%34 = tail call i32 @pushback(i32 %4)
br label %35
35: ; preds = %28, %25, %33, %22, %0
%36 = phi i32 [ %23, %22 ], [ 63, %33 ], [ %1, %0 ], [ 63, %25 ], [ 63, %28 ]
ret i32 %36
}