#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 */
scalar_t__ EOF;
scalar_t__ check_valid(int, int);
int /*<<< orphan*/ init(int);
scalar_t__ memcmp(char *, char *, int);
int /*<<< orphan*/ move_onto(int, int);
int /*<<< orphan*/ move_over(int, int);
int /*<<< orphan*/ pile_onto(int, int);
int /*<<< orphan*/ pile_over(int, int);
int /*<<< orphan*/ print_blocks(int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ scanf(char *, ...);
int main() {
  int num_blocks;
  char cmd[32], option[32];
  int src_block_id, tgt_block_id;
  int i;
  scanf("%d\n", &num_blocks);
  init(num_blocks);
  while (scanf("%s", &cmd[0]) != EOF && memcmp(cmd, "quit", 4) != 0) {
    scanf("%d %s %d\n", &src_block_id, &option[0], &tgt_block_id);
    if (check_valid(src_block_id, tgt_block_id) == 0) {
      continue;
    }
    if (memcmp(cmd, "move", 4) == 0) {
      if (memcmp(option, "onto", 4) == 0) {
        move_onto(src_block_id, tgt_block_id);
      } else {
        move_over(src_block_id, tgt_block_id);
      }
    } else {
      if (memcmp(option, "onto", 4) == 0) {
        pile_onto(src_block_id, tgt_block_id);
      } else {
        pile_over(src_block_id, tgt_block_id);
      }
    }
  }
  for (i = 0; i < num_blocks; i++) {
    printf("%d:", i);
    print_blocks(i);
    printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe58(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   10b0 <scanf@plt>
mov    -0x8(%rbp),%edi
call   1080 <init@plt>
lea    -0x30(%rbp),%rsi
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   10b0 <scanf@plt>
mov    %rax,%rcx
xor    %eax,%eax
mov    0x2e01(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0x5d(%rbp)
je     1212 <main+0x72>
lea    -0x30(%rbp),%rdi
lea    0xe05(%rip),%rsi
mov    $0x4,%edx
call   1060 <memcmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x5d(%rbp)
mov    -0x5d(%rbp),%al
test   $0x1,%al
jne    1222 <main+0x82>
jmp    12f8 <main+0x158>
lea    -0x50(%rbp),%rdx
lea    0xddb(%rip),%rdi
lea    -0x54(%rbp),%rsi
lea    -0x58(%rbp),%rcx
mov    $0x0,%al
call   10b0 <scanf@plt>
mov    -0x54(%rbp),%edi
mov    -0x58(%rbp),%esi
call   1040 <check_valid@plt>
cmp    $0x0,%rax
jne    1256 <main+0xb6>
jmp    11c9 <main+0x29>
lea    -0x30(%rbp),%rdi
lea    0xdb1(%rip),%rsi
mov    $0x4,%edx
call   1060 <memcmp@plt>
cmp    $0x0,%rax
jne    12b4 <main+0x114>
lea    -0x50(%rbp),%rdi
lea    0xd97(%rip),%rsi
mov    $0x4,%edx
call   1060 <memcmp@plt>
cmp    $0x0,%rax
jne    12a4 <main+0x104>
mov    -0x54(%rbp),%edi
mov    -0x58(%rbp),%esi
call   10a0 <move_onto@plt>
jmp    12af <main+0x10f>
mov    -0x54(%rbp),%edi
mov    -0x58(%rbp),%esi
call   1090 <move_over@plt>
jmp    12f3 <main+0x153>
lea    -0x50(%rbp),%rdi
lea    0xd58(%rip),%rsi
mov    $0x4,%edx
call   1060 <memcmp@plt>
cmp    $0x0,%rax
jne    12e3 <main+0x143>
mov    -0x54(%rbp),%edi
mov    -0x58(%rbp),%esi
call   10c0 <pile_onto@plt>
jmp    12ee <main+0x14e>
mov    -0x54(%rbp),%edi
mov    -0x58(%rbp),%esi
call   1030 <pile_over@plt>
jmp    12f3 <main+0x153>
jmp    11c9 <main+0x29>
movl   $0x0,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1340 <main+0x1a0>
mov    -0x5c(%rbp),%esi
lea    0xd07(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x5c(%rbp),%edi
call   1070 <print_blocks@plt>
lea    0xce5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    12ff <main+0x15f>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
lea    0xe49(%rip),%rdi
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   10c0 <scanf@plt>
mov    0x4(%rsp),%edi
call   1090 <init@plt>
lea    0xe1f(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   10c0 <scanf@plt>
mov    0x2df4(%rip),%r12
cmp    (%r12),%rax
jne    1247 <main+0x97>
cmpl   $0x0,0x4(%rsp)
jle    1236 <main+0x86>
lea    0xe14(%rip),%rbx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebp,%edi
call   1080 <print_blocks@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%ebp
cmp    0x4(%rsp),%ebp
jl     1210 <main+0x60>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x10(%rsp),%rbx
lea    0x30(%rsp),%r13
lea    0x8(%rsp),%rbp
lea    0xda3(%rip),%r15
jmp    1278 <main+0xc8>
nop
call   1040 <pile_over@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   10c0 <scanf@plt>
cmp    (%r12),%rax
je     11fa <main+0x4a>
mov    %rbx,%rdi
lea    0xd81(%rip),%rsi
mov    $0x4,%edx
call   1070 <memcmp@plt>
test   %rax,%rax
je     11fa <main+0x4a>
lea    0xd6c(%rip),%rdi
lea    0xc(%rsp),%rsi
mov    %r13,%rdx
mov    %rbp,%rcx
xor    %eax,%eax
call   10c0 <scanf@plt>
mov    0xc(%rsp),%edi
mov    0x8(%rsp),%esi
call   1050 <check_valid@plt>
test   %rax,%rax
je     1265 <main+0xb5>
mov    %rbx,%rdi
lea    0xd48(%rip),%rsi
mov    $0x4,%edx
call   1070 <memcmp@plt>
mov    %rax,%r14
mov    %r13,%rdi
lea    0xd36(%rip),%rsi
mov    $0x4,%edx
call   1070 <memcmp@plt>
mov    0xc(%rsp),%edi
mov    0x8(%rsp),%esi
test   %r14,%r14
je     1310 <main+0x160>
test   %rax,%rax
jne    1260 <main+0xb0>
call   10d0 <pile_onto@plt>
jmp    1265 <main+0xb5>
nopl   0x0(%rax,%rax,1)
test   %rax,%rax
je     131f <main+0x16f>
call   10a0 <move_over@plt>
jmp    1265 <main+0xb5>
call   10b0 <move_onto@plt>
jmp    1265 <main+0xb5>

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [3 x i8] c"%s\00"
@EOF = global i64 0
@.str.2 = [5 x i8] c"quit\00"
@.str.3 = [10 x i8] c"%d %s %d\0A\00"
@.str.4 = [5 x i8] c"move\00"
@.str.5 = [5 x i8] c"onto\00"
@.str.6 = [4 x i8] c"%d:\00"
@.str.7 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [32 x i8]
%4 = alloca [32 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i64 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %2
%10 = call i32 @init(i32 %9)
br label %11
11: ; preds = %60, %29, %0
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%13 = call i64 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = load i64, i64* @EOF
%15 = icmp ne i64 %13, %14
br i1 %15, label %16, label %20
16: ; preds = %11
%17 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%18 = call i64 @memcmp(i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%19 = icmp ne i64 %18, 0
br label %20
20: ; preds = %16, %11
%21 = phi i1 [ false, %11 ], [ %19, %16 ]
br i1 %21, label %22, label %61
22: ; preds = %20
%23 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%24 = call i64 (i8*, ...) @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32* %5, i8* %23, i32* %6)
%25 = load i32, i32* %5
%26 = load i32, i32* %6
%27 = call i64 @check_valid(i32 %25, i32 %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %22
br label %11
30: ; preds = %22
%31 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%32 = call i64 @memcmp(i8* %31, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %47
34: ; preds = %30
%35 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%36 = call i64 @memcmp(i8* %35, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 4)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %34
%39 = load i32, i32* %5
%40 = load i32, i32* %6
%41 = call i32 @move_onto(i32 %39, i32 %40)
br label %46
42: ; preds = %34
%43 = load i32, i32* %5
%44 = load i32, i32* %6
%45 = call i32 @move_over(i32 %43, i32 %44)
br label %46
46: ; preds = %42, %38
br label %60
47: ; preds = %30
%48 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%49 = call i64 @memcmp(i8* %48, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 4)
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %55
51: ; preds = %47
%52 = load i32, i32* %5
%53 = load i32, i32* %6
%54 = call i32 @pile_onto(i32 %52, i32 %53)
br label %59
55: ; preds = %47
%56 = load i32, i32* %5
%57 = load i32, i32* %6
%58 = call i32 @pile_over(i32 %56, i32 %57)
br label %59
59: ; preds = %55, %51
br label %60
60: ; preds = %59, %46
br label %11
61: ; preds = %20
store i32 0, i32* %7
br label %62
62: ; preds = %72, %61
%63 = load i32, i32* %7
%64 = load i32, i32* %2
%65 = icmp slt i32 %63, %64
br i1 %65, label %66, label %75
66: ; preds = %62
%67 = load i32, i32* %7
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %67)
%69 = load i32, i32* %7
%70 = call i32 @print_blocks(i32 %69)
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %72
72: ; preds = %66
%73 = load i32, i32* %7
%74 = add nsw i32 %73, 1
store i32 %74, i32* %7
br label %62
75: ; preds = %62
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [3 x i8] c"%s\00"
@EOF = global i64 0
@.str.2 = [5 x i8] c"quit\00"
@.str.3 = [10 x i8] c"%d %s %d\0A\00"
@.str.4 = [5 x i8] c"move\00"
@.str.5 = [5 x i8] c"onto\00"
@.str.6 = [4 x i8] c"%d:\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [32 x i8]
%3 = alloca [32 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %1 to i8*
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%9 = bitcast i32* %4 to i8*
%10 = bitcast i32* %5 to i8*
%11 = call i64 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %1)
%12 = load i32, i32* %1
%13 = call i32 @init(i32 %12)
%14 = call i64 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%15 = load i64, i64* @EOF
%16 = icmp eq i64 %14, %15
br i1 %16, label %47, label %17
17: ; preds = %0, %43
%18 = call i64 @memcmp(i8* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%19 = icmp eq i64 %18, 0
br i1 %19, label %47, label %20
20: ; preds = %17
%21 = call i64 (i8*, ...) @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32* %4, i8* %8, i32* %5)
%22 = load i32, i32* %4
%23 = load i32, i32* %5
%24 = call i64 @check_valid(i32 %22, i32 %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %43, label %26
26: ; preds = %20
%27 = call i64 @memcmp(i8* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%28 = icmp eq i64 %27, 0
%29 = call i64 @memcmp(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 4)
%30 = icmp eq i64 %29, 0
%31 = load i32, i32* %4
%32 = load i32, i32* %5
br i1 %28, label %33, label %38
33: ; preds = %26
br i1 %30, label %34, label %36
34: ; preds = %33
%35 = call i32 @move_onto(i32 %31, i32 %32)
br label %43
36: ; preds = %33
%37 = call i32 @move_over(i32 %31, i32 %32)
br label %43
38: ; preds = %26
br i1 %30, label %39, label %41
39: ; preds = %38
%40 = call i32 @pile_onto(i32 %31, i32 %32)
br label %43
41: ; preds = %38
%42 = call i32 @pile_over(i32 %31, i32 %32)
br label %43
43: ; preds = %36, %34, %41, %39, %20
%44 = call i64 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%45 = load i64, i64* @EOF
%46 = icmp eq i64 %44, %45
br i1 %46, label %47, label %17
47: ; preds = %17, %43, %0
%48 = load i32, i32* %1
%49 = icmp sgt i32 %48, 0
br i1 %49, label %50, label %58
50: ; preds = %47, %50
%51 = phi i32 [ %55, %50 ], [ 0, %47 ]
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %51)
%53 = call i32 @print_blocks(i32 %51)
%54 = call i32 @putchar(i32 10)
%55 = add nuw nsw i32 %51, 1
%56 = load i32, i32* %1
%57 = icmp slt i32 %55, %56
br i1 %57, label %50, label %58
58: ; preds = %50, %47
ret i32 0
}