#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;
double atof(char *);
int getop(char *);
double getvar(char *);
double pop();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ push(double);
int /*<<< orphan*/ putvar(char *, double);
int /*<<< orphan*/ strlen(char *);
int main() {
  double result = 0.0;
  int type;
  double op2;
  char s[100];
  while ((type = getop(s)) != EOF) {
    switch (type) {
    case '0':
      push(atof(s));
      break;
    case 'a':
      if (s[strlen(s) - 2] == '\n') {
        s[strlen(s) - 2] = '\0';
        putvar(s, pop());
      } else {
        push(getvar(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.0) {
        push(pop() / op2);
      } else {
        printf("error: zero divisor\n");
      }
      break;
    case '%':
      op2 = pop();
      if (op2 != 0.0) {
        push((int)pop() % (int)op2);
      } else {
        printf("error: zero divsor\n");
      }
      break;
    case '~':
      push(result);
      break;
    case '\n':
      result = pop();
      printf("\t%.8g\n", result);
      break;
    default:
      printf("error: unknown command %s\n", s);
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
lea    -0x90(%rbp),%rdi
call   1080 <getop@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e38(%rip),%rcx
cmp    (%rcx),%eax
je     1478 <main+0x2f8>
mov    -0x14(%rbp),%eax
mov    %eax,-0x94(%rbp)
sub    $0xa,%eax
je     143a <main+0x2ba>
jmp    11cf <main+0x4f>
mov    -0x94(%rbp),%eax
sub    $0x25,%eax
je     13ce <main+0x24e>
jmp    11e3 <main+0x63>
mov    -0x94(%rbp),%eax
sub    $0x2a,%eax
je     132b <main+0x1ab>
jmp    11f7 <main+0x77>
mov    -0x94(%rbp),%eax
sub    $0x2b,%eax
je     12fc <main+0x17c>
jmp    120b <main+0x8b>
mov    -0x94(%rbp),%eax
sub    $0x2d,%eax
je     135a <main+0x1da>
jmp    121f <main+0x9f>
mov    -0x94(%rbp),%eax
sub    $0x2f,%eax
je     137c <main+0x1fc>
jmp    1233 <main+0xb3>
mov    -0x94(%rbp),%eax
sub    $0x30,%eax
je     126f <main+0xef>
jmp    1247 <main+0xc7>
mov    -0x94(%rbp),%eax
sub    $0x61,%eax
je     1285 <main+0x105>
jmp    125b <main+0xdb>
mov    -0x94(%rbp),%eax
sub    $0x7e,%eax
je     142b <main+0x2ab>
jmp    145e <main+0x2de>
lea    -0x90(%rbp),%rdi
call   1040 <atof@plt>
call   1090 <push@plt>
jmp    1473 <main+0x2f3>
lea    -0x90(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x2,%eax
cltq
movsbl -0x90(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    12e6 <main+0x166>
lea    -0x90(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x2,%eax
cltq
movb   $0x0,-0x90(%rbp,%rax,1)
lea    -0x90(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    $0x0,%al
call   1070 <pop@plt>
mov    -0xa0(%rbp),%rdi
call   10a0 <putvar@plt>
jmp    12f7 <main+0x177>
lea    -0x90(%rbp),%rdi
call   1030 <getvar@plt>
call   1090 <push@plt>
jmp    1473 <main+0x2f3>
mov    $0x0,%al
call   1070 <pop@plt>
movsd  %xmm0,-0xa8(%rbp)
ff
mov    $0x0,%al
call   1070 <pop@plt>
movaps %xmm0,%xmm1
movsd  -0xa8(%rbp),%xmm0
ff
addsd  %xmm1,%xmm0
call   1090 <push@plt>
jmp    1473 <main+0x2f3>
mov    $0x0,%al
call   1070 <pop@plt>
movsd  %xmm0,-0xb0(%rbp)
ff
mov    $0x0,%al
call   1070 <pop@plt>
movaps %xmm0,%xmm1
movsd  -0xb0(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
call   1090 <push@plt>
jmp    1473 <main+0x2f3>
mov    $0x0,%al
call   1070 <pop@plt>
movsd  %xmm0,-0x20(%rbp)
mov    $0x0,%al
call   1070 <pop@plt>
subsd  -0x20(%rbp),%xmm0
call   1090 <push@plt>
jmp    1473 <main+0x2f3>
mov    $0x0,%al
call   1070 <pop@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    13a5 <main+0x225>
jp     13a5 <main+0x225>
jmp    13bb <main+0x23b>
mov    $0x0,%al
call   1070 <pop@plt>
divsd  -0x20(%rbp),%xmm0
call   1090 <push@plt>
jmp    13c9 <main+0x249>
lea    0xc3e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1473 <main+0x2f3>
mov    $0x0,%al
call   1070 <pop@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    13f7 <main+0x277>
jp     13f7 <main+0x277>
jmp    1418 <main+0x298>
mov    $0x0,%al
call   1070 <pop@plt>
cvttsd2si %xmm0,%eax
cvttsd2si -0x20(%rbp),%ecx
cltd
idiv   %ecx
cvtsi2sd %edx,%xmm0
call   1090 <push@plt>
jmp    1426 <main+0x2a6>
lea    0xbf6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1473 <main+0x2f3>
movsd  -0x10(%rbp),%xmm0
call   1090 <push@plt>
jmp    1473 <main+0x2f3>
mov    $0x0,%al
call   1070 <pop@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
lea    0xbd7(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
jmp    1473 <main+0x2f3>
lea    -0x90(%rbp),%rsi
lea    0xbc4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    119a <main+0x1a>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1090 <getop@plt>
mov    0x2e36(%rip),%rbp
cmp    0x0(%rbp),%eax
jne    11c8 <main+0x38>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xf2d(%rip),%r14
lea    0xf2d(%rip),%r15
lea    0xe2b(%rip),%r12
lea    0xf4d(%rip),%r13
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
jmp    120d <main+0x7d>
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
nopl   (%rax)
mov    %rbx,%rdi
call   1090 <getop@plt>
cmp    0x0(%rbp),%eax
je     11b7 <main+0x27>
lea    -0x25(%rax),%ecx
cmp    $0x3c,%ecx
ja     1260 <main+0xd0>
movslq (%r12,%rcx,4),%rax
add    %r12,%rax
jmp    *%rax
xor    %eax,%eax
call   1080 <pop@plt>
ucomisd 0xdd3(%rip),%xmm0
jne    1235 <main+0xa5>
jnp    1387 <main+0x1f7>
xor    %eax,%eax
movsd  %xmm0,(%rsp)
call   1080 <pop@plt>
cvttsd2si %xmm0,%eax
cvttsd2si (%rsp),%ecx
cltd
idiv   %ecx
xorps  %xmm0,%xmm0
cvtsi2sd %edx,%xmm0
call   10a0 <push@plt>
jmp    1200 <main+0x70>
nopl   0x0(%rax,%rax,1)
cmp    $0xa,%eax
je     1359 <main+0x1c9>
cmp    $0x7e,%eax
jne    11f0 <main+0x60>
movsd  0x8(%rsp),%xmm0
call   10a0 <push@plt>
jmp    1200 <main+0x70>
xor    %eax,%eax
call   1080 <pop@plt>
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1080 <pop@plt>
mulsd  (%rsp),%xmm0
call   10a0 <push@plt>
jmp    1200 <main+0x70>
xor    %eax,%eax
call   1080 <pop@plt>
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1080 <pop@plt>
addsd  (%rsp),%xmm0
call   10a0 <push@plt>
jmp    1200 <main+0x70>
xor    %eax,%eax
call   1080 <pop@plt>
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1080 <pop@plt>
subsd  (%rsp),%xmm0
call   10a0 <push@plt>
jmp    1200 <main+0x70>
xor    %eax,%eax
call   1080 <pop@plt>
ucomisd 0xd10(%rip),%xmm0
jne    12f8 <main+0x168>
jnp    1398 <main+0x208>
xor    %eax,%eax
movsd  %xmm0,(%rsp)
call   1080 <pop@plt>
divsd  (%rsp),%xmm0
call   10a0 <push@plt>
jmp    1200 <main+0x70>
mov    %rbx,%rdi
call   1050 <atof@plt>
call   10a0 <push@plt>
jmp    1200 <main+0x70>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cltq
cmpb   $0xa,-0x2(%rax,%rbx,1)
jne    1375 <main+0x1e5>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cltq
movb   $0x0,-0x2(%rax,%rbx,1)
xor    %eax,%eax
call   1080 <pop@plt>
mov    %rbx,%rdi
call   10b0 <putvar@plt>
jmp    1200 <main+0x70>
xor    %eax,%eax
call   1080 <pop@plt>
mov    %r14,%rdi
movsd  %xmm0,0x8(%rsp)
mov    $0x1,%al
call   1070 <printf@plt>
jmp    1200 <main+0x70>
mov    %rbx,%rdi
call   1030 <getvar@plt>
call   10a0 <push@plt>
jmp    1200 <main+0x70>
lea    0xd90(%rip),%rdi
call   1040 <puts@plt>
jmp    1200 <main+0x70>
mov    %r13,%rdi
call   1040 <puts@plt>
jmp    1200 <main+0x70>

LLVM IR (-O0):
@EOF = global i32 0
@.str = [21 x i8] c"error: zero divisor\0A\00"
@.str.1 = [20 x i8] c"error: zero divsor\0A\00"
@.str.2 = [7 x i8] c"\09%.8g\0A\00"
@.str.3 = [27 x i8] c"error: unknown command %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca i32
%4 = alloca double
%5 = alloca [100 x i8]
store i32 0, i32* %1
store double 0.000000e+00, double* %2
br label %6
6: ; preds = %93, %0
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%8 = call i32 @getop(i8* %7)
store i32 %8, i32* %3
%9 = load i32, i32* @EOF
%10 = icmp ne i32 %8, %9
br i1 %10, label %11, label %94
11: ; preds = %6
%12 = load i32, i32* %3
switch i32 %12, label %90 [
i32 48, label %13
i32 97, label %17
i32 43, label %40
i32 42, label %45
i32 45, label %50
i32 47, label %56
i32 37, label %68
i32 126, label %83
i32 10, label %86
]
13: ; preds = %11
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%15 = call double @atof(i8* %14)
%16 = call i32 @push(double %15)
br label %93
17: ; preds = %11
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%19 = call i32 @strlen(i8* %18)
%20 = sub nsw i32 %19, 2
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 10
br i1 %25, label %26, label %35
26: ; preds = %17
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%28 = call i32 @strlen(i8* %27)
%29 = sub nsw i32 %28, 2
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %30
store i8 0, i8* %31
%32 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%33 = call double (...) @pop()
%34 = call i32 @putvar(i8* %32, double %33)
br label %39
35: ; preds = %17
%36 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%37 = call double @getvar(i8* %36)
%38 = call i32 @push(double %37)
br label %39
39: ; preds = %35, %26
br label %93
40: ; preds = %11
%41 = call double (...) @pop()
%42 = call double (...) @pop()
%43 = fadd double %41, %42
%44 = call i32 @push(double %43)
br label %93
45: ; preds = %11
%46 = call double (...) @pop()
%47 = call double (...) @pop()
%48 = fmul double %46, %47
%49 = call i32 @push(double %48)
br label %93
50: ; preds = %11
%51 = call double (...) @pop()
store double %51, double* %4
%52 = call double (...) @pop()
%53 = load double, double* %4
%54 = fsub double %52, %53
%55 = call i32 @push(double %54)
br label %93
56: ; preds = %11
%57 = call double (...) @pop()
store double %57, double* %4
%58 = load double, double* %4
%59 = fcmp une double %58, 0.000000e+00
br i1 %59, label %60, label %65
60: ; preds = %56
%61 = call double (...) @pop()
%62 = load double, double* %4
%63 = fdiv double %61, %62
%64 = call i32 @push(double %63)
br label %67
65: ; preds = %56
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %67
67: ; preds = %65, %60
br label %93
68: ; preds = %11
%69 = call double (...) @pop()
store double %69, double* %4
%70 = load double, double* %4
%71 = fcmp une double %70, 0.000000e+00
br i1 %71, label %72, label %80
72: ; preds = %68
%73 = call double (...) @pop()
%74 = fptosi double %73 to i32
%75 = load double, double* %4
%76 = fptosi double %75 to i32
%77 = srem i32 %74, %76
%78 = sitofp i32 %77 to double
%79 = call i32 @push(double %78)
br label %82
80: ; preds = %68
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %82
82: ; preds = %80, %72
br label %93
83: ; preds = %11
%84 = load double, double* %2
%85 = call i32 @push(double %84)
br label %93
86: ; preds = %11
%87 = call double (...) @pop()
store double %87, double* %2
%88 = load double, double* %2
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %88)
br label %93
90: ; preds = %11
%91 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %91)
br label %93
93: ; preds = %90, %86, %83, %82, %67, %50, %45, %40, %39, %13
br label %6
94: ; preds = %6
ret i32 0
}

LLVM IR (-O2):
@EOF = global i32 0
@.str.2 = [7 x i8] c"\09%.8g\0A\00"
@.str.3 = [27 x i8] c"error: unknown command %s\0A\00"
@str = [19 x i8] c"error: zero divsor\00"
@str.4 = [20 x i8] c"error: zero divisor\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = call i32 @getop(i8* %2)
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %77, label %6
6: ; preds = %0, %72
%7 = phi i32 [ %74, %72 ], [ %3, %0 ]
%8 = phi double [ %73, %72 ], [ 0.000000e+00, %0 ]
switch i32 %7, label %70 [
i32 48, label %9
i32 97, label %12
i32 43, label %29
i32 42, label %34
i32 45, label %39
i32 47, label %44
i32 37, label %53
i32 126, label %65
i32 10, label %67
]
9: ; preds = %6
%10 = call double @atof(i8* %2)
%11 = call i32 @push(double %10)
br label %72
12: ; preds = %6
%13 = call i32 @strlen(i8* %2)
%14 = add nsw i32 %13, -2
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 10
br i1 %18, label %19, label %26
19: ; preds = %12
%20 = call i32 @strlen(i8* %2)
%21 = add nsw i32 %20, -2
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %22
store i8 0, i8* %23
%24 = call double (...) @pop()
%25 = call i32 @putvar(i8* %2, double %24)
br label %72
26: ; preds = %12
%27 = call double @getvar(i8* %2)
%28 = call i32 @push(double %27)
br label %72
29: ; preds = %6
%30 = call double (...) @pop()
%31 = call double (...) @pop()
%32 = fadd double %30, %31
%33 = call i32 @push(double %32)
br label %72
34: ; preds = %6
%35 = call double (...) @pop()
%36 = call double (...) @pop()
%37 = fmul double %35, %36
%38 = call i32 @push(double %37)
br label %72
39: ; preds = %6
%40 = call double (...) @pop()
%41 = call double (...) @pop()
%42 = fsub double %41, %40
%43 = call i32 @push(double %42)
br label %72
44: ; preds = %6
%45 = call double (...) @pop()
%46 = fcmp une double %45, 0.000000e+00
br i1 %46, label %47, label %51
47: ; preds = %44
%48 = call double (...) @pop()
%49 = fdiv double %48, %45
%50 = call i32 @push(double %49)
br label %72
51: ; preds = %44
%52 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.4, i64 0, i64 0))
br label %72
53: ; preds = %6
%54 = call double (...) @pop()
%55 = fcmp une double %54, 0.000000e+00
br i1 %55, label %56, label %63
56: ; preds = %53
%57 = call double (...) @pop()
%58 = fptosi double %57 to i32
%59 = fptosi double %54 to i32
%60 = srem i32 %58, %59
%61 = sitofp i32 %60 to double
%62 = call i32 @push(double %61)
br label %72
63: ; preds = %53
%64 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %72
65: ; preds = %6
%66 = call i32 @push(double %8)
br label %72
67: ; preds = %6
%68 = call double (...) @pop()
%69 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %68)
br label %72
70: ; preds = %6
%71 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %2)
br label %72
72: ; preds = %56, %63, %47, %51, %19, %26, %70, %67, %65, %39, %34, %29, %9
%73 = phi double [ %8, %70 ], [ %68, %67 ], [ %8, %65 ], [ %8, %56 ], [ %8, %63 ], [ %8, %47 ], [ %8, %51 ], [ %8, %39 ], [ %8, %34 ], [ %8, %29 ], [ %8, %19 ], [ %8, %26 ], [ %8, %9 ]
%74 = call i32 @getop(i8* %2)
%75 = load i32, i32* @EOF
%76 = icmp eq i32 %74, %75
br i1 %76, label %77, label %6
77: ; preds = %72, %0
ret i32 0
}