#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[]) {
  char s[100];
  double op2;
  while (--argc > 0) {
    ungets(" ");
    ungets(*++argv);
    switch (getop(s)) {
    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;
    default:
      printf("error: unknown command %s \n", s);
      argc = 1;
      break;
    }
  }
  printf("\t %8g\n", pop());
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%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    12f6 <main+0x196>
lea    0xe8a(%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    -0x80(%rbp),%rdi
call   1070 <getop@plt>
add    $0xffffffd6,%eax
mov    %eax,%ecx
mov    %rcx,-0x90(%rbp)
sub    $0x6,%eax
ja     12d8 <main+0x178>
mov    -0x90(%rbp),%rax
lea    0xe25(%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    12f1 <main+0x191>
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    12f1 <main+0x191>
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    12f1 <main+0x191>
mov    $0x0,%al
call   1060 <pop@plt>
movsd  %xmm0,-0x88(%rbp)
ff
mov    $0x0,%al
call   1060 <pop@plt>
subsd  -0x88(%rbp),%xmm0
ff
call   1080 <push@plt>
jmp    12f1 <main+0x191>
mov    $0x0,%al
call   1060 <pop@plt>
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x88(%rbp),%xmm0
ff
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    12ac <main+0x14c>
jp     12ac <main+0x14c>
jmp    12c5 <main+0x165>
mov    $0x0,%al
call   1060 <pop@plt>
divsd  -0x88(%rbp),%xmm0
ff
call   1080 <push@plt>
jmp    12d3 <main+0x173>
lea    0xd52(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12f1 <main+0x191>
lea    -0x80(%rbp),%rsi
lea    0xd51(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x8(%rbp)
jmp    1179 <main+0x19>
mov    $0x0,%al
call   1060 <pop@plt>
lea    0xd4c(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
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
cmp    $0x2,%edi
jl     1296 <main+0x126>
mov    %rsi,%rbx
mov    %edi,%ebp
add    $0x8,%rbx
lea    0xec3(%rip),%r14
lea    0x10(%rsp),%r15
lea    0xe65(%rip),%r13
lea    0xe9d(%rip),%r12
nopw   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>
add    $0xffffffd6,%eax
cmp    $0x6,%eax
ja     1283 <main+0x113>
movslq 0x0(%r13,%rax,4),%rax
add    %r13,%rax
jmp    *%rax
xor    %eax,%eax
call   1070 <pop@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1070 <pop@plt>
mulsd  0x8(%rsp),%xmm0
jmp    1262 <main+0xf2>
xor    %eax,%eax
call   1070 <pop@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1070 <pop@plt>
addsd  0x8(%rsp),%xmm0
jmp    1262 <main+0xf2>
xor    %eax,%eax
call   1070 <pop@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1070 <pop@plt>
subsd  0x8(%rsp),%xmm0
jmp    1262 <main+0xf2>
xor    %eax,%eax
call   1070 <pop@plt>
ucomisd 0xdbf(%rip),%xmm0
jne    1245 <main+0xd5>
jnp    1279 <main+0x109>
xor    %eax,%eax
movsd  %xmm0,0x8(%rsp)
call   1070 <pop@plt>
divsd  0x8(%rsp),%xmm0
jmp    1262 <main+0xf2>
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    1296 <main+0x126>
mov    %r12,%rdi
call   1030 <puts@plt>
jmp    1267 <main+0xf7>
lea    0xd9a(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1070 <pop@plt>
lea    0xd9c(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@.str.1 = [22 x i8] c"error: zero divisor \0A\00"
@.str.2 = [28 x i8] c"error: unknown command %s \0A\00"
@.str.3 = [7 x i8] c"\09 %8g\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [100 x i8]
%7 = alloca double
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 [100 x i8], [100 x i8]* %6, i64 0, i64 0
%19 = call i32 @getop(i8* %18)
switch i32 %19, label %52 [
i32 48, label %20
i32 43, label %24
i32 42, label %29
i32 45, label %34
i32 47, label %40
]
20: ; preds = %12
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %6, 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()
%31 = call double (...) @pop()
%32 = fmul double %30, %31
%33 = call i32 @push(double %32)
br label %55
34: ; preds = %12
%35 = call double (...) @pop()
store double %35, double* %7
%36 = call double (...) @pop()
%37 = load double, double* %7
%38 = fsub double %36, %37
%39 = call i32 @push(double %38)
br label %55
40: ; preds = %12
%41 = call double (...) @pop()
store double %41, double* %7
%42 = load double, double* %7
%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* %7
%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 ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %51
51: ; preds = %49, %44
br label %55
52: ; preds = %12
%53 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %53)
store i32 1, i32* %4
br label %55
55: ; preds = %52, %51, %34, %29, %24, %20
br label %8
56: ; preds = %8
%57 = call double (...) @pop()
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), double %57)
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
@.str.2 = [28 x i8] c"error: unknown command %s \0A\00"
@.str.3 = [7 x i8] c"\09 %8g\0A\00"
@str = [21 x i8] c"error: zero divisor \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 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 48, label %15
i32 43, label %18
i32 42, label %23
i32 45, label %28
i32 47, 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 = fmul double %24, %25
%27 = call i32 @push(double %26)
br label %44
28: ; preds = %6
%29 = call double (...) @pop()
%30 = call double (...) @pop()
%31 = fsub double %30, %29
%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 ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %44
42: ; preds = %6
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 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 ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), double %47)
ret i32 0
}