#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 */
struct Context {
  int dummy;
};
typedef int ssize_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
struct Context *createContext();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ freeContext(struct Context *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
double interpret(struct Context *, char *);
int /*<<< orphan*/ printf(char *, double, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
char *strchr(char *, char);
char *strdup(char *);
int main(int argc, char *argv[]) {
  FILE *input_file = stdin;
  if (argc == 2) {
    input_file = fopen(argv[1], "r");
    if (!input_file) {
      fprintf(stderr, "Unable to open file %s!\n", argv[1]);
      return EXIT_FAILURE;
    }
  }
  if (argc > 2) {
    fprintf(stderr, "Usage: %s [filename]\nToo many arguments!", argv[0]);
    return EXIT_FAILURE;
  }
  size_t len;
  ssize_t read;
  char *line = NULL;
  struct Context *ctx = createContext();
  while ((read = getline(&line, &len, input_file)) != -1) {
    char *pos;
    if ((pos = strchr(line, '\n')) != NULL) {
      *pos = '\0';
    }
    char *line_copy = strdup(line);
    printf("%f // %s\n", interpret(ctx, line_copy), line);
    free(line_copy);
  }
  free(line);
  freeContext(ctx);
  fclose(input_file);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e1b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1234 <main+0x84>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe13(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    122f <main+0x7f>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xde9(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2dab(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    131d <main+0x16d>
jmp    1234 <main+0x84>
cmpl   $0x2,-0x8(%rbp)
jle    126b <main+0xbb>
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdc6(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d6f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    131d <main+0x16d>
movq   $0x0,-0x30(%rbp)
mov    $0x0,%al
call   10a0 <createContext@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdx
lea    -0x30(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   10c0 <getline@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
je     12f6 <main+0x146>
mov    -0x30(%rbp),%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
je     12be <main+0x10e>
mov    -0x40(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rdi
call   10d0 <strdup@plt>
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   10b0 <interpret@plt>
mov    -0x30(%rbp),%rsi
lea    0xd61(%rip),%rdi
call   1060 <printf@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
jmp    127e <main+0xce>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1080 <freeContext@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2cb0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11f4 <main+0x44>
mov    0x8(%rbx),%rdi
lea    0xe2f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1224 <main+0x74>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xe10(%rip),%rsi
jmp    1209 <main+0x59>
jle    121a <main+0x6a>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe12(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2dbb(%rip),%rax
jmp    12f0 <main+0x140>
mov    0x2dc7(%rip),%rax
mov    (%rax),%r14
movq   $0x0,0x8(%rsp)
xor    %eax,%eax
call   10a0 <createContext@plt>
mov    %rax,%rbx
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %r14,%rdx
call   10c0 <getline@plt>
cmp    $0xffffffff,%eax
je     12cf <main+0x11f>
lea    0xdeb(%rip),%r15
lea    0x8(%rsp),%r12
lea    0x10(%rsp),%r13
jmp    12ae <main+0xfe>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbp,%rdi
call   10d0 <strdup@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %rax,%rsi
call   10b0 <interpret@plt>
mov    0x8(%rsp),%rsi
mov    %r15,%rdi
call   1060 <printf@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
call   10c0 <getline@plt>
cmp    $0xffffffff,%eax
je     12cf <main+0x11f>
mov    0x8(%rsp),%rbp
mov    %rbp,%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1270 <main+0xc0>
movb   $0x0,(%rax)
mov    0x8(%rsp),%rbp
jmp    1270 <main+0xc0>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1080 <freeContext@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    0x2cd8(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.Context = type { i32 }
@stdin = global i32* null
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [25 x i8] c"Unable to open file %s!\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [41 x i8] c"Usage: %s [filename]\0AToo many arguments!\00"
@.str.3 = [10 x i8] c"%f // %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i8*
%10 = alloca %struct.Context*
%11 = alloca i8*
%12 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32*, i32** @stdin
store i32* %13, i32** %6
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 2
br i1 %15, label %16, label %31
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %20, i32** %6
%21 = load i32*, i32** %6
%22 = icmp ne i32* %21, null
br i1 %22, label %30, label %23
23: ; preds = %16
%24 = load i32, i32* @stderr
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = load i32, i32* @EXIT_FAILURE
store i32 %29, i32* %3
br label %71
30: ; preds = %16
br label %31
31: ; preds = %30, %2
%32 = load i32, i32* %4
%33 = icmp sgt i32 %32, 2
br i1 %33, label %34, label %41
34: ; preds = %31
%35 = load i32, i32* @stderr
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 0
%38 = load i8*, i8** %37
%39 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* %38)
%40 = load i32, i32* @EXIT_FAILURE
store i32 %40, i32* %3
br label %71
41: ; preds = %31
store i8* null, i8** %9
%42 = call %struct.Context* (...) @createContext()
store %struct.Context* %42, %struct.Context** %10
br label %43
43: ; preds = %53, %41
%44 = load i32*, i32** %6
%45 = call i32 @getline(i8** %9, i64* %7, i32* %44)
store i32 %45, i32* %8
%46 = icmp ne i32 %45, -1
br i1 %46, label %47, label %63
47: ; preds = %43
%48 = load i8*, i8** %9
%49 = call i8* @strchr(i8* %48, i8 signext 10)
store i8* %49, i8** %11
%50 = icmp ne i8* %49, null
br i1 %50, label %51, label %53
51: ; preds = %47
%52 = load i8*, i8** %11
store i8 0, i8* %52
br label %53
53: ; preds = %51, %47
%54 = load i8*, i8** %9
%55 = call i8* @strdup(i8* %54)
store i8* %55, i8** %12
%56 = load %struct.Context*, %struct.Context** %10
%57 = load i8*, i8** %12
%58 = call double @interpret(%struct.Context* %56, i8* %57)
%59 = load i8*, i8** %9
%60 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), double %58, i8* %59)
%61 = load i8*, i8** %12
%62 = call i32 @free(i8* %61)
br label %43
63: ; preds = %43
%64 = load i8*, i8** %9
%65 = call i32 @free(i8* %64)
%66 = load %struct.Context*, %struct.Context** %10
%67 = call i32 @freeContext(%struct.Context* %66)
%68 = load i32*, i32** %6
%69 = call i32 @fclose(i32* %68)
%70 = load i32, i32* @EXIT_SUCCESS
store i32 %70, i32* %3
br label %71
71: ; preds = %63, %34, %23
%72 = load i32, i32* %3
ret i32 %72
}

LLVM IR (-O2):
%struct.Context = type { i32 }
@stdin = global i32* null
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [25 x i8] c"Unable to open file %s!\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [41 x i8] c"Usage: %s [filename]\0AToo many arguments!\00"
@.str.3 = [10 x i8] c"%f // %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %6, label %16
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, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %24
11: ; preds = %6
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %7
%14 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
br label %52
16: ; preds = %2
%17 = load i32*, i32** @stdin
%18 = icmp sgt i32 %0, 2
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %1
%22 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = load i32, i32* @EXIT_FAILURE
br label %52
24: ; preds = %6, %16
%25 = phi i32* [ %17, %16 ], [ %9, %6 ]
%26 = bitcast i64* %3 to i8*
%27 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%28 = tail call %struct.Context* (...) @createContext()
%29 = call i32 @getline(i8** %4, i64* %3, i32* %25)
%30 = icmp eq i32 %29, -1
br i1 %30, label %46, label %31
31: ; preds = %24, %37
%32 = load i8*, i8** %4
%33 = call i8* @strchr(i8* dereferenceable(1) %32, i8 signext 10)
%34 = icmp eq i8* %33, null
br i1 %34, label %37, label %35
35: ; preds = %31
store i8 0, i8* %33
%36 = load i8*, i8** %4
br label %37
37: ; preds = %35, %31
%38 = phi i8* [ %36, %35 ], [ %32, %31 ]
%39 = call i8* @strdup(i8* %38)
%40 = call double @interpret(%struct.Context* %28, i8* %39)
%41 = load i8*, i8** %4
%42 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), double %40, i8* %41)
%43 = call i32 @free(i8* %39)
%44 = call i32 @getline(i8** %4, i64* %3, i32* %25)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %31
46: ; preds = %37, %24
%47 = load i8*, i8** %4
%48 = call i32 @free(i8* %47)
%49 = call i32 @freeContext(%struct.Context* %28)
%50 = call i32 @fclose(i32* %25)
%51 = load i32, i32* @EXIT_SUCCESS
br label %52
52: ; preds = %46, %19, %11
%53 = phi i32 [ %23, %19 ], [ %51, %46 ], [ %15, %11 ]
ret i32 %53
}