// File: /workspace/github_c_makefile_star2_O1/sasairc[P]clangsay/src/libbenly/src/file.c
// Function: load_file_to_array
int load_file_to_array(char*** dest, size_t th_x, size_t th_y, FILE* fp)
{
    int     c       = 0,
            status  = 0;

    size_t  x       = 0,
            y       = 0;

    char*   tmp     = NULL,
        **  buf     = NULL;

    if ((tmp = (char*)
                malloc(sizeof(char) * th_x)) == NULL) {
        status = -1; goto ERR;
    } else {
        memset(tmp, '\0', th_x);
    }
    if ((buf = (char**)
                malloc(sizeof(char*) * th_y)) == NULL) {
        status = -2; goto ERR;
    }
    while (1) {
        c = fgetc(fp);
        switch (c) {
            case    '\n':
            case    EOF:
                /* no data */
                if (c == EOF && x == 0 && y == 0) {
                    if (tmp != NULL) {
                        free(tmp);
                        tmp = NULL;
                    }
                    if (buf != NULL) {
                        free(buf);
                        buf = NULL;
                    }
                    return 0;
                }
                if (y >= th_y) {
                    th_y += th_y;
                    if ((buf = (char**)
                                realloc(buf, sizeof(char*) * th_y)) == NULL) {
                        status = -3; goto ERR;
                    }
                }
                if ((*(buf + y) = (char*)
                            malloc(sizeof(char) * (x + 1))) == NULL) {
                    status = -4; goto ERR;
                } else {
                    memcpy(*(buf + y), tmp, x);
                    *(*(buf + y) + x) = '\0';
                    memset(tmp, '\0', th_x);
                }
                if (c == '\n') {
                    x = 0;
                    y++;
                } else if (c == EOF) {
                    goto ENDLOOP;
                }
                break;
            default:
                if (x >= th_x) {
                    th_x += th_x;
                    if ((tmp = (char*)
                                realloc(tmp, sizeof(char) * th_x)) == NULL) {
                        status = -5; goto ERR;
                    }
                }
                *(tmp + x) = c;
                x++;
                break;
        }
    }

ENDLOOP:
    if (tmp != NULL)
        free(tmp);

    *(buf + y) = NULL;
    *dest = buf;

    return y;

ERR:
    switch (status) {
        case    -5:
        case    -4:
        case    -3:
            if (buf != NULL)
        case    -2:
            if (tmp != NULL)
                free(tmp);
        case    -1:
            break;
    }

    return status;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, 0x20(%rsp)
movq %rdx, %rbp
movq %rsi, %r13
movq %rdi, %rbx
movq %rsi, %rdi
callq 0x1090
testq %rax, %rax
je 0x130b
movq %rax, %r14
xorl %r15d, %r15d
movq %rax, %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0x1050
leaq (,%rbp,8), %rdi
callq 0x1090
testq %rax, %rax
je 0x1318
movq %rax, %r12
movq %r13, 0x8(%rsp)
movq %rbx, 0x18(%rsp)
xorl %r13d, %r13d
xorl %ebx, %ebx
leaq 0x1(%r13), %rax
movq %rax, 0x10(%rsp)
movq 0x20(%rsp), %rdi
callq 0x1060
movl %eax, %r15d
cmpl $0xa, %eax
je 0x123a
cmpl $-0x1, %r15d
jne 0x12d7
testq %rbx, %rbx
sete %al
testq %r13, %r13
sete %cl
cmpl $-0x1, %r15d
sete %dl
andb %al, %cl
andb %dl, %cl
cmpb $0x1, %cl
je 0x131f
cmpq %rbp, %rbx
jb 0x127d
movq %rbp, %rsi
shlq $0x4, %rsi
movq %r12, %rdi
callq 0x10a0
testq %rax, %rax
je 0x1354
movq %rax, %r12
addq %rbp, %rbp
movq 0x10(%rsp), %rdi
callq 0x1090
movq %rax, (%r12,%rbx,8)
testq %rax, %rax
je 0x1333
movq %rax, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x1070
movq (%r12,%rbx,8), %rax
movb $0x0, (%rax,%r13)
movq %r14, %rdi
xorl %esi, %esi
movq 0x8(%rsp), %rdx
callq 0x1050
cmpl $0xa, %r15d
je 0x12cc
cmpl $-0x1, %r15d
jne 0x121e
jmp 0x133a
incq %rbx
xorl %r13d, %r13d
jmp 0x1215
movq 0x8(%rsp), %rsi
cmpq %rsi, %r13
jb 0x12fd
addq %rsi, %rsi
movq %r14, %rdi
movq %rsi, 0x8(%rsp)
callq 0x10a0
movq %rax, %r14
testq %rax, %rax
je 0x139b
movb %r15b, (%r14,%r13)
movq 0x10(%rsp), %r13
jmp 0x1215
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
xorl %r14d, %r14d
xorl %r15d, %r15d
jmp 0x1363
movl $0xfffffffe, %ebx       # imm = 0xFFFFFFFE
jmp 0x1363
movq %r14, %rdi
callq 0x1030
movq %r12, %rdi
callq 0x1030
xorl %ebx, %ebx
jmp 0x138a
movl $0xfffffffc, %ebx       # imm = 0xFFFFFFFC
jmp 0x135c
movq %r14, %rdi
callq 0x1030
movq $0x0, (%r12,%rbx,8)
movq 0x18(%rsp), %rax
movq %r12, (%rax)
jmp 0x138a
movl $0xfffffffd, %ebx       # imm = 0xFFFFFFFD
xorl %r12d, %r12d
testq %r12, %r12
setne %r15b
leal 0x5(%rbx), %eax
cmpl $0x3, %eax
jae 0x1378
testq %r14, %r14
setne %al
testb %al, %r15b
jne 0x1382
jmp 0x138a
cmpl $-0x2, %ebx
jne 0x138a
testq %r14, %r14
je 0x138a
movq %r14, %rdi
callq 0x1030
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xfffffffb, %ebx       # imm = 0xFFFFFFFB
xorl %r14d, %r14d
jmp 0x135c