#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 EvaluateHighestPriorityOperator(int *, char *, int *, int);
int ParseExpression(char *, int *, char *, int *);
int /*<<< orphan*/ PrintExpression(int *, char *, int *, int);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int main() {
  char expression[1000] = {0};
  int numbers[1000] = {0};
  char operators[1000] = {0};
  int priorities[1000] = {0};
  int op_count = 0;
  scanf("%1000s", expression);
  printf("input expression is: '%s'\n", expression);
  op_count = ParseExpression(expression, numbers, operators, priorities);
  PrintExpression(numbers, operators, priorities, op_count);
  for (; op_count > 0;) {
    op_count = EvaluateHighestPriorityOperator(numbers, operators, priorities,
                                               op_count);
    PrintExpression(numbers, operators, priorities, op_count);
  }
  if (op_count == 0) {
    printf("result of expression '%s' is %d\n", expression, numbers[0]);
  } else {
    printf("failed to evaluate expression '%s'\n", expression);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2730,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x3f0(%rbp),%rdi
xor    %esi,%esi
mov    $0x3e8,%edx
call   1050 <memset@plt>
lea    -0x1390(%rbp),%rdi
xor    %esi,%esi
mov    $0xfa0,%edx
call   1050 <memset@plt>
lea    -0x1780(%rbp),%rdi
xor    %esi,%esi
mov    $0x3e8,%edx
call   1050 <memset@plt>
lea    -0x2720(%rbp),%rdi
xor    %esi,%esi
mov    $0xfa0,%edx
call   1050 <memset@plt>
movl   $0x0,-0x2724(%rbp)
lea    -0x3f0(%rbp),%rsi
lea    0xe2a(%rip),%rdi
call   1060 <scanf@plt>
lea    -0x3f0(%rbp),%rsi
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x3f0(%rbp),%rdi
lea    -0x1390(%rbp),%rsi
lea    -0x1780(%rbp),%rdx
lea    -0x2720(%rbp),%rcx
call   1070 <ParseExpression@plt>
mov    %eax,-0x2724(%rbp)
lea    -0x1390(%rbp),%rdi
lea    -0x1780(%rbp),%rsi
lea    -0x2720(%rbp),%rdx
mov    -0x2724(%rbp),%ecx
call   1080 <PrintExpression@plt>
cmpl   $0x0,-0x2724(%rbp)
jle    128f <main+0x12f>
lea    -0x1390(%rbp),%rdi
lea    -0x1780(%rbp),%rsi
lea    -0x2720(%rbp),%rdx
mov    -0x2724(%rbp),%ecx
call   1030 <EvaluateHighestPriorityOperator@plt>
mov    %eax,-0x2724(%rbp)
lea    -0x1390(%rbp),%rdi
lea    -0x1780(%rbp),%rsi
lea    -0x2720(%rbp),%rdx
mov    -0x2724(%rbp),%ecx
call   1080 <PrintExpression@plt>
jmp    1237 <main+0xd7>
cmpl   $0x0,-0x2724(%rbp)
jne    12bc <main+0x15c>
lea    -0x3f0(%rbp),%rsi
mov    -0x1390(%rbp),%edx
lea    0xd72(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12d1 <main+0x171>
lea    -0x3f0(%rbp),%rsi
lea    0xd79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x2730,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x2728,%rsp
mov    %rsp,%rbx
mov    $0x3e8,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
lea    0x7e0(%rsp),%r14
mov    $0xfa0,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
lea    0x3f0(%rsp),%r15
mov    $0x3e8,%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
lea    0x1780(%rsp),%r12
mov    $0xfa0,%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
lea    0xe34(%rip),%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
lea    0xe2c(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
call   1070 <ParseExpression@plt>
mov    %eax,%ebx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %eax,%ecx
call   1080 <PrintExpression@plt>
test   %ebx,%ebx
jle    1256 <main+0xf6>
lea    0x7e0(%rsp),%r14
lea    0x3f0(%rsp),%r15
lea    0x1780(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %ebx,%ecx
call   1030 <EvaluateHighestPriorityOperator@plt>
mov    %eax,%ebx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %eax,%ecx
call   1080 <PrintExpression@plt>
test   %ebx,%ebx
jg     1230 <main+0xd0>
test   %ebx,%ebx
je     126d <main+0x10d>
lea    0xde2(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1285 <main+0x125>
mov    0x7e0(%rsp),%edx
lea    0xda7(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x2728,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%1000s\00"
@.str.1 = [27 x i8] c"input expression is: '%s'\0A\00"
@.str.2 = [33 x i8] c"result of expression '%s' is %d\0A\00"
@.str.3 = [36 x i8] c"failed to evaluate expression '%s'\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1000 x i8]
%3 = alloca [1000 x i32]
%4 = alloca [1000 x i8]
%5 = alloca [1000 x i32]
%6 = alloca i32
store i32 0, i32* %1
%7 = bitcast [1000 x i8]* %2 to i8*
%8 = bitcast [1000 x i32]* %3 to i8*
%9 = bitcast [1000 x i8]* %4 to i8*
%10 = bitcast [1000 x i32]* %5 to i8*
store i32 0, i32* %6
%11 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%12 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%14 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%16 = getelementptr inbounds [1000 x i32], [1000 x i32]* %3, i64 0, i64 0
%17 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%18 = getelementptr inbounds [1000 x i32], [1000 x i32]* %5, i64 0, i64 0
%19 = call i32 @ParseExpression(i8* %15, i32* %16, i8* %17, i32* %18)
store i32 %19, i32* %6
%20 = getelementptr inbounds [1000 x i32], [1000 x i32]* %3, i64 0, i64 0
%21 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%22 = getelementptr inbounds [1000 x i32], [1000 x i32]* %5, i64 0, i64 0
%23 = load i32, i32* %6
%24 = call i32 @PrintExpression(i32* %20, i8* %21, i32* %22, i32 %23)
br label %25
25: ; preds = %28, %0
%26 = load i32, i32* %6
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %39
28: ; preds = %25
%29 = getelementptr inbounds [1000 x i32], [1000 x i32]* %3, i64 0, i64 0
%30 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%31 = getelementptr inbounds [1000 x i32], [1000 x i32]* %5, i64 0, i64 0
%32 = load i32, i32* %6
%33 = call i32 @EvaluateHighestPriorityOperator(i32* %29, i8* %30, i32* %31, i32 %32)
store i32 %33, i32* %6
%34 = getelementptr inbounds [1000 x i32], [1000 x i32]* %3, i64 0, i64 0
%35 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%36 = getelementptr inbounds [1000 x i32], [1000 x i32]* %5, i64 0, i64 0
%37 = load i32, i32* %6
%38 = call i32 @PrintExpression(i32* %34, i8* %35, i32* %36, i32 %37)
br label %25
39: ; preds = %25
%40 = load i32, i32* %6
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %47
42: ; preds = %39
%43 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%44 = getelementptr inbounds [1000 x i32], [1000 x i32]* %3, i64 0, i64 0
%45 = load i32, i32* %44
%46 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %43, i32 %45)
br label %50
47: ; preds = %39
%48 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%49 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* %48)
br label %50
50: ; preds = %47, %42
%51 = load i32, i32* %1
ret i32 %51
}

LLVM IR (-O2):
@.str = [7 x i8] c"%1000s\00"
@.str.1 = [27 x i8] c"input expression is: '%s'\0A\00"
@.str.2 = [33 x i8] c"result of expression '%s' is %d\0A\00"
@.str.3 = [36 x i8] c"failed to evaluate expression '%s'\0A\00"
define i32 @main() {
%1 = alloca [1000 x i8]
%2 = alloca [1000 x i32]
%3 = alloca [1000 x i8]
%4 = alloca [1000 x i32]
%5 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%6 = bitcast [1000 x i32]* %2 to i8*
%7 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%8 = bitcast [1000 x i32]* %4 to i8*
%9 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %5)
%10 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%11 = getelementptr inbounds [1000 x i32], [1000 x i32]* %2, i64 0, i64 0
%12 = getelementptr inbounds [1000 x i32], [1000 x i32]* %4, i64 0, i64 0
%13 = call i32 @ParseExpression(i8* %5, i32* %11, i8* %7, i32* %12)
%14 = call i32 @PrintExpression(i32* %11, i8* %7, i32* %12, i32 %13)
%15 = icmp sgt i32 %13, 0
br i1 %15, label %16, label %21
16: ; preds = %0, %16
%17 = phi i32 [ %18, %16 ], [ %13, %0 ]
%18 = call i32 @EvaluateHighestPriorityOperator(i32* %11, i8* %7, i32* %12, i32 %17)
%19 = call i32 @PrintExpression(i32* %11, i8* %7, i32* %12, i32 %18)
%20 = icmp sgt i32 %18, 0
br i1 %20, label %16, label %21
21: ; preds = %16, %0
%22 = phi i32 [ %13, %0 ], [ %18, %16 ]
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i32, i32* %11
%26 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %5, i32 %25)
br label %29
27: ; preds = %21
%28 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* %5)
br label %29
29: ; preds = %27, %24
ret i32 0
}