#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 atof(char *);
int getop(char *);
double pop();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ push(int);
main(int argc, char *argv[]) {
  int type;
  double op2;
  int i;
  if (argc < 2) {
    printf("Usage: expr [number]... [operator]...\n");
    return 0;
  }
  while (--argc > 0)
    switch (type = getop(*++argv)) {
    case '0':
      push(atof(*argv));
      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 divisor\n");
      break;
    default:
      printf("error: unknown command %s\n", *argv);
      break;
    }
  printf("\t%.8g\n", pop());
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    118a <main+0x3a>
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1361 <main+0x211>
jmp    118f <main+0x3f>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    1345 <main+0x1f5>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
call   1060 <getop@plt>
mov    %eax,-0x14(%rbp)
add    $0xffffffdb,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0xb,%eax
ja     132b <main+0x1db>
mov    -0x30(%rbp),%rax
lea    0xe27(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <atof@plt>
mov    %eax,%edi
call   1070 <push@plt>
jmp    1340 <main+0x1f0>
mov    $0x0,%al
call   1050 <pop@plt>
movsd  %xmm0,-0x38(%rbp)
mov    $0x0,%al
call   1050 <pop@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1070 <push@plt>
jmp    1340 <main+0x1f0>
mov    $0x0,%al
call   1050 <pop@plt>
movsd  %xmm0,-0x40(%rbp)
mov    $0x0,%al
call   1050 <pop@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1070 <push@plt>
jmp    1340 <main+0x1f0>
mov    $0x0,%al
call   1050 <pop@plt>
movsd  %xmm0,-0x20(%rbp)
mov    $0x0,%al
call   1050 <pop@plt>
subsd  -0x20(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1070 <push@plt>
jmp    1340 <main+0x1f0>
mov    $0x0,%al
call   1050 <pop@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    12a3 <main+0x153>
jp     12a3 <main+0x153>
jmp    12bd <main+0x16d>
mov    $0x0,%al
call   1050 <pop@plt>
divsd  -0x20(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1070 <push@plt>
jmp    12cb <main+0x17b>
lea    0xd93(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1340 <main+0x1f0>
mov    $0x0,%al
call   1050 <pop@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    12f9 <main+0x1a9>
jp     12f9 <main+0x1a9>
jmp    1318 <main+0x1c8>
mov    $0x0,%al
call   1050 <pop@plt>
cvttsd2si %xmm0,%eax
cvttsd2si -0x20(%rbp),%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1070 <push@plt>
jmp    1326 <main+0x1d6>
lea    0xd38(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1340 <main+0x1f0>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd33(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    118f <main+0x3f>
mov    $0x0,%al
call   1050 <pop@plt>
lea    0xd34(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jge    1182 <main+0x22>
lea    0xef6(%rip),%rdi
call   1030 <puts@plt>
jmp    12cf <main+0x16f>
mov    %rsi,%rbx
mov    %edi,%ebp
add    $0x1,%ebp
add    $0x8,%rbx
lea    0xea3(%rip),%r14
lea    0xe6c(%rip),%r12
lea    0xeb7(%rip),%r15
jmp    11d8 <main+0x78>
xor    %eax,%eax
call   1060 <pop@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1060 <pop@plt>
subsd  0x8(%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1080 <push@plt>
add    $0xffffffff,%ebp
add    $0x8,%rbx
cmp    $0x2,%ebp
jbe    12ba <main+0x15a>
mov    (%rbx),%rdi
call   1070 <getop@plt>
add    $0xffffffdb,%eax
cmp    $0xb,%eax
ja     1226 <main+0xc6>
movslq (%r12,%rax,4),%rax
add    %r12,%rax
jmp    *%rax
xor    %eax,%eax
call   1060 <pop@plt>
ucomisd 0xe00(%rip),%xmm0
jne    1208 <main+0xa8>
jnp    12ad <main+0x14d>
xor    %eax,%eax
movsd  %xmm0,0x8(%rsp)
call   1060 <pop@plt>
cvttsd2si %xmm0,%eax
cvttsd2si 0x8(%rsp),%ecx
cltd
idiv   %ecx
mov    %edx,%edi
jmp    11c3 <main+0x63>
mov    (%rbx),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11c8 <main+0x68>
xor    %eax,%eax
call   1060 <pop@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1060 <pop@plt>
mulsd  0x8(%rsp),%xmm0
jmp    11bf <main+0x5f>
xor    %eax,%eax
call   1060 <pop@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1060 <pop@plt>
addsd  0x8(%rsp),%xmm0
jmp    11bf <main+0x5f>
xor    %eax,%eax
call   1060 <pop@plt>
ucomisd 0xd7e(%rip),%xmm0
jne    1286 <main+0x126>
jnp    12ad <main+0x14d>
xor    %eax,%eax
movsd  %xmm0,0x8(%rsp)
call   1060 <pop@plt>
divsd  0x8(%rsp),%xmm0
jmp    11bf <main+0x5f>
mov    (%rbx),%rdi
call   1040 <atof@plt>
mov    %eax,%edi
jmp    11c3 <main+0x63>
mov    %r15,%rdi
call   1030 <puts@plt>
jmp    11c8 <main+0x68>
xor    %eax,%eax
call   1060 <pop@plt>
lea    0xd8b(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [39 x i8] c"Usage: expr [number]... [operator]...\0A\00"
@.str.1 = [21 x i8] c"error: zero divisor\0A\00"
@.str.2 = [27 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 i32
%7 = alloca double
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %82
13: ; preds = %2
br label %14
14: ; preds = %78, %13
%15 = load i32, i32* %4
%16 = add nsw i32 %15, -1
store i32 %16, i32* %4
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %79
18: ; preds = %14
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i32 1
store i8** %20, i8*** %5
%21 = load i8*, i8** %20
%22 = call i32 @getop(i8* %21)
store i32 %22, i32* %6
switch i32 %22, label %74 [
i32 48, label %23
i32 43, label %28
i32 42, label %34
i32 45, label %40
i32 47, label %47
i32 37, label %60
]
23: ; preds = %18
%24 = load i8**, i8*** %5
%25 = load i8*, i8** %24
%26 = call i32 @atof(i8* %25)
%27 = call i32 @push(i32 %26)
br label %78
28: ; preds = %18
%29 = call double (...) @pop()
%30 = call double (...) @pop()
%31 = fadd double %29, %30
%32 = fptosi double %31 to i32
%33 = call i32 @push(i32 %32)
br label %78
34: ; preds = %18
%35 = call double (...) @pop()
%36 = call double (...) @pop()
%37 = fmul double %35, %36
%38 = fptosi double %37 to i32
%39 = call i32 @push(i32 %38)
br label %78
40: ; preds = %18
%41 = call double (...) @pop()
store double %41, double* %7
%42 = call double (...) @pop()
%43 = load double, double* %7
%44 = fsub double %42, %43
%45 = fptosi double %44 to i32
%46 = call i32 @push(i32 %45)
br label %78
47: ; preds = %18
%48 = call double (...) @pop()
store double %48, double* %7
%49 = load double, double* %7
%50 = fcmp une double %49, 0.000000e+00
br i1 %50, label %51, label %57
51: ; preds = %47
%52 = call double (...) @pop()
%53 = load double, double* %7
%54 = fdiv double %52, %53
%55 = fptosi double %54 to i32
%56 = call i32 @push(i32 %55)
br label %59
57: ; preds = %47
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %59
59: ; preds = %57, %51
br label %78
60: ; preds = %18
%61 = call double (...) @pop()
store double %61, double* %7
%62 = load double, double* %7
%63 = fcmp une double %62, 0.000000e+00
br i1 %63, label %64, label %71
64: ; preds = %60
%65 = call double (...) @pop()
%66 = fptosi double %65 to i32
%67 = load double, double* %7
%68 = fptosi double %67 to i32
%69 = srem i32 %66, %68
%70 = call i32 @push(i32 %69)
br label %73
71: ; preds = %60
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %73
73: ; preds = %71, %64
br label %78
74: ; preds = %18
%75 = load i8**, i8*** %5
%76 = load i8*, i8** %75
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %76)
br label %78
78: ; preds = %74, %73, %59, %40, %34, %28, %23
br label %14
79: ; preds = %14
%80 = call double (...) @pop()
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), double %80)
store i32 0, i32* %3
br label %82
82: ; preds = %79, %11
%83 = load i32, i32* %3
ret i32 %83
}

LLVM IR (-O2):
@.str.2 = [27 x i8] c"error: unknown command %s\0A\00"
@.str.3 = [7 x i8] c"\09%.8g\0A\00"
@str.4 = [20 x i8] c"error: zero divisor\00"
@str.5 = [38 x i8] c"Usage: expr [number]... [operator]...\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.5, i64 0, i64 0))
br label %64
6: ; preds = %2, %59
%7 = phi i32 [ %9, %59 ], [ %0, %2 ]
%8 = phi i8** [ %10, %59 ], [ %1, %2 ]
%9 = add nsw i32 %7, -1
%10 = getelementptr inbounds i8*, i8** %8, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @getop(i8* %11)
switch i32 %12, label %56 [
i32 48, label %13
i32 43, label %17
i32 42, label %23
i32 45, label %29
i32 47, label %35
i32 37, label %45
]
13: ; preds = %6
%14 = load i8*, i8** %10
%15 = tail call i32 @atof(i8* %14)
%16 = tail call i32 @push(i32 %15)
br label %59
17: ; preds = %6
%18 = tail call double (...) @pop()
%19 = tail call double (...) @pop()
%20 = fadd double %18, %19
%21 = fptosi double %20 to i32
%22 = tail call i32 @push(i32 %21)
br label %59
23: ; preds = %6
%24 = tail call double (...) @pop()
%25 = tail call double (...) @pop()
%26 = fmul double %24, %25
%27 = fptosi double %26 to i32
%28 = tail call i32 @push(i32 %27)
br label %59
29: ; preds = %6
%30 = tail call double (...) @pop()
%31 = tail call double (...) @pop()
%32 = fsub double %31, %30
%33 = fptosi double %32 to i32
%34 = tail call i32 @push(i32 %33)
br label %59
35: ; preds = %6
%36 = tail call double (...) @pop()
%37 = fcmp une double %36, 0.000000e+00
br i1 %37, label %38, label %43
38: ; preds = %35
%39 = tail call double (...) @pop()
%40 = fdiv double %39, %36
%41 = fptosi double %40 to i32
%42 = tail call i32 @push(i32 %41)
br label %59
43: ; preds = %35
%44 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.4, i64 0, i64 0))
br label %59
45: ; preds = %6
%46 = tail call double (...) @pop()
%47 = fcmp une double %46, 0.000000e+00
br i1 %47, label %48, label %54
48: ; preds = %45
%49 = tail call double (...) @pop()
%50 = fptosi double %49 to i32
%51 = fptosi double %46 to i32
%52 = srem i32 %50, %51
%53 = tail call i32 @push(i32 %52)
br label %59
54: ; preds = %45
%55 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.4, i64 0, i64 0))
br label %59
56: ; preds = %6
%57 = load i8*, i8** %10
%58 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %57)
br label %59
59: ; preds = %48, %54, %38, %43, %56, %29, %23, %17, %13
%60 = icmp ugt i32 %7, 2
br i1 %60, label %6, label %61
61: ; preds = %59
%62 = tail call double (...) @pop()
%63 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), double %62)
br label %64
64: ; preds = %61, %4
ret i32 0
}