// File: /workspace/github_c_makefile_star2_O3/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, %r13
movq %rsi, %r12
movq %rdi, %rbx
movl $0x1, %edi
callq 0x1070
testq %rax, %rax
je 0x1300
movq %rax, %r14
leaq (,%r13,8), %rdi
callq 0x10a0
testq %rax, %rax
je 0x1307
movq %rax, %r15
movq %r12, 0x8(%rsp)
movq %rbx, 0x18(%rsp)
xorl %r12d, %r12d
xorl %ebx, %ebx
leaq 0x1(%r12), %rax
movq %rax, 0x10(%rsp)
movq 0x20(%rsp), %rdi
callq 0x1060
movl %eax, %ebp
cmpl $0xa, %eax
je 0x1236
cmpl $-0x1, %ebp
jne 0x12d0
testq %rbx, %rbx
sete %al
testq %r12, %r12
sete %cl
cmpl $-0x1, %ebp
sete %dl
andb %al, %cl
andb %dl, %cl
cmpb $0x1, %cl
je 0x130e
cmpq %r13, %rbx
jb 0x1278
movq %r13, %rsi
shlq $0x4, %rsi
movq %r15, %rdi
callq 0x10b0
testq %rax, %rax
je 0x1350
movq %rax, %r15
addq %r13, %r13
movq 0x10(%rsp), %rdi
callq 0x10a0
movq %rax, (%r15,%rbx,8)
testq %rax, %rax
je 0x1322
movq %rax, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x1080
movq (%r15,%rbx,8), %rax
movb $0x0, (%rax,%r12)
movq %r14, %rdi
xorl %esi, %esi
movq 0x8(%rsp), %rdx
callq 0x1050
cmpl $0xa, %ebp
je 0x12c5
cmpl $-0x1, %ebp
jne 0x121c
jmp 0x1336
incq %rbx
xorl %r12d, %r12d
jmp 0x1212
movq 0x8(%rsp), %rsi
cmpq %rsi, %r12
jb 0x12f2
addq %rsi, %rsi
movq %r14, %rdi
movq %rsi, 0x8(%rsp)
callq 0x10b0
movq %rax, %r14
testq %rax, %rax
je 0x1366
movb %bpl, (%r14,%r12)
movq 0x10(%rsp), %r12
jmp 0x1212
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x1355
movl $0xfffffffe, %ebx       # imm = 0xFFFFFFFE
jmp 0x132c
movq %r14, %rdi
callq 0x1030
movq %r15, %rdi
callq 0x1030
xorl %ebx, %ebx
jmp 0x1355
movl $0xfffffffc, %ebx       # imm = 0xFFFFFFFC
testq %r14, %r14
je 0x1355
movq %r14, %rdi
callq 0x1030
jmp 0x1355
movq %r14, %rdi
callq 0x1030
movq $0x0, (%r15,%rbx,8)
movq 0x18(%rsp), %rax
movq %r15, (%rax)
jmp 0x1355
movl $0xfffffffd, %ebx       # imm = 0xFFFFFFFD
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xfffffffb, %ebx       # imm = 0xFFFFFFFB
jmp 0x1355