#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 *);
int getop(char *);
double pop();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ push(double);
int /*<<< orphan*/ ungets(char *);
int main(int argc, char *argv[]) {
  double op2;
  char s[50];
  while (--argc > 0) {
    ungets(" ");
    ungets(*++argv);
    switch (getop(s)) {
    case 0:
      push(atof(s));
      break;
    case '+':
      push(pop() + pop());
      break;
    case '-':
      op2 = pop();
      push(pop() - op2);
      break;
    case 'm':
      push(pop() * pop());
      break;
    case 'd':
      op2 = pop();
      if (op2 != 0.0)
        push(pop() / op2);
      else
        printf("math error: divide by 0\n");
      break;
    default:
      printf("error: unindentified character %s\n", s);
      argc = 1;
      break;
    }
  }
  printf("result is %f\n", pop());
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%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    1302 <main+0x1a2>
lea    0xe71(%rip),%rdi
call   1040 <ungets@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
call   1040 <ungets@plt>
lea    -0x50(%rbp),%rdi
call   1070 <getop@plt>
mov    %eax,%ecx
mov    %ecx,-0x54(%rbp)
test   %eax,%eax
je     120b <main+0xab>
jmp    11c7 <main+0x67>
mov    -0x54(%rbp),%eax
sub    $0x2b,%eax
je     121e <main+0xbe>
jmp    11d8 <main+0x78>
mov    -0x54(%rbp),%eax
sub    $0x2d,%eax
je     1247 <main+0xe7>
jmp    11e9 <main+0x89>
mov    -0x54(%rbp),%eax
sub    $0x64,%eax
je     1292 <main+0x132>
jmp    11fa <main+0x9a>
mov    -0x54(%rbp),%eax
sub    $0x6d,%eax
je     1269 <main+0x109>
jmp    12e4 <main+0x184>
lea    -0x50(%rbp),%rdi
call   1030 <atof@plt>
call   1080 <push@plt>
jmp    12fd <main+0x19d>
mov    $0x0,%al
call   1060 <pop@plt>
movsd  %xmm0,-0x60(%rbp)
mov    $0x0,%al
call   1060 <pop@plt>
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
addsd  %xmm1,%xmm0
call   1080 <push@plt>
jmp    12fd <main+0x19d>
mov    $0x0,%al
call   1060 <pop@plt>
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1060 <pop@plt>
subsd  -0x18(%rbp),%xmm0
call   1080 <push@plt>
jmp    12fd <main+0x19d>
mov    $0x0,%al
call   1060 <pop@plt>
movsd  %xmm0,-0x68(%rbp)
mov    $0x0,%al
call   1060 <pop@plt>
movaps %xmm0,%xmm1
movsd  -0x68(%rbp),%xmm0
mulsd  %xmm1,%xmm0
call   1080 <push@plt>
jmp    12fd <main+0x19d>
mov    $0x0,%al
call   1060 <pop@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    12bb <main+0x15b>
jp     12bb <main+0x15b>
jmp    12d1 <main+0x171>
mov    $0x0,%al
call   1060 <pop@plt>
divsd  -0x18(%rbp),%xmm0
call   1080 <push@plt>
jmp    12df <main+0x17f>
lea    0xd2a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12fd <main+0x19d>
lea    -0x50(%rbp),%rsi
lea    0xd2c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x8(%rbp)
jmp    1176 <main+0x16>
mov    $0x0,%al
call   1060 <pop@plt>
lea    0xd2e(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x50,%rsp
cmp    $0x2,%edi
jl     12a9 <main+0x139>
mov    %rsi,%rbx
mov    %edi,%ebp
add    $0x8,%rbx
lea    0xe73(%rip),%r14
lea    0x10(%rsp),%r15
lea    0xe9a(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1050 <ungets@plt>
mov    (%rbx),%rdi
call   1050 <ungets@plt>
mov    %r15,%rdi
call   1080 <getop@plt>
cmp    $0x2c,%eax
jle    1200 <main+0x90>
cmp    $0x2d,%eax
je     1229 <main+0xb9>
cmp    $0x64,%eax
je     1245 <main+0xd5>
cmp    $0x6d,%eax
jne    1296 <main+0x126>
xor    %eax,%eax
call   1070 <pop@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1070 <pop@plt>
mulsd  0x8(%rsp),%xmm0
jmp    1275 <main+0x105>
nopl   0x0(%rax)
test   %eax,%eax
je     126d <main+0xfd>
cmp    $0x2b,%eax
jne    1296 <main+0x126>
xor    %eax,%eax
call   1070 <pop@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1070 <pop@plt>
addsd  0x8(%rsp),%xmm0
jmp    1275 <main+0x105>
xor    %eax,%eax
call   1070 <pop@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1070 <pop@plt>
subsd  0x8(%rsp),%xmm0
jmp    1275 <main+0x105>
xor    %eax,%eax
call   1070 <pop@plt>
ucomisd 0xdac(%rip),%xmm0
jne    1258 <main+0xe8>
jnp    128c <main+0x11c>
xor    %eax,%eax
movsd  %xmm0,0x8(%rsp)
call   1070 <pop@plt>
divsd  0x8(%rsp),%xmm0
jmp    1275 <main+0x105>
mov    %r15,%rdi
call   1040 <atof@plt>
call   1090 <push@plt>
add    $0xffffffff,%ebp
add    $0x8,%rbx
cmp    $0x1,%ebp
ja     11b0 <main+0x40>
jmp    12a9 <main+0x139>
mov    %r12,%rdi
call   1030 <puts@plt>
jmp    127a <main+0x10a>
lea    0xd6d(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1070 <pop@plt>
lea    0xd76(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@.str.1 = [25 x i8] c"math error: divide by 0\0A\00"
@.str.2 = [35 x i8] c"error: unindentified character %s\0A\00"
@.str.3 = [14 x i8] c"result is %f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
%7 = alloca [50 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %8
8: ; preds = %55, %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 %56
12: ; preds = %8
%13 = call i32 @ungets(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i32 1
store i8** %15, i8*** %5
%16 = load i8*, i8** %15
%17 = call i32 @ungets(i8* %16)
%18 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%19 = call i32 @getop(i8* %18)
switch i32 %19, label %52 [
i32 0, label %20
i32 43, label %24
i32 45, label %29
i32 109, label %35
i32 100, label %40
]
20: ; preds = %12
%21 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%22 = call double @atof(i8* %21)
%23 = call i32 @push(double %22)
br label %55
24: ; preds = %12
%25 = call double (...) @pop()
%26 = call double (...) @pop()
%27 = fadd double %25, %26
%28 = call i32 @push(double %27)
br label %55
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 %55
35: ; preds = %12
%36 = call double (...) @pop()
%37 = call double (...) @pop()
%38 = fmul double %36, %37
%39 = call i32 @push(double %38)
br label %55
40: ; preds = %12
%41 = call double (...) @pop()
store double %41, double* %6
%42 = load double, double* %6
%43 = fcmp une double %42, 0.000000e+00
br i1 %43, label %44, label %49
44: ; preds = %40
%45 = call double (...) @pop()
%46 = load double, double* %6
%47 = fdiv double %45, %46
%48 = call i32 @push(double %47)
br label %51
49: ; preds = %40
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %51
51: ; preds = %49, %44
br label %55
52: ; preds = %12
%53 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %53)
store i32 1, i32* %4
br label %55
55: ; preds = %52, %51, %35, %29, %24, %20
br label %8
56: ; preds = %8
%57 = call double (...) @pop()
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), double %57)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
@.str.2 = [35 x i8] c"error: unindentified character %s\0A\00"
@.str.3 = [14 x i8] c"result is %f\0A\00"
@str = [24 x i8] c"math error: divide by 0\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [50 x i8]
%4 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %46
6: ; preds = %2, %44
%7 = phi i32 [ %9, %44 ], [ %0, %2 ]
%8 = phi i8** [ %11, %44 ], [ %1, %2 ]
%9 = add nsw i32 %7, -1
%10 = call i32 @ungets(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds i8*, i8** %8, i64 1
%12 = load i8*, i8** %11
%13 = call i32 @ungets(i8* %12)
%14 = call i32 @getop(i8* %4)
switch i32 %14, label %42 [
i32 0, label %15
i32 43, label %18
i32 45, label %23
i32 109, label %28
i32 100, label %33
]
15: ; preds = %6
%16 = call double @atof(i8* %4)
%17 = call i32 @push(double %16)
br label %44
18: ; preds = %6
%19 = call double (...) @pop()
%20 = call double (...) @pop()
%21 = fadd double %19, %20
%22 = call i32 @push(double %21)
br label %44
23: ; preds = %6
%24 = call double (...) @pop()
%25 = call double (...) @pop()
%26 = fsub double %25, %24
%27 = call i32 @push(double %26)
br label %44
28: ; preds = %6
%29 = call double (...) @pop()
%30 = call double (...) @pop()
%31 = fmul double %29, %30
%32 = call i32 @push(double %31)
br label %44
33: ; preds = %6
%34 = call double (...) @pop()
%35 = fcmp une double %34, 0.000000e+00
br i1 %35, label %36, label %40
36: ; preds = %33
%37 = call double (...) @pop()
%38 = fdiv double %37, %34
%39 = call i32 @push(double %38)
br label %44
40: ; preds = %33
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
br label %44
42: ; preds = %6
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* %4)
br label %46
44: ; preds = %36, %40, %28, %23, %18, %15
%45 = icmp ugt i32 %9, 1
br i1 %45, label %6, label %46
46: ; preds = %44, %42, %2
%47 = call double (...) @pop()
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), double %47)
ret i32 0
}