// File: /workspace/github_c_makefile_star2_O2/Cotix[P]cReddit/libreddit/token.c
// Function: performIdentAction
int performIdentAction(TokenParser *p, TokenIdent *identifiers, int i, va_list args)
{
    char *tmp = NULL;
    int performedAction = 0, len;

    time_t created_time_t;
    struct tm *localtime_internal_data;
    struct tm *created_struct_tm;
    char *formatted_time_string;

    READ_TOKEN_TO_TMP(p->block->memory, tmp, p->tokens[p->currentToken]);

    if (TOKEN_EQUALS(tmp, identifiers[i].name)) {
        switch(identifiers[i].action) {
        case TOKEN_CHECK_CALL:
            (p->currentToken)++;
            CALL_TOKEN_FUNC(identifiers[i].funcCallback, p, identifiers, args);
            performedAction = 1;
            break;

        case TOKEN_SET_PARSE:
            (p->currentToken)++;
            if (identifiers[i].freeFlag) {
                free(*((char**)identifiers[i].value));
                free(*(identifiers[i].parseStrWide));
                free(*(identifiers[i].parseStr));
            }

            *((char**)identifiers[i].value) = getCopyOfToken(p->block->memory, p->tokens[p->currentToken]);

            len = p->tokens[p->currentToken].end - p->tokens[p->currentToken].start;

            *(identifiers[i].parseStr)     = redditParseEscCodes    (*((char**)identifiers[i].value), len);
            *(identifiers[i].parseStrWide) = redditParseEscCodesWide(*((char**)identifiers[i].value), len);

            break;

        case TOKEN_SET:
            (p->currentToken)++;
            READ_TOKEN_TO_TMP(p->block->memory, tmp, p->tokens[p->currentToken]);
            switch(identifiers[i].type) {
            case TOKEN_BOOL:
                if (TOKEN_IS_TRUE(p->block->memory, p->tokens[p->currentToken]))
                    *((unsigned int *)identifiers[i].value) |= identifiers[i].bitMask;
                else
                    *((unsigned int *)identifiers[i].value) &= ~identifiers[i].bitMask;

                break;
            case TOKEN_INT:
                *((int*)(identifiers[i].value)) = atoi(tmp);
                break;
            case TOKEN_STRING:
            case TOKEN_OBJECT:
                if (identifiers[i].freeFlag)
                    free(*((char**)identifiers[i].value));

                *((char**)identifiers[i].value) = getCopyOfToken(p->block->memory, p->tokens[p->currentToken]);
                break;
            case TOKEN_DATE:
                // Process the tmp char* string as a date
                created_time_t = atol(tmp);
                created_struct_tm = (struct tm *)(rmalloc(sizeof(struct tm)));
                formatted_time_string = (char *)(rmalloc(CREATE_DATE_FORMAT_BYTE_COUNT));
                
                // Convert created_time_t (seconds since epoch) to 
                // the struct tm object of localtime_internal_data. After we get
                // the value, copy the internal data (static data)to a newly created
                // struct tm object.
                localtime_internal_data = localtime(&created_time_t);
                if (localtime_internal_data != NULL)
                {
                    memcpy(created_struct_tm, localtime_internal_data, sizeof(struct tm));

                    // Use strftime to convert the struct tm to a formatted string. The
                    // format for the string is specified by CREATE_DATE_FORMAT
                    if (0 != strftime(formatted_time_string, CREATE_DATE_FORMAT_BYTE_COUNT, 
                                CREATE_DATE_FORMAT, created_struct_tm))
                    {
                        *((char**)identifiers[i].value) = formatted_time_string;
                    }
                }

                // Free only created_struct_tm, don't free formatted_time_string
                // because that data is now pointed to by identifiers[i].value
                free(created_struct_tm);
                break;
            }
            performedAction = 1;

            break;
        }
    }

    free(tmp);
    return performedAction;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %r13
movl %edx, %ebp
movq %rsi, %r12
movq %rdi, %r15
movq 0x8(%rdi), %rax
movslq 0x14(%rdi), %rcx
imulq $0x1c, %rcx, %rcx
movl 0x8(%rax,%rcx), %edx
subl 0x4(%rax,%rcx), %edx
incl %edx
movslq %edx, %rsi
xorl %edi, %edi
callq 0x34f5
movq %rax, %rbx
movq (%r15), %rax
movq 0x8(%r15), %rcx
movslq 0x14(%r15), %rdx
imulq $0x1c, %rdx, %rdx
movslq 0x4(%rcx,%rdx), %rdi
movq (%rax), %rsi
addq %rdi, %rsi
movslq 0x8(%rcx,%rdx), %rdx
subq %rdi, %rdx
movq %rbx, %rdi
callq 0x2180
movq 0x8(%r15), %rax
movslq 0x14(%r15), %rcx
imulq $0x1c, %rcx, %rcx
movslq 0x8(%rax,%rcx), %rdx
movslq 0x4(%rax,%rcx), %rax
subq %rax, %rdx
movb $0x0, (%rbx,%rdx)
movslq %ebp, %rax
imulq $0x38, %rax, %r14
movq (%r12,%r14), %rsi
movq %rbx, %rdi
callq 0x2160
testl %eax, %eax
je 0x440c
xorl %ebp, %ebp
movq %rbx, %rdi
callq 0x2050
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq %r12, %r14
movl 0xc(%r14), %eax
testl %eax, %eax
je 0x44d0
cmpl $0x1, %eax
je 0x444b
cmpl $0x2, %eax
jne 0x43f1
incl 0x14(%r15)
movq 0x10(%r13), %rax
movq %rsp, %rdx
movq %rax, 0x10(%rdx)
movups (%r13), %xmm0
movaps %xmm0, (%rdx)
movq %r15, %rdi
movq %r12, %rsi
callq *0x30(%r14)
pushq $0x1
popq %rbp
jmp 0x43f3
movl 0x14(%r15), %eax
incl %eax
movl %eax, 0x14(%r15)
cmpb $0x1, 0x2c(%r14)
jne 0x4484
movq 0x10(%r14), %rax
movq (%rax), %rdi
callq 0x2050
movq 0x20(%r14), %rax
movq (%rax), %rdi
callq 0x2050
movq 0x18(%r14), %rax
movq (%rax), %rdi
callq 0x2050
movl 0x14(%r15), %eax
movq 0x8(%r15), %rcx
cltq
imulq $0x1c, %rax, %rdx
movslq 0x4(%rcx,%rdx), %r12
movl 0x8(%rcx,%rdx), %ebp
subl %r12d, %ebp
js 0x45c2
movq (%r15), %rax
leal 0x1(%rbp), %edi
addq (%rax), %r12
callq 0x34e0
movq %rax, %r13
movl %ebp, %ebp
movq %rax, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x2180
movb $0x0, (%r13,%rbp)
movslq 0x14(%r15), %rax
jmp 0x45c5
movslq 0x14(%r15), %rax
incq %rax
movl %eax, 0x14(%r15)
movq 0x8(%r15), %rcx
imulq $0x1c, %rax, %rax
movl 0x8(%rcx,%rax), %edx
subl 0x4(%rcx,%rax), %edx
incl %edx
movslq %edx, %rsi
movq %rbx, %rdi
callq 0x34f5
movq %rax, %rbx
movq (%r15), %rax
movq 0x8(%r15), %rcx
movslq 0x14(%r15), %rdx
imulq $0x1c, %rdx, %rdx
movslq 0x4(%rcx,%rdx), %rdi
movq (%rax), %rsi
addq %rdi, %rsi
movslq 0x8(%rcx,%rdx), %rdx
subq %rdi, %rdx
movq %rbx, %rdi
callq 0x2180
movq 0x8(%r15), %rax
movslq 0x14(%r15), %rcx
imulq $0x1c, %rcx, %rcx
movslq 0x8(%rax,%rcx), %rdx
movslq 0x4(%rax,%rcx), %rax
subq %rax, %rdx
movb $0x0, (%rbx,%rdx)
movl 0x8(%r14), %eax
pushq $0x1
popq %rbp
cmpq $0x4, %rax
ja 0x43f3
leaq 0x1b22(%rip), %rcx      # 0x607c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpb $0x1, 0x2c(%r14)
jne 0x4576
movq 0x10(%r14), %rax
movq (%rax), %rdi
callq 0x2050
movq 0x8(%r15), %rax
movslq 0x14(%r15), %rcx
imulq $0x1c, %rcx, %rcx
movslq 0x4(%rax,%rcx), %r12
movl 0x8(%rax,%rcx), %r13d
subl %r12d, %r13d
js 0x46d8
movq (%r15), %rax
leal 0x1(%r13), %edi
addq (%rax), %r12
callq 0x34e0
movq %rax, %r15
movl %r13d, %r13d
movq %rax, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x2180
movb $0x0, (%r15,%r13)
jmp 0x46db
xorl %r13d, %r13d
movq 0x10(%r14), %rcx
movq %r13, (%rcx)
movq 0x8(%r15), %rcx
imulq $0x1c, %rax, %rax
movl 0x8(%rcx,%rax), %ebp
subl 0x4(%rcx,%rax), %ebp
movq 0x10(%r14), %rax
movq (%rax), %rdi
movl %ebp, %esi
callq 0x2280
movq 0x18(%r14), %rcx
movq %rax, (%rcx)
movq 0x10(%r14), %rax
movq (%rax), %rdi
movl %ebp, %esi
callq 0x2040
movq 0x20(%r14), %rcx
movq %rax, (%rcx)
jmp 0x43f1
movq %rbx, %rdi
callq 0x2220
movq %rsp, %r13
movq %rax, (%r13)
pushq $0x38
popq %rdi
callq 0x34e0
movq %rax, %r15
pushq $0x20
popq %rdi
callq 0x34e0
movq %rax, %r12
movq %r13, %rdi
callq 0x2060
testq %rax, %rax
je 0x467f
movq 0x30(%rax), %rcx
movq %rcx, 0x30(%r15)
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups 0x20(%rax), %xmm2
movups %xmm2, 0x20(%r15)
movups %xmm1, 0x10(%r15)
movups %xmm0, (%r15)
leaq 0x1bbb(%rip), %rdx      # 0x6220
pushq $0x20
popq %rsi
movq %r12, %rdi
movq %r15, %rcx
callq 0x2200
testq %rax, %rax
je 0x467f
movq 0x10(%r14), %rax
movq %r12, (%rax)
movq %r15, %rdi
callq 0x2050
jmp 0x43f3
callq 0x2030
movq (%rax), %rax
movq (%r15), %rcx
movq 0x8(%r15), %rdx
movq (%rcx), %rcx
movslq 0x14(%r15), %rsi
imulq $0x1c, %rsi, %rsi
movslq 0x4(%rdx,%rsi), %rdx
movsbq (%rcx,%rdx), %rcx
cmpl $0x54, (%rax,%rcx,4)
movl 0x28(%r14), %eax
jne 0x46e7
movq 0x10(%r14), %rcx
orl %eax, (%rcx)
jmp 0x43f3
movq %rbx, %rdi
callq 0x2250
movq 0x10(%r14), %rcx
movl %eax, (%rcx)
jmp 0x43f3
xorl %r15d, %r15d
movq 0x10(%r14), %rax
movq %r15, (%rax)
jmp 0x43f3
notl %eax
movq 0x10(%r14), %rcx
andl %eax, (%rcx)
jmp 0x43f3