#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 evaluate_postfix(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int getopt(int, char **, char *);
int /*<<< orphan*/ printFile(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ test_createStack();
int /*<<< orphan*/ test_initalizeStack();
int /*<<< orphan*/ test_pop();
int /*<<< orphan*/ test_push();
int /*<<< orphan*/ test_top();
int /*<<< orphan*/ test_topAndPop();
int main(int argc, char **argv) {
  extern char *optarg;
  int c, err = 0;
  char *filename;
  static char usage[] = "usage: %s [-b filename] [-s]\n";
  while ((c = getopt(argc, argv, "b:s")) != -1) {
    switch (c) {
    case 'b':
      filename = optarg;
      printf("Postfix expression: ");
      printFile(filename);
      int res = evaluate_postfix(filename);
      printf("res: %d\n", res);
      break;
    case 's':
      printf("///////////////////////\n");
      printf("// STACK TEST\n");
      printf("///////////////////////\n\n");
      test_initalizeStack();
      printf("\n");
      test_createStack();
      printf("\n");
      test_push();
      printf("\n");
      test_top();
      printf("\n");
      test_pop();
      printf("\n");
      test_topAndPop();
      printf("\n");
      break;
    case '?':
      err = 1;
      break;
    }
  }
  if (err) {
    fprintf(stderr, usage, argv[0]);
    exit(1);
  }
  exit(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)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe15(%rip),%rdx
call   10c0 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     1332 <main+0x172>
mov    -0x14(%rbp),%eax
mov    %eax,-0x28(%rbp)
sub    $0x3f,%eax
je     1326 <main+0x166>
jmp    1210 <main+0x50>
mov    -0x28(%rbp),%eax
sub    $0x62,%eax
je     1232 <main+0x72>
jmp    1221 <main+0x61>
mov    -0x28(%rbp),%eax
sub    $0x73,%eax
je     1279 <main+0xb9>
jmp    132d <main+0x16d>
mov    0x2da7(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
lea    0xdbd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <printFile@plt>
mov    -0x20(%rbp),%rdi
call   1080 <evaluate_postfix@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    0xdac(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    132d <main+0x16d>
lea    0xda2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdad(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdae(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   10a0 <test_initalizeStack@plt>
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <test_createStack@plt>
lea    0xd9c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   10b0 <test_push@plt>
lea    0xd87(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   10e0 <test_top@plt>
lea    0xd72(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1070 <test_pop@plt>
lea    0xd5d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <test_topAndPop@plt>
lea    0xd48(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    132d <main+0x16d>
movl   $0x1,-0x18(%rbp)
jmp    11dd <main+0x1d>
cmpl   $0x0,-0x18(%rbp)
je     1362 <main+0x1a2>
mov    0x2c95(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0x2d3d(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    $0x1,%al
mov    %eax,0x4(%rsp)
lea    0xe03(%rip),%r14
lea    0xe36(%rip),%r15
lea    0xe3d(%rip),%r12
jmp    1251 <main+0x71>
nopl   (%rax)
cmp    $0x62,%eax
jne    12ef <main+0x10f>
mov    0x2dc0(%rip),%rax
mov    (%rax),%r13
lea    0xdda(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r13,%rdi
call   1050 <printFile@plt>
mov    %r13,%rdi
call   10a0 <evaluate_postfix@plt>
lea    0xdd1(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   10e0 <getopt@plt>
cmp    $0x72,%eax
jle    1210 <main+0x30>
cmp    $0x73,%eax
jne    1251 <main+0x71>
lea    0xdb3(%rip),%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
call   1040 <puts@plt>
mov    %r12,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   10c0 <test_initalizeStack@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1080 <test_createStack@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   10d0 <test_push@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1100 <test_top@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1090 <test_pop@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1070 <test_topAndPop@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1251 <main+0x71>
cmp    $0x3f,%eax
je     12ff <main+0x11f>
cmp    $0xffffffff,%eax
jne    1251 <main+0x71>
jmp    130c <main+0x12c>
movl   $0x0,0x4(%rsp)
jmp    1251 <main+0x71>
testb  $0x1,0x4(%rsp)
je     131a <main+0x13a>
xor    %edi,%edi
call   10f0 <exit@plt>
mov    0x2cb7(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0x2d73(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@main.usage = internal global [30 x i8] c"usage: %s [-b filename] [-s]\0A\00"
@.str = [4 x i8] c"b:s\00"
@optarg = external global i8*
@.str.1 = [21 x i8] c"Postfix expression: \00"
@.str.2 = [9 x i8] c"res: %d\0A\00"
@.str.3 = [25 x i8] c"///////////////////////\0A\00"
@.str.4 = [15 x i8] c"// STACK TEST\0A\00"
@.str.5 = [26 x i8] c"///////////////////////\0A\0A\00"
@.str.6 = [2 x i8] c"\0A\00"
@stderr = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
br label %10
10: ; preds = %43, %2
%11 = load i32, i32* %4
%12 = load i8**, i8*** %5
%13 = call i32 @getopt(i32 %11, i8** %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 %13, i32* %6
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %44
15: ; preds = %10
%16 = load i32, i32* %6
switch i32 %16, label %43 [
i32 98, label %17
i32 115, label %26
i32 63, label %42
]
17: ; preds = %15
%18 = load i8*, i8** @optarg
store i8* %18, i8** %8
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%20 = load i8*, i8** %8
%21 = call i32 @printFile(i8* %20)
%22 = load i8*, i8** %8
%23 = call i32 @evaluate_postfix(i8* %22)
store i32 %23, i32* %9
%24 = load i32, i32* %9
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %24)
br label %43
26: ; preds = %15
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
%30 = call i32 (...) @test_initalizeStack()
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%32 = call i32 (...) @test_createStack()
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%34 = call i32 (...) @test_push()
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%36 = call i32 (...) @test_top()
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%38 = call i32 (...) @test_pop()
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%40 = call i32 (...) @test_topAndPop()
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %43
42: ; preds = %15
store i32 1, i32* %7
br label %43
43: ; preds = %15, %42, %26, %17
br label %10
44: ; preds = %10
%45 = load i32, i32* %7
%46 = icmp ne i32 %45, 0
br i1 %46, label %47, label %54
47: ; preds = %44
%48 = load i32, i32* @stderr
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 0
%51 = load i8*, i8** %50
%52 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @main.usage, i64 0, i64 0), i8* %51)
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %44
%55 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@main.usage = internal global [30 x i8] c"usage: %s [-b filename] [-s]\0A\00"
@.str = [4 x i8] c"b:s\00"
@optarg = external global i8*
@.str.1 = [21 x i8] c"Postfix expression: \00"
@.str.2 = [9 x i8] c"res: %d\0A\00"
@stderr = global i32 0
@str = [24 x i8] c"///////////////////////\00"
@str.7 = [14 x i8] c"// STACK TEST\00"
@str.8 = [25 x i8] c"///////////////////////\0A\00"
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %5, %2
%4 = phi i1 [ true, %2 ], [ false, %5 ]
br label %5
5: ; preds = %7, %3
%6 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
switch i32 %6, label %7 [
i32 -1, label %30
i32 98, label %8
i32 115, label %14
i32 63, label %3
]
7: ; preds = %5, %14, %8
br label %5
8: ; preds = %5
%9 = load i8*, i8** @optarg
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 @printFile(i8* %9)
%12 = tail call i32 @evaluate_postfix(i8* %9)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %12)
br label %7
14: ; preds = %5
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.7, i64 0, i64 0))
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.8, i64 0, i64 0))
%18 = tail call i32 (...) @test_initalizeStack()
%19 = tail call i32 @putchar(i32 10)
%20 = tail call i32 (...) @test_createStack()
%21 = tail call i32 @putchar(i32 10)
%22 = tail call i32 (...) @test_push()
%23 = tail call i32 @putchar(i32 10)
%24 = tail call i32 (...) @test_top()
%25 = tail call i32 @putchar(i32 10)
%26 = tail call i32 (...) @test_pop()
%27 = tail call i32 @putchar(i32 10)
%28 = tail call i32 (...) @test_topAndPop()
%29 = tail call i32 @putchar(i32 10)
br label %7
30: ; preds = %5
br i1 %4, label %36, label %31
31: ; preds = %30
%32 = load i32, i32* @stderr
%33 = load i8*, i8** %1
%34 = tail call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @main.usage, i64 0, i64 0), i8* %33)
%35 = tail call i32 @exit(i32 1)
unreachable
36: ; preds = %30
%37 = tail call i32 @exit(i32 0)
unreachable
}