#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 getop();
double pop();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ push(double);
int /*<<< orphan*/ scanf(char *, double *);
int main(int argc, char **argv) {
  int type;
  double op2, val;
  while ((type = getop()) != EOF) {
    switch (type) {
    case '0':
      scanf("%lf", &val);
      push(val);
      break;
    case '+':
      push(pop() + pop());
      break;
    case '*':
      push(pop() * pop());
      break;
    case '-':
      op2 = pop();
      push(pop() - op2);
      break;
    case '/':
      op2 = pop();
      if (op2 != 0.0) {
        push(pop() / op2);
      } else {
        printf("Error: divided by zeros\n");
      }
      break;
    case '\n':
      printf("\t%.8g\n", pop());
      break;
    default:
      printf("Error: unknown command \n");
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <getop@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e71(%rip),%rcx
cmp    (%rcx),%eax
je     12ba <main+0x16a>
mov    -0x14(%rbp),%eax
add    $0xfffffff6,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x26,%eax
ja     12a7 <main+0x157>
mov    -0x30(%rbp),%rax
lea    0xe61(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xeed(%rip),%rdi
lea    -0x28(%rbp),%rsi
call   1060 <scanf@plt>
movsd  -0x28(%rbp),%xmm0
call   1070 <push@plt>
jmp    12b5 <main+0x165>
mov    $0x0,%al
call   1040 <pop@plt>
movsd  %xmm0,-0x38(%rbp)
mov    $0x0,%al
call   1040 <pop@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
addsd  %xmm1,%xmm0
call   1070 <push@plt>
jmp    12b5 <main+0x165>
mov    $0x0,%al
call   1040 <pop@plt>
movsd  %xmm0,-0x40(%rbp)
mov    $0x0,%al
call   1040 <pop@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm1,%xmm0
call   1070 <push@plt>
jmp    12b5 <main+0x165>
mov    $0x0,%al
call   1040 <pop@plt>
movsd  %xmm0,-0x20(%rbp)
mov    $0x0,%al
call   1040 <pop@plt>
subsd  -0x20(%rbp),%xmm0
call   1070 <push@plt>
jmp    12b5 <main+0x165>
mov    $0x0,%al
call   1040 <pop@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1264 <main+0x114>
jp     1264 <main+0x114>
jmp    127a <main+0x12a>
mov    $0x0,%al
call   1040 <pop@plt>
divsd  -0x20(%rbp),%xmm0
call   1070 <push@plt>
jmp    1288 <main+0x138>
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12b5 <main+0x165>
mov    $0x0,%al
call   1040 <pop@plt>
lea    0xe1e(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    12b5 <main+0x165>
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1166 <main+0x16>
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
xor    %eax,%eax
call   1060 <getop@plt>
mov    0x2e6c(%rip),%rbp
cmp    0x0(%rbp),%eax
jne    1192 <main+0x32>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xf2e(%rip),%r14
lea    0xe68(%rip),%r15
lea    0xf01(%rip),%r12
lea    0xef6(%rip),%r13
lea    0x10(%rsp),%rbx
jmp    11dc <main+0x7c>
xor    %eax,%eax
call   1050 <pop@plt>
mov    %r12,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <getop@plt>
cmp    0x0(%rbp),%eax
je     1181 <main+0x21>
add    $0xfffffff6,%eax
cmp    $0x26,%eax
ja     120e <main+0xae>
movslq (%r15,%rax,4),%rax
add    %r15,%rax
jmp    *%rax
xor    %eax,%eax
call   1050 <pop@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1050 <pop@plt>
mulsd  0x8(%rsp),%xmm0
call   1080 <push@plt>
jmp    11d0 <main+0x70>
mov    %r14,%rdi
jmp    12ad <main+0x14d>
xor    %eax,%eax
call   1050 <pop@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1050 <pop@plt>
addsd  0x8(%rsp),%xmm0
call   1080 <push@plt>
jmp    11d0 <main+0x70>
xor    %eax,%eax
call   1050 <pop@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1050 <pop@plt>
subsd  0x8(%rsp),%xmm0
call   1080 <push@plt>
jmp    11d0 <main+0x70>
xor    %eax,%eax
call   1050 <pop@plt>
ucomisd 0xd96(%rip),%xmm0
jne    126e <main+0x10e>
jnp    12a6 <main+0x146>
xor    %eax,%eax
movsd  %xmm0,0x8(%rsp)
call   1050 <pop@plt>
divsd  0x8(%rsp),%xmm0
call   1080 <push@plt>
jmp    11d0 <main+0x70>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
movsd  0x10(%rsp),%xmm0
call   1080 <push@plt>
jmp    11d0 <main+0x70>
lea    0xe02(%rip),%rdi
call   1030 <puts@plt>
jmp    11d0 <main+0x70>

LLVM IR (-O0):
@EOF = global i32 0
@.str = [4 x i8] c"%lf\00"
@.str.1 = [25 x i8] c"Error: divided by zeros\0A\00"
@.str.2 = [7 x i8] c"\09%.8g\0A\00"
@.str.3 = [25 x i8] c"Error: unknown command \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca double
%8 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %9
9: ; preds = %52, %2
%10 = call i32 (...) @getop()
store i32 %10, i32* %6
%11 = load i32, i32* @EOF
%12 = icmp ne i32 %10, %11
br i1 %12, label %13, label %53
13: ; preds = %9
%14 = load i32, i32* %6
switch i32 %14, label %50 [
i32 48, label %15
i32 43, label %19
i32 42, label %24
i32 45, label %29
i32 47, label %35
i32 10, label %47
]
15: ; preds = %13
%16 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double* %8)
%17 = load double, double* %8
%18 = call i32 @push(double %17)
br label %52
19: ; preds = %13
%20 = call double (...) @pop()
%21 = call double (...) @pop()
%22 = fadd double %20, %21
%23 = call i32 @push(double %22)
br label %52
24: ; preds = %13
%25 = call double (...) @pop()
%26 = call double (...) @pop()
%27 = fmul double %25, %26
%28 = call i32 @push(double %27)
br label %52
29: ; preds = %13
%30 = call double (...) @pop()
store double %30, double* %7
%31 = call double (...) @pop()
%32 = load double, double* %7
%33 = fsub double %31, %32
%34 = call i32 @push(double %33)
br label %52
35: ; preds = %13
%36 = call double (...) @pop()
store double %36, double* %7
%37 = load double, double* %7
%38 = fcmp une double %37, 0.000000e+00
br i1 %38, label %39, label %44
39: ; preds = %35
%40 = call double (...) @pop()
%41 = load double, double* %7
%42 = fdiv double %40, %41
%43 = call i32 @push(double %42)
br label %46
44: ; preds = %35
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %46
46: ; preds = %44, %39
br label %52
47: ; preds = %13
%48 = call double (...) @pop()
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %48)
br label %52
50: ; preds = %13
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %52
52: ; preds = %50, %47, %46, %29, %24, %19, %15
br label %9
53: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@EOF = global i32 0
@.str = [4 x i8] c"%lf\00"
@.str.2 = [7 x i8] c"\09%.8g\0A\00"
@str = [24 x i8] c"Error: divided by zeros\00"
@str.4 = [24 x i8] c"Error: unknown command \00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca double
%4 = bitcast double* %3 to i8*
%5 = call i32 (...) @getop()
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %5, %6
br i1 %7, label %47, label %8
8: ; preds = %2, %43
%9 = phi i32 [ %44, %43 ], [ %5, %2 ]
switch i32 %9, label %41 [
i32 48, label %10
i32 43, label %14
i32 42, label %19
i32 45, label %24
i32 47, label %29
i32 10, label %38
]
10: ; preds = %8
%11 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), double* %3)
%12 = load double, double* %3
%13 = call i32 @push(double %12)
br label %43
14: ; preds = %8
%15 = call double (...) @pop()
%16 = call double (...) @pop()
%17 = fadd double %15, %16
%18 = call i32 @push(double %17)
br label %43
19: ; preds = %8
%20 = call double (...) @pop()
%21 = call double (...) @pop()
%22 = fmul double %20, %21
%23 = call i32 @push(double %22)
br label %43
24: ; preds = %8
%25 = call double (...) @pop()
%26 = call double (...) @pop()
%27 = fsub double %26, %25
%28 = call i32 @push(double %27)
br label %43
29: ; preds = %8
%30 = call double (...) @pop()
%31 = fcmp une double %30, 0.000000e+00
br i1 %31, label %32, label %36
32: ; preds = %29
%33 = call double (...) @pop()
%34 = fdiv double %33, %30
%35 = call i32 @push(double %34)
br label %43
36: ; preds = %29
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %43
38: ; preds = %8
%39 = call double (...) @pop()
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %39)
br label %43
41: ; preds = %8
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.4, i64 0, i64 0))
br label %43
43: ; preds = %32, %36, %41, %38, %24, %19, %14, %10
%44 = call i32 (...) @getop()
%45 = load i32, i32* @EOF
%46 = icmp eq i32 %44, %45
br i1 %46, label %47, label %8
47: ; preds = %43, %2
ret i32 0
}