#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 */
double atof(char *);
char getop(char *);
double pop();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ push(double);
int main(int argc, char *argv[]) {
  double op2;
  char ch;
  while (--argc > 0) {
    ch = getop(*++argv);
    switch (ch) {
    case 'n':
      push(atof(*argv));
      break;
    case '+':
      push(pop() + pop());
      break;
    case '-':
      op2 = pop();
      push(pop() - op2);
      break;
    case '*':
      push(pop() * pop());
      break;
    case '/':
      op2 = pop();
      push(pop() / op2);
      break;
    default:
      printf("Error: unknown operator\n");
      break;
    }
  }
  printf("final result is: %g\n", pop());
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    12ab <main+0x15b>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
call   1060 <getop@plt>
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0x2a,%eax
je     124d <main+0xfd>
jmp    11a8 <main+0x58>
mov    -0x20(%rbp),%eax
sub    $0x2b,%eax
je     1202 <main+0xb2>
jmp    11b9 <main+0x69>
mov    -0x20(%rbp),%eax
sub    $0x2d,%eax
je     122b <main+0xdb>
jmp    11ca <main+0x7a>
mov    -0x20(%rbp),%eax
sub    $0x2f,%eax
je     1276 <main+0x126>
jmp    11db <main+0x8b>
mov    -0x20(%rbp),%eax
sub    $0x6e,%eax
jne    1298 <main+0x148>
jmp    11ec <main+0x9c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <atof@plt>
call   1070 <push@plt>
jmp    12a6 <main+0x156>
mov    $0x0,%al
call   1050 <pop@plt>
movsd  %xmm0,-0x28(%rbp)
mov    $0x0,%al
call   1050 <pop@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
addsd  %xmm1,%xmm0
call   1070 <push@plt>
jmp    12a6 <main+0x156>
mov    $0x0,%al
call   1050 <pop@plt>
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1050 <pop@plt>
subsd  -0x18(%rbp),%xmm0
call   1070 <push@plt>
jmp    12a6 <main+0x156>
mov    $0x0,%al
call   1050 <pop@plt>
movsd  %xmm0,-0x30(%rbp)
mov    $0x0,%al
call   1050 <pop@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
call   1070 <push@plt>
jmp    12a6 <main+0x156>
mov    $0x0,%al
call   1050 <pop@plt>
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1050 <pop@plt>
divsd  -0x18(%rbp),%xmm0
call   1070 <push@plt>
jmp    12a6 <main+0x156>
lea    0xd61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1166 <main+0x16>
mov    $0x0,%al
call   1050 <pop@plt>
lea    0xd60(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jl     126a <main+0x10a>
mov    %rsi,%rbx
mov    %edi,%ebp
add    $0x1,%ebp
add    $0x8,%rbx
lea    0xeaa(%rip),%r14
lea    0xe76(%rip),%r15
jmp    11b0 <main+0x50>
mov    %r14,%rdi
call   1030 <puts@plt>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0xffffffff,%ebp
add    $0x8,%rbx
cmp    $0x2,%ebp
jbe    126a <main+0x10a>
mov    (%rbx),%rdi
call   1070 <getop@plt>
movsbl %al,%eax
lea    -0x2a(%rax),%ecx
cmp    $0x5,%ecx
ja     11f0 <main+0x90>
movslq (%r15,%rcx,4),%rax
add    %r15,%rax
jmp    *%rax
xor    %eax,%eax
call   1060 <pop@plt>
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1060 <pop@plt>
mulsd  (%rsp),%xmm0
call   1080 <push@plt>
jmp    11a0 <main+0x40>
nopl   0x0(%rax,%rax,1)
cmp    $0x6e,%eax
jne    118c <main+0x2c>
mov    (%rbx),%rdi
call   1040 <atof@plt>
call   1080 <push@plt>
jmp    11a0 <main+0x40>
xor    %eax,%eax
call   1060 <pop@plt>
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1060 <pop@plt>
addsd  (%rsp),%xmm0
call   1080 <push@plt>
jmp    11a0 <main+0x40>
xor    %eax,%eax
call   1060 <pop@plt>
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1060 <pop@plt>
subsd  (%rsp),%xmm0
call   1080 <push@plt>
jmp    11a0 <main+0x40>
xor    %eax,%eax
call   1060 <pop@plt>
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1060 <pop@plt>
divsd  (%rsp),%xmm0
call   1080 <push@plt>
jmp    11a0 <main+0x40>
xor    %eax,%eax
call   1060 <pop@plt>
lea    0xda0(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Error: unknown operator\0A\00"
@.str.1 = [21 x i8] c"final result is: %g\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
%7 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %8
8: ; preds = %48, %2
%9 = load i32, i32* %4
%10 = add nsw i32 %9, -1
store i32 %10, i32* %4
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %49
12: ; preds = %8
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i32 1
store i8** %14, i8*** %5
%15 = load i8*, i8** %14
%16 = call signext i8 @getop(i8* %15)
store i8 %16, i8* %7
%17 = load i8, i8* %7
%18 = sext i8 %17 to i32
switch i32 %18, label %46 [
i32 110, label %19
i32 43, label %24
i32 45, label %29
i32 42, label %35
i32 47, label %40
]
19: ; preds = %12
%20 = load i8**, i8*** %5
%21 = load i8*, i8** %20
%22 = call double @atof(i8* %21)
%23 = call i32 @push(double %22)
br label %48
24: ; preds = %12
%25 = call double (...) @pop()
%26 = call double (...) @pop()
%27 = fadd double %25, %26
%28 = call i32 @push(double %27)
br label %48
29: ; preds = %12
%30 = call double (...) @pop()
store double %30, double* %6
%31 = call double (...) @pop()
%32 = load double, double* %6
%33 = fsub double %31, %32
%34 = call i32 @push(double %33)
br label %48
35: ; preds = %12
%36 = call double (...) @pop()
%37 = call double (...) @pop()
%38 = fmul double %36, %37
%39 = call i32 @push(double %38)
br label %48
40: ; preds = %12
%41 = call double (...) @pop()
store double %41, double* %6
%42 = call double (...) @pop()
%43 = load double, double* %6
%44 = fdiv double %42, %43
%45 = call i32 @push(double %44)
br label %48
46: ; preds = %12
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %48
48: ; preds = %46, %40, %35, %29, %24, %19
br label %8
49: ; preds = %8
%50 = call double (...) @pop()
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), double %50)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [21 x i8] c"final result is: %g\0A\00"
@str = [24 x i8] c"Error: unknown operator\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %40
4: ; preds = %2, %38
%5 = phi i32 [ %7, %38 ], [ %0, %2 ]
%6 = phi i8** [ %8, %38 ], [ %1, %2 ]
%7 = add nsw i32 %5, -1
%8 = getelementptr inbounds i8*, i8** %6, i64 1
%9 = load i8*, i8** %8
%10 = tail call signext i8 @getop(i8* %9)
%11 = sext i8 %10 to i32
switch i32 %11, label %36 [
i32 110, label %12
i32 43, label %16
i32 45, label %21
i32 42, label %26
i32 47, label %31
]
12: ; preds = %4
%13 = load i8*, i8** %8
%14 = tail call double @atof(i8* %13)
%15 = tail call i32 @push(double %14)
br label %38
16: ; preds = %4
%17 = tail call double (...) @pop()
%18 = tail call double (...) @pop()
%19 = fadd double %17, %18
%20 = tail call i32 @push(double %19)
br label %38
21: ; preds = %4
%22 = tail call double (...) @pop()
%23 = tail call double (...) @pop()
%24 = fsub double %23, %22
%25 = tail call i32 @push(double %24)
br label %38
26: ; preds = %4
%27 = tail call double (...) @pop()
%28 = tail call double (...) @pop()
%29 = fmul double %27, %28
%30 = tail call i32 @push(double %29)
br label %38
31: ; preds = %4
%32 = tail call double (...) @pop()
%33 = tail call double (...) @pop()
%34 = fdiv double %33, %32
%35 = tail call i32 @push(double %34)
br label %38
36: ; preds = %4
%37 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %38
38: ; preds = %36, %31, %26, %21, %16, %12
%39 = icmp ugt i32 %5, 2
br i1 %39, label %4, label %40
40: ; preds = %38, %2
%41 = tail call double (...) @pop()
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), double %41)
ret i32 0
}