#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();
char *in2pos(char *);
char *in2pre(char *);
int /*<<< orphan*/ printf(char *, char *);
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) Infix to Postfix");
    puts(" ( 2) Infix to Prefix");
    scanf(" %u%*c", &ch);
    switch (ch) {
    case 0:
      puts("Bye!");
      break;
    case 1:
      puts("Expression?");
      if (!(s = getstr()))
        goto alocerr;
      printf("= %s\n", in2pos(s));
      free(s);
      break;
    case 2:
      puts("Expression?");
      if (!(s = getstr()))
        goto alocerr;
      printf("= %s\n", in2pre(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    0xe73(%rip),%rdi
call   1050 <puts@plt>
lea    0xe7d(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   10b0 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
test   %eax,%eax
je     1214 <main+0x84>
jmp    11f2 <main+0x62>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
je     1225 <main+0x95>
jmp    1203 <main+0x73>
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
je     1271 <main+0xe1>
jmp    12bd <main+0x12d>
lea    0xe3f(%rip),%rdi
call   1050 <puts@plt>
jmp    12c9 <main+0x139>
lea    0xe33(%rip),%rdi
call   1050 <puts@plt>
mov    $0x0,%al
call   1070 <getstr@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    124b <main+0xbb>
jmp    12e9 <main+0x159>
mov    -0x10(%rbp),%rdi
call   10a0 <in2pos@plt>
mov    %rax,%rsi
lea    0xe0d(%rip),%rdi
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
jmp    12c9 <main+0x139>
lea    0xde7(%rip),%rdi
call   1050 <puts@plt>
mov    $0x0,%al
call   1070 <getstr@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1297 <main+0x107>
jmp    12e9 <main+0x159>
mov    -0x10(%rbp),%rdi
call   1090 <in2pre@plt>
mov    %rax,%rsi
lea    0xdc1(%rip),%rdi
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
jmp    12c9 <main+0x139>
lea    0xdad(%rip),%rdi
call   1050 <puts@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
cmpl   $0x0,-0x8(%rbp)
jne    119f <main+0xf>
movl   $0x0,-0x4(%rbp)
jmp    1305 <main+0x175>
mov    0x2cf0(%rip),%rax
mov    (%rax),%edi
lea    0xd8a(%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    0xe5e(%rip),%r14
lea    0xe72(%rip),%rbx
lea    0xe76(%rip),%rbp
lea    0xe86(%rip),%r13
lea    0xe95(%rip),%r15
lea    0x4(%rsp),%r12
jmp    11f1 <main+0x61>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0xe9a(%rip),%rdi
call   1050 <puts@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
cmpl   $0x0,0x4(%rsp)
je     12cd <main+0x13d>
mov    %r14,%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
call   1050 <puts@plt>
mov    %rbp,%rdi
call   1050 <puts@plt>
mov    %r13,%rdi
call   1050 <puts@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   10b0 <scanf@plt>
mov    0x4(%rsp),%eax
cmp    $0x2,%eax
je     1280 <main+0xf0>
cmp    $0x1,%eax
je     1240 <main+0xb0>
test   %eax,%eax
jne    11d0 <main+0x40>
lea    0xe25(%rip),%rdi
jmp    11d7 <main+0x47>
nopw   0x0(%rax,%rax,1)
lea    0xe18(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1070 <getstr@plt>
test   %rax,%rax
je     12d1 <main+0x141>
mov    %rax,%r14
mov    %rax,%rdi
call   10a0 <in2pos@plt>
lea    0xe01(%rip),%rdi
mov    %rax,%rsi
call   1060 <printf@plt>
mov    %r14,%rdi
jmp    12b5 <main+0x125>
nopw   0x0(%rax,%rax,1)
lea    0xdd8(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1070 <getstr@plt>
test   %rax,%rax
je     12d1 <main+0x141>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <in2pre@plt>
lea    0xdc1(%rip),%rdi
mov    %rax,%rsi
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xd3f(%rip),%r14
lea    0xd53(%rip),%rbx
jmp    11dc <main+0x4c>
xor    %eax,%eax
jmp    12eb <main+0x15b>
mov    0x2d08(%rip),%rax
mov    (%rax),%edi
lea    0xda2(%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 = [23 x i8] c" ( 1) Infix to Postfix\00"
@.str.3 = [22 x i8] c" ( 2) Infix to Prefix\00"
@.str.4 = [7 x i8] c" %u%*c\00"
@.str.5 = [5 x i8] c"Bye!\00"
@.str.6 = [12 x i8] c"Expression?\00"
@.str.7 = [6 x i8] c"= %s\0A\00"
@.str.8 = [18 x i8] c"Incorrect Choice!\00"
@stderr = global i32 0
@.str.9 = [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 = %39, %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 ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @puts(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32* %2)
%10 = load i32, i32* %2
switch i32 %10, label %35 [
i32 0, label %11
i32 1, label %13
i32 2, label %24
]
11: ; preds = %4
%12 = call i32 @puts(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %37
13: ; preds = %4
%14 = call i32 @puts(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
%15 = call i8* (...) @getstr()
store i8* %15, i8** %3
%16 = icmp ne i8* %15, null
br i1 %16, label %18, label %17
17: ; preds = %13
br label %43
18: ; preds = %13
%19 = load i8*, i8** %3
%20 = call i8* @in2pos(i8* %19)
%21 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8* %20)
%22 = load i8*, i8** %3
%23 = call i32 @free(i8* %22)
br label %37
24: ; preds = %4
%25 = call i32 @puts(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
%26 = call i8* (...) @getstr()
store i8* %26, i8** %3
%27 = icmp ne i8* %26, null
br i1 %27, label %29, label %28
28: ; preds = %24
br label %43
29: ; preds = %24
%30 = load i8*, i8** %3
%31 = call i8* @in2pre(i8* %30)
%32 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8* %31)
%33 = load i8*, i8** %3
%34 = call i32 @free(i8* %33)
br label %37
35: ; preds = %4
%36 = call i32 @puts(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0))
br label %37
37: ; preds = %35, %29, %18, %11
%38 = call i32 @putchar(i8 signext 10)
br label %39
39: ; preds = %37
%40 = load i32, i32* %2
%41 = icmp ne i32 %40, 0
br i1 %41, label %4, label %42
42: ; preds = %39
store i32 0, i32* %1
br label %46
43: ; preds = %28, %17
%44 = load i32, i32* @stderr
%45 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.9, i64 0, i64 0))
store i32 12, i32* %1
br label %46
46: ; preds = %43, %42
%47 = load i32, i32* %1
ret i32 %47
}

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 = [23 x i8] c" ( 1) Infix to Postfix\00"
@.str.3 = [22 x i8] c" ( 2) Infix to Prefix\00"
@.str.4 = [7 x i8] c" %u%*c\00"
@.str.5 = [5 x i8] c"Bye!\00"
@.str.6 = [12 x i8] c"Expression?\00"
@.str.7 = [6 x i8] c"= %s\0A\00"
@.str.8 = [18 x i8] c"Incorrect Choice!\00"
@stderr = global i32 0
@.str.9 = [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 = %30, %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 ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32* %1)
%9 = load i32, i32* %1
switch i32 %9, label %28 [
i32 0, label %10
i32 1, label %12
i32 2, label %20
]
10: ; preds = %3
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %30
12: ; preds = %3
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
%14 = call i8* (...) @getstr()
%15 = icmp eq i8* %14, null
br i1 %15, label %34, label %16
16: ; preds = %12
%17 = call i8* @in2pos(i8* %14)
%18 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8* %17)
%19 = call i32 @free(i8* %14)
br label %30
20: ; preds = %3
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
%22 = call i8* (...) @getstr()
%23 = icmp eq i8* %22, null
br i1 %23, label %34, label %24
24: ; preds = %20
%25 = call i8* @in2pre(i8* %22)
%26 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8* %25)
%27 = call i32 @free(i8* %22)
br label %30
28: ; preds = %3
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0))
br label %30
30: ; preds = %28, %24, %16, %10
%31 = call i32 @putchar(i8 signext 10)
%32 = load i32, i32* %1
%33 = icmp eq i32 %32, 0
br i1 %33, label %37, label %3
34: ; preds = %20, %12
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.9, i64 0, i64 0))
br label %37
37: ; preds = %30, %34
%38 = phi i32 [ 12, %34 ], [ 0, %30 ]
ret i32 %38
}