#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);
int /*<<< orphan*/ puts(char *);
scalar_t__ scanf(char *, ...);
int main(void) {
  int k, queue[100000], head = 0, tail = 0;
  scanf("%*d");
  while (scanf("%d", &k) != EOF) {
    switch (k) {
    case 1:
      scanf("%d", &queue[tail]);
      if (++tail == 100000)
        tail = 0;
      break;
    case 2:
      if (head != tail)
        printf("%d\n", queue[head]);
      else
        puts("-1");
      break;
    default:
      if (head != tail) {
        if (++head == 100000)
          head = 0;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x61aa0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x61a94(%rbp)
movl   $0x0,-0x61a98(%rbp)
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
lea    0xe99(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    0x2e6b(%rip),%rcx
cmp    (%rcx),%rax
je     1284 <main+0x154>
mov    -0x8(%rbp),%eax
mov    %eax,-0x61a9c(%rbp)
sub    $0x1,%eax
je     11b1 <main+0x81>
jmp    119d <main+0x6d>
mov    -0x61a9c(%rbp),%eax
sub    $0x2,%eax
je     11fd <main+0xcd>
jmp    123f <main+0x10f>
movslq -0x61a98(%rbp),%rax
lea    -0x61a90(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x61a98(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x61a98(%rbp)
cmp    $0x186a0,%eax
jne    11f8 <main+0xc8>
movl   $0x0,-0x61a98(%rbp)
jmp    127f <main+0x14f>
mov    -0x61a94(%rbp),%eax
cmp    -0x61a98(%rbp),%eax
je     122e <main+0xfe>
movslq -0x61a94(%rbp),%rax
mov    -0x61a90(%rbp,%rax,4),%esi
lea    0xde3(%rip),%rdi
call   1040 <printf@plt>
jmp    123a <main+0x10a>
lea    0xdd6(%rip),%rdi
call   1030 <puts@plt>
jmp    127f <main+0x14f>
mov    -0x61a94(%rbp),%eax
cmp    -0x61a98(%rbp),%eax
je     127a <main+0x14a>
mov    -0x61a94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x61a94(%rbp)
cmp    $0x186a0,%eax
jne    1275 <main+0x145>
movl   $0x0,-0x61a94(%rbp)
jmp    127a <main+0x14a>
jmp    127f <main+0x14f>
jmp    1164 <main+0x34>
xor    %eax,%eax
add    $0x61aa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x61a98,%rsp
lea    0xeb8(%rip),%rdi
xor    %r13d,%r13d
xor    %eax,%eax
call   1050 <scanf@plt>
lea    0xeab(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x2e7c(%rip),%rbp
cmp    0x0(%rbp),%rax
jne    1186 <main+0x56>
xor    %eax,%eax
add    $0x61a98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe77(%rip),%rbx
lea    0xc(%rsp),%r12
xor    %r14d,%r14d
xor    %r15d,%r15d
jmp    11d7 <main+0xa7>
nopw   0x0(%rax,%rax,1)
movslq %r14d,%rax
lea    (%rsp,%rax,4),%rsi
add    $0x10,%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <scanf@plt>
add    $0x1,%r14d
cmp    $0x186a0,%r14d
cmove  %r13d,%r14d
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
cmp    0x0(%rbp),%rax
je     1172 <main+0x42>
mov    0xc(%rsp),%eax
cmp    $0x2,%eax
je     11f0 <main+0xc0>
cmp    $0x1,%eax
je     11a0 <main+0x70>
cmp    %r14d,%r15d
jne    1206 <main+0xd6>
mov    %r14d,%r15d
jmp    11c4 <main+0x94>
nop
cmp    %r14d,%r15d
jne    1217 <main+0xe7>
lea    0xe0f(%rip),%rdi
call   1030 <puts@plt>
mov    %r14d,%r15d
jmp    11c4 <main+0x94>
add    $0x1,%r15d
cmp    $0x186a0,%r15d
cmove  %r13d,%r15d
jmp    11c4 <main+0x94>
movslq %r15d,%rax
mov    0x10(%rsp,%rax,4),%esi
lea    0xde2(%rip),%rdi
call   1040 <printf@plt>
jmp    11c4 <main+0x94>

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

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