#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 convertToPostfixFromInfix(char *, int);
char getchar();
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
scalar_t__ realloc(char *, int);
int calculateExpression() {
  int sizeOfExpression = 20, currentInputSize = 0;
  char ch;
  char *expression = (char *)malloc(sizeOfExpression * sizeof(char));
  printf("Input Expression, end with symbol '=': \n");
  while ((ch = getchar()) != '=') {
    if (sizeOfExpression == currentInputSize + 1) {
      sizeOfExpression *= 2;
      expression = (char *)realloc(expression, sizeOfExpression);
    }
    expression[currentInputSize++] = ch;
    expression[currentInputSize] = '\0';
  }
  return convertToPostfixFromInfix(expression, currentInputSize + 1);
}


x86 assembly (clang, -O0):
<calculateExpression>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x14,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
lea    0xe80(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x9(%rbp)
movsbl %al,%eax
cmp    $0x3d,%eax
je     11ee <calculateExpression+0x9e>
mov    -0x4(%rbp),%eax
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jne    11c5 <calculateExpression+0x75>
mov    -0x4(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1070 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x9(%rbp),%dl
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x8(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
movslq -0x8(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1185 <calculateExpression+0x35>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
add    $0x1,%esi
call   1060 <convertToPostfixFromInfix@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculateExpression>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x14,%r14d
mov    $0x14,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
lea    0xe8f(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0x3d,%al
jne    119a <calculateExpression+0x4a>
mov    $0x1,%ebp
mov    %r15,%rdi
mov    %ebp,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <convertToPostfixFromInfix@plt>
mov    %eax,%ebx
mov    $0x1,%ebp
jmp    11cb <calculateExpression+0x7b>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %bl,-0x1(%r15,%rbp,1)
movb   $0x0,(%r15,%rbp,1)
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ebx
add    $0x1,%rbp
cmp    $0x3d,%al
je     1186 <calculateExpression+0x36>
mov    %r14d,%eax
cmp    %rax,%rbp
jne    11b0 <calculateExpression+0x60>
add    %r14d,%r14d
mov    %r15,%rdi
mov    %r14d,%esi
call   1070 <realloc@plt>
mov    %rax,%r15
jmp    11b0 <calculateExpression+0x60>

LLVM IR (-O0):
@.str = [41 x i8] c"Input Expression, end with symbol '=': \0A\00"
define i32 @calculateExpression() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8
%4 = alloca i8*
store i32 20, i32* %1
store i32 0, i32* %2
%5 = load i32, i32* %1
%6 = sext i32 %5 to i64
%7 = mul i64 %6, 1
%8 = trunc i64 %7 to i32
%9 = call i64 @malloc(i32 %8)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %4
%11 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %28, %0
%13 = call signext i8 (...) @getchar()
store i8 %13, i8* %3
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 61
br i1 %15, label %16, label %39
16: ; preds = %12
%17 = load i32, i32* %1
%18 = load i32, i32* %2
%19 = add nsw i32 %18, 1
%20 = icmp eq i32 %17, %19
br i1 %20, label %21, label %28
21: ; preds = %16
%22 = load i32, i32* %1
%23 = mul nsw i32 %22, 2
store i32 %23, i32* %1
%24 = load i8*, i8** %4
%25 = load i32, i32* %1
%26 = call i64 @realloc(i8* %24, i32 %25)
%27 = inttoptr i64 %26 to i8*
store i8* %27, i8** %4
br label %28
28: ; preds = %21, %16
%29 = load i8, i8* %3
%30 = load i8*, i8** %4
%31 = load i32, i32* %2
%32 = add nsw i32 %31, 1
store i32 %32, i32* %2
%33 = sext i32 %31 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
store i8 %29, i8* %34
%35 = load i8*, i8** %4
%36 = load i32, i32* %2
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
store i8 0, i8* %38
br label %12
39: ; preds = %12
%40 = load i8*, i8** %4
%41 = load i32, i32* %2
%42 = add nsw i32 %41, 1
%43 = call i32 @convertToPostfixFromInfix(i8* %40, i32 %42)
ret i32 %43
}

LLVM IR (-O2):
@str = [40 x i8] c"Input Expression, end with symbol '=': \00"
define i32 @calculateExpression() {
%1 = tail call i64 @malloc(i32 20)
%2 = inttoptr i64 %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
%4 = tail call signext i8 (...) @getchar()
%5 = icmp eq i8 %4, 61
br i1 %5, label %28, label %6
6: ; preds = %0, %18
%7 = phi i64 [ %11, %18 ], [ 0, %0 ]
%8 = phi i8 [ %23, %18 ], [ %4, %0 ]
%9 = phi i8* [ %20, %18 ], [ %2, %0 ]
%10 = phi i32 [ %19, %18 ], [ 20, %0 ]
%11 = add nuw i64 %7, 1
%12 = zext i32 %10 to i64
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %18
14: ; preds = %6
%15 = shl nsw i32 %10, 1
%16 = tail call i64 @realloc(i8* %9, i32 %15)
%17 = inttoptr i64 %16 to i8*
br label %18
18: ; preds = %14, %6
%19 = phi i32 [ %15, %14 ], [ %10, %6 ]
%20 = phi i8* [ %17, %14 ], [ %9, %6 ]
%21 = getelementptr inbounds i8, i8* %20, i64 %7
store i8 %8, i8* %21
%22 = getelementptr inbounds i8, i8* %20, i64 %11
store i8 0, i8* %22
%23 = tail call signext i8 (...) @getchar()
%24 = icmp eq i8 %23, 61
br i1 %24, label %25, label %6
25: ; preds = %18
%26 = trunc i64 %11 to i32
%27 = add i32 %26, 1
br label %28
28: ; preds = %25, %0
%29 = phi i32 [ 1, %0 ], [ %27, %25 ]
%30 = phi i8* [ %2, %0 ], [ %20, %25 ]
%31 = tail call i32 @convertToPostfixFromInfix(i8* %30, i32 %29)
ret i32 %31
}