#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ infix_to_postfix(char *);
int /*<<< orphan*/ printf(char *, ...);
long solve_postfix(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
char *strndup(char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  char *expression;
  long result = 0;
  if (argc < 2) {
    printf("Usage: %s expression\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  if (!(expression = strndup(argv[1], strlen(argv[1])))) {
    fprintf(stderr, ("main: Out of memory!\n"));
    exit(EXIT_FAILURE);
  }
  result = solve_postfix(infix_to_postfix(expression));
  printf("Result: %ld\n", result);
  free(expression);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11cb <main+0x4b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
call   1060 <strndup@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1220 <main+0xa0>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
lea    0xe09(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1070 <infix_to_postfix@plt>
mov    %eax,%edi
call   1090 <solve_postfix@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x1,%edi
jle    11d0 <main+0x50>
mov    0x8(%rsi),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <strndup@plt>
test   %rax,%rax
je     11e3 <main+0x63>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <infix_to_postfix@plt>
mov    %eax,%edi
call   1090 <solve_postfix@plt>
lea    0xe72(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    (%rsi),%rsi
lea    0xe26(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11f8 <main+0x78>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
lea    0xe23(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"Usage: %s expression\0A\00"
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.1 = [22 x i8] c"main: Out of memory!\0A\00"
@.str.2 = [13 x i8] c"Result: %ld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %7
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @strlen(i8* %23)
%25 = call i8* @strndup(i8* %20, i32 %24)
store i8* %25, i8** %6
%26 = icmp ne i8* %25, null
br i1 %26, label %32, label %27
27: ; preds = %17
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %17
%33 = load i8*, i8** %6
%34 = call i32 @infix_to_postfix(i8* %33)
%35 = call i64 @solve_postfix(i32 %34)
store i64 %35, i64* %7
%36 = load i64, i64* %7
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i64 %36)
%38 = load i8*, i8** %6
%39 = call i32 @free(i8* %38)
ret i32 0
}

LLVM IR (-O2):
@.str = [22 x i8] c"Usage: %s expression\0A\00"
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.1 = [22 x i8] c"main: Out of memory!\0A\00"
@.str.2 = [13 x i8] c"Result: %ld\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @strlen(i8* %11)
%13 = tail call i8* @strndup(i8* %11, i32 %12)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %20
15: ; preds = %9
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = tail call i32 @exit(i32 %18)
unreachable
20: ; preds = %9
%21 = tail call i32 @infix_to_postfix(i8* %13)
%22 = tail call i64 @solve_postfix(i32 %21)
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i64 %22)
%24 = tail call i32 @free(i8* %13)
ret i32 0
}