// File: /workspace/github_c_makefile_star2_O2/MuvikLabs[P]runt/irunt.c
// Function: irunt_begin
runt_int irunt_begin(int argc, char *argv[], runt_int (*loader)(runt_vm *))
{
    irunt_data irunt;
    char  *line = NULL;
    size_t len = 0;
    ssize_t read;
    runt_vm *vm;
    int argpos = 0;

    irunt_init(&irunt);
    argpos = irunt_parse_args(&irunt, argc, argv);

    if(argpos < 0) return 1;

    argv = &argv[argc - argpos];
    argc = argpos;
    vm = &irunt.vm;

    vm->argc = argc;
    vm->argv = argv;
    vm->argpos = argpos;

    irunt.mem = malloc(irunt.memsize);
    irunt.cells = malloc(sizeof(runt_cell) * irunt.ncells);

    runt_cell_pool_set(vm, irunt.cells, irunt.ncells);
    runt_cell_pool_init(vm);

    runt_memory_pool_set(vm, irunt.mem, irunt.memsize);

    vm->loader = loader;
    loader(vm);
    runt_pmark_set(vm);

    if(irunt.batch_mode) {
        runt_set_state(vm, RUNT_MODE_INTERACTIVE, RUNT_ON);
    }

    if(argc > 1) load_dictionary(vm, argv[1]);
    if(irunt.batch_mode && argc == 0) load_dictionary_handle(vm, stdin);
    if(!irunt.batch_mode) {
        runt_set_state(vm, RUNT_MODE_INTERACTIVE, RUNT_ON);
        while(runt_is_alive(vm) == RUNT_OK) {
            printf("> ");
            fflush(stdout);
            read = runt_getline(&line, &len, stdin);
            parse(vm, line, read);
        }
    }

    runt_close_plugins(vm);

    free(line);
    free(irunt.cells);
    free(irunt.mem);

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x14f8, %rsp           # imm = 0x14F8
movq %rdx, 0x10(%rsp)
movq %rsi, %r14
andq $0x0, 0x8(%rsp)
movl %edi, %ebp
andq $0x0, 0x18(%rsp)
leaq 0x20(%rsp), %r15
movq %r15, %rdi
callq 0x1294
movabsq $0x20000000001, %rax    # imm = 0x20000000001
movq %rax, 0x14c8(%r15)
movq $0x3d0900, 0x14d0(%r15) # imm = 0x3D0900
cmpl $0x1, %ebp
jne 0x5535
xorl %r13d, %r13d
movl $0x3d0900, %r12d        # imm = 0x3D0900
movl $0x200, %r15d           # imm = 0x200
jmp 0x55ca
pushq $0x1
popq %rbx
movl $0x3d0900, %r12d        # imm = 0x3D0900
movl $0x200, %r15d           # imm = 0x200
movl %ebp, %r13d
cmpl %ebp, %ebx
jge 0x55c1
movslq %ebx, %rax
movq (%r14,%rax,8), %rdx
cmpb $0x2d, (%rdx)
jne 0x55c1
movzbl 0x1(%rdx), %ecx
cmpl $0x6d, %ecx
je 0x5596
cmpl $0x63, %ecx
je 0x5580
cmpl $0x69, %ecx
je 0x55af
cmpl $0x62, %ecx
jne 0x579a
movl $0x1, 0x14e8(%rsp)
jmp 0x55b7
movq 0x8(%r14,%rax,8), %rdi
callq 0x1140
movl %eax, %r15d
movl %eax, 0x14ec(%rsp)
jmp 0x55ab
movq 0x8(%r14,%rax,8), %rdi
callq 0x1100
movq %rax, %r12
movq %rax, 0x14f0(%rsp)
pushq $0x2
jmp 0x55b9
andl $0x0, 0x14e8(%rsp)
pushq $0x1
popq %rax
subl %eax, %r13d
addl %eax, %ebx
jmp 0x5547
testl %r13d, %r13d
js 0x57ad
subl %r13d, %ebp
movslq %ebp, %rax
leaq (%r14,%rax,8), %rbx
leaq 0x20(%rsp), %r14
movl %r13d, 0x11e8(%r14)
movq %rbx, 0x11e0(%r14)
movl %r13d, 0x11ec(%r14)
movq %r12, %rdi
callq 0x10d0
movq %rax, 0x14b8(%r14)
movl %r15d, %eax
imulq $0x28, %rax, %rdi
callq 0x10d0
movq %rax, 0x14c0(%r14)
movq %r14, %rdi
movq %rax, %rsi
movl %r15d, %edx
callq 0x14a2
movq %r14, %rdi
callq 0x14ba
movq 0x14b8(%r14), %rsi
movl 0x14d0(%r14), %edx
movq %r14, %rdi
callq 0x1507
movq 0x10(%rsp), %rax
movq %rax, 0x1200(%r14)
movq %r14, %rdi
callq *%rax
movq %r14, %rdi
callq 0x2c81
cmpl $0x0, 0x14c8(%r14)
je 0x566f
leaq 0x20(%rsp), %rdi
pushq $0x2
popq %rsi
pushq $0x3
popq %rdx
callq 0x13d3
cmpl $0x2, %r13d
jb 0x56bd
movq 0x8(%rbx), %rbx
leaq 0xd50(%rip), %rsi       # 0x63d0
movq %rbx, %rdi
callq 0x1120
testq %rax, %rax
je 0x56a7
movq %rax, %r14
leaq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0x57c2
movq %r14, %rdi
callq 0x1060
jmp 0x56bd
leaq 0xdea(%rip), %rsi       # 0x6498
leaq 0x20(%rsp), %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x18da
movl 0x14e8(%rsp), %eax
testl %eax, %eax
sete %cl
testl %r13d, %r13d
setne %dl
orb %cl, %dl
jne 0x56f0
movq 0x48fe(%rip), %rax      # 0x9fd8
movq (%rax), %rsi
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
callq 0x57c2
movl 0x14c8(%rbx), %eax
testl %eax, %eax
je 0x572a
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
callq 0x2dfd
movq 0x8(%rsp), %rdi
callq 0x1040
movq 0x14c0(%rbx), %rdi
callq 0x1040
movq 0x14b8(%rbx), %rdi
callq 0x1040
xorl %eax, %eax
jmp 0x57b0
leaq 0x20(%rsp), %rbx
pushq $0x2
popq %rsi
pushq $0x3
popq %rdx
movq %rbx, %rdi
callq 0x13d3
leaq 0xe2f(%rip), %r14       # 0x6573
movq 0x4885(%rip), %r13      # 0x9fd0
movq 0x4886(%rip), %rbp      # 0x9fd8
leaq 0x8(%rsp), %r15
leaq 0x18(%rsp), %r12
movq %rbx, %rdi
callq 0x2c36
cmpl $0x1, %eax
jne 0x56f4
movq %r14, %rdi
xorl %eax, %eax
callq 0x1080
movq (%r13), %rdi
callq 0x10e0
movq (%rbp), %rdx
movq %r15, %rdi
movq %r12, %rsi
callq 0x2f03
movq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x549e
jmp 0x575c
leaq 0xdd5(%rip), %rsi       # 0x6576
leaq 0x20(%rsp), %rdi
xorl %eax, %eax
callq 0x18da
pushq $0x1
popq %rax
addq $0x14f8, %rsp           # imm = 0x14F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq