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

    int     code    = 0,
            recs    = 0;

    short   status  = 0;

    char*   buf     = NULL;

    size_t  len     = 0,
            x_bufl  = BUFLEN;

    if ((buf = (char*)
            malloc(sizeof(char) * x_bufl)) == NULL) {
        status = -1; goto ERR;
    }

    rewind(fp);
    while ((code = fgetc(fp)) != EOF) {
        if (code == LF) {
            if (offset > 0) {
                offset--;
                continue;
            }
            if (add_data_polyaness(recs, count_keys(buf), buf, &polyaness) < 0) {
                status = -2; goto ERR;
            }
            memset(buf, '\0', x_bufl);
            recs++;
            len = 0;
        } else {
            if (offset > 0)
                continue;
            if (len == (x_bufl - 1)) {
                x_bufl += BUFLEN;
                if ((buf = (char*)
                        realloc(buf, sizeof(char) * x_bufl)) == NULL) {
                    status = -3; goto ERR;
                }
            }
            *(buf + len) = code;
            len++;
        }
    }
    free(buf);

    return 0;

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

    if (buf != NULL) {
        free(buf);
        buf = NULL;
    }

    return status;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0xfb14
movq -0x20(%rbp), %rax
cmpq $0x0, (%rax)
jne 0xfb20
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xfd36
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movw $0x0, -0x2a(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x1000, -0x48(%rbp)    # imm = 0x1000
movq -0x48(%rbp), %rdi
shlq $0x0, %rdi
callq 0x20e0
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
jne 0xfb6e
movw $0xffff, -0x2a(%rbp)    # imm = 0xFFFF
jmp 0xfc7b
movq -0x10(%rbp), %rdi
callq 0x2250
movq -0x10(%rbp), %rdi
callq 0x21c0
movl %eax, -0x24(%rbp)
cmpl $-0x1, %eax
je 0xfc66
cmpl $0xa, -0x24(%rbp)
jne 0xfbf6
cmpl $0x0, -0x14(%rbp)
jle 0xfba3
movl -0x14(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xfb77
movl -0x28(%rbp), %eax
movl %eax, -0x4c(%rbp)
movq -0x38(%rbp), %rdi
callq 0x10070
movl -0x4c(%rbp), %edi
movl %eax, %esi
movq -0x38(%rbp), %rdx
leaq -0x20(%rbp), %rcx
callq 0xfd40
cmpl $0x0, %eax
jge 0xfbd4
movw $0xfffe, -0x2a(%rbp)    # imm = 0xFFFE
jmp 0xfc7b
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rdx
xorl %esi, %esi
callq 0x2050
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
movq $0x0, -0x40(%rbp)
jmp 0xfc61
cmpl $0x0, -0x14(%rbp)
jle 0xfc01
jmp 0xfb77
movq -0x40(%rbp), %rax
movq -0x48(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jne 0xfc45
movq -0x48(%rbp), %rax
addq $0x1000, %rax           # imm = 0x1000
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rsi
shlq $0x0, %rsi
callq 0x2360
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
jne 0xfc43
movw $0xfffd, -0x2a(%rbp)    # imm = 0xFFFD
jmp 0xfc7b
jmp 0xfc45
movl -0x24(%rbp), %eax
movb %al, %dl
movq -0x38(%rbp), %rax
movq -0x40(%rbp), %rcx
movb %dl, (%rax,%rcx)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0xfb77
movq -0x38(%rbp), %rdi
callq 0x2170
movl $0x0, -0x4(%rbp)
jmp 0xfd36
movswl -0x2a(%rbp), %eax
movl %eax, -0x50(%rbp)
subl $-0x3, %eax
je 0xfce8
jmp 0xfc89
movl -0x50(%rbp), %eax
subl $-0x2, %eax
je 0xfcce
jmp 0xfc93
movl -0x50(%rbp), %eax
subl $-0x1, %eax
jne 0xfd17
jmp 0xfc9d
movq 0x633c(%rip), %rax      # 0x15fe0
movq (%rax), %rax
movq %rax, -0x58(%rbp)
callq 0x2300
movl (%rax), %edi
callq 0x2220
movq -0x58(%rbp), %rdi
movq %rax, %rdx
leaq 0x247d(%rip), %rsi      # 0x12142
movb $0x0, %al
callq 0x23a0
jmp 0xfd17
movq 0x630b(%rip), %rax      # 0x15fe0
movq (%rax), %rdi
leaq 0x248f(%rip), %rsi      # 0x1216e
movb $0x0, %al
callq 0x23a0
jmp 0xfd17
movq 0x62f1(%rip), %rax      # 0x15fe0
movq (%rax), %rax
movq %rax, -0x60(%rbp)
callq 0x2300
movl (%rax), %edi
callq 0x2220
movq -0x60(%rbp), %rdi
movq %rax, %rdx
leaq 0x249a(%rip), %rsi      # 0x121aa
movb $0x0, %al
callq 0x23a0
cmpq $0x0, -0x38(%rbp)
je 0xfd2f
movq -0x38(%rbp), %rdi
callq 0x2170
movq $0x0, -0x38(%rbp)
movswl -0x2a(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nop