// File: /workspace/github_c_makefile_star2_O2/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, %r12
movq %rsi, %r13
movq %rdi, %r15
pushq $0x1
popq %rdi
callq 0x1070
testq %rax, %rax
je 0x1300
movq %rax, %rbx
leaq (,%r12,8), %rdi
callq 0x10a0
testq %rax, %rax
je 0x1305
movq %rax, %r14
movq %r13, 0x8(%rsp)
movq %r15, 0x18(%rsp)
xorl %ebp, %ebp
xorl %r15d, %r15d
leaq 0x1(%rbp), %rax
movq %rax, 0x10(%rsp)
movq 0x20(%rsp), %rdi
callq 0x1060
movl %eax, %r13d
cmpl $0xa, %eax
je 0x1235
cmpl $-0x1, %r13d
jne 0x12d0
testq %r15, %r15
sete %al
testq %rbp, %rbp
sete %cl
cmpl $-0x1, %r13d
sete %dl
andb %al, %cl
andb %dl, %cl
cmpb $0x1, %cl
je 0x130a
cmpq %r12, %r15
jb 0x1278
movq %r12, %rsi
shlq $0x4, %rsi
movq %r14, %rdi
callq 0x10b0
testq %rax, %rax
je 0x1359
movq %rax, %r14
addq %r12, %r12
movq 0x10(%rsp), %rdi
callq 0x10a0
movq %rax, (%r14,%r15,8)
testq %rax, %rax
je 0x131e
movq %rax, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x1080
movq (%r14,%r15,8), %rax
movb $0x0, (%rax,%rbp)
movq %rbx, %rdi
xorl %esi, %esi
movq 0x8(%rsp), %rdx
callq 0x1050
cmpl $0xa, %r13d
je 0x12c6
cmpl $-0x1, %r13d
jne 0x1219
jmp 0x1330
incq %r15
xorl %ebp, %ebp
jmp 0x1210
movq 0x8(%rsp), %rsi
cmpq %rsi, %rbp
jb 0x12f2
addq %rsi, %rsi
movq %rbx, %rdi
movq %rsi, 0x8(%rsp)
callq 0x10b0
movq %rax, %rbx
testq %rax, %rax
je 0x135d
movb %r13b, (%rbx,%rbp)
movq 0x10(%rsp), %rbp
jmp 0x1210
pushq $-0x1
popq %rbp
jmp 0x1348
pushq $-0x2
popq %rbp
jmp 0x1326
movq %rbx, %rdi
callq 0x1030
movq %r14, %rdi
callq 0x1030
xorl %ebp, %ebp
jmp 0x1348
pushq $-0x4
popq %rbp
testq %rbx, %rbx
je 0x1348
movq %rbx, %rdi
callq 0x1030
jmp 0x1348
movq %rbx, %rdi
callq 0x1030
andq $0x0, (%r14,%r15,8)
movq 0x18(%rsp), %rax
movq %r14, (%rax)
movl %r15d, %ebp
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $-0x3
jmp 0x1302
pushq $-0x5
jmp 0x1302