#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int eval(char *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *, ...);
int strlen(char *);
char *to_postfix(char *);
int main(int argc, char *argv[]) {
  char buffer[100];
  if (argc != 2) {
    printf("correct ussage: %s <input file>\n", argv[0]);
    return 1;
  }
  FILE *fp = fopen(argv[1], "r");
  if (fp == NULL) {
    printf("unable to open file: %s\n", argv[1]);
    return 1;
  }
  while (fgets(buffer, 100, fp)) {
    if (buffer[strlen(buffer) - 1] == '\n') {
      buffer[strlen(buffer) - 1] = '\0';
    }
    char *postfix = to_postfix(buffer);
    int result = eval(postfix);
    printf("%s = %d\n", buffer, result);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11a4 <main+0x44>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1288 <main+0x128>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe6e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
jne    11ef <main+0x8f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1288 <main+0x128>
jmp    11f4 <main+0x94>
lea    -0x80(%rbp),%rdi
mov    -0x88(%rbp),%rdx
mov    $0x64,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1281 <main+0x121>
lea    -0x80(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x80(%rbp,%rax,1),%eax
cmp    $0xa,%eax
jne    1242 <main+0xe2>
lea    -0x80(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x80(%rbp,%rax,1)
lea    -0x80(%rbp),%rdi
call   1060 <to_postfix@plt>
mov    %rax,-0x90(%rbp)
mov    -0x90(%rbp),%rdi
call   1080 <eval@plt>
mov    %eax,-0x94(%rbp)
lea    -0x80(%rbp),%rsi
mov    -0x94(%rbp),%edx
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11f4 <main+0x94>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    1216 <main+0xb6>
mov    0x8(%rbx),%rdi
lea    0xea0(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     121f <main+0xbf>
mov    %rax,%r14
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1246 <main+0xe6>
lea    0xe87(%rip),%r15
xor    %ebp,%ebp
jmp    11f4 <main+0x94>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1060 <to_postfix@plt>
mov    %rax,%rdi
call   1080 <eval@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1239 <main+0xd9>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    11c0 <main+0x60>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
jmp    11c0 <main+0x60>
lea    0xde3(%rip),%rdi
jmp    122a <main+0xca>
add    $0x8,%rbx
lea    0xdf9(%rip),%rdi
mov    (%rbx),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebp,%ebp
jmp    1239 <main+0xd9>

LLVM IR (-O0):
@.str = [33 x i8] c"correct ussage: %s <input file>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [25 x i8] c"unable to open file: %s\0A\00"
@.str.3 = [9 x i8] c"%s = %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [100 x i8]
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 1, i32* %3
br label %59
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %7
%22 = load i32*, i32** %7
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %29
24: ; preds = %17
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %27)
store i32 1, i32* %3
br label %59
29: ; preds = %17
br label %30
30: ; preds = %50, %29
%31 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%32 = load i32*, i32** %7
%33 = call i64 @fgets(i8* %31, i32 100, i32* %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %58
35: ; preds = %30
%36 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%37 = call i32 @strlen(i8* %36)
%38 = sub nsw i32 %37, 1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 10
br i1 %43, label %44, label %50
44: ; preds = %35
%45 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%46 = call i32 @strlen(i8* %45)
%47 = sub nsw i32 %46, 1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %48
store i8 0, i8* %49
br label %50
50: ; preds = %44, %35
%51 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%52 = call i8* @to_postfix(i8* %51)
store i8* %52, i8** %8
%53 = load i8*, i8** %8
%54 = call i32 @eval(i8* %53)
store i32 %54, i32* %9
%55 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%56 = load i32, i32* %9
%57 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %55, i32 %56)
br label %30
58: ; preds = %30
store i32 0, i32* %3
br label %59
59: ; preds = %58, %24, %12
%60 = load i32, i32* %3
ret i32 %60
}

LLVM IR (-O2):
@.str = [33 x i8] c"correct ussage: %s <input file>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [25 x i8] c"unable to open file: %s\0A\00"
@.str.3 = [9 x i8] c"%s = %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %6, label %32
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %32, label %11
11: ; preds = %6
%12 = call i64 @fgets(i8* %4, i32 100, i32* %9)
%13 = icmp eq i64 %12, 0
br i1 %13, label %37, label %14
14: ; preds = %11, %26
%15 = call i32 @strlen(i8* %4)
%16 = add nsw i32 %15, -1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 10
br i1 %20, label %21, label %26
21: ; preds = %14
%22 = call i32 @strlen(i8* %4)
%23 = add nsw i32 %22, -1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %24
store i8 0, i8* %25
br label %26
26: ; preds = %21, %14
%27 = call i8* @to_postfix(i8* %4)
%28 = call i32 @eval(i8* %27)
%29 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %4, i32 %28)
%30 = call i64 @fgets(i8* %4, i32 100, i32* %9)
%31 = icmp eq i64 %30, 0
br i1 %31, label %37, label %14
32: ; preds = %6, %2
%33 = phi i8** [ %1, %2 ], [ %7, %6 ]
%34 = phi i8* [ getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), %6 ]
%35 = load i8*, i8** %33
%36 = tail call i32 (i8*, i8*, ...) @printf(i8* %34, i8* %35)
br label %37
37: ; preds = %26, %32, %11
%38 = phi i32 [ 0, %11 ], [ 1, %32 ], [ 0, %26 ]
ret i32 %38
}