// File: /workspace/github_c_makefile_star2_O3/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 0x10da4
movq %rdi, %rbx
movq 0x10(%rdi), %rax
testq %rax, %rax
je 0x10dc3
movl 0x78(%rbx), %edi
testl %edi, %edi
je 0x10de2
movq 0x38(%rbx), %rsi
movq 0x48(%rbx), %rdx
movq %rdx, 0x50(%rbx)
movq %rsi, 0x48(%rbx)
movl $0x1, %ebp
cmpq %rdx, %rsi
je 0x10d93
cmpl $0x1, %edi
jne 0x10bfc
movq 0x18(%rbx), %rdi
subq %rsi, %rdx
callq *%rax
testl %eax, %eax
je 0x10d80
movq 0x38(%rbx), %rax
movq %rax, 0x50(%rbx)
movq %rax, 0x48(%rbx)
jmp 0x10d93
xorl %eax, %eax
xorl %ecx, %ecx
cmpl $0x2, %edi
setne %al
sete %cl
movq %rax, %rdi
xorq $0x3, %rdi
leaq 0x2(%rax), %r8
movl $0xf0, %r9d
movl $0x3, %r10d
xorl %r11d, %r11d
movzbl (%rsi), %r14d
movl $0x1, %edx
testb %r14b, %r14b
js 0x10c72
addq %rdx, %rsi
movq %rsi, 0x48(%rbx)
movl %r14d, %r15d
shrl $0x8, %r15d
movl $0x2, %edx
movq %rcx, %rsi
movq %rax, %r12
movq 0x70(%rbx), %r13
movb %r15b, (%r13,%rsi)
movq 0x70(%rbx), %rsi
movb %r14b, (%rsi,%r12)
addq 0x70(%rbx), %rdx
movq 0x48(%rbx), %rsi
movq %rdx, 0x70(%rbx)
cmpq 0x50(%rbx), %rsi
jne 0x10c23
jmp 0x10d54
movl %r14d, %edx
andl $-0x20, %edx
cmpl $0xc0, %edx
jne 0x10c8b
andl $0x1f, %r14d
movl $0x2, %edx
jmp 0x10ce5
movl %r14d, %r15d
andl $-0x10, %r15d
movl %r14d, %r12d
andl $-0x8, %r12d
xorl %edx, %edx
cmpl %r9d, %r12d
sete %dl
shll $0x2, %edx
cmpl $0xe0, %r15d
cmoveq %r10, %rdx
jne 0x10cb7
andl $0xf, %r14d
jmp 0x10cc6
andl $0x7, %r14d
cmpl $0xf0, %r12d
cmovnel %r11d, %r14d
cmpl $0xf0, %r12d
setne %r12b
cmpl $0xe0, %r15d
setne %r15b
testb %r12b, %r15b
jne 0x10c31
movl $0x1, %r12d
movl %r14d, %r15d
movzbl (%rsi,%r12), %r14d
shll $0x6, %r15d
andl $0x3f, %r14d
orl %r15d, %r14d
incq %r12
cmpq %r12, %rdx
jne 0x10ceb
addq %rdx, %rsi
movq %rsi, 0x48(%rbx)
cmpl $0xffff, %r15d          # imm = 0xFFFF
jbe 0x10c38
leal -0x10000(%r14), %edx
movl %edx, %esi
shrl $0x12, %esi
addb $-0x28, %sil
movq 0x70(%rbx), %r12
movb %sil, (%r12,%rcx)
shrl $0xa, %edx
movq 0x70(%rbx), %rsi
movb %dl, (%rsi,%rax)
shrl $0x8, %r15d
addb $-0x24, %r15b
movl $0x4, %edx
movq %rdi, %rsi
movq %r8, %r12
jmp 0x10c4a
movq 0x18(%rbx), %rdi
movq 0x58(%rbx), %rsi
subq %rsi, %rdx
callq *0x10(%rbx)
testl %eax, %eax
je 0x10d80
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 0x10d93
movl $0x6, (%rbx)
leaq 0x7ed7(%rip), %rax      # 0x18c64
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 0x6432(%rip), %rdi      # 0x171dd
leaq 0x7e80(%rip), %rsi      # 0x18c32
leaq 0x7e82(%rip), %rcx      # 0x18c3b
movl $0x24, %edx
callq 0x2100
leaq 0x64ce(%rip), %rdi      # 0x17298
leaq 0x7e61(%rip), %rsi      # 0x18c32
leaq 0x7e63(%rip), %rcx      # 0x18c3b
movl $0x25, %edx
callq 0x2100
leaq 0x659b(%rip), %rdi      # 0x17384
leaq 0x7e42(%rip), %rsi      # 0x18c32
leaq 0x7e44(%rip), %rcx      # 0x18c3b
movl $0x26, %edx
callq 0x2100
nopl (%rax)