// File: /workspace/github_c_makefile_star2_O2/mijallen[P]SimpleHTTPServer/lib/libyaml/src/writer.c
// Function: yaml_emitter_flush
YAML_DECLARE(int)
yaml_emitter_flush(yaml_emitter_t *emitter)
{
    int low, high;

    assert(emitter);    /* Non-NULL emitter object is expected. */
    assert(emitter->write_handler); /* Write handler must be set. */
    assert(emitter->encoding);  /* Output encoding must be set. */

    emitter->buffer.last = emitter->buffer.pointer;
    emitter->buffer.pointer = emitter->buffer.start;

    /* Check if the buffer is empty. */

    if (emitter->buffer.start == emitter->buffer.last) {
        return 1;
    }

    /* If the output encoding is UTF-8, we don't need to recode the buffer. */

    if (emitter->encoding == YAML_UTF8_ENCODING)
    {
        if (emitter->write_handler(emitter->write_handler_data,
                    emitter->buffer.start,
                    emitter->buffer.last - emitter->buffer.start)) {
            emitter->buffer.last = emitter->buffer.start;
            emitter->buffer.pointer = emitter->buffer.start;
            return 1;
        }
        else {
            return yaml_emitter_set_writer_error(emitter, "write error");
        }
    }

    /* Recode the buffer into the raw buffer. */

    low = (emitter->encoding == YAML_UTF16LE_ENCODING ? 0 : 1);
    high = (emitter->encoding == YAML_UTF16LE_ENCODING ? 1 : 0);

    while (emitter->buffer.pointer != emitter->buffer.last)
    {
        unsigned char octet;
        unsigned int width;
        unsigned int value;
        size_t k;

        /* 
         * See the "reader.c" code for more details on UTF-8 encoding.  Note
         * that we assume that the buffer contains a valid UTF-8 sequence.
         */

        /* Read the next UTF-8 character. */

        octet = emitter->buffer.pointer[0];

        width = (octet & 0x80) == 0x00 ? 1 :
                (octet & 0xE0) == 0xC0 ? 2 :
                (octet & 0xF0) == 0xE0 ? 3 :
                (octet & 0xF8) == 0xF0 ? 4 : 0;

        value = (octet & 0x80) == 0x00 ? octet & 0x7F :
                (octet & 0xE0) == 0xC0 ? octet & 0x1F :
                (octet & 0xF0) == 0xE0 ? octet & 0x0F :
                (octet & 0xF8) == 0xF0 ? octet & 0x07 : 0;

        for (k = 1; k < width; k ++) {
            octet = emitter->buffer.pointer[k];
            value = (value << 6) + (octet & 0x3F);
        }

        emitter->buffer.pointer += width;

        /* Write the character. */

        if (value < 0x10000)
        {
            emitter->raw_buffer.last[high] = value >> 8;
            emitter->raw_buffer.last[low] = value & 0xFF;

            emitter->raw_buffer.last += 2;
        }
        else
        {
            /* Write the character using a surrogate pair (check "reader.c"). */

            value -= 0x10000;
            emitter->raw_buffer.last[high] = 0xD8 + (value >> 18);
            emitter->raw_buffer.last[low] = (value >> 10) & 0xFF;
            emitter->raw_buffer.last[high+2] = 0xDC + ((value >> 8) & 0xFF);
            emitter->raw_buffer.last[low+2] = value & 0xFF;

            emitter->raw_buffer.last += 4;
        }
    }

    /* Write the raw buffer. */

    if (emitter->write_handler(emitter->write_handler_data,
                emitter->raw_buffer.start,
                emitter->raw_buffer.last - emitter->raw_buffer.start)) {
        emitter->buffer.last = emitter->buffer.start;
        emitter->buffer.pointer = emitter->buffer.start;
        emitter->raw_buffer.last = emitter->raw_buffer.start;
        emitter->raw_buffer.pointer = emitter->raw_buffer.start;
        return 1;
    }
    else {
        return yaml_emitter_set_writer_error(emitter, "write error");
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0x1029c
movq %rdi, %rbx
movq 0x10(%rdi), %rax
testq %rax, %rax
je 0x102b5
movl 0x78(%rbx), %edi
testl %edi, %edi
je 0x102ce
movq 0x38(%rbx), %rsi
movq 0x48(%rbx), %rdx
movq %rdx, 0x50(%rbx)
movq %rsi, 0x48(%rbx)
pushq $0x1
popq %rbp
cmpq %rdx, %rsi
je 0x1028b
cmpl $0x1, %edi
jne 0x100f2
movq 0x18(%rbx), %rdi
subq %rsi, %rdx
callq *%rax
testl %eax, %eax
je 0x10278
movq 0x38(%rbx), %rax
movq %rax, 0x50(%rbx)
movq %rax, 0x48(%rbx)
jmp 0x1028b
xorl %eax, %eax
xorl %ecx, %ecx
cmpl $0x2, %edi
setne %al
sete %cl
movq %rax, %rdi
xorq $0x3, %rdi
leaq 0x2(%rax), %r8
pushq $0x1
popq %r9
pushq $0x2
popq %r10
pushq $0x4
popq %r14
cmpq %rdx, %rsi
je 0x10248
movzbl (%rsi), %edx
testb %dl, %dl
js 0x1012b
movq %r9, %r13
jmp 0x1018f
movl %edx, %r11d
andl $-0x20, %r11d
cmpl $0xc0, %r11d
jne 0x10143
andl $0x1f, %edx
movq %r10, %r13
jmp 0x1018f
movl %edx, %r11d
andl $-0x10, %r11d
movl %edx, %r12d
andl $-0x8, %r12d
xorl %r13d, %r13d
movl $0xf0, %r15d
cmpl %r15d, %r12d
sete %r13b
shll $0x2, %r13d
cmpl $0xe0, %r11d
pushq $0x3
popq %r11
cmoveq %r11, %r13
jne 0x1017b
andl $0xf, %edx
jmp 0x1018f
andl $0x7, %edx
cmpl $0xf0, %r12d
movl $0x0, %r11d
cmovnel %r11d, %edx
cmpl $0x2, %r13d
jb 0x101d2
movl %edx, %r11d
movzbl 0x1(%rsi), %edx
shll $0x6, %r11d
andl $0x3f, %edx
orl %r11d, %edx
cmpl $0x2, %r13d
je 0x101d2
movl %edx, %r11d
movzbl 0x2(%rsi), %edx
shll $0x6, %r11d
andl $0x3f, %edx
orl %r11d, %edx
cmpl $0x4, %r13d
jb 0x101d2
movzbl 0x3(%rsi), %r11d
shll $0x6, %edx
andl $0x3f, %r11d
orl %r11d, %edx
addq %r13, %rsi
movq %rsi, 0x48(%rbx)
cmpl $0xffff, %edx           # imm = 0xFFFF
ja 0x101f1
movl %edx, %esi
shrl $0x8, %esi
movq %rcx, %r12
movq %rax, %r13
movq %r10, %r11
jmp 0x10227
leal -0x10000(%rdx), %esi
movl %esi, %r11d
shrl $0x12, %r11d
addb $-0x28, %r11b
movq 0x70(%rbx), %r12
movb %r11b, (%r12,%rcx)
shrl $0xa, %esi
movq 0x70(%rbx), %r11
movb %sil, (%r11,%rax)
movl %edx, %esi
shrl $0x8, %esi
addb $-0x24, %sil
movq %rdi, %r12
movq %r8, %r13
movq %r14, %r11
movq 0x70(%rbx), %r15
movb %sil, (%r15,%r12)
movq 0x70(%rbx), %rsi
movb %dl, (%rsi,%r13)
addq %r11, 0x70(%rbx)
movq 0x48(%rbx), %rsi
movq 0x50(%rbx), %rdx
jmp 0x10116
movq 0x18(%rbx), %rdi
movq 0x58(%rbx), %rsi
movq 0x70(%rbx), %rdx
subq %rsi, %rdx
callq *0x10(%rbx)
testl %eax, %eax
je 0x10278
movq 0x38(%rbx), %rax
movq 0x58(%rbx), %rcx
movq %rax, 0x50(%rbx)
movq %rax, 0x48(%rbx)
movq %rcx, 0x70(%rbx)
movq %rcx, 0x68(%rbx)
jmp 0x1028b
movl $0x6, (%rbx)
leaq 0x79cf(%rip), %rax      # 0x17c54
movq %rax, 0x8(%rbx)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5f3a(%rip), %rdi      # 0x161dd
leaq 0x7978(%rip), %rsi      # 0x17c22
leaq 0x797a(%rip), %rcx      # 0x17c2b
pushq $0x24
jmp 0x102e5
leaq 0x5fdc(%rip), %rdi      # 0x16298
leaq 0x795f(%rip), %rsi      # 0x17c22
leaq 0x7961(%rip), %rcx      # 0x17c2b
pushq $0x25
jmp 0x102e5
leaq 0x60af(%rip), %rdi      # 0x16384
leaq 0x7946(%rip), %rsi      # 0x17c22
leaq 0x7948(%rip), %rcx      # 0x17c2b
pushq $0x26
popq %rdx
callq 0x2100
nop