#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*/ printf(char *, char);
int /*<<< orphan*/ scanf(char *, char *);
scalar_t__ strcmp(char *, char *);
int main(void) {
  int sp = 0;
  char block[1000], inst[4];
  while (1) {
    scanf(" %s", inst);
    if (strcmp(inst, "quit") == 0)
      break;
    if (strcmp(inst, "pop") == 0) {
      printf("%c\n", block[sp - 1]);
      sp--;
    } else {
      scanf(" %c\n", &block[sp]);
      sp++;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    -0x3f4(%rbp),%rsi
lea    0xea9(%rip),%rdi
call   1050 <scanf@plt>
lea    -0x3f4(%rbp),%rdi
lea    0xe9a(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    117e <main+0x4e>
jmp    11ed <main+0xbd>
lea    -0x3f4(%rbp),%rdi
lea    0xe7d(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11c5 <main+0x95>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
cltq
lea    0xe64(%rip),%rdi
movsbl -0x3f0(%rbp,%rax,1),%esi
ff
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    11e8 <main+0xb8>
movslq -0x8(%rbp),%rax
lea    -0x3f0(%rbp),%rsi
add    %rax,%rsi
lea    0xe33(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1149 <main+0x19>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3f8,%rsp
lea    0xeb8(%rip),%rdi
lea    0xc(%rsp),%rbx
mov    %rbx,%rsi
call   1050 <scanf@plt>
lea    0xea8(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11fa <main+0xca>
xor    %r15d,%r15d
lea    0xe92(%rip),%r14
lea    0xc(%rsp),%rbx
lea    0xe7d(%rip),%r12
lea    0xe7a(%rip),%r13
lea    0xe7c(%rip),%rbp
jmp    11cf <main+0x9f>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    (%rsp,%r15,1),%rsi
add    $0x10,%rsi
mov    %rbp,%rdi
call   1050 <scanf@plt>
add    $0x1,%r15d
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11fa <main+0xca>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
movslq %r15d,%r15
test   %rax,%rax
jne    11a0 <main+0x70>
movsbl 0xf(%rsp,%r15,1),%esi
add    $0xffffffffffffffff,%r15
lea    0xe1b(%rip),%rdi
call   1030 <printf@plt>
jmp    11b4 <main+0x84>
xor    %eax,%eax
add    $0x3f8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c" %s\00"
@.str.1 = [5 x i8] c"quit\00"
@.str.2 = [4 x i8] c"pop\00"
@.str.3 = [4 x i8] c"%c\0A\00"
@.str.4 = [5 x i8] c" %c\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [1000 x i8]
%4 = alloca [4 x i8]
store i32 0, i32* %1
store i32 0, i32* %2
br label %5
5: ; preds = %0, %32
%6 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%7 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%9 = call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %5
br label %33
12: ; preds = %5
%13 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%14 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %25
16: ; preds = %12
%17 = load i32, i32* %2
%18 = sub nsw i32 %17, 1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8 signext %21)
%23 = load i32, i32* %2
%24 = add nsw i32 %23, -1
store i32 %24, i32* %2
br label %32
25: ; preds = %12
%26 = load i32, i32* %2
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 %27
%29 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %28)
%30 = load i32, i32* %2
%31 = add nsw i32 %30, 1
store i32 %31, i32* %2
br label %32
32: ; preds = %25, %16
br label %5
33: ; preds = %11
ret i32 0
}

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