#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
char *getstr();
int /*<<< orphan*/ ineval(char *);
int /*<<< orphan*/ poseval(char *);
int /*<<< orphan*/ preeval(char *);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, unsigned int *);
int /*<<< orphan*/ stderr;
int main() {
  unsigned ch;
  char *s;
  do {
    puts("What would you like to do?");
    puts(" ( 0) Exit");
    puts(" ( 1) Postfix Evaluation");
    puts(" ( 2) Prefix  Evaluation");
    puts(" ( 3) Infix   Evaluation");
    scanf(" %u%*c", &ch);
    switch (ch) {
    case 0:
      puts("Bye!");
      break;
    case 1:
      puts("Expression?");
      if (!(s = getstr()))
        goto alocerr;
      printf("= %.2lf\n", poseval(s));
      free(s);
      break;
    case 2:
      puts("Expression?");
      if (!(s = getstr()))
        goto alocerr;
      printf("= %.2lf\n", preeval(s));
      free(s);
      break;
    case 3:
      puts("Expression?");
      if (!(s = getstr()))
        goto alocerr;
      printf("= %.2lf\n", ineval(s));
      free(s);
      break;
    default:
      puts("Incorrect Choice!");
      break;
    }
    putchar('\n');
  } while (ch);
  return 0;
alocerr:
  fprintf(stderr, "Allocation Error! Core Dumped!\n");
  return 12;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe5a(%rip),%rdi
call   1050 <puts@plt>
lea    0xe69(%rip),%rdi
call   1050 <puts@plt>
lea    0xe68(%rip),%rdi
call   1050 <puts@plt>
lea    0xe75(%rip),%rdi
call   1050 <puts@plt>
lea    0xe82(%rip),%rdi
call   1050 <puts@plt>
lea    0xe8f(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   10a0 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %rax,-0x18(%rbp)
sub    $0x3,%rax
ja     1312 <main+0x172>
mov    -0x18(%rbp),%rax
lea    0xde9(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe61(%rip),%rdi
call   1050 <puts@plt>
jmp    131e <main+0x17e>
lea    0xe55(%rip),%rdi
call   1050 <puts@plt>
mov    $0x0,%al
call   1070 <getstr@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1257 <main+0xb7>
jmp    133e <main+0x19e>
mov    -0x10(%rbp),%rdi
call   10b0 <poseval@plt>
mov    %eax,%esi
lea    0xe30(%rip),%rdi
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
jmp    131e <main+0x17e>
lea    0xe0a(%rip),%rdi
call   1050 <puts@plt>
mov    $0x0,%al
call   1070 <getstr@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    12a2 <main+0x102>
jmp    133e <main+0x19e>
mov    -0x10(%rbp),%rdi
call   1090 <preeval@plt>
mov    %eax,%esi
lea    0xde5(%rip),%rdi
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
jmp    131e <main+0x17e>
lea    0xdbf(%rip),%rdi
call   1050 <puts@plt>
mov    $0x0,%al
call   1070 <getstr@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    12ed <main+0x14d>
jmp    133e <main+0x19e>
mov    -0x10(%rbp),%rdi
call   10c0 <ineval@plt>
mov    %eax,%esi
lea    0xd9a(%rip),%rdi
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
jmp    131e <main+0x17e>
lea    0xd89(%rip),%rdi
call   1050 <puts@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
cmpl   $0x0,-0x8(%rbp)
jne    11af <main+0xf>
movl   $0x0,-0x4(%rbp)
jmp    135a <main+0x1ba>
mov    0x2c9b(%rip),%rax
mov    (%rax),%edi
lea    0xd66(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0xc,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xeb6(%rip),%r12
lea    0xec8(%rip),%rbp
lea    0x4(%rsp),%r14
lea    0xe3b(%rip),%r13
jmp    11f1 <main+0x51>
nopw   0x0(%rax,%rax,1)
lea    0xecb(%rip),%rdi
call   1050 <puts@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
cmpl   $0x0,0x4(%rsp)
je     131e <main+0x17e>
lea    0xe18(%rip),%rdi
call   1050 <puts@plt>
lea    0xe27(%rip),%rdi
call   1050 <puts@plt>
lea    0xe26(%rip),%rdi
call   1050 <puts@plt>
lea    0xe33(%rip),%rdi
call   1050 <puts@plt>
mov    %r12,%rdi
call   1050 <puts@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   10a0 <scanf@plt>
mov    0x4(%rsp),%eax
cmp    $0x3,%rax
ja     11d0 <main+0x30>
movslq 0x0(%r13,%rax,4),%rax
add    %r13,%rax
jmp    *%rax
lea    0xe39(%rip),%rdi
jmp    11d7 <main+0x37>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xe26(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1070 <getstr@plt>
test   %rax,%rax
je     1322 <main+0x182>
mov    %rax,%r15
mov    %rax,%rdi
call   10b0 <poseval@plt>
lea    0xe0b(%rip),%rdi
mov    %eax,%esi
call   1060 <printf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
jmp    11dc <main+0x3c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xdd6(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1070 <getstr@plt>
test   %rax,%rax
je     1322 <main+0x182>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <preeval@plt>
jmp    1303 <main+0x163>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0xda6(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1070 <getstr@plt>
test   %rax,%rax
je     1322 <main+0x182>
mov    %rax,%rbx
mov    %rax,%rdi
call   10c0 <ineval@plt>
lea    0xd8f(%rip),%rdi
mov    %eax,%esi
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    11dc <main+0x3c>
xor    %eax,%eax
jmp    133c <main+0x19c>
mov    0x2cb7(%rip),%rax
mov    (%rax),%edi
lea    0xd82(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0xc,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"What would you like to do?\00"
@.str.1 = [11 x i8] c" ( 0) Exit\00"
@.str.2 = [25 x i8] c" ( 1) Postfix Evaluation\00"
@.str.3 = [25 x i8] c" ( 2) Prefix Evaluation\00"
@.str.4 = [25 x i8] c" ( 3) Infix Evaluation\00"
@.str.5 = [7 x i8] c" %u%*c\00"
@.str.6 = [5 x i8] c"Bye!\00"
@.str.7 = [12 x i8] c"Expression?\00"
@.str.8 = [9 x i8] c"= %.2lf\0A\00"
@.str.9 = [18 x i8] c"Incorrect Choice!\00"
@stderr = global i32 0
@.str.10 = [32 x i8] c"Allocation Error! Core Dumped!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
store i32 0, i32* %1
br label %4
4: ; preds = %51, %0
%5 = call i32 @puts(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%9 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32* %2)
%11 = load i32, i32* %2
switch i32 %11, label %47 [
i32 0, label %12
i32 1, label %14
i32 2, label %25
i32 3, label %36
]
12: ; preds = %4
%13 = call i32 @puts(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %49
14: ; preds = %4
%15 = call i32 @puts(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
%16 = call i8* (...) @getstr()
store i8* %16, i8** %3
%17 = icmp ne i8* %16, null
br i1 %17, label %19, label %18
18: ; preds = %14
br label %55
19: ; preds = %14
%20 = load i8*, i8** %3
%21 = call i32 @poseval(i8* %20)
%22 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i32 %21)
%23 = load i8*, i8** %3
%24 = call i32 @free(i8* %23)
br label %49
25: ; preds = %4
%26 = call i32 @puts(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
%27 = call i8* (...) @getstr()
store i8* %27, i8** %3
%28 = icmp ne i8* %27, null
br i1 %28, label %30, label %29
29: ; preds = %25
br label %55
30: ; preds = %25
%31 = load i8*, i8** %3
%32 = call i32 @preeval(i8* %31)
%33 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i32 %32)
%34 = load i8*, i8** %3
%35 = call i32 @free(i8* %34)
br label %49
36: ; preds = %4
%37 = call i32 @puts(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
%38 = call i8* (...) @getstr()
store i8* %38, i8** %3
%39 = icmp ne i8* %38, null
br i1 %39, label %41, label %40
40: ; preds = %36
br label %55
41: ; preds = %36
%42 = load i8*, i8** %3
%43 = call i32 @ineval(i8* %42)
%44 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i32 %43)
%45 = load i8*, i8** %3
%46 = call i32 @free(i8* %45)
br label %49
47: ; preds = %4
%48 = call i32 @puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0))
br label %49
49: ; preds = %47, %41, %30, %19, %12
%50 = call i32 @putchar(i8 signext 10)
br label %51
51: ; preds = %49
%52 = load i32, i32* %2
%53 = icmp ne i32 %52, 0
br i1 %53, label %4, label %54
54: ; preds = %51
store i32 0, i32* %1
br label %58
55: ; preds = %40, %29, %18
%56 = load i32, i32* @stderr
%57 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.10, i64 0, i64 0))
store i32 12, i32* %1
br label %58
58: ; preds = %55, %54
%59 = load i32, i32* %1
ret i32 %59
}

LLVM IR (-O2):
@.str = [27 x i8] c"What would you like to do?\00"
@.str.1 = [11 x i8] c" ( 0) Exit\00"
@.str.2 = [25 x i8] c" ( 1) Postfix Evaluation\00"
@.str.3 = [25 x i8] c" ( 2) Prefix Evaluation\00"
@.str.4 = [25 x i8] c" ( 3) Infix Evaluation\00"
@.str.5 = [7 x i8] c" %u%*c\00"
@.str.6 = [5 x i8] c"Bye!\00"
@.str.7 = [12 x i8] c"Expression?\00"
@.str.8 = [9 x i8] c"= %.2lf\0A\00"
@.str.9 = [18 x i8] c"Incorrect Choice!\00"
@stderr = global i32 0
@.str.10 = [32 x i8] c"Allocation Error! Core Dumped!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
br label %3
3: ; preds = %39, %0
%4 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32* %1)
%10 = load i32, i32* %1
switch i32 %10, label %37 [
i32 0, label %11
i32 1, label %13
i32 2, label %21
i32 3, label %29
]
11: ; preds = %3
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %39
13: ; preds = %3
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
%15 = call i8* (...) @getstr()
%16 = icmp eq i8* %15, null
br i1 %16, label %43, label %17
17: ; preds = %13
%18 = call i32 @poseval(i8* %15)
%19 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i32 %18)
%20 = call i32 @free(i8* %15)
br label %39
21: ; preds = %3
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
%23 = call i8* (...) @getstr()
%24 = icmp eq i8* %23, null
br i1 %24, label %43, label %25
25: ; preds = %21
%26 = call i32 @preeval(i8* %23)
%27 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i32 %26)
%28 = call i32 @free(i8* %23)
br label %39
29: ; preds = %3
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
%31 = call i8* (...) @getstr()
%32 = icmp eq i8* %31, null
br i1 %32, label %43, label %33
33: ; preds = %29
%34 = call i32 @ineval(i8* %31)
%35 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i32 %34)
%36 = call i32 @free(i8* %31)
br label %39
37: ; preds = %3
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0))
br label %39
39: ; preds = %37, %33, %25, %17, %11
%40 = call i32 @putchar(i8 signext 10)
%41 = load i32, i32* %1
%42 = icmp eq i32 %41, 0
br i1 %42, label %46, label %3
43: ; preds = %29, %21, %13
%44 = load i32, i32* @stderr
%45 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.10, i64 0, i64 0))
br label %46
46: ; preds = %39, %43
%47 = phi i32 [ 12, %43 ], [ 0, %39 ]
ret i32 %47
}