// File: /workspace/github_c_makefile_star2_O2/sasairc[P]yasuna/src/libpolyaness/src/polyaness.c
// Function: init_polyaness
int init_polyaness(FILE* fp, int offset, polyaness_t** polyaness)
{
    if (fp == NULL)
        return -1;

    int             i       = 0,
                    j       = 0,
                    code    = 0,
                    recs    = 0;

    short           status  = 0;

    polyaness_t*    pt      = NULL;

    rewind(fp);
    while ((code = fgetc(fp)) != EOF) {
        if (code == LF) {
            if (offset > 0) {
                offset--;
                continue;
            }
            recs++;
        }
    }

    if ((pt = (polyaness_t*)
            malloc(sizeof(polyaness_t))) == NULL) {
        status = -1; goto ERR;
    }
    if ((pt->record = (polyaness_cell**)
            malloc(sizeof(polyaness_cell*) * (recs + 1))) == NULL) {
        status = -2; goto ERR;
    }

    pt->recs = recs;
    j = recs;
    while (i <= j) {
        if ((pt->record[i] = (polyaness_cell*)
                malloc(sizeof(polyaness_cell))) == NULL) {
            status = -3; goto ERR;
        }
        pt->record[i]->key = NULL;
        pt->record[i]->key = NULL;

        if ((pt->record[j] = (polyaness_cell*)
                malloc(sizeof(polyaness_cell))) == NULL) {
            status = -4; goto ERR;
        }
        pt->record[j]->key = NULL;
        pt->record[j]->key = NULL;

        i++;
        j--;
    }
    *polyaness = pt;

    return 0;

ERR:
    switch (status) {
        case    -1:
        case    -2:
        case    -3:
        case    -4:
            fprintf(stderr, "polyaness: init_polyaness(): malloc(): %s\n",
                    strerror(errno));
            break;
    }

    if (pt->record != NULL) {
        while (i >= 0) {
            if (pt->record[i] != NULL) {
                free(pt->record[i]);
                pt->record[i] = NULL;
            }
            i--;
        }
        free(pt->record);
        pt->record = NULL;
    }
    if (pt != NULL) {
        free(pt);
        pt = NULL;
    }

    return status;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0x919a
movq %rdx, %r12
movl %esi, %ebx
movq %rdi, %r14
callq 0x2270
xorl %ebp, %ebp
movq %r14, %rdi
callq 0x21e0
cmpl $-0x1, %eax
je 0x9111
cmpl $0xa, %eax
jne 0x90f3
testl %ebx, %ebx
jg 0x910d
incl %ebp
jmp 0x90f3
decl %ebx
jmp 0x90f3
pushq $0x10
popq %rdi
callq 0x20e0
movq %rax, %rbx
testq %rax, %rax
je 0x919f
movslq %ebp, %r15
leaq 0x8(,%r15,8), %rdi
callq 0x20e0
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x91a7
movq %rax, %r14
movq %r12, (%rsp)
movl %ebp, (%rbx)
xorl %r13d, %r13d
pushq $0x18
popq %r12
pushq $-0x3
popq %rbp
cmpq %r15, %r13
jg 0x918f
movq %r12, %rdi
callq 0x20e0
movq %rax, (%r14,%r13,8)
testq %rax, %rax
je 0x91b5
andq $0x0, 0x8(%rax)
movq (%r14,%r13,8), %rax
andq $0x0, 0x8(%rax)
movq %r12, %rdi
callq 0x20e0
movq %rax, (%r14,%r15,8)
testq %rax, %rax
je 0x91b2
andq $0x0, 0x8(%rax)
incq %r13
decq %r15
jmp 0x914d
movq (%rsp), %rax
movq %rbx, (%rax)
xorl %ebp, %ebp
jmp 0x9214
pushq $-0x1
popq %rbp
jmp 0x9214
pushq $-0x1
popq %rbp
xorl %r13d, %r13d
jmp 0x91b5
pushq $-0x2
popq %rbp
xorl %r14d, %r14d
xorl %r13d, %r13d
jmp 0x91b5
pushq $-0x4
popq %rbp
movq 0x6e2c(%rip), %rax      # 0xffe8
movq (%rax), %r15
callq 0x2340
movl (%rax), %edi
callq 0x2240
leaq 0x1f41(%rip), %rsi      # 0xb113
movq %r15, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2400
testq %r14, %r14
jne 0x91ff
jmp 0x920c
movl %r13d, %r15d
movq (%r14,%r15,8), %rdi
testq %rdi, %rdi
je 0x91fc
callq 0x2190
andq $0x0, (%r14,%r15,8)
decl %r13d
testl %r13d, %r13d
jns 0x91e6
movq %r14, %rdi
callq 0x2190
movq %rbx, %rdi
callq 0x2190
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq