#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 *);
double fmod(double, double);
int getop(char *);
double pop();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ push(double);
int main(void) {
  int type;
  double op2;
  char s[100];
  int adv = 0;
  while ((type = getop(s)) != EOF) {
    switch (type) {
    case '0':
      push(atof(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(fmod(pop(), op2));
      else
        printf("error: zero divisor\n");
      break;
    case '\n':
      if (!adv)
        printf("\t%.8g\n", pop());
      adv = 0;
      break;
    case ' ':
      adv = 1;
      break;
    default:
      printf("error: unknown command %s\n", s);
      printf("use 'h' to get help\n");
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x84(%rbp)
lea    -0x80(%rbp),%rdi
call   1070 <getop@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e59(%rip),%rcx
cmp    (%rcx),%eax
je     1367 <main+0x207>
mov    -0x8(%rbp),%eax
add    $0xfffffff6,%eax
mov    %eax,%ecx
mov    %rcx,-0x90(%rbp)
sub    $0x26,%eax
ja     1342 <main+0x1e2>
mov    -0x90(%rbp),%rax
lea    0xe43(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    -0x80(%rbp),%rdi
call   1030 <atof@plt>
call   1080 <push@plt>
jmp    1362 <main+0x202>
mov    $0x0,%al
call   1060 <pop@plt>
movsd  %xmm0,-0x98(%rbp)
ff
mov    $0x0,%al
call   1060 <pop@plt>
movaps %xmm0,%xmm1
movsd  -0x98(%rbp),%xmm0
ff
addsd  %xmm1,%xmm0
call   1080 <push@plt>
jmp    1362 <main+0x202>
mov    $0x0,%al
call   1060 <pop@plt>
movsd  %xmm0,-0xa0(%rbp)
ff
mov    $0x0,%al
call   1060 <pop@plt>
movaps %xmm0,%xmm1
movsd  -0xa0(%rbp),%xmm0
ff
mulsd  %xmm1,%xmm0
call   1080 <push@plt>
jmp    1362 <main+0x202>
mov    $0x0,%al
call   1060 <pop@plt>
movsd  %xmm0,-0x10(%rbp)
mov    $0x0,%al
call   1060 <pop@plt>
subsd  -0x10(%rbp),%xmm0
call   1080 <push@plt>
jmp    1362 <main+0x202>
mov    $0x0,%al
call   1060 <pop@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1282 <main+0x122>
jp     1282 <main+0x122>
jmp    1298 <main+0x138>
mov    $0x0,%al
call   1060 <pop@plt>
divsd  -0x10(%rbp),%xmm0
call   1080 <push@plt>
jmp    12a6 <main+0x146>
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1362 <main+0x202>
mov    $0x0,%al
call   1060 <pop@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    12d4 <main+0x174>
jp     12d4 <main+0x174>
jmp    12ef <main+0x18f>
mov    $0x0,%al
call   1060 <pop@plt>
movsd  -0x10(%rbp),%xmm1
call   1050 <fmod@plt>
call   1080 <push@plt>
jmp    12fd <main+0x19d>
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1362 <main+0x202>
cmpl   $0x0,-0x84(%rbp)
jne    1324 <main+0x1c4>
mov    $0x0,%al
call   1060 <pop@plt>
lea    0xd94(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movl   $0x0,-0x84(%rbp)
jmp    1362 <main+0x202>
movl   $0x1,-0x84(%rbp)
jmp    1362 <main+0x202>
lea    -0x80(%rbp),%rsi
lea    0xd6b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd78(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    117c <main+0x1c>
xor    %eax,%eax
add    $0xa0,%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),%rdi
call   1080 <getop@plt>
mov    0x2e59(%rip),%rbp
cmp    0x0(%rbp),%eax
jne    11a5 <main+0x35>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x10(%rsp),%rbx
lea    0xf29(%rip),%r15
lea    0xe50(%rip),%r12
xor    %r14d,%r14d
jmp    11f8 <main+0x88>
xor    %eax,%eax
call   1070 <pop@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1070 <pop@plt>
subsd  0x8(%rsp),%xmm0
nopw   0x0(%rax,%rax,1)
call   1090 <push@plt>
mov    %r14d,%r13d
mov    %rbx,%rdi
call   1080 <getop@plt>
mov    %r13d,%r14d
cmp    0x0(%rbp),%eax
je     1194 <main+0x24>
add    $0xfffffff6,%eax
cmp    $0x26,%eax
ja     1231 <main+0xc1>
mov    $0x1,%r13d
movslq (%r12,%rax,4),%rax
add    %r12,%rax
jmp    *%rax
xor    %r13d,%r13d
test   %r14d,%r14d
jne    11e8 <main+0x78>
xor    %r13d,%r13d
xor    %eax,%eax
call   1070 <pop@plt>
lea    0xe7c(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
jmp    11e8 <main+0x78>
lea    0xe73(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
jmp    12fb <main+0x18b>
xor    %eax,%eax
call   1070 <pop@plt>
ucomisd 0xda7(%rip),%xmm0
jne    1261 <main+0xf1>
jnp    12f4 <main+0x184>
xor    %eax,%eax
movsd  %xmm0,0x8(%rsp)
call   1070 <pop@plt>
movsd  0x8(%rsp),%xmm1
call   1060 <fmod@plt>
jmp    11e0 <main+0x70>
xor    %eax,%eax
call   1070 <pop@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1070 <pop@plt>
mulsd  0x8(%rsp),%xmm0
jmp    11e0 <main+0x70>
xor    %eax,%eax
call   1070 <pop@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1070 <pop@plt>
addsd  0x8(%rsp),%xmm0
jmp    11e0 <main+0x70>
xor    %eax,%eax
call   1070 <pop@plt>
ucomisd 0xd35(%rip),%xmm0
jne    12cf <main+0x15f>
jnp    12f4 <main+0x184>
xor    %eax,%eax
movsd  %xmm0,0x8(%rsp)
call   1070 <pop@plt>
divsd  0x8(%rsp),%xmm0
jmp    11e0 <main+0x70>
mov    %rbx,%rdi
call   1040 <atof@plt>
jmp    11e0 <main+0x70>
lea    0xdcb(%rip),%rdi
call   1030 <puts@plt>
jmp    11e5 <main+0x75>

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

LLVM IR (-O2):
@EOF = global i32 0
@.str.1 = [7 x i8] c"\09%.8g\0A\00"
@.str.2 = [27 x i8] c"error: unknown command %s\0A\00"
@str.4 = [20 x i8] c"error: zero divisor\00"
@str.5 = [20 x i8] c"use 'h' to get help\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 %58, label %6
6: ; preds = %0, %53
%7 = phi i32 [ %55, %53 ], [ %3, %0 ]
%8 = phi i32 [ %54, %53 ], [ 0, %0 ]
switch i32 %7, label %50 [
i32 48, label %9
i32 43, label %12
i32 42, label %17
i32 45, label %22
i32 47, label %27
i32 37, label %36
i32 10, label %45
i32 32, label %53
]
9: ; preds = %6
%10 = call double @atof(i8* %2)
%11 = call i32 @push(double %10)
br label %53
12: ; preds = %6
%13 = call double (...) @pop()
%14 = call double (...) @pop()
%15 = fadd double %13, %14
%16 = call i32 @push(double %15)
br label %53
17: ; preds = %6
%18 = call double (...) @pop()
%19 = call double (...) @pop()
%20 = fmul double %18, %19
%21 = call i32 @push(double %20)
br label %53
22: ; preds = %6
%23 = call double (...) @pop()
%24 = call double (...) @pop()
%25 = fsub double %24, %23
%26 = call i32 @push(double %25)
br label %53
27: ; preds = %6
%28 = call double (...) @pop()
%29 = fcmp une double %28, 0.000000e+00
br i1 %29, label %30, label %34
30: ; preds = %27
%31 = call double (...) @pop()
%32 = fdiv double %31, %28
%33 = call i32 @push(double %32)
br label %53
34: ; preds = %27
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.4, i64 0, i64 0))
br label %53
36: ; preds = %6
%37 = call double (...) @pop()
%38 = fcmp une double %37, 0.000000e+00
br i1 %38, label %39, label %43
39: ; preds = %36
%40 = call double (...) @pop()
%41 = call double @fmod(double %40, double %37)
%42 = call i32 @push(double %41)
br label %53
43: ; preds = %36
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.4, i64 0, i64 0))
br label %53
45: ; preds = %6
%46 = icmp eq i32 %8, 0
br i1 %46, label %47, label %53
47: ; preds = %45
%48 = call double (...) @pop()
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), double %48)
br label %53
50: ; preds = %6
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%52 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.5, i64 0, i64 0))
br label %53
53: ; preds = %6, %45, %47, %39, %43, %30, %34, %50, %22, %17, %12, %9
%54 = phi i32 [ %8, %50 ], [ %8, %39 ], [ %8, %43 ], [ %8, %30 ], [ %8, %34 ], [ %8, %22 ], [ %8, %17 ], [ %8, %12 ], [ %8, %9 ], [ 0, %47 ], [ 0, %45 ], [ 1, %6 ]
%55 = call i32 @getop(i8* %2)
%56 = load i32, i32* @EOF
%57 = icmp eq i32 %55, %56
br i1 %57, label %58, label %6
58: ; preds = %53, %0
ret i32 0
}