// File: /workspace/github_c_makefile_star2_O0/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
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x130(%rbp)
movq %rdi, %r10
movq %r10, -0x128(%rbp)
testb %al, %al
je 0xe7c5
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)
movq %r9, -0xf8(%rbp)
movq %r8, -0x100(%rbp)
movq %rcx, -0x108(%rbp)
movq %rdx, -0x110(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x100, -0x38(%rbp)     # imm = 0x100
movb $0x0, -0x39(%rbp)
callq 0xd5b0
movq -0x38(%rbp), %rdi
callq 0xd560
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0xe81e
movb $0x1, -0x39(%rbp)
movl $0x1, -0x4c(%rbp)
jmp 0xe920
movb $0x0, -0x4d(%rbp)
movl $0x0, -0x54(%rbp)
movb -0x4d(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0xe837
jmp 0xe90c
leaq -0x30(%rbp), %rax
leaq -0x120(%rbp), %rcx
movq %rcx, 0x10(%rax)
leaq 0x10(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl $0x30, 0x4(%rax)
movl $0x10, (%rax)
movq -0x48(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x10(%rbp), %rdx
leaq -0x30(%rbp), %rcx
callq 0xd250
movl %eax, -0x58(%rbp)
cmpl $0x0, -0x58(%rbp)
jge 0xe87f
movb $0x1, -0x4d(%rbp)
jmp 0xe8f1
movslq -0x58(%rbp), %rax
cmpq -0x38(%rbp), %rax
jb 0xe8bd
movl -0x58(%rbp), %eax
addl $0x1, %eax
cltq
movq %rax, -0x38(%rbp)
movq -0x48(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0xd6e0
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0xe8b3
movb $0x1, -0x4d(%rbp)
jmp 0xe8bb
movq -0x60(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0xe8ef
movq -0x130(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0xd590
jmp 0xe8cf
movb $0x1, -0x4d(%rbp)
jmp 0xe8ef
movq -0x130(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
callq 0xd240
jmp 0xe942
jmp 0xe8f1
leaq -0x30(%rbp), %rax
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
cmpl $0x5, %eax
jbe 0xe907
movb $0x1, -0x4d(%rbp)
jmp 0xe829
movq -0x48(%rbp), %rdi
callq 0xd4e0
movb $0x1, -0x39(%rbp)
movl $0x1, -0x4c(%rbp)
testb $0x1, -0x39(%rbp)
jne 0xe932
movq -0x130(%rbp), %rdi
callq 0xd240
movq -0x128(%rbp), %rax
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
movq -0x68(%rbp), %rdi
callq 0xd750
nopl (%rax,%rax)