// File: /workspace/github_c_makefile_star2_O1/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, %r13
movq %rdx, %rbx
movq %rsi, %r12
cmpl $0x0, 0x23255(%rip)     # 0x2c38c
jle 0x9160
movq %r15, (%rsp)
leaq 0xcd3e(%rip), %rdi      # 0x15e82
leaq 0xc163(%rip), %rsi      # 0x152ae
movl $0x591, %edx            # imm = 0x591
movq %r12, %rcx
movq %rbx, %r8
movq %r13, %r9
xorl %eax, %eax
callq 0xc960
movq %rbx, 0x20(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x23d0
testq %rax, %rax
je 0x9384
movq %rax, %rbx
movq %r13, %rdi
callq 0x2110
leaq (%rax,%r13), %rbp
subq %rax, %r15
movl $0x0, 0x14(%rsp)
movq %r12, 0x28(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x23d0
testq %rax, %rax
je 0x9268
movq %rax, %r14
cmpl $0x0, 0x231d6(%rip)     # 0x2c38c
jle 0x91d5
leaq 0xcd26(%rip), %rdi      # 0x15ee5
leaq 0xc0e8(%rip), %rsi      # 0x152ae
movl $0x5ad, %edx            # imm = 0x5AD
movq %r14, %rcx
xorl %eax, %eax
callq 0xc960
movq %r14, %rdi
movl $0x3d, %esi
callq 0x2120
testq %rax, %rax
je 0x9266
movq %rax, %r14
movq %rbp, 0x30(%rsp)
movq %r13, %rbp
movb -0x1(%rax), %r13b
leaq 0x1(%rax), %r12
cmpl $0x0, 0x2318b(%rip)     # 0x2c38c
jle 0x9220
leaq 0xcd15(%rip), %rdi      # 0x15f1f
leaq 0xc09d(%rip), %rsi      # 0x152ae
movl $0x5bb, %edx            # imm = 0x5BB
movq %r12, %rcx
xorl %eax, %eax
callq 0xc960
cmpb $0x22, (%r12)
jne 0x9252
movl $0x1, 0x14(%rsp)
cmpl $0x0, 0x23156(%rip)     # 0x2c38c
jle 0x9252
leaq 0xcd18(%rip), %rdi      # 0x15f57
leaq 0xc068(%rip), %rsi      # 0x152ae
movl $0x5c0, %edx            # imm = 0x5C0
xorl %eax, %eax
callq 0xc960
cmpl $0x0, 0x14(%rsp)
je 0x926f
leaq 0x2(%r14), %rdi
leaq 0xcd3f(%rip), %rsi      # 0x15fa3
jmp 0x9279
xorl %ebx, %ebx
xorl %eax, %eax
jmp 0x9372
movq %r12, %rdi
leaq 0xcd2f(%rip), %rsi      # 0x15fa8
callq 0x2300
movq %rax, %rbx
movq %r14, %rax
testq %rbx, %rbx
je 0x9291
movb $0x0, (%rbx)
movq %rbx, %rcx
jmp 0x929e
leaq 0x1(%rax), %rcx
cmpb $0x0, 0x1(%rax)
movq %rcx, %rax
jne 0x9291
movq 0x18(%rsp), %rax
movq %rcx, (%rax)
cmpb $0x22, (%r12)
jne 0x92cc
movq %r14, %r12
addq $0x2, %r12
movq %r12, %rdi
callq 0x2110
cltq
cmpb $0x22, 0x1(%r14,%rax)
jne 0x92cc
movb $0x0, -0x1(%r12,%rax)
cmpb $0x2a, %r13b
jne 0x92da
movq %r12, %rdi
callq 0x905c
cmpl $0x0, 0x230ab(%rip)     # 0x2c38c
movq %rbp, %r13
jle 0x9306
leaq 0xccc1(%rip), %rdi      # 0x15fae
leaq 0xbfba(%rip), %rsi      # 0x152ae
movl $0x5e8, %edx            # imm = 0x5E8
movq %r12, %rcx
movq %r13, %r8
xorl %eax, %eax
callq 0xc960
movq 0x30(%rsp), %rbp
movq %rbp, %rdi
movq %r15, %rsi
leaq 0xed75(%rip), %rdx      # 0x1808d
movq %r12, %rcx
xorl %eax, %eax
callq 0x2140
movq %r12, %rdi
callq 0x2110
movslq %eax, %r14
subq %r14, %r15
cmpl $0x0, 0x23055(%rip)     # 0x2c38c
jle 0x9359
leaq 0xccbe(%rip), %rdi      # 0x15ffe
leaq 0xbf67(%rip), %rsi      # 0x152ae
movl $0x5ed, %edx            # imm = 0x5ED
movq %r15, %rcx
movq %r13, %r8
xorl %eax, %eax
callq 0xc960
addq %r14, %rbp
movb $0x1, %al
testq %rbx, %rbx
movq 0x28(%rsp), %r12
je 0x9370
movb $0x0, (%rbx)
incq %rbx
jmp 0x9372
xorl %ebx, %ebx
testb %al, %al
je 0x9384
testq %rbx, %rbx
je 0x9384
testq %r15, %r15
jne 0x9198
cmpl $0x0, 0x23001(%rip)     # 0x2c38c
jle 0x93b7
movq 0x18(%rsp), %rax
movq (%rax), %r8
movq %r8, %rcx
subq 0x20(%rsp), %rcx
leaq 0xcc9d(%rip), %rdi      # 0x16041
leaq 0xbf03(%rip), %rsi      # 0x152ae
movl $0x5fa, %edx            # imm = 0x5FA
xorl %eax, %eax
callq 0xc960
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq