// File: /workspace/github_c_makefile_star2_O0/sasairc[P]yasuna/src/libpolyaness/src/polyaness.c
// Function: add_data_polyaness
static
int add_data_polyaness(int record, int keys, const char* str, polyaness_t*** polyaness)
{
    int             i       = 0;

    short           status  = 0;

    char**          key     = NULL,
        **          value   = NULL;

    size_t          head    = 0,
                    tail    = 0;

    key = (char**)
        malloc(sizeof(char*) * keys);
    value = (char**)
        malloc(sizeof(char*) * keys);

    if (key == NULL || value == NULL) {
        status = -1; goto ERR;
    }
    
    while (i < keys) {
        if (*(str + head) == COL) {
            if ((*(key + i) = (char*)
                    malloc(sizeof(char) * (head - tail + 1))) == NULL) {
                status = -2; goto ERR;
            }
            memcpy(*(key + i), str + tail, head - tail);
            *(*(key + i) + head - tail) = '\0';

            head++;
            tail = head;
        } else if (*(str + head) == TAB || *(str + head) == '\0') {
            if ((*(value + i) = (char*)
                    malloc(sizeof(char) * (head - tail + 1))) == NULL) {
                status = -3; goto ERR;
            }
            memcpy(*(value + i), str + tail, head - tail);
            *(*(value + i) + head - tail) = '\0';

            head++;
            tail = head;
            i++;
        }
        head++;
    }

    (*(*polyaness))->record[record]->keys = keys;
    (*(*polyaness))->record[record]->key = key;
    (*(*polyaness))->record[record]->value = value;

    return 0;

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

    keys = i;
    if (key != NULL) {
        i = keys;
        while (i >= 0) {
            if (*(key + i) != NULL)
                free(*(key + i));
            i--;
        }
        free(key);
    }
    if (value != NULL) {
        i = keys;
        while (i >= 0) {
            if (*(value + i) != NULL)
                free(*(value + i));
            i--;
        }
        free(value);
    }

    return status;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movl %edi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movw $0x0, -0x26(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movslq -0xc(%rbp), %rdi
shlq $0x3, %rdi
callq 0x20e0
movq %rax, -0x30(%rbp)
movslq -0xc(%rbp), %rdi
shlq $0x3, %rdi
callq 0x20e0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0xfdb3
cmpq $0x0, -0x38(%rbp)
jne 0xfdbe
movw $0xffff, -0x26(%rbp)    # imm = 0xFFFF
jmp 0xff8d
jmp 0xfdc0
movl -0x24(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0xff2a
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x3a, %eax
jne 0xfe67
movq -0x40(%rbp), %rdi
subq -0x48(%rbp), %rdi
addq $0x1, %rdi
shlq $0x0, %rdi
callq 0x20e0
movq -0x30(%rbp), %rcx
movslq -0x24(%rbp), %rdx
movq %rax, (%rcx,%rdx,8)
cmpq $0x0, %rax
jne 0xfe13
movw $0xfffe, -0x26(%rbp)    # imm = 0xFFFE
jmp 0xff8d
movq -0x30(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x18(%rbp), %rsi
addq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
subq -0x48(%rbp), %rdx
callq 0x23c0
movq -0x30(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
addq -0x40(%rbp), %rax
xorl %ecx, %ecx
subq -0x48(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0xff19
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x9, %eax
je 0xfe8d
movq -0x18(%rbp), %rax
movq -0x40(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0xff17
movq -0x40(%rbp), %rdi
subq -0x48(%rbp), %rdi
addq $0x1, %rdi
shlq $0x0, %rdi
callq 0x20e0
movq -0x38(%rbp), %rcx
movslq -0x24(%rbp), %rdx
movq %rax, (%rcx,%rdx,8)
cmpq $0x0, %rax
jne 0xfebf
movw $0xfffd, -0x26(%rbp)    # imm = 0xFFFD
jmp 0xff8d
movq -0x38(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x18(%rbp), %rsi
addq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
subq -0x48(%rbp), %rdx
callq 0x23c0
movq -0x38(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
addq -0x40(%rbp), %rax
xorl %ecx, %ecx
subq -0x48(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x48(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xff19
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0xfdc0
movl -0xc(%rbp), %ecx
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movslq -0x8(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movl %ecx, (%rax)
movq -0x30(%rbp), %rcx
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movslq -0x8(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rcx
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movslq -0x8(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movq %rcx, 0x10(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x10065
movswl -0x26(%rbp), %eax
addl $0x3, %eax
subl $0x2, %eax
ja 0xffca
jmp 0xff9b
movq 0x603e(%rip), %rax      # 0x15fe0
movq (%rax), %rax
movq %rax, -0x50(%rbp)
callq 0x2300
movl (%rax), %edi
callq 0x2220
movq -0x50(%rbp), %rdi
movq %rax, %rdx
leaq 0x2214(%rip), %rsi      # 0x121d7
movb $0x0, %al
callq 0x23a0
movl -0x24(%rbp), %eax
movl %eax, -0xc(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x10017
movl -0xc(%rbp), %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jl 0x1000e
movq -0x30(%rbp), %rax
movslq -0x24(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x10003
movq -0x30(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x2170
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xffdd
movq -0x30(%rbp), %rdi
callq 0x2170
cmpq $0x0, -0x38(%rbp)
je 0x1005e
movl -0xc(%rbp), %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jl 0x10055
movq -0x38(%rbp), %rax
movslq -0x24(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x1004a
movq -0x38(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x2170
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x10024
movq -0x38(%rbp), %rdi
callq 0x2170
movswl -0x26(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nop