// File: /workspace/github_c_makefile_star2_O0/hoobaa[P]ficl/extras.c
// Function: ficlPrimitiveLoad
static void ficlPrimitiveLoad(ficlVm *vm)
{
    char    buffer[BUFFER_SIZE];
    char    filename[BUFFER_SIZE];
    ficlCountedString *counted = (ficlCountedString *)filename;
    int     line = 0;
    FILE   *f;
    int     result = 0;
    ficlCell    oldSourceId;
	ficlString s;

    ficlVmGetString(vm, counted, '\n');

    if (FICL_COUNTED_STRING_GET_LENGTH(*counted) <= 0)
    {
        ficlVmTextOut(vm, "Warning (load): nothing happened\n");
        return;
    }

    /*
    ** get the file's size and make sure it exists 
    */

    f = fopen(FICL_COUNTED_STRING_GET_POINTER(*counted), "r");
    if (!f)
    {
        ficlVmTextOut(vm, "Unable to open file ");
        ficlVmTextOut(vm, FICL_COUNTED_STRING_GET_POINTER(*counted));
        ficlVmTextOut(vm, "\n");
        ficlVmThrow(vm, FICL_VM_STATUS_QUIT);
    }

    oldSourceId = vm->sourceId;
    vm->sourceId.p = (void *)f;

    /* feed each line to ficlExec */
    while (fgets(buffer, BUFFER_SIZE, f))
    {
        int length = strlen(buffer) - 1;

        line++;
        if (length <= 0)
            continue;

        if (buffer[length] == '\n')
            buffer[length--] = '\0';

		FICL_STRING_SET_POINTER(s, buffer);
		FICL_STRING_SET_LENGTH(s, length + 1);
        result = ficlVmExecuteString(vm, s);
        /* handle "bye" in loaded files. --lch */
        switch (result)
        {
            case FICL_VM_STATUS_OUT_OF_TEXT:
            case FICL_VM_STATUS_USER_EXIT:
                break;

            default:
                vm->sourceId = oldSourceId;
                fclose(f);
                ficlVmThrowError(vm, "Error loading file <%s> line %d", FICL_COUNTED_STRING_GET_POINTER(*counted), line);
                break; 
        }
    }
    /*
    ** Pass an empty line with SOURCE-ID == -1 to flush
    ** any pending REFILLs (as required by FILE wordset)
    */
    vm->sourceId.i = -1;
	FICL_STRING_SET_FROM_CSTRING(s, "");
    ficlVmExecuteString(vm, s);

    vm->sourceId = oldSourceId;
    fclose(f);

    /* handle "bye" in loaded files. --lch */
    if (result == FICL_VM_STATUS_USER_EXIT)
        ficlVmThrow(vm, FICL_VM_STATUS_USER_EXIT);
    return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x250, %rsp            # imm = 0x250
movq %rdi, -0x8(%rbp)
leaq -0x210(%rbp), %rax
movq %rax, -0x218(%rbp)
movl $0x0, -0x21c(%rbp)
movl $0x0, -0x22c(%rbp)
movq -0x8(%rbp), %rdi
movq -0x218(%rbp), %rsi
movl $0xa, %edx
callq 0x8fa0
movq -0x218(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x0, %eax
jg 0x109fa
movq -0x8(%rbp), %rdi
leaq 0x5bdd(%rip), %rsi      # 0x165cd
callq 0x95e0
jmp 0x10c09
movq -0x218(%rbp), %rdi
addq $0x1, %rdi
leaq 0x5242(%rip), %rsi      # 0x15c4e
callq 0x3290
movq %rax, -0x228(%rbp)
cmpq $0x0, -0x228(%rbp)
jne 0x10a64
movq -0x8(%rbp), %rdi
leaq 0x5bc2(%rip), %rsi      # 0x165ef
callq 0x95e0
movq -0x8(%rbp), %rdi
movq -0x218(%rbp), %rsi
addq $0x1, %rsi
callq 0x95e0
movq -0x8(%rbp), %rdi
leaq 0x4954(%rip), %rsi      # 0x153a5
callq 0x95e0
movq -0x8(%rbp), %rdi
movl $0xffffffc8, %esi       # imm = 0xFFFFFFC8
callq 0x8d90
movq -0x8(%rbp), %rax
movq 0x78(%rax), %rax
movq %rax, -0x238(%rbp)
movq -0x228(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x78(%rax)
leaq -0x110(%rbp), %rdi
movq -0x228(%rbp), %rdx
movl $0x100, %esi            # imm = 0x100
callq 0x3150
cmpq $0x0, %rax
je 0x10b96
leaq -0x110(%rbp), %rdi
callq 0x30d0
subq $0x1, %rax
movl %eax, -0x24c(%rbp)
movl -0x21c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x21c(%rbp)
cmpl $0x0, -0x24c(%rbp)
jg 0x10ad4
jmp 0x10a82
movslq -0x24c(%rbp), %rax
movsbl -0x110(%rbp,%rax), %eax
cmpl $0xa, %eax
jne 0x10b03
movl -0x24c(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x24c(%rbp)
cltq
movb $0x0, -0x110(%rbp,%rax)
leaq -0x110(%rbp), %rax
movq %rax, -0x240(%rbp)
movl -0x24c(%rbp), %eax
incl %eax
cltq
movq %rax, -0x248(%rbp)
movq -0x8(%rbp), %rdi
movq -0x248(%rbp), %rsi
movq -0x240(%rbp), %rdx
callq 0x9720
movl %eax, -0x22c(%rbp)
movl -0x22c(%rbp), %eax
orl $0x2, %eax
subl $0xfffffeff, %eax       # imm = 0xFFFFFEFF
je 0x10b51
jmp 0x10b53
jmp 0x10b91
movq -0x8(%rbp), %rax
movq -0x238(%rbp), %rcx
movq %rcx, 0x78(%rax)
movq -0x228(%rbp), %rdi
callq 0x30c0
movq -0x8(%rbp), %rdi
movq -0x218(%rbp), %rdx
addq $0x1, %rdx
movl -0x21c(%rbp), %ecx
leaq 0x5a7a(%rip), %rsi      # 0x16604
movb $0x0, %al
callq 0x8dc0
jmp 0x10a82
movq -0x8(%rbp), %rax
movq $-0x1, 0x78(%rax)
leaq 0x47fd(%rip), %rax      # 0x153a6
movq %rax, -0x240(%rbp)
movq $0x0, -0x248(%rbp)
movq -0x8(%rbp), %rdi
movq -0x248(%rbp), %rsi
movq -0x240(%rbp), %rdx
callq 0x9720
movq -0x8(%rbp), %rax
movq -0x238(%rbp), %rcx
movq %rcx, 0x78(%rax)
movq -0x228(%rbp), %rdi
callq 0x30c0
cmpl $0xfffffefd, -0x22c(%rbp) # imm = 0xFFFFFEFD
jne 0x10c07
movq -0x8(%rbp), %rdi
movl $0xfffffefd, %esi       # imm = 0xFFFFFEFD
callq 0x8d90
jmp 0x10c09
addq $0x250, %rsp            # imm = 0x250
popq %rbp
retq
nopw %cs:(%rax,%rax)