// File: /workspace/github_cpp_makefile_star2_O2/vgteam[P]stream/src/stream.hpp
// Function: bool stream::for_each<Person>(std::istream&, std::function<void (Person&)>&, std::function<void (unsigned long)>&)
bool for_each(std::istream& in,
              std::function<void(T&)>& lambda,
              std::function<void(uint64_t)>& handle_count) {

    ::google::protobuf::io::ZeroCopyInputStream *raw_in =
          new ::google::protobuf::io::IstreamInputStream(&in);
    ::google::protobuf::io::GzipInputStream *gzip_in =
          new ::google::protobuf::io::GzipInputStream(raw_in);
    ::google::protobuf::io::CodedInputStream *coded_in =
          new ::google::protobuf::io::CodedInputStream(gzip_in);

    uint64_t count;
    coded_in->ReadVarint64((::google::protobuf::uint64*) &count);
    // this loop handles a chunked file with many pieces
    // such as we might write in a multithreaded process
    if (!count) return !count;
    do {

        handle_count(count);

        std::string s;
        for (uint64_t i = 0; i < count; ++i) {
            uint32_t msgSize = 0;
            delete coded_in;
            coded_in = new ::google::protobuf::io::CodedInputStream(gzip_in);
            // the messages are prefixed by their size
            coded_in->ReadVarint32(&msgSize);
            if ((msgSize > 0) &&
                (coded_in->ReadString(&s, msgSize))) {
                T object;
                object.ParseFromString(s);
                lambda(object);
            }
        }
    } while (coded_in->ReadVarint64((::google::protobuf::uint64*) &count));

    delete coded_in;
    delete gzip_in;
    delete raw_in;

    return !count;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdx, 0x18(%rsp)
movq %rsi, 0x20(%rsp)
movq %rdi, %rbx
pushq $0x50
popq %rdi
callq 0x42b0
movq %rax, %r14
pushq $-0x1
popq %rdx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x42a0
movl $0xb0, %edi
callq 0x42b0
movq %rax, %r12
pushq $-0x1
popq %rcx
movq %rax, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x4420
pushq $0x50
popq %rdi
callq 0x42b0
movq %rax, %r13
movq %rax, %rdi
movq %r12, %rsi
callq 0x64b6
leaq 0x8(%rsp), %rbx
movq %r13, %rdi
movq %rbx, %rsi
callq 0x64f2
cmpq $0x0, (%rbx)
je 0x6410
movq %r14, 0x10(%rsp)
pushq $0x50
popq %rbp
leaq 0x4(%rsp), %rbx
leaq 0x48(%rsp), %r15
movq 0x8(%rsp), %rsi
movq 0x18(%rsp), %rdi
callq 0x6526
leaq 0x38(%rsp), %rax
movq %rax, 0x28(%rsp)
andq $0x0, 0x30(%rsp)
movb $0x0, 0x38(%rsp)
xorl %r14d, %r14d
cmpq 0x8(%rsp), %r14
jae 0x63be
andl $0x0, 0x4(%rsp)
movq %r13, %rdi
callq 0x4390
movq %r13, %rdi
movq %rbp, %rsi
callq 0x42c0
movq %rbp, %rdi
callq 0x42b0
movq %rax, %r13
movq %rax, %rdi
movq %r12, %rsi
callq 0x64b6
movq %r13, %rdi
movq %rbx, %rsi
callq 0x6540
movl 0x4(%rsp), %edx
testl %edx, %edx
je 0x63b6
movq %r13, %rdi
leaq 0x28(%rsp), %rsi
callq 0x4130
testb %al, %al
je 0x63b6
movq %r15, %rdi
callq 0x5228
movq %r15, %rdi
leaq 0x28(%rsp), %rsi
callq 0x4490
movq 0x20(%rsp), %rdi
movq %r15, %rsi
callq 0x6572
movq %r15, %rdi
callq 0x4738
incq %r14
jmp 0x632f
leaq 0x28(%rsp), %rdi
callq 0x4150
movq %r13, %rdi
leaq 0x8(%rsp), %rsi
callq 0x64f2
testb %al, %al
jne 0x6308
movq %r13, %rdi
callq 0x4390
pushq $0x50
popq %rsi
movq %r13, %rdi
callq 0x42c0
movq (%r12), %rax
movq %r12, %rdi
callq *0x8(%rax)
movq 0x10(%rsp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
cmpq $0x0, 0x8(%rsp)
sete %al
jmp 0x6412
movb $0x1, %al
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
pushq $0x50
popq %rsi
movq %r13, %rdi
jmp 0x6442
movq %rax, %rbx
movl $0xb0, %esi
movq %r12, %rdi
jmp 0x6442
movq %rax, %rbx
pushq $0x50
popq %rsi
movq %r14, %rdi
callq 0x42c0
jmp 0x6477
jmp 0x646a
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x4738
jmp 0x646d
movq %rax, %rbx
pushq $0x50
popq %rsi
movq %r13, %rdi
callq 0x42c0
jmp 0x646d
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x4150
movq %rbx, %rdi
callq 0x4470
nop