// File: vgteam[P]stream/src/stream.hpp
// Function: bool stream::write<Person>(std::ostream&, unsigned long, std::function<Person (unsigned long)>&)
bool write(std::ostream& out, uint64_t count, std::function<T(uint64_t)>& lambda) {

    ::google::protobuf::io::ZeroCopyOutputStream *raw_out =
          new ::google::protobuf::io::OstreamOutputStream(&out);
    ::google::protobuf::io::GzipOutputStream *gzip_out =
          new ::google::protobuf::io::GzipOutputStream(raw_out);
    ::google::protobuf::io::CodedOutputStream *coded_out =
          new ::google::protobuf::io::CodedOutputStream(gzip_out);

    // prefix the chunk with the number of objects
    coded_out->WriteVarint64(count);

    std::string s;
    uint64_t written = 0;
    for (uint64_t n = 0; n < count; ++n, ++written) {
        lambda(n).SerializeToString(&s);
        // and prefix each object with its size
        coded_out->WriteVarint32(s.size());
        coded_out->WriteRaw(s.data(), s.size());
    }

    delete coded_out;
    delete gzip_out;
    delete raw_out;

    return !count || written == count;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x48, %edi
callq 0x4320
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xa8(%rbp)
movq -0x8(%rbp), %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x4100
jmp 0x9e0e
movq -0xa8(%rbp), %rax
movq %rax, -0x20(%rbp)
movl $0xa8, %edi
callq 0x4320
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xb0(%rbp)
movq -0x20(%rbp), %rsi
callq 0x45d0
jmp 0x9e3b
movq -0xb0(%rbp), %rax
movq %rax, -0x38(%rbp)
movl $0x50, %edi
callq 0x4320
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xb8(%rbp)
movq -0x38(%rbp), %rsi
callq 0xa5e0
jmp 0x9e68
movq -0xb8(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0xa610
leaq -0x60(%rbp), %rdi
callq 0x4420
movq $0x0, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
movq -0x70(%rbp), %rax
cmpq -0x10(%rbp), %rax
jae 0x9ff7
movq -0x18(%rbp), %rsi
movq -0x70(%rbp), %rdx
leaq -0xa0(%rbp), %rdi
callq 0xa670
jmp 0x9ebd
leaq -0xa0(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x41c0
jmp 0x9ecf
leaq -0xa0(%rbp), %rdi
callq 0x4b60
movq -0x40(%rbp), %rax
movq %rax, -0xc0(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x4230
movq -0xc0(%rbp), %rdi
movl %eax, %esi
callq 0xa6d0
jmp 0x9eff
movq -0x40(%rbp), %rax
movq %rax, -0xd0(%rbp)
leaq -0x60(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
callq 0x41d0
movq -0xd8(%rbp), %rdi
movq %rax, -0xc8(%rbp)
callq 0x4230
movq -0xd0(%rbp), %rdi
movq -0xc8(%rbp), %rsi
movl %eax, %edx
callq 0xa720
jmp 0x9f44
jmp 0x9f46
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x9e99
movq -0xa8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x48, %esi
callq 0x4330
jmp 0xa0b0
movq -0xb0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0xa8, %esi
callq 0x4330
jmp 0xa0b0
movq -0xb8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x50, %esi
callq 0x4330
jmp 0xa0b0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0xa0a7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x4b60
jmp 0xa0a7
movq -0x40(%rbp), %rax
movq %rax, -0xe0(%rbp)
cmpq $0x0, %rax
je 0xa025
movq -0xe0(%rbp), %rdi
callq 0x4300
movq -0xe0(%rbp), %rdi
movl $0x50, %esi
callq 0x4330
movq -0x38(%rbp), %rax
movq %rax, -0xe8(%rbp)
cmpq $0x0, %rax
je 0xa043
movq -0xe8(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movq -0x20(%rbp), %rax
movq %rax, -0xf0(%rbp)
cmpq $0x0, %rax
je 0xa061
movq -0xf0(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movb $0x1, %al
cmpq $0x0, -0x10(%rbp)
movb %al, -0xf1(%rbp)
je 0xa081
movq -0x68(%rbp), %rax
cmpq -0x10(%rbp), %rax
sete %al
movb %al, -0xf1(%rbp)
movb -0xf1(%rbp), %al
movb %al, -0xf2(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x41f0
movb -0xf2(%rbp), %al
andb $0x1, %al
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
leaq -0x60(%rbp), %rdi
callq 0x41f0
movq -0x28(%rbp), %rdi
callq 0x4580
nopl (%rax)