#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 /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *stderr;
void print_io_code(FILE *fp, const char **code_ptr) {
  const char *code = *code_ptr;
  switch (*++code) {
  case ' ':
    switch (*++code) {
    case ' ':
      fputs("  "
            "putchar(pop());\n",
            fp);
      break;
    case '\t':
      fputs("  "
            "printf(\"%d\", pop());\n",
            fp);
      break;
    case '\n':
      fputs("Undefined I/O command is detected: [TN][SN]\n", stderr);
      break;
    }
    break;
  case '\t':
    switch (*++code) {
    case ' ':
      fputs("  "
            "fflush(stdout);\n"
            "  "
            "heap[pop()] = getchar();\n",
            fp);
      break;
    case '\t':
      fputs("  "
            "fflush(stdout);\n"
            "  "
            "scanf(\"%d\", &heap[pop()]);\n",
            fp);
      break;
    case '\n':
      fputs("Undefined I/O command is detected: [TN][TN]\n", stderr);
      break;
    }
    break;
  case '\n':
    fputs("Undefined I/O command is detected: [TN][N]\n", stderr);
    break;
  }
  *code_ptr = code;
}


x86 assembly (clang, -O0):
<print_io_code>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbl 0x1(%rax),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x9,%eax
je     11fc <print_io_code+0xec>
jmp    114f <print_io_code+0x3f>
mov    -0x1c(%rbp),%eax
sub    $0xa,%eax
je     1287 <print_io_code+0x177>
jmp    1160 <print_io_code+0x50>
mov    -0x1c(%rbp),%eax
sub    $0x20,%eax
jne    129d <print_io_code+0x18d>
jmp    1171 <print_io_code+0x61>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbl 0x1(%rax),%eax
mov    %eax,-0x20(%rbp)
sub    $0x9,%eax
je     11cc <print_io_code+0xbc>
jmp    1195 <print_io_code+0x85>
mov    -0x20(%rbp),%eax
sub    $0xa,%eax
je     11e1 <print_io_code+0xd1>
jmp    11a6 <print_io_code+0x96>
mov    -0x20(%rbp),%eax
sub    $0x20,%eax
jne    11f7 <print_io_code+0xe7>
jmp    11b7 <print_io_code+0xa7>
mov    -0x8(%rbp),%rsi
lea    0xe3e(%rip),%rdi
call   1030 <fputs@plt>
jmp    11f7 <print_io_code+0xe7>
mov    -0x8(%rbp),%rsi
lea    0xe3c(%rip),%rdi
call   1030 <fputs@plt>
jmp    11f7 <print_io_code+0xe7>
mov    0x2df8(%rip),%rax
mov    (%rax),%rsi
lea    0xe39(%rip),%rdi
call   1030 <fputs@plt>
jmp    129d <print_io_code+0x18d>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbl 0x1(%rax),%eax
mov    %eax,-0x24(%rbp)
sub    $0x9,%eax
je     1257 <print_io_code+0x147>
jmp    1220 <print_io_code+0x110>
mov    -0x24(%rbp),%eax
sub    $0xa,%eax
je     126c <print_io_code+0x15c>
jmp    1231 <print_io_code+0x121>
mov    -0x24(%rbp),%eax
sub    $0x20,%eax
jne    1282 <print_io_code+0x172>
jmp    1242 <print_io_code+0x132>
mov    -0x8(%rbp),%rsi
lea    0xe0b(%rip),%rdi
call   1030 <fputs@plt>
jmp    1282 <print_io_code+0x172>
mov    -0x8(%rbp),%rsi
lea    0xe24(%rip),%rdi
call   1030 <fputs@plt>
jmp    1282 <print_io_code+0x172>
mov    0x2d6d(%rip),%rax
mov    (%rax),%rsi
lea    0xe39(%rip),%rdi
call   1030 <fputs@plt>
jmp    129d <print_io_code+0x18d>
mov    0x2d52(%rip),%rax
mov    (%rax),%rsi
lea    0xe4b(%rip),%rdi
call   1030 <fputs@plt>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_io_code>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rcx
mov    (%rsi),%r15
movsbl 0x1(%r15),%eax
cmp    $0x9,%eax
je     1167 <print_io_code+0x57>
lea    0x1(%r15),%rbx
cmp    $0xa,%eax
je     118d <print_io_code+0x7d>
cmp    $0x20,%eax
jne    1201 <print_io_code+0xf1>
movsbl 0x2(%r15),%eax
add    $0x2,%r15
cmp    $0x9,%eax
je     11af <print_io_code+0x9f>
cmp    $0xa,%eax
je     11bd <print_io_code+0xad>
cmp    $0x20,%eax
jne    11fe <print_io_code+0xee>
lea    0xea3(%rip),%rdi
mov    $0x12,%esi
jmp    11f4 <print_io_code+0xe4>
movsbl 0x2(%r15),%eax
add    $0x2,%r15
cmp    $0x9,%eax
je     11d0 <print_io_code+0xc0>
cmp    $0xa,%eax
je     11de <print_io_code+0xce>
cmp    $0x20,%eax
jne    11fe <print_io_code+0xee>
lea    0xed2(%rip),%rdi
mov    $0x2d,%esi
jmp    11f4 <print_io_code+0xe4>
mov    0x2e4c(%rip),%rax
mov    (%rax),%rcx
lea    0xf45(%rip),%rdi
mov    $0x2b,%esi
mov    $0x1,%edx
call   1030 <fwrite@plt>
jmp    1201 <print_io_code+0xf1>
lea    0xe5d(%rip),%rdi
mov    $0x17,%esi
jmp    11f4 <print_io_code+0xe4>
mov    0x2e1c(%rip),%rax
mov    (%rax),%rcx
lea    0xe5d(%rip),%rdi
jmp    11ef <print_io_code+0xdf>
lea    0xeaf(%rip),%rdi
mov    $0x2f,%esi
jmp    11f4 <print_io_code+0xe4>
mov    0x2dfb(%rip),%rax
mov    (%rax),%rcx
lea    0xec7(%rip),%rdi
mov    $0x2c,%esi
mov    $0x1,%edx
call   1030 <fwrite@plt>
mov    %r15,%rbx
mov    %rbx,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [19 x i8] c" putchar(pop());\0A\00"
@.str.1 = [24 x i8] c" printf(\22%d\22, pop());\0A\00"
@.str.2 = [45 x i8] c"Undefined I/O command is detected: [TN][SN]\0A\00"
@stderr = global i32* null
@.str.3 = [46 x i8] c" fflush(stdout);\0A heap[pop()] = getchar();\0A\00"
@.str.4 = [48 x i8] c" fflush(stdout);\0A scanf(\22%d\22, &heap[pop()]);\0A\00"
@.str.5 = [45 x i8] c"Undefined I/O command is detected: [TN][TN]\0A\00"
@.str.6 = [44 x i8] c"Undefined I/O command is detected: [TN][N]\0A\00"
define void @print_io_code(i32* %0, i8** %1) {
%3 = alloca i32*
%4 = alloca i8**
%5 = alloca i8*
store i32* %0, i32** %3
store i8** %1, i8*** %4
%6 = load i8**, i8*** %4
%7 = load i8*, i8** %6
store i8* %7, i8** %5
%8 = load i8*, i8** %5
%9 = getelementptr inbounds i8, i8* %8, i32 1
store i8* %9, i8** %5
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
switch i32 %11, label %45 [
i32 32, label %12
i32 9, label %27
i32 10, label %42
]
12: ; preds = %2
%13 = load i8*, i8** %5
%14 = getelementptr inbounds i8, i8* %13, i32 1
store i8* %14, i8** %5
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
switch i32 %16, label %26 [
i32 32, label %17
i32 9, label %20
i32 10, label %23
]
17: ; preds = %12
%18 = load i32*, i32** %3
%19 = call i32 @fputs(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32* %18)
br label %26
20: ; preds = %12
%21 = load i32*, i32** %3
%22 = call i32 @fputs(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32* %21)
br label %26
23: ; preds = %12
%24 = load i32*, i32** @stderr
%25 = call i32 @fputs(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32* %24)
br label %26
26: ; preds = %12, %23, %20, %17
br label %45
27: ; preds = %2
%28 = load i8*, i8** %5
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %5
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
switch i32 %31, label %41 [
i32 32, label %32
i32 9, label %35
i32 10, label %38
]
32: ; preds = %27
%33 = load i32*, i32** %3
%34 = call i32 @fputs(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32* %33)
br label %41
35: ; preds = %27
%36 = load i32*, i32** %3
%37 = call i32 @fputs(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i32* %36)
br label %41
38: ; preds = %27
%39 = load i32*, i32** @stderr
%40 = call i32 @fputs(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0), i32* %39)
br label %41
41: ; preds = %27, %38, %35, %32
br label %45
42: ; preds = %2
%43 = load i32*, i32** @stderr
%44 = call i32 @fputs(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.6, i64 0, i64 0), i32* %43)
br label %45
45: ; preds = %2, %42, %41, %26
%46 = load i8*, i8** %5
%47 = load i8**, i8*** %4
store i8* %46, i8** %47
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c" putchar(pop());\0A\00"
@.str.1 = [24 x i8] c" printf(\22%d\22, pop());\0A\00"
@.str.2 = [45 x i8] c"Undefined I/O command is detected: [TN][SN]\0A\00"
@stderr = global i32* null
@.str.3 = [46 x i8] c" fflush(stdout);\0A heap[pop()] = getchar();\0A\00"
@.str.4 = [48 x i8] c" fflush(stdout);\0A scanf(\22%d\22, &heap[pop()]);\0A\00"
@.str.5 = [45 x i8] c"Undefined I/O command is detected: [TN][TN]\0A\00"
@.str.6 = [44 x i8] c"Undefined I/O command is detected: [TN][N]\0A\00"
define void @print_io_code(i32* nocapture %0, i8** nocapture %1) {
%3 = load i8*, i8** %1
%4 = getelementptr inbounds i8, i8* %3, i64 1
%5 = load i8, i8* %4
%6 = sext i8 %5 to i32
switch i32 %6, label %32 [
i32 32, label %7
i32 9, label %18
i32 10, label %29
]
7: ; preds = %2
%8 = getelementptr inbounds i8, i8* %3, i64 2
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
switch i32 %10, label %32 [
i32 32, label %11
i32 9, label %13
i32 10, label %15
]
11: ; preds = %7
%12 = tail call i64 @fwrite(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i64 18, i64 1, i32* %0)
br label %32
13: ; preds = %7
%14 = tail call i64 @fwrite(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i64 23, i64 1, i32* %0)
br label %32
15: ; preds = %7
%16 = load i32*, i32** @stderr
%17 = tail call i64 @fwrite(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i64 44, i64 1, i32* %16)
br label %32
18: ; preds = %2
%19 = getelementptr inbounds i8, i8* %3, i64 2
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
switch i32 %21, label %32 [
i32 32, label %22
i32 9, label %24
i32 10, label %26
]
22: ; preds = %18
%23 = tail call i64 @fwrite(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i64 45, i64 1, i32* %0)
br label %32
24: ; preds = %18
%25 = tail call i64 @fwrite(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i64 47, i64 1, i32* %0)
br label %32
26: ; preds = %18
%27 = load i32*, i32** @stderr
%28 = tail call i64 @fwrite(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0), i64 44, i64 1, i32* %27)
br label %32
29: ; preds = %2
%30 = load i32*, i32** @stderr
%31 = tail call i64 @fwrite(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.6, i64 0, i64 0), i64 43, i64 1, i32* %30)
br label %32
32: ; preds = %22, %24, %26, %18, %11, %13, %15, %7, %2, %29
%33 = phi i8* [ %4, %2 ], [ %4, %29 ], [ %19, %18 ], [ %19, %26 ], [ %19, %24 ], [ %19, %22 ], [ %8, %7 ], [ %8, %15 ], [ %8, %13 ], [ %8, %11 ]
store i8* %33, i8** %1
ret void
}