#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 EOF;
int atoi(char *);
int /*<<< orphan*/ clear();
int getop(char *, int);
int pop();
int /*<<< orphan*/ printf(char *, ...);
int push(int);
int main() {
  int type;
  char s[20];
  int op2;
  while ((type = getop(s, 20)) != EOF) {
    switch (type) {
    case '0':
      push(atoi(s));
      break;
    case '+':
      push(pop() + pop());
      break;
    case '*':
      push(pop() * pop());
      break;
    case '-':
      op2 = pop();
      push(pop() - op2);
      break;
    case '/':
      op2 = pop();
      if (op2 != 0)
        push(pop() / op2);
      else
        printf("zero divisor popped\n");
      break;
    case '=':
      printf("\n%d\n\n", push(pop()));
      break;
    case 'c':
      clear();
      break;
    case '9':
      printf("%.20s ... is too long\n", s);
      break;
    default:
      printf("unknown command %c\n", type);
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0x14,%esi
call   1050 <getop@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e61(%rip),%rcx
cmp    (%rcx),%eax
je     12c8 <main+0x168>
mov    -0x8(%rbp),%eax
add    $0xffffffd6,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x39,%eax
ja     12b2 <main+0x152>
mov    -0x30(%rbp),%rax
lea    0xe51(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    -0x20(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,%edi
call   1060 <push@plt>
jmp    12c3 <main+0x163>
mov    $0x0,%al
call   1040 <pop@plt>
mov    %eax,-0x34(%rbp)
mov    $0x0,%al
call   1040 <pop@plt>
mov    -0x34(%rbp),%edi
add    %eax,%edi
call   1060 <push@plt>
jmp    12c3 <main+0x163>
mov    $0x0,%al
call   1040 <pop@plt>
mov    %eax,-0x38(%rbp)
mov    $0x0,%al
call   1040 <pop@plt>
mov    -0x38(%rbp),%edi
imul   %eax,%edi
call   1060 <push@plt>
jmp    12c3 <main+0x163>
mov    $0x0,%al
call   1040 <pop@plt>
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1040 <pop@plt>
mov    %eax,%edi
sub    -0x24(%rbp),%edi
call   1060 <push@plt>
jmp    12c3 <main+0x163>
mov    $0x0,%al
call   1040 <pop@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1259 <main+0xf9>
mov    $0x0,%al
call   1040 <pop@plt>
cltd
idivl  -0x24(%rbp)
mov    %eax,%edi
call   1060 <push@plt>
jmp    1267 <main+0x107>
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12c3 <main+0x163>
mov    $0x0,%al
call   1040 <pop@plt>
mov    %eax,%edi
call   1060 <push@plt>
mov    %eax,%esi
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12c3 <main+0x163>
mov    $0x0,%al
call   1080 <clear@plt>
jmp    12c3 <main+0x163>
lea    -0x20(%rbp),%rsi
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12c3 <main+0x163>
mov    -0x8(%rbp),%esi
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    116f <main+0xf>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsp,%rdi
mov    $0x14,%esi
call   1060 <getop@plt>
mov    0x2e56(%rip),%r15
cmp    (%r15),%eax
jne    11a8 <main+0x38>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsp,%rbx
lea    0xe4e(%rip),%r14
lea    0xf35(%rip),%r12
lea    0xf28(%rip),%r13
jmp    11e3 <main+0x73>
mov    %rbx,%rdi
call   1080 <atoi@plt>
mov    %eax,%edi
call   1070 <push@plt>
mov    %rbx,%rdi
mov    $0x14,%esi
call   1060 <getop@plt>
cmp    (%r15),%eax
je     1197 <main+0x27>
lea    -0x2a(%rax),%ecx
cmp    $0x39,%ecx
ja     121f <main+0xaf>
movslq (%r14,%rcx,4),%rcx
add    %r14,%rcx
jmp    *%rcx
xor    %eax,%eax
call   1050 <pop@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <pop@plt>
imul   %eax,%ebp
jmp    121b <main+0xab>
xor    %eax,%eax
call   1050 <pop@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <pop@plt>
add    %eax,%ebp
mov    %ebp,%edi
jmp    11cc <main+0x5c>
lea    0xedf(%rip),%rdi
mov    %eax,%esi
jmp    127f <main+0x10f>
xor    %eax,%eax
call   1050 <pop@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <pop@plt>
sub    %ebp,%eax
jmp    11ca <main+0x5a>
xor    %eax,%eax
call   1050 <pop@plt>
test   %eax,%eax
je     1297 <main+0x127>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <pop@plt>
cltd
idiv   %ebp
jmp    11ca <main+0x5a>
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11d1 <main+0x61>
xor    %eax,%eax
call   1050 <pop@plt>
mov    %eax,%edi
call   1070 <push@plt>
mov    %r13,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11d1 <main+0x61>
xor    %eax,%eax
call   1090 <clear@plt>
jmp    11d1 <main+0x61>
lea    0xe7b(%rip),%rdi
call   1030 <puts@plt>
jmp    11d1 <main+0x61>

LLVM IR (-O0):
@EOF = global i32 0
@.str = [21 x i8] c"zero divisor popped\0A\00"
@.str.1 = [6 x i8] c"\0A%d\0A\0A\00"
@.str.2 = [23 x i8] c"%.20s ... is too long\0A\00"
@.str.3 = [20 x i8] c"unknown command %c\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [20 x i8]
%4 = alloca i32
store i32 0, i32* %1
br label %5
5: ; preds = %56, %0
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%7 = call i32 @getop(i8* %6, i32 20)
store i32 %7, i32* %2
%8 = load i32, i32* @EOF
%9 = icmp ne i32 %7, %8
br i1 %9, label %10, label %57
10: ; preds = %5
%11 = load i32, i32* %2
switch i32 %11, label %53 [
i32 48, label %12
i32 43, label %16
i32 42, label %21
i32 45, label %26
i32 47, label %32
i32 61, label %44
i32 99, label %48
i32 57, label %50
]
12: ; preds = %10
%13 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%14 = call i32 @atoi(i8* %13)
%15 = call i32 @push(i32 %14)
br label %56
16: ; preds = %10
%17 = call i32 (...) @pop()
%18 = call i32 (...) @pop()
%19 = add nsw i32 %17, %18
%20 = call i32 @push(i32 %19)
br label %56
21: ; preds = %10
%22 = call i32 (...) @pop()
%23 = call i32 (...) @pop()
%24 = mul nsw i32 %22, %23
%25 = call i32 @push(i32 %24)
br label %56
26: ; preds = %10
%27 = call i32 (...) @pop()
store i32 %27, i32* %4
%28 = call i32 (...) @pop()
%29 = load i32, i32* %4
%30 = sub nsw i32 %28, %29
%31 = call i32 @push(i32 %30)
br label %56
32: ; preds = %10
%33 = call i32 (...) @pop()
store i32 %33, i32* %4
%34 = load i32, i32* %4
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %32
%37 = call i32 (...) @pop()
%38 = load i32, i32* %4
%39 = sdiv i32 %37, %38
%40 = call i32 @push(i32 %39)
br label %43
41: ; preds = %32
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %43
43: ; preds = %41, %36
br label %56
44: ; preds = %10
%45 = call i32 (...) @pop()
%46 = call i32 @push(i32 %45)
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %46)
br label %56
48: ; preds = %10
%49 = call i32 (...) @clear()
br label %56
50: ; preds = %10
%51 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %51)
br label %56
53: ; preds = %10
%54 = load i32, i32* %2
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %54)
br label %56
56: ; preds = %53, %50, %48, %44, %43, %26, %21, %16, %12
br label %5
57: ; preds = %5
ret i32 0
}

LLVM IR (-O2):
@EOF = global i32 0
@.str.1 = [6 x i8] c"\0A%d\0A\0A\00"
@.str.2 = [23 x i8] c"%.20s ... is too long\0A\00"
@.str.3 = [20 x i8] c"unknown command %c\0A\00"
@str = [20 x i8] c"zero divisor popped\00"
define i32 @main() {
%1 = alloca [20 x i8]
%2 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%3 = call i32 @getop(i8* %2, i32 20)
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %49, label %6
6: ; preds = %0, %45
%7 = phi i32 [ %46, %45 ], [ %3, %0 ]
switch i32 %7, label %43 [
i32 48, label %8
i32 43, label %11
i32 42, label %16
i32 45, label %21
i32 47, label %26
i32 61, label %35
i32 99, label %39
i32 57, label %41
]
8: ; preds = %6
%9 = call i32 @atoi(i8* %2)
%10 = call i32 @push(i32 %9)
br label %45
11: ; preds = %6
%12 = call i32 (...) @pop()
%13 = call i32 (...) @pop()
%14 = add nsw i32 %13, %12
%15 = call i32 @push(i32 %14)
br label %45
16: ; preds = %6
%17 = call i32 (...) @pop()
%18 = call i32 (...) @pop()
%19 = mul nsw i32 %18, %17
%20 = call i32 @push(i32 %19)
br label %45
21: ; preds = %6
%22 = call i32 (...) @pop()
%23 = call i32 (...) @pop()
%24 = sub nsw i32 %23, %22
%25 = call i32 @push(i32 %24)
br label %45
26: ; preds = %6
%27 = call i32 (...) @pop()
%28 = icmp eq i32 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %26
%30 = call i32 (...) @pop()
%31 = sdiv i32 %30, %27
%32 = call i32 @push(i32 %31)
br label %45
33: ; preds = %26
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %45
35: ; preds = %6
%36 = call i32 (...) @pop()
%37 = call i32 @push(i32 %36)
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %37)
br label %45
39: ; preds = %6
%40 = call i32 (...) @clear()
br label %45
41: ; preds = %6
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %2)
br label %45
43: ; preds = %6
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %7)
br label %45
45: ; preds = %29, %33, %43, %41, %39, %35, %21, %16, %11, %8
%46 = call i32 @getop(i8* %2, i32 20)
%47 = load i32, i32* @EOF
%48 = icmp eq i32 %46, %47
br i1 %48, label %49, label %6
49: ; preds = %45, %0
ret i32 0
}