// File: /workspace/github_c_makefile_star2_O3/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, %rbx
movq %rsi, %r14
movl %edi, %ebp
xorl %r13d, %r13d
movq %r13, 0x8(%rsp)
movq %r13, 0x18(%rsp)
leaq 0x20(%rsp), %r15
movq %r15, %rdi
callq 0x1348
movabsq $0x20000000001, %rax    # imm = 0x20000000001
movq %rax, 0x14c8(%r15)
movq $0x3d0900, 0x14d0(%r15) # imm = 0x3D0900
cmpl $0x1, %ebp
movq %rbx, 0x10(%rsp)
jne 0x6245
movl $0x3d0900, %r12d        # imm = 0x3D0900
movl $0x200, %r15d           # imm = 0x200
jmp 0x630a
jle 0x62f2
movl $0x1, %ebx
movl $0x3d0900, %r12d        # imm = 0x3D0900
movl $0x200, %r15d           # imm = 0x200
movl %ebp, %r13d
movslq %ebx, %rax
movq (%r14,%rax,8), %rdx
cmpb $0x2d, (%rdx)
jne 0x6301
movzbl 0x1(%rdx), %ecx
cmpl $0x68, %ecx
jg 0x629c
cmpl $0x62, %ecx
je 0x62c6
cmpl $0x63, %ecx
jne 0x6506
movq 0x8(%r14,%rax,8), %rdi
callq 0x1140
movl %eax, %r15d
movl %eax, 0x14ec(%rsp)
jmp 0x62bf
cmpl $0x69, %ecx
je 0x62d3
cmpl $0x6d, %ecx
jne 0x6506
movq 0x8(%r14,%rax,8), %rdi
callq 0x1100
movq %rax, %r12
movq %rax, 0x14f0(%rsp)
movl $0x2, %eax
jmp 0x62e3
movl $0x1, 0x14e8(%rsp)
jmp 0x62de
movl $0x0, 0x14e8(%rsp)
movl $0x1, %eax
subl %eax, %r13d
addl %eax, %ebx
cmpl %ebp, %ebx
jl 0x625f
jmp 0x6301
movl $0x3d0900, %r12d        # imm = 0x3D0900
movl $0x200, %r15d           # imm = 0x200
movl %ebp, %r13d
testl %r13d, %r13d
js 0x6519
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
shlq $0x3, %rax
leaq (%rax,%rax,4), %rdi
callq 0x10d0
movq %rax, 0x14c0(%r14)
movq %r14, %rdi
movq %rax, %rsi
movl %r15d, %edx
callq 0x1615
movq %r14, %rdi
callq 0x1632
movq 0x14b8(%r14), %rsi
movl 0x14d0(%r14), %edx
movq %r14, %rdi
callq 0x168e
movq 0x10(%rsp), %rax
movq %rax, 0x1200(%r14)
movq %r14, %rdi
callq *%rax
movq %r14, %rdi
callq 0x35ff
cmpl $0x0, 0x14c8(%r14)
je 0x63b7
leaq 0x20(%rsp), %rdi
movl $0x2, %esi
movl $0x3, %edx
callq 0x14e5
cmpl $0x2, %r13d
jb 0x63ef
movq 0x8(%rbx), %rbx
leaq 0x1008(%rip), %rsi      # 0x73d0
movq %rbx, %rdi
callq 0x1120
testq %rax, %rax
je 0x641b
movq %rax, %r14
leaq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0x6530
movq %r14, %rdi
callq 0x1060
jmp 0x6431
movl 0x14e8(%rsp), %eax
testl %eax, %eax
sete %cl
testl %r13d, %r13d
setne %dl
orb %cl, %dl
jne 0x6438
movq 0x4bcc(%rip), %rax      # 0xafd8
movq (%rax), %rsi
leaq 0x20(%rsp), %rdi
callq 0x6530
jmp 0x6431
leaq 0x1076(%rip), %rsi      # 0x7498
leaq 0x20(%rsp), %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x1cb9
movl 0x14e8(%rsp), %eax
testl %eax, %eax
jne 0x64d3
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
movl $0x2, %esi
movl $0x3, %edx
callq 0x14e5
movq %rbx, %rdi
callq 0x35b0
cmpl $0x1, %eax
jne 0x64d3
movq 0x4b65(%rip), %rbp      # 0xafd0
movq 0x4b66(%rip), %rbx      # 0xafd8
leaq 0x8(%rsp), %r14
leaq 0x18(%rsp), %r15
leaq 0x20(%rsp), %r12
leaq 0x10eb(%rip), %rdi      # 0x7573
xorl %eax, %eax
callq 0x1080
movq (%rbp), %rdi
callq 0x10e0
movq (%rbx), %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x38ff
movq 0x8(%rsp), %r13
movq %r12, %rdi
callq 0x35ff
movq %r12, %rdi
movq %r13, %rsi
callq 0x2aad
movq %r12, %rdi
callq 0x3635
movq %r12, %rdi
callq 0x35b0
cmpl $0x1, %eax
je 0x6481
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
callq 0x37b3
movq 0x8(%rsp), %rdi
callq 0x1040
movq 0x14c0(%rbx), %rdi
callq 0x1040
movq 0x14b8(%rbx), %rdi
callq 0x1040
xorl %eax, %eax
jmp 0x651e
leaq 0x1069(%rip), %rsi      # 0x7576
leaq 0x20(%rsp), %rdi
xorl %eax, %eax
callq 0x1cb9
movl $0x1, %eax
addq $0x14f8, %rsp           # imm = 0x14F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq