#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;
int /*<<< orphan*/ printf(char *, int);
scalar_t__ scanf(char *, ...);
int main(void) {
  int n, top = -1, num[100000];
  scanf("%d");
  while (scanf("%d", &n) != EOF) {
    if (n == 1) {
      if (top >= 0)
        top--;
    } else if (n == 2) {
      if (top >= 0)
        printf("%d\n", num[top]);
    } else
      scanf("%d", &num[++top]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x61a90,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0xc(%rbp)
lea    0xec0(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
lea    0xeb2(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
mov    0x2e88(%rip),%rcx
cmp    (%rcx),%rax
je     11ec <main+0xcc>
cmpl   $0x1,-0x8(%rbp)
jne    118b <main+0x6b>
cmpl   $0x0,-0xc(%rbp)
jl     1186 <main+0x66>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    11e7 <main+0xc7>
cmpl   $0x2,-0x8(%rbp)
jne    11bb <main+0x9b>
cmpl   $0x0,-0xc(%rbp)
jl     11b6 <main+0x96>
movslq -0xc(%rbp),%rax
mov    -0x61a90(%rbp,%rax,4),%esi
lea    0xe52(%rip),%rdi
call   1030 <printf@plt>
jmp    11e2 <main+0xc2>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
cltq
lea    -0x61a90(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1040 <scanf@plt>
jmp    11e7 <main+0xc7>
jmp    1147 <main+0x27>
xor    %eax,%eax
add    $0x61a90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x61a90,%rsp
lea    0xeca(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <scanf@plt>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x2e92(%rip),%r12
cmp    (%r12),%rax
jne    116e <main+0x4e>
xor    %eax,%eax
add    $0x61a90,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffffffff,%ebp
lea    0xe89(%rip),%r14
lea    0xe7f(%rip),%rbx
lea    0xc(%rsp),%r15
jmp    11bb <main+0x9b>
nopl   0x0(%rax,%rax,1)
movslq %ebp,%rax
add    $0x1,%ebp
lea    (%rsp,%rax,4),%rsi
add    $0x14,%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <scanf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmp    (%r12),%rax
je     115c <main+0x3c>
mov    0xc(%rsp),%eax
cmp    $0x2,%eax
je     11e0 <main+0xc0>
cmp    $0x1,%eax
jne    1190 <main+0x70>
mov    %ebp,%eax
sar    $0x1f,%eax
not    %eax
add    %eax,%ebp
jmp    11a8 <main+0x88>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
test   %ebp,%ebp
js     11a8 <main+0x88>
mov    %ebp,%eax
mov    0x10(%rsp,%rax,4),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
jmp    11a8 <main+0x88>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@EOF = global i64 0
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [100000 x i32]
store i32 0, i32* %1
store i32 -1, i32* %3
%5 = call i64 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %40, %0
%7 = call i64 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%8 = load i64, i64* @EOF
%9 = icmp ne i64 %7, %8
br i1 %9, label %10, label %41
10: ; preds = %6
%11 = load i32, i32* %2
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = load i32, i32* %3
%15 = icmp sge i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load i32, i32* %3
%18 = add nsw i32 %17, -1
store i32 %18, i32* %3
br label %19
19: ; preds = %16, %13
br label %40
20: ; preds = %10
%21 = load i32, i32* %2
%22 = icmp eq i32 %21, 2
br i1 %22, label %23, label %33
23: ; preds = %20
%24 = load i32, i32* %3
%25 = icmp sge i32 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %23
%27 = load i32, i32* %3
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [100000 x i32], [100000 x i32]* %4, i64 0, i64 %28
%30 = load i32, i32* %29
%31 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %26, %23
br label %39
33: ; preds = %20
%34 = load i32, i32* %3
%35 = add nsw i32 %34, 1
store i32 %35, i32* %3
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [100000 x i32], [100000 x i32]* %4, i64 0, i64 %36
%38 = call i64 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %37)
br label %39
39: ; preds = %33, %32
br label %40
40: ; preds = %39, %19
br label %6
41: ; preds = %6
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@EOF = global i64 0
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100000 x i32]
%3 = bitcast i32* %1 to i8*
%4 = bitcast [100000 x i32]* %2 to i8*
%5 = tail call i64 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = call i64 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%7 = load i64, i64* @EOF
%8 = icmp eq i64 %6, %7
br i1 %8, label %33, label %9
9: ; preds = %0, %28
%10 = phi i32 [ %29, %28 ], [ -1, %0 ]
%11 = load i32, i32* %1
switch i32 %11, label %23 [
i32 1, label %12
i32 2, label %16
]
12: ; preds = %9
%13 = ashr i32 %10, 31
%14 = xor i32 %13, -1
%15 = add nsw i32 %10, %14
br label %28
16: ; preds = %9
%17 = icmp sgt i32 %10, -1
br i1 %17, label %18, label %28
18: ; preds = %16
%19 = zext i32 %10 to i64
%20 = getelementptr inbounds [100000 x i32], [100000 x i32]* %2, i64 0, i64 %19
%21 = load i32, i32* %20
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %21)
br label %28
23: ; preds = %9
%24 = add nsw i32 %10, 1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [100000 x i32], [100000 x i32]* %2, i64 0, i64 %25
%27 = call i64 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %26)
br label %28
28: ; preds = %12, %23, %18, %16
%29 = phi i32 [ %10, %18 ], [ %10, %16 ], [ %24, %23 ], [ %15, %12 ]
%30 = call i64 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%31 = load i64, i64* @EOF
%32 = icmp eq i64 %30, %31
br i1 %32, label %33, label %9
33: ; preds = %28, %0
ret i32 0
}