#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 lobject {
  int dummy;
};
struct lemon {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ builtin_init(struct lemon *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ larray_append(struct lemon *, struct lobject *, int,
                                 struct lobject **);
struct lobject *larray_create(struct lemon *, int /*<<< orphan*/,
                              int /*<<< orphan*/ *);
int /*<<< orphan*/ lemon_add_global(struct lemon *, char *, struct lobject *);
int /*<<< orphan*/ lemon_compile(struct lemon *);
struct lemon *lemon_create();
int /*<<< orphan*/ lemon_destroy(struct lemon *);
int /*<<< orphan*/ lemon_input_set_file(struct lemon *, char *);
int /*<<< orphan*/ lemon_machine_execute(struct lemon *);
int /*<<< orphan*/ lemon_machine_reset(struct lemon *);
struct lobject *lstring_create(struct lemon *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ shell(struct lemon *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  int i;
  struct lemon *lemon;
  struct lobject *objects;
  lemon = lemon_create();
  if (!lemon) {
    printf("create lemon fail\n");
    return 0;
  }
  builtin_init(lemon);
  if (argc < 2) {
    shell(lemon);
  } else {
    if (!lemon_input_set_file(lemon, argv[1])) {
      fprintf(stderr, "open '%s' file fail\n", argv[1]);
      lemon_destroy(lemon);
      exit(1);
    }
    objects = larray_create(lemon, 0, NULL);
    for (i = 1; i < argc; i++) {
      struct lobject *value;
      value = lstring_create(lemon, argv[i], strlen(argv[i]));
      larray_append(lemon, objects, 1, &value);
    }
    lemon_add_global(lemon, "argv", objects);
    if (!lemon_compile(lemon)) {
      fprintf(stderr, "lemon: syntax error\n");
      lemon_destroy(lemon);
      exit(1);
    }
    lemon_machine_reset(lemon);
    lemon_machine_execute(lemon);
  }
  lemon_destroy(lemon);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   10a0 <lemon_create@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1244 <main+0x44>
lea    0xdcd(%rip),%rdi
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13a9 <main+0x1a9>
mov    -0x20(%rbp),%rdi
call   10d0 <builtin_init@plt>
cmpl   $0x2,-0x8(%rbp)
jge    1265 <main+0x65>
mov    -0x20(%rbp),%rdi
call   1110 <shell@plt>
jmp    1399 <main+0x199>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1120 <lemon_input_set_file@plt>
cmp    $0x0,%eax
jne    12b1 <main+0xb1>
mov    0x2d5a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd7c(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   10e0 <lemon_destroy@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <larray_create@plt>
mov    %rax,-0x28(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1337 <main+0x137>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   10c0 <lstring_create@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x1,%edx
lea    -0x30(%rbp),%rcx
call   1090 <larray_append@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    12cb <main+0xcb>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xce2(%rip),%rsi
call   1050 <lemon_add_global@plt>
mov    -0x20(%rbp),%rdi
call   10f0 <lemon_compile@plt>
cmp    $0x0,%eax
jne    1387 <main+0x187>
mov    0x2c7c(%rip),%rax
mov    (%rax),%edi
lea    0xcc0(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   10e0 <lemon_destroy@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1030 <lemon_machine_reset@plt>
mov    -0x20(%rbp),%rdi
call   1080 <lemon_machine_execute@plt>
mov    -0x20(%rbp),%rdi
call   10e0 <lemon_destroy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebp
xor    %eax,%eax
call   10a0 <lemon_create@plt>
test   %rax,%rax
je     1239 <main+0x39>
mov    %rax,%r13
mov    %rax,%rdi
call   10d0 <builtin_init@plt>
cmp    $0x1,%ebp
jg     124a <main+0x4a>
mov    %r13,%rdi
call   1110 <shell@plt>
jmp    12e7 <main+0xe7>
lea    0xdef(%rip),%rdi
call   1030 <puts@plt>
jmp    12ef <main+0xef>
mov    0x8(%r14),%rsi
mov    %r13,%rdi
call   1120 <lemon_input_set_file@plt>
test   %eax,%eax
je     1300 <main+0x100>
mov    %r13,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <larray_create@plt>
mov    %rax,%r15
mov    %ebp,%ebx
mov    $0x1,%r12d
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r14,%r12,8),%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   10c0 <lstring_create@plt>
mov    %rax,(%rsp)
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
mov    %rsp,%rcx
call   1090 <larray_append@plt>
add    $0x1,%r12
cmp    %r12,%rbx
jne    1280 <main+0x80>
lea    0xd55(%rip),%rsi
mov    %r13,%rdi
mov    %r15,%rdx
call   1060 <lemon_add_global@plt>
mov    %r13,%rdi
call   10f0 <lemon_compile@plt>
test   %eax,%eax
je     131d <main+0x11d>
mov    %r13,%rdi
call   1040 <lemon_machine_reset@plt>
mov    %r13,%rdi
call   1080 <lemon_machine_execute@plt>
mov    %r13,%rdi
call   10e0 <lemon_destroy@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cd9(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xcec(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
jmp    1334 <main+0x134>
mov    0x2cbc(%rip),%rax
mov    (%rax),%edi
lea    0xced(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    %r13,%rdi
call   10e0 <lemon_destroy@plt>
mov    $0x1,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.lemon = type { i32 }
%struct.lobject = type { i32 }
@.str = [19 x i8] c"create lemon fail\0A\00"
@stderr = global i32 0
@.str.1 = [21 x i8] c"open '%s' file fail\0A\00"
@.str.2 = [5 x i8] c"argv\00"
@.str.3 = [21 x i8] c"lemon: syntax error\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.lemon*
%8 = alloca %struct.lobject*
%9 = alloca %struct.lobject*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call %struct.lemon* (...) @lemon_create()
store %struct.lemon* %10, %struct.lemon** %7
%11 = load %struct.lemon*, %struct.lemon** %7
%12 = icmp ne %struct.lemon* %11, null
br i1 %12, label %15, label %13
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %87
15: ; preds = %2
%16 = load %struct.lemon*, %struct.lemon** %7
%17 = call i32 @builtin_init(%struct.lemon* %16)
%18 = load i32, i32* %4
%19 = icmp slt i32 %18, 2
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = load %struct.lemon*, %struct.lemon** %7
%22 = call i32 @shell(%struct.lemon* %21)
br label %84
23: ; preds = %15
%24 = load %struct.lemon*, %struct.lemon** %7
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @lemon_input_set_file(%struct.lemon* %24, i8* %27)
%29 = icmp ne i32 %28, 0
br i1 %29, label %39, label %30
30: ; preds = %23
%31 = load i32, i32* @stderr
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %34)
%36 = load %struct.lemon*, %struct.lemon** %7
%37 = call i32 @lemon_destroy(%struct.lemon* %36)
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %23
%40 = load %struct.lemon*, %struct.lemon** %7
%41 = call %struct.lobject* @larray_create(%struct.lemon* %40, i32 0, i32* null)
store %struct.lobject* %41, %struct.lobject** %8
store i32 1, i32* %6
br label %42
42: ; preds = %63, %39
%43 = load i32, i32* %6
%44 = load i32, i32* %4
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %66
46: ; preds = %42
%47 = load %struct.lemon*, %struct.lemon** %7
%48 = load i8**, i8*** %5
%49 = load i32, i32* %6
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8*, i8** %48, i64 %50
%52 = load i8*, i8** %51
%53 = load i8**, i8*** %5
%54 = load i32, i32* %6
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8*, i8** %53, i64 %55
%57 = load i8*, i8** %56
%58 = call i32 @strlen(i8* %57)
%59 = call %struct.lobject* @lstring_create(%struct.lemon* %47, i8* %52, i32 %58)
store %struct.lobject* %59, %struct.lobject** %9
%60 = load %struct.lemon*, %struct.lemon** %7
%61 = load %struct.lobject*, %struct.lobject** %8
%62 = call i32 @larray_append(%struct.lemon* %60, %struct.lobject* %61, i32 1, %struct.lobject** %9)
br label %63
63: ; preds = %46
%64 = load i32, i32* %6
%65 = add nsw i32 %64, 1
store i32 %65, i32* %6
br label %42
66: ; preds = %42
%67 = load %struct.lemon*, %struct.lemon** %7
%68 = load %struct.lobject*, %struct.lobject** %8
%69 = call i32 @lemon_add_global(%struct.lemon* %67, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %struct.lobject* %68)
%70 = load %struct.lemon*, %struct.lemon** %7
%71 = call i32 @lemon_compile(%struct.lemon* %70)
%72 = icmp ne i32 %71, 0
br i1 %72, label %79, label %73
73: ; preds = %66
%74 = load i32, i32* @stderr
%75 = call i32 (i32, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%76 = load %struct.lemon*, %struct.lemon** %7
%77 = call i32 @lemon_destroy(%struct.lemon* %76)
%78 = call i32 @exit(i32 1)
unreachable
79: ; preds = %66
%80 = load %struct.lemon*, %struct.lemon** %7
%81 = call i32 @lemon_machine_reset(%struct.lemon* %80)
%82 = load %struct.lemon*, %struct.lemon** %7
%83 = call i32 @lemon_machine_execute(%struct.lemon* %82)
br label %84
84: ; preds = %79, %20
%85 = load %struct.lemon*, %struct.lemon** %7
%86 = call i32 @lemon_destroy(%struct.lemon* %85)
store i32 0, i32* %3
br label %87
87: ; preds = %84, %13
%88 = load i32, i32* %3
ret i32 %88
}

LLVM IR (-O2):
%struct.lobject = type { i32 }
%struct.lemon = type { i32 }
@stderr = global i32 0
@.str.1 = [21 x i8] c"open '%s' file fail\0A\00"
@.str.2 = [5 x i8] c"argv\00"
@.str.3 = [21 x i8] c"lemon: syntax error\0A\00"
@str = [18 x i8] c"create lemon fail\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.lobject*
%4 = tail call %struct.lemon* (...) @lemon_create()
%5 = icmp eq %struct.lemon* %4, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %51
8: ; preds = %2
%9 = tail call i32 @builtin_init(%struct.lemon* %4)
%10 = icmp slt i32 %0, 2
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @shell(%struct.lemon* %4)
br label %49
13: ; preds = %8
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32 @lemon_input_set_file(%struct.lemon* %4, i8* %15)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %13
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %14
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = tail call i32 @lemon_destroy(%struct.lemon* %4)
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %13
%25 = tail call %struct.lobject* @larray_create(%struct.lemon* %4, i32 0, i32* null)
%26 = bitcast %struct.lobject** %3 to i8*
%27 = zext i32 %0 to i64
br label %28
28: ; preds = %24, %28
%29 = phi i64 [ 1, %24 ], [ %35, %28 ]
%30 = getelementptr inbounds i8*, i8** %1, i64 %29
%31 = load i8*, i8** %30
%32 = call i32 @strlen(i8* %31)
%33 = call %struct.lobject* @lstring_create(%struct.lemon* %4, i8* %31, i32 %32)
store %struct.lobject* %33, %struct.lobject** %3
%34 = call i32 @larray_append(%struct.lemon* %4, %struct.lobject* %25, i32 1, %struct.lobject** %3)
%35 = add nuw nsw i64 %29, 1
%36 = icmp eq i64 %35, %27
br i1 %36, label %37, label %28
37: ; preds = %28
%38 = call i32 @lemon_add_global(%struct.lemon* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %struct.lobject* %25)
%39 = call i32 @lemon_compile(%struct.lemon* %4)
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %46
41: ; preds = %37
%42 = load i32, i32* @stderr
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%44 = call i32 @lemon_destroy(%struct.lemon* %4)
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %37
%47 = call i32 @lemon_machine_reset(%struct.lemon* %4)
%48 = call i32 @lemon_machine_execute(%struct.lemon* %4)
br label %49
49: ; preds = %46, %11
%50 = call i32 @lemon_destroy(%struct.lemon* %4)
br label %51
51: ; preds = %49, %6
ret i32 0
}