#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 calc_rpn();
int /*<<< orphan*/ print_queue();
int /*<<< orphan*/ printf(char *, ...);
double rspop();
int shunting_yard(char const *, int);
int strlen(char const *);
int main() {
  int res;
  const char input[] = "(3+4)*2+2*3";
  int len = strlen(input);
  printf("Processing formula \"%s\"\n\n", input);
  res = shunting_yard(input, len);
  if (res)
    return res;
  printf("Pre-processing complete... Shunting-yard result (reverse Polish "
         "notation):\n");
  print_queue();
  printf("\n");
  res = calc_rpn();
  if (res)
    return res;
  printf("Processing complete...\nRPN result = %.9f\n", rspop());
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe8a(%rip),%rax
mov    %rax,-0x14(%rbp)
mov    0xe88(%rip),%eax
mov    %eax,-0xc(%rbp)
lea    -0x14(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
lea    -0x14(%rbp),%rsi
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x14(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1030 <shunting_yard@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11c5 <main+0x65>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1223 <main+0xc3>
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1080 <print_queue@plt>
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1050 <calc_rpn@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1207 <main+0xa7>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1223 <main+0xc3>
mov    $0x0,%al
call   1070 <rspop@plt>
lea    0xe5d(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
movabs $0x2b322a29342b3328,%rax
2a 32 2b
mov    %rax,0x8(%rsp)
movl   $0x332a32,0x10(%rsp)
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
lea    0xe59(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <shunting_yard@plt>
test   %eax,%eax
jne    120a <main+0x8a>
lea    0xe7e(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   10a0 <print_queue@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1070 <calc_rpn@plt>
test   %eax,%eax
jne    120a <main+0x8a>
xor    %eax,%eax
call   1090 <rspop@plt>
lea    0xe25(%rip),%rdi
mov    $0x1,%al
call   1080 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.input = [12 x i8] c"(3+4)*2+2*3\00"
@.str = [26 x i8] c"Processing formula \22%s\22\0A\0A\00"
@.str.1 = [76 x i8] c"Pre-processing complete... Shunting-yard result (reverse Polish notation):\0A\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [42 x i8] c"Processing complete...\0ARPN result = %.9f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [12 x i8]
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [12 x i8]* %3 to i8*
%6 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %4
%8 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%11 = load i32, i32* %4
%12 = call i32 @shunting_yard(i8* %10, i32 %11)
store i32 %12, i32* %2
%13 = load i32, i32* %2
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %0
%16 = load i32, i32* %2
store i32 %16, i32* %1
br label %29
17: ; preds = %0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 (...) @print_queue()
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 (...) @calc_rpn()
store i32 %21, i32* %2
%22 = load i32, i32* %2
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %17
%25 = load i32, i32* %2
store i32 %25, i32* %1
br label %29
26: ; preds = %17
%27 = call double (...) @rspop()
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), double %27)
store i32 0, i32* %1
br label %29
29: ; preds = %26, %24, %15
%30 = load i32, i32* %1
ret i32 %30
}

LLVM IR (-O2):
@__const.main.input = [12 x i8] c"(3+4)*2+2*3\00"
@.str = [26 x i8] c"Processing formula \22%s\22\0A\0A\00"
@.str.3 = [42 x i8] c"Processing complete...\0ARPN result = %.9f\0A\00"
@str = [75 x i8] c"Pre-processing complete... Shunting-yard result (reverse Polish notation):\00"
define i32 @main() {
%1 = alloca [12 x i8]
%2 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%3 = call i32 @strlen(i8* %2)
%4 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %2)
%5 = call i32 @shunting_yard(i8* %2, i32 %3)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %16
7: ; preds = %0
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([75 x i8], [75 x i8]* @str, i64 0, i64 0))
%9 = call i32 (...) @print_queue()
%10 = call i32 @putchar(i32 10)
%11 = call i32 (...) @calc_rpn()
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %7
%14 = call double (...) @rspop()
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), double %14)
br label %16
16: ; preds = %7, %0, %13
%17 = phi i32 [ 0, %13 ], [ %5, %0 ], [ %11, %7 ]
ret i32 %17
}