// File: /workspace/github_c_makefile_star2_O1/eiselekd[P]MinimalLisp/lf.c
// Function: main
int
main(int argc, char **argv) 
{
    lfctx _cctx; struct lfctx *lfctx = &_cctx; ctx *lctx = (ctx *)&_cctx; 
    fctx *cctx = (fctx*)&_cctx; int c, i, l; FILE *f; char v[32]; struct v *list;
    struct v *fx = 0, *r; char *m = 0; int ml = 0, o;
    memset(&_cctx,0,sizeof(struct lfctx));
    
    atexit(colreset);
    signal(SIGINT, sigint);
    
    /* input */
    cctx->fc = -1;
    for (i = argc-1; i >= 1; i--) {
        l = strlen(argv[i]);
        if (argv[i][l-1] == 'f') {
            if (f = fopen(argv[i],"r")) {
                cctx->f[++cctx->fc] = f;
            }
        } else if (argv[i][l-1] == 'l') {
            FILE *f;
            if (argv[i] && (f = fopen(argv[i],"r"))) {
                o = ml;
                fseek(f, 0, SEEK_END); 
                ml += (l = ftell(f));
                fseek(f, 0, SEEK_SET);
                if (m) {
                    m = (char *)realloc(m,ml+1);
                } else {
                    m = (char *)malloc(ml+1);
                }
                fread(&m[o], 1, l, f);
                m[ml] = 0;
                fclose(f);
            }
        }
    }
    
    lf_init(&_cctx) ;
    
    r = mkCons(g_QUIT, 0);
    cctx->ip = r;
    fx = NEXT(cctx);
    
    FPRINTF(FDBG, "Compile Forth interpreter\n");
    while(fx) {
        fx = fop(fx)(cctx);
    }
    
    lf_remap(&_cctx);
    
    /* scan lisp program */
    if (!m)
        return 0;
    
    list = scan((ctx *)cctx, m);
    
    PUSH(list);
    
    printh ((ctx*)cctx, stdout, list);
    
    if (!(r = find(cctx, unique((ctx *)cctx, "evlist", 6)))) {
        return 0;
    }
    
    cctx->ip = mkCons(cdr(r), mkCons(g_END,0));
    fx = NEXT(cctx);
    EPUSH(lctx->env);
    
    FPRINTF(FDBG, "Execute Forth Lisp interpreter\n");
    /* execute lisp interpreter */
    while(fx) {
        fx = fop(fx)(cctx);
    }
    
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
movq %rsi, %r14
movl %edi, %ebx
leaq -0x1b8(%rbp), %r12
xorl %r15d, %r15d
movl $0x188, %edx            # imm = 0x188
movq %r12, %rdi
xorl %esi, %esi
callq 0x2080
leaq -0x5e(%rip), %rdi       # 0x10571
callq 0x108c0
leaq -0x75(%rip), %rsi       # 0x10566
movl $0x2, %edi
callq 0x20b0
movq $-0x1, 0x90(%r12)
cmpl $0x2, %ebx
jl 0x10713
movl %ebx, %ebx
incq %rbx
leaq 0xcf0(%rip), %r13       # 0x112f6
movq $0x0, -0x30(%rbp)
movq -0x10(%r14,%rbx,8), %r12
movq %r12, %rdi
callq 0x2060
decl %eax
cltq
movzbl (%r12,%rax), %eax
cmpl $0x6c, %eax
je 0x10665
cmpl $0x66, %eax
jne 0x10704
movq %r12, %rdi
movq %r13, %rsi
callq 0x2160
testq %rax, %rax
je 0x10704
movq -0x128(%rbp), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, -0x128(%rbp)
movq %rax, -0x1a0(%rbp,%rcx,8)
jmp 0x10704
testq %r12, %r12
je 0x10704
movq %r12, %rdi
movq %r13, %rsi
callq 0x2160
testq %rax, %rax
je 0x10704
movq %rax, %r12
movq %rax, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x2140
movq %r12, %rdi
callq 0x20d0
movq %rax, %r13
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2140
leal (%r15,%r13), %eax
incl %eax
movslq %eax, %rsi
movq -0x30(%rbp), %rdi
testq %rdi, %rdi
je 0x106c4
callq 0x2150
jmp 0x106cc
movq %rsi, %rdi
callq 0x2100
movslq %r15d, %rdi
addl %r13d, %r15d
addq %rax, %rdi
movslq %r13d, %rdx
movl $0x1, %esi
movq %r12, %rcx
movq %rax, %r13
callq 0x2040
movslq %r15d, %rax
movq %r13, -0x30(%rbp)
movb $0x0, (%r13,%rax)
movq %r12, %rdi
callq 0x2050
leaq 0xbf2(%rip), %r13       # 0x112f6
decq %rbx
cmpq $0x2, %rbx
jg 0x1060e
jmp 0x1071b
movq $0x0, -0x30(%rbp)
leaq -0x1b8(%rbp), %r14
movq %r14, %rdi
callq 0xf1b0
movq 0x4f5f(%rip), %rbx      # 0x15690
movl $0x18, %edi
callq 0x2100
movq %rax, %rcx
andb $-0x10, (%rax)
movq %rbx, 0x8(%rax)
xorl %eax, %eax
movq %rax, 0x10(%rcx)
movq %rbx, 0x138(%r14)
movq %rax, 0x130(%r14)
testq %rbx, %rbx
je 0x1076a
movq 0x8(%rbx), %rax
jmp 0x1076a
movq %r14, %rdi
callq *0x8(%rax)
testq %rax, %rax
jne 0x10764
leaq -0x1b8(%rbp), %rdi
callq 0x1044c
movq -0x30(%rbp), %rsi
testq %rsi, %rsi
je 0x108ab
leaq -0x1b8(%rbp), %r14
movq %r14, %rdi
callq 0x3887
movq %rax, %rbx
movq 0x120(%r14), %r15
movl $0x18, %edi
callq 0x2100
andb $-0x10, (%rax)
movq %rbx, 0x8(%rax)
movq %r15, 0x10(%rax)
movq %rax, 0x120(%r14)
movq 0x4814(%rip), %rax      # 0x14fd8
movq (%rax), %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x2ac5
leaq 0xcd1(%rip), %rsi       # 0x114aa
movq %r14, %rdi
movl $0x6, %edx
callq 0x36a6
movq 0x148(%r14), %rcx
testq %rcx, %rcx
je 0x1080e
movq 0x8(%rcx), %rdx
testq %rdx, %rdx
je 0x10801
movq 0x8(%rdx), %rsi
jmp 0x10803
xorl %esi, %esi
cmpq %rax, %rsi
je 0x10810
movq 0x10(%rcx), %rcx
jmp 0x107ed
xorl %edx, %edx
testq %rdx, %rdx
je 0x108ab
movq 0x10(%rdx), %r14
movq 0x4dbc(%rip), %r15      # 0x155e0
movl $0x18, %edi
callq 0x2100
movq %rax, %rbx
andb $-0x10, (%rax)
movq %r15, 0x8(%rax)
movq $0x0, 0x10(%rax)
movl $0x18, %edi
callq 0x2100
andb $-0x10, (%rax)
movq %r14, 0x8(%rax)
movq %rbx, 0x10(%rax)
movq %r14, -0x80(%rbp)
movq %rbx, -0x88(%rbp)
testq %r14, %r14
je 0x1086b
movq 0x8(%r14), %rbx
jmp 0x1086d
xorl %ebx, %ebx
movq -0x1b0(%rbp), %r14
movq -0x40(%rbp), %r15
movl $0x18, %edi
callq 0x2100
andb $-0x10, (%rax)
movq %r14, 0x8(%rax)
movq %r15, 0x10(%rax)
movq %rax, -0x40(%rbp)
testq %rbx, %rbx
je 0x108ab
leaq -0x1b8(%rbp), %r14
movq %r14, %rdi
callq *0x8(%rbx)
movq %rax, %rbx
testq %rax, %rax
jne 0x1089d
xorl %eax, %eax
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop