// File: /workspace/github_c_makefile_star2_O1/patriciogonzalezvivo[P]tprint/include/serial/list_ports_linux.cc
// Function: format[abi:cxx11](char const*, ...)
string
format(const char* format, ...)
{
    va_list ap;

    size_t buffer_size_bytes = 256;

    string result;

    char* buffer = (char*)malloc(buffer_size_bytes);

    if( buffer == NULL )
        return result;

    bool done = false;

    unsigned int loop_count = 0;

    while(!done)
    {
        va_start(ap, format);

        int return_value = vsnprintf(buffer, buffer_size_bytes, format, ap);

        if( return_value < 0 )
        {
            done = true;
        }
        else if( return_value >= buffer_size_bytes )
        {
            // Realloc and try again.

            buffer_size_bytes = return_value + 1;

            char* new_buffer_ptr = (char*)realloc(buffer, buffer_size_bytes);

            if( new_buffer_ptr == NULL )
            {
                done = true;
            }
            else
            {
                buffer = new_buffer_ptr;
            }
        }
        else
        {
            result = buffer;
            done = true;
        }

        va_end(ap);

        if( ++loop_count > 5 )
            done = true;
    }

    free(buffer);

    return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %rsi, -0x50(%rbp)
movq %rdx, -0x110(%rbp)
movq %rcx, -0x108(%rbp)
movq %r8, -0x100(%rbp)
movq %r9, -0xf8(%rbp)
testb %al, %al
je 0x94cf
movaps %xmm0, -0xf0(%rbp)
movaps %xmm1, -0xe0(%rbp)
movaps %xmm2, -0xd0(%rbp)
movaps %xmm3, -0xc0(%rbp)
movaps %xmm4, -0xb0(%rbp)
movaps %xmm5, -0xa0(%rbp)
movaps %xmm6, -0x90(%rbp)
movaps %xmm7, -0x80(%rbp)
leaq 0x10(%rdi), %rbx
movq %rbx, (%rdi)
movq $0x0, 0x8(%rdi)
movq %rdi, -0x38(%rbp)
movb $0x0, 0x10(%rdi)
movl $0x100, %edi            # imm = 0x100
callq 0x8430
movq %rax, -0x30(%rbp)
testq %rax, %rax
je 0x95d5
movq %rbx, -0x40(%rbp)
xorl %r14d, %r14d
movl $0x1, %ebx
movl $0x100, %r15d           # imm = 0x100
leaq -0x120(%rbp), %rax
movq %rax, -0x60(%rbp)
leaq 0x10(%rbp), %rax
movq %rax, -0x68(%rbp)
movabsq $0x3000000010, %rax     # imm = 0x3000000010
movq %rax, -0x70(%rbp)
movq -0x30(%rbp), %rdi
movq %r15, %rsi
movq -0x50(%rbp), %rdx
leaq -0x70(%rbp), %rcx
callq 0x81f0
movb $0x1, %r12b
testl %eax, %eax
js 0x95b0
movl %eax, %r13d
movl %eax, %eax
cmpq %rax, %r15
jbe 0x9583
movq -0x38(%rbp), %r14
movq 0x8(%r14), %rax
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %r13
movq %r13, %rdi
callq 0x8170
movq %r14, %rdi
xorl %esi, %esi
movq -0x48(%rbp), %rdx
movq %r13, %rcx
movq %rax, %r8
callq 0x8520
jmp 0x95b0
incl %r13d
movq -0x30(%rbp), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0x8590
testq %rax, %rax
movzbl %r14b, %r12d
movl $0x1, %ecx
cmovel %ecx, %r12d
cmovneq %rax, %r15
movq %r15, -0x30(%rbp)
movq %r13, %r15
cmpl $0x6, %ebx
movzbl %r12b, %r14d
movl $0x1, %eax
cmovael %eax, %r14d
incl %ebx
testb $0x1, %r14b
je 0x950f
movq -0x30(%rbp), %rdi
callq 0x83f0
movq -0x38(%rbp), %rax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq -0x38(%rbp), %rax
movq (%rax), %rdi
cmpq -0x40(%rbp), %rdi
je 0x960a
movq -0x40(%rbp), %rax
movq (%rax), %rsi
incq %rsi
callq 0x8320
movq %r14, %rdi
callq 0x8600