// File: /workspace/github_c_makefile_star2_O1/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 0xa000
movq %rdx, %r14
movl %esi, %ebx
movq %rdi, %r15
callq 0x2270
xorl %ebp, %ebp
movq %r15, %rdi
callq 0x21e0
cmpl $-0x1, %eax
je 0x9f45
cmpl $0xa, %eax
jne 0x9f27
testl %ebx, %ebx
jg 0x9f41
incl %ebp
jmp 0x9f27
decl %ebx
jmp 0x9f27
movl $0x10, %edi
callq 0x20e0
movq %rax, %rbx
testq %rax, %rax
je 0xa016
movslq %ebp, %rax
leaq 0x8(,%rax,8), %rdi
callq 0x20e0
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0xa01d
movl %ebp, (%rbx)
testl %ebp, %ebp
js 0x9ff9
movl %ebp, %r12d
decq %r12
xorl %r13d, %r13d
xorl %r15d, %r15d
movl $0x18, %edi
callq 0x20e0
movq 0x8(%rbx), %rcx
movq %rax, (%rcx,%r15,8)
testq %rax, %rax
je 0xa027
movq 0x8(%rbx), %rbp
movq (%rbp,%r15,8), %rax
movq %r13, 0x8(%rax)
movq (%rbp,%r15,8), %rax
movq %r13, 0x8(%rax)
movl $0x18, %edi
callq 0x20e0
movq %rax, 0x8(%rbp,%r12,8)
testq %rax, %rax
je 0xa02e
movq 0x8(%rbx), %rax
movq 0x8(%rax,%r12,8), %rcx
movq %r13, 0x8(%rcx)
movq 0x8(%rax,%r12,8), %rax
movq %r13, 0x8(%rax)
leaq 0x1(%r15), %rax
leaq -0x1(%r12), %rcx
cmpq %r12, %r15
movq %rcx, %r12
movq %rax, %r15
jl 0x9f8a
movq %rbx, (%r14)
xorl %ebp, %ebp
jmp 0xa005
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0xa022
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
xorl %r15d, %r15d
jmp 0xa036
movl $0xfffffffd, %ebp       # imm = 0xFFFFFFFD
jmp 0xa033
movl $0xfffffffc, %ebp       # imm = 0xFFFFFFFC
movl %r15d, %r15d
movq 0x6fab(%rip), %rax      # 0x10fe8
movq (%rax), %r14
callq 0x2340
movl (%rax), %edi
callq 0x2240
leaq 0x20dc(%rip), %rsi      # 0xc12f
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x23f0
cmpq $0x0, 0x8(%rbx)
je 0xa0a0
incq %r15
movq 0x8(%rbx), %rax
movq -0x8(%rax,%r15,8), %rdi
testq %rdi, %rdi
je 0xa08a
callq 0x2190
movq 0x8(%rbx), %rax
movq $0x0, -0x8(%rax,%r15,8)
decq %r15
jg 0xa06a
movq 0x8(%rbx), %rdi
callq 0x2190
movq $0x0, 0x8(%rbx)
testq %rbx, %rbx
je 0xa005
movq %rbx, %rdi
callq 0x2190
jmp 0xa005