// File: /workspace/github_c_makefile_star2_O2/inflex[P]ripMIME/MIME_headers.c
// Function: MIMEH_recompose_multivalue
int MIMEH_recompose_multivalue( struct MIMEH_header_info *hinfo, char *header_name_prefix, char *header_value, char *buffer, size_t buffer_size, char **data_end_point )
{
    int result = 0;
    char *start_position = header_value;


    DMIMEH LOGGER_log("%s:%d:MIMEH_recompose_multivalue:DEBUG: seeking for %s in %s and appending to '%s'. Buffer size=%d", FL, header_name_prefix, header_value,buffer, buffer_size );


    // Locate the first part of the multipart string
    start_position = strstr(header_value, header_name_prefix);
    if (start_position != NULL)
    {
        char *q;
        char *buffer_start;
		  int is_quoted = 0;

        // Setup our buffer insertion point for what ever new data we extract
        buffer_start = buffer +strlen(buffer);
        buffer_size -= strlen(buffer);

        q = start_position;

        // If the string we're looking for exists, then continue...
        do {
            char *p;
            char *end_point;
            char end_point_char='\0';
            int decode_data=0;
            int q_len;

            p = strstr(q, header_name_prefix);
            if (p == NULL) break;

            DMIMEH LOGGER_log("%s:%d:MIMEH_recompose_multivalue:DEBUG: prefix = '''%s'''", FL, p);

            q = strchr(p,'=');
            if (q == NULL) break;

            // Test to see if we have to look for a language encoding specification *sigh*
            if (*(q-1) == '*')
            {
                decode_data=1;
            }

            // Move the pointer past the '=' separator
            q++;

            DMIMEH LOGGER_log("%s:%d:MIMEH_recompose_multivalue:DEBUG: data = '''%s'''", FL, q);

				// Is our string quoted (ie, will likely contain whitespace)
				//
				if (*q == '"') {
					DMIMEH LOGGER_log("%s:%d:MIMEH_recompose_multivalue:DEBUG: multipart segment is quote-prefixed", FL);
					is_quoted = 1;
				}

            // Find where this multipart string ends
				//
				//
				if (is_quoted) end_point = strpbrk(q+1,";\r\n\"");
				else end_point = strpbrk(q, ";\t\n\r ");
            if (end_point != NULL)
            {
                *end_point = '\0';
                end_point_char = *end_point;
                *data_end_point = end_point; // Set this so we know where to start decoding the next time we call this fn
            } else {
                char *ep;

                // If strpbrk comes up with nothing, then we set the data_end_point to the end of the string
                ep = q;
                while (*ep != '\0') ep++;
                *data_end_point = ep;
            }

            // Trim off quotes.
            if (*q == '"')
            {
                int bl;

                //  LOGGER_log("%s:%d:DEBUG: Trimming '%s'", FL, q);
                q++;
                bl = strlen(q);
                if (*(q +bl -1) == '"') *(q +bl -1) = '\0';
                //LOGGER_log("%s:%d:DEBUG: Trim done, '%s'", FL, q);
            }

            if (decode_data == 1)
            {
                MIMEH_decode_multivalue_language_string(q);
            }

            DMIMEH LOGGER_log("%s:%d:MIMEH_recompose_multivalue:DEBUG: segment value = '%s', appending to '%s'", FL, q, buffer);
            snprintf(buffer_start,buffer_size,"%s",q);
            q_len = strlen(q);
            buffer_size -= q_len;
            buffer_start += q_len;
            DMIMEH LOGGER_log("%s:%d:MIMEH_recompose_multivalue:DEBUG: Buffer[remaining=%d]= '%s'", FL, buffer_size,buffer);

            if (end_point != NULL)
            {
                *end_point = end_point_char;
                q = end_point +1;
            }
            else q = NULL;

        } while ((q != NULL)&&(buffer_size > 0));

    }

    DMIMEH LOGGER_log("%s:%d:MIMEH_recompose_multivalue:DEBUG: End point set to: [%d] '%s'",FL, (*data_end_point -header_value), *data_end_point);
    return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, 0x18(%rsp)
movq %r8, %r15
movq %rcx, %r12
movq %rdx, %rbx
movq %rsi, %r14
cmpl $0x0, 0x225aa(%rip)     # 0x2b38c
jle 0x8e0b
movq %r15, (%rsp)
leaq 0xc0c3(%rip), %rdi      # 0x14eb2
leaq 0xb4e8(%rip), %rsi      # 0x142de
movl $0x591, %edx            # imm = 0x591
movq %r14, %rcx
movq %rbx, %r8
movq %r12, %r9
xorl %eax, %eax
callq 0xc2a1
movq %rbx, 0x20(%rsp)
movq %rbx, %rdi
movq %r14, 0x30(%rsp)
movq %r14, %rsi
callq 0x23d0
testq %rax, %rax
je 0x902f
movq %rax, %rbx
movq %r12, %rdi
callq 0x2110
leaq (%r12,%rax), %rbp
subq %rax, %r15
movl $0x0, 0x14(%rsp)
movq %r12, 0x28(%rsp)
movq %rbx, %rdi
movq 0x30(%rsp), %rsi
callq 0x23d0
testq %rax, %rax
je 0x902f
movq %rax, %rbx
cmpl $0x0, 0x22524(%rip)     # 0x2b38c
jle 0x8e87
leaq 0xc0a4(%rip), %rdi      # 0x14f15
leaq 0xb466(%rip), %rsi      # 0x142de
movl $0x5ad, %edx            # imm = 0x5AD
movq %rbx, %rcx
xorl %eax, %eax
callq 0xc2a1
movq %rbx, %rdi
pushq $0x3d
popq %rsi
callq 0x2120
testq %rax, %rax
je 0x902f
movq %rax, %r13
movb -0x1(%rax), %r12b
leaq 0x1(%rax), %r14
cmpl $0x0, 0x224df(%rip)     # 0x2b38c
jle 0x8ecc
leaq 0xc099(%rip), %rdi      # 0x14f4f
leaq 0xb421(%rip), %rsi      # 0x142de
movl $0x5bb, %edx            # imm = 0x5BB
movq %r14, %rcx
xorl %eax, %eax
callq 0xc2a1
cmpb $0x22, (%r14)
jne 0x8f05
cmpl $0x0, 0x224b3(%rip)     # 0x2b38c
pushq $0x1
popq %rax
movl %eax, 0x14(%rsp)
jle 0x8f10
leaq 0xc09e(%rip), %rdi      # 0x14f87
leaq 0xb3ee(%rip), %rsi      # 0x142de
movl $0x5c0, %edx            # imm = 0x5C0
xorl %eax, %eax
callq 0xc2a1
pushq $0x1
popq %rax
movl %eax, 0x14(%rsp)
jmp 0x8f10
cmpl $0x0, 0x14(%rsp)
je 0x9010
leaq 0x2(%r13), %rdi
leaq 0xc0b8(%rip), %rsi      # 0x14fd3
callq 0x2300
movq %rax, %rbx
movq %r13, %rax
testq %rbx, %rbx
je 0x8f33
movb $0x0, (%rbx)
movq %rbx, %rcx
jmp 0x8f40
leaq 0x1(%rax), %rcx
cmpb $0x0, 0x1(%rax)
movq %rcx, %rax
jne 0x8f33
movq 0x18(%rsp), %rax
movq %rcx, (%rax)
cmpb $0x22, (%r14)
jne 0x8f6d
movq %r13, %r14
addq $0x2, %r14
movq %r14, %rdi
callq 0x2110
cltq
cmpb $0x22, 0x1(%r13,%rax)
jne 0x8f6d
movb $0x0, -0x1(%r14,%rax)
cmpb $0x2a, %r12b
jne 0x8f7b
movq %r14, %rdi
callq 0x8d16
cmpl $0x0, 0x2240a(%rip)     # 0x2b38c
movq 0x28(%rsp), %r12
jle 0x8fa9
leaq 0xc04e(%rip), %rdi      # 0x14fde
leaq 0xb347(%rip), %rsi      # 0x142de
movl $0x5e8, %edx            # imm = 0x5E8
movq %r14, %rcx
movq %r12, %r8
xorl %eax, %eax
callq 0xc2a1
movq %rbp, %rdi
movq %r15, %rsi
leaq 0xe0aa(%rip), %rdx      # 0x17060
movq %r14, %rcx
xorl %eax, %eax
callq 0x2140
movq %r14, %rdi
callq 0x2110
movslq %eax, %r14
subq %r14, %r15
cmpl $0x0, 0x223b7(%rip)     # 0x2b38c
jle 0x8ff7
leaq 0xc050(%rip), %rdi      # 0x1502e
leaq 0xb2f9(%rip), %rsi      # 0x142de
movl $0x5ed, %edx            # imm = 0x5ED
movq %r15, %rcx
movq %r12, %r8
xorl %eax, %eax
callq 0xc2a1
testq %rbx, %rbx
je 0x902f
addq %r14, %rbp
movb $0x0, (%rbx)
incq %rbx
testq %r15, %r15
jne 0x8e48
jmp 0x902f
movq %r14, %rdi
leaq 0xbfbe(%rip), %rsi      # 0x14fd8
callq 0x2300
movq %rax, %rbx
movl $0x0, 0x14(%rsp)
jmp 0x8f23
cmpl $0x0, 0x22356(%rip)     # 0x2b38c
jle 0x9062
movq 0x18(%rsp), %rax
movq (%rax), %r8
movq %r8, %rcx
subq 0x20(%rsp), %rcx
leaq 0xc022(%rip), %rdi      # 0x15071
leaq 0xb288(%rip), %rsi      # 0x142de
movl $0x5fa, %edx            # imm = 0x5FA
xorl %eax, %eax
callq 0xc2a1
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq