#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 /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ scanf(char *, char *);
int throw(int /*<<< orphan*/, int *, int, int);
int undo(int);
int game(int n, int k) {
  int stack[k + 1];
  stack[0] = 0;
  int curr = 0;
  while (k--) {
    char str[7];
    scanf("%s", str);
    if (str[0] == 'u')
      curr = undo(curr);
    else
      curr = throw(atoi(str), stack, curr, n);
  }
  return stack[curr];
}


x86 assembly (clang, -O0):
<game>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,%ecx
mov    %rsp,%rax
mov    %rax,-0x10(%rbp)
lea    0xf(,%rcx,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rax
sub    %rdx,%rax
mov    %rax,-0x30(%rbp)
mov    %rax,%rsp
mov    %rcx,-0x18(%rbp)
movl   $0x0,(%rax)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     11ea <game+0xaa>
lea    -0x23(%rbp),%rsi
lea    0xe5a(%rip),%rdi
call   1050 <scanf@plt>
movsbl -0x23(%rbp),%eax
cmp    $0x75,%eax
jne    11c8 <game+0x88>
mov    -0x1c(%rbp),%edi
call   1030 <undo@plt>
mov    %eax,-0x1c(%rbp)
jmp    11e5 <game+0xa5>
lea    -0x23(%rbp),%rdi
call   1060 <atoi@plt>
mov    -0x30(%rbp),%rsi
mov    %eax,%edi
mov    -0x1c(%rbp),%edx
mov    -0x4(%rbp),%ecx
call   1040 <throw@plt>
mov    %eax,-0x1c(%rbp)
jmp    1187 <game+0x47>
mov    -0x30(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x10(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<game>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebx
mov    %edi,-0x2c(%rbp)
lea    0x1(%rbx),%eax
mov    %rsp,%rcx
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
mov    %rcx,%r15
sub    %rax,%r15
mov    %r15,%rsp
neg    %rax
movl   $0x0,(%rcx,%rax,1)
test   %esi,%esi
je     11d6 <game+0x96>
xor    %r14d,%r14d
lea    0xe77(%rip),%r12
lea    -0x33(%rbp),%r13
jmp    11af <game+0x6f>
nop
mov    %r13,%rdi
call   1060 <atoi@plt>
mov    %eax,%edi
mov    %r15,%rsi
mov    %r14d,%edx
mov    -0x2c(%rbp),%ecx
call   1040 <throw@plt>
mov    %eax,%r14d
test   %ebx,%ebx
je     11cd <game+0x8d>
add    $0xffffffff,%ebx
mov    %r12,%rdi
mov    %r13,%rsi
call   1050 <scanf@plt>
cmpb   $0x75,-0x33(%rbp)
jne    1190 <game+0x50>
mov    %r14d,%edi
call   1030 <undo@plt>
jmp    11a8 <game+0x68>
movslq %r14d,%rax
mov    (%r15,%rax,4),%eax
jmp    11d8 <game+0x98>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
define i32 @game(i32 %0, i32 %1) {
%3 = alloca [7 x i8]
%4 = add nsw i32 %1, 1
%5 = zext i32 %4 to i64
%6 = alloca i32, i64 %5
store i32 0, i32* %6
%7 = icmp eq i32 %1, 0
br i1 %7, label %29, label %8
8: ; preds = %2
%9 = getelementptr inbounds [7 x i8], [7 x i8]* %3, i64 0, i64 0
br label %10
10: ; preds = %8, %22
%11 = phi i32 [ %1, %8 ], [ %13, %22 ]
%12 = phi i32 [ 0, %8 ], [ %23, %22 ]
%13 = add nsw i32 %11, -1
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %9)
%15 = load i8, i8* %9
%16 = icmp eq i8 %15, 117
br i1 %16, label %17, label %19
17: ; preds = %10
%18 = call i32 @undo(i32 %12)
br label %22
19: ; preds = %10
%20 = call i32 @atoi(i8* %9)
%21 = call i32 @throw(i32 %20, i32* %6, i32 %12, i32 %0)
br label %22
22: ; preds = %19, %17
%23 = phi i32 [ %18, %17 ], [ %21, %19 ]
%24 = icmp eq i32 %13, 0
br i1 %24, label %25, label %10
25: ; preds = %22
%26 = sext i32 %23 to i64
%27 = getelementptr inbounds i32, i32* %6, i64 %26
%28 = load i32, i32* %27
br label %29
29: ; preds = %2, %25
%30 = phi i32 [ %28, %25 ], [ 0, %2 ]
ret i32 %30
}