// File: /workspace/github_c_makefile_star2_O3/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 0x9e21
movq %rdx, %r15
movl %esi, %ebx
movq %rdi, %r14
callq 0x2270
xorl %ebp, %ebp
movq %r14, %rdi
callq 0x21e0
cmpl $-0x1, %eax
je 0x9d81
cmpl $0xa, %eax
jne 0x9d63
testl %ebx, %ebx
jg 0x9d7d
incl %ebp
jmp 0x9d63
decl %ebx
jmp 0x9d63
movl $0x10, %edi
callq 0x20e0
movq %rax, %rbx
testq %rax, %rax
je 0x9e2b
movslq %ebp, %rax
leaq 0x8(,%rax,8), %rdi
callq 0x20e0
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x9e35
movl %ebp, (%rbx)
testl %ebp, %ebp
js 0x9e17
movq %rax, %r14
movl %ebp, %r13d
decq %r13
xorl %ebp, %ebp
xorl %r12d, %r12d
movl $0x18, %edi
callq 0x20e0
movq %rax, (%r14,%r12,8)
testq %rax, %rax
je 0x9e42
movq %rbp, 0x8(%rax)
movq (%r14,%r12,8), %rax
movq %rbp, 0x8(%rax)
movl $0x18, %edi
callq 0x20e0
movq %rax, 0x8(%r14,%r13,8)
testq %rax, %rax
je 0x9e49
movq $0x0, 0x8(%rax)
leaq 0x1(%r12), %rax
leaq -0x1(%r13), %rcx
cmpq %r13, %r12
movq %rcx, %r13
movq %rax, %r12
jl 0x9dc8
movq %rbx, (%r15)
xorl %ebp, %ebp
jmp 0x9eb0
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x9eb0
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
xorl %r12d, %r12d
jmp 0x9e51
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
xorl %r14d, %r14d
xorl %r12d, %r12d
jmp 0x9e51
movl $0xfffffffd, %ebp       # imm = 0xFFFFFFFD
jmp 0x9e4e
movl $0xfffffffc, %ebp       # imm = 0xFFFFFFFC
movl %r12d, %r12d
movq 0x7190(%rip), %rax      # 0x10fe8
movq (%rax), %r15
callq 0x2340
movl (%rax), %edi
callq 0x2240
leaq 0x22e1(%rip), %rsi      # 0xc14f
movq %r15, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2400
testq %r14, %r14
je 0x9ea8
incq %r12
movq -0x8(%r14,%r12,8), %rdi
testq %rdi, %rdi
je 0x9e9b
callq 0x2190
movq $0x0, -0x8(%r14,%r12,8)
decq %r12
jg 0x9e83
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