// File: /workspace/github_c_makefile_star2_O1/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 $0x14e8, %rsp           # imm = 0x14E8
movq %rdx, %rbx
movq %rsi, %r14
movl %edi, %ebp
xorl %r13d, %r13d
movq %r13, (%rsp)
movq %r13, 0x8(%rsp)
leaq 0x10(%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
je 0x644b
movl %ebp, %r13d
jle 0x644b
movl $0x1, %r15d
movl %ebp, %r13d
movslq %r15d, %rax
movq (%r14,%rax,8), %rdx
cmpb $0x2d, (%rdx)
jne 0x644b
movzbl 0x1(%rdx), %ecx
cmpl $0x68, %ecx
jg 0x63d2
cmpl $0x62, %ecx
je 0x6410
cmpl $0x63, %ecx
jne 0x63f6
movq 0x8(%r14,%rax,8), %rdi
callq 0x1140
movl %eax, 0x14dc(%rsp)
jmp 0x63ee
cmpl $0x69, %ecx
je 0x641d
cmpl $0x6d, %ecx
jne 0x63f6
movq 0x8(%r14,%rax,8), %rdi
callq 0x1100
movq %rax, 0x14e0(%rsp)
movl $0x2, %r12d
jmp 0x642e
xorl %r12d, %r12d
leaq 0x10(%rsp), %rdi
leaq 0x1171(%rip), %rsi      # 0x7576
xorl %eax, %eax
callq 0x1cfe
movb $0x1, %al
jmp 0x6430
movl $0x1, 0x14d8(%rsp)
jmp 0x6428
movl $0x0, 0x14d8(%rsp)
movl $0x1, %r12d
xorl %eax, %eax
testb %al, %al
jne 0x6445
subl %r12d, %r13d
addl %r12d, %r15d
cmpl %ebp, %r15d
jl 0x639c
jmp 0x644b
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
testl %r13d, %r13d
js 0x6540
subl %r13d, %ebp
movslq %ebp, %rax
leaq (%r14,%rax,8), %r12
leaq 0x10(%rsp), %r14
movl %r13d, 0x11e8(%r14)
movq %r12, 0x11e0(%r14)
movl %r13d, 0x11ec(%r14)
movq 0x14d0(%r14), %rdi
callq 0x10d0
movq %rax, 0x14b8(%r14)
movl 0x14cc(%r14), %r15d
movq %r15, %rax
shlq $0x3, %rax
leaq (%rax,%rax,4), %rdi
callq 0x10d0
movq %rax, 0x14c0(%r14)
movq %r14, %rdi
movq %rax, %rsi
movl %r15d, %edx
callq 0x1637
movq %r14, %rdi
callq 0x1654
movq 0x14b8(%r14), %rsi
movl 0x14d0(%r14), %edx
movq %r14, %rdi
callq 0x16b0
movq %rbx, 0x1200(%r14)
movq %r14, %rdi
callq *%rbx
movq %r14, %rdi
callq 0x36c0
cmpl $0x0, 0x14c8(%r14)
je 0x6507
leaq 0x10(%rsp), %rdi
movl $0x2, %esi
movl $0x3, %edx
callq 0x1507
cmpl $0x2, %r13d
jl 0x6560
movq 0x8(%r12), %rbx
leaq 0xeb7(%rip), %rsi       # 0x73d0
movq %rbx, %rdi
callq 0x1120
testq %rax, %rax
je 0x654a
movq %rax, %r14
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x6663
movq %r14, %rdi
callq 0x1060
jmp 0x6560
movl $0x1, %eax
jmp 0x6651
leaq 0xf47(%rip), %rsi       # 0x7498
leaq 0x10(%rsp), %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x1cfe
testl %r13d, %r13d
jne 0x6583
cmpl $0x0, 0x14d8(%rsp)
je 0x6583
movq 0x4a62(%rip), %rax      # 0xafd8
movq (%rax), %rsi
leaq 0x10(%rsp), %rdi
callq 0x6663
cmpl $0x0, 0x14d8(%rsp)
jne 0x6621
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movl $0x2, %esi
movl $0x3, %edx
callq 0x1507
movq %rbx, %rdi
callq 0x3671
cmpl $0x1, %eax
jne 0x6621
movq 0x4a14(%rip), %rbp      # 0xafd0
movq 0x4a15(%rip), %rbx      # 0xafd8
movq %rsp, %r14
leaq 0x8(%rsp), %r15
leaq 0x10(%rsp), %r12
leaq 0xf9c(%rip), %rdi       # 0x7573
xorl %eax, %eax
callq 0x1080
movq (%rbp), %rdi
callq 0x10e0
movq (%rbx), %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x39be
movq (%rsp), %r13
movq %r12, %rdi
callq 0x36c0
movq %r12, %rdi
movq %r13, %rsi
callq 0x2ba6
movq %r12, %rdi
callq 0x36f6
movq %r12, %rdi
callq 0x3671
cmpl $0x1, %eax
je 0x65d0
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x3874
movq (%rsp), %rdi
callq 0x1040
movq 0x14c0(%rbx), %rdi
callq 0x1040
movq 0x14b8(%rbx), %rdi
callq 0x1040
xorl %eax, %eax
addq $0x14e8, %rsp           # imm = 0x14E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq