// File: kztomita[P]http-dump/./http2_socket.h
// Function: http2_frame read_http2_frame<boost::asio::ssl::stream<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::execution::any_executor<boost::asio::execution::context_as_t<boost::asio::execution_context&>, boost::asio::execution::detail::blocking::never_t<0>, boost::asio::execution::prefer_only<boost::asio::execution::detail::blocking::possibly_t<0>>, boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::tracked_t<0>>, boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::untracked_t<0>>, boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::fork_t<0>>, boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::continuation_t<0>>>>>>(boost::asio::ssl::stream<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::execution::any_executor<boost::asio::execution::context_as_t<boost::asio::execution_context&>, boost::asio::execution::detail::blocking::never_t<0>, boost::asio::execution::prefer_only<boost::asio::execution::detail::blocking::possibly_t<0>>, boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::tracked_t<0>>, boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::untracked_t<0>>, boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::fork_t<0>>, boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::continuation_t<0>>>>>&)
http2_frame read_http2_frame(SyncReadStream& socket) {
  namespace asio = boost::asio;

  asio::streambuf receive_buffer;

  asio::read(socket, receive_buffer, boost::asio::transfer_exactly(9));

  const char* headerp = asio::buffer_cast<const char*>(receive_buffer.data());

  http2_frame frame;

  std::memcpy(&frame.header(), headerp, 9);
  receive_buffer.consume(9);

  uint payload_size = frame.header().length();

  if (payload_size) {
    frame.payload().resize(payload_size);

    asio::read(socket, receive_buffer, boost::asio::transfer_exactly(payload_size));

    const char* payloadp = asio::buffer_cast<const char*>(receive_buffer.data());
    std::memcpy(frame.payload_buffer(), payloadp, payload_size);
  }

  debug_message("RECV");
  debug_dump(frame);

  return frame;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movq %rdi, -0x118(%rbp)
movq %rdi, %rax
movq %rax, -0x110(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
callq 0x16fc0
movq %rax, -0x108(%rbp)
leaq -0x71(%rbp), %rdi
movq %rdi, -0x100(%rbp)
callq 0xddb0
movq -0x108(%rbp), %rsi
movq -0x100(%rbp), %rdx
leaq -0x70(%rbp), %rdi
callq 0x52b20
jmp 0x59879
leaq -0x71(%rbp), %rdi
callq 0xe180
movq -0x10(%rbp), %rax
movq %rax, -0x128(%rbp)
movl $0x9, %edi
callq 0x5ccb0
movq %rax, -0x120(%rbp)
jmp 0x598a0
movq -0x128(%rbp), %rdi
movq -0x120(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rdx
leaq -0x70(%rbp), %rsi
callq 0x5cc60
jmp 0x598c7
leaq -0x70(%rbp), %rdi
movq %rdi, -0x130(%rbp)
callq 0x534d0
movq %rax, -0xa8(%rbp)
movq %rdx, -0xa0(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x534b0
movq -0x118(%rbp), %rdi
movq %rax, -0x98(%rbp)
movb $0x0, -0xa9(%rbp)
callq 0x5c510
movq -0x118(%rbp), %rdi
callq 0x5c530
movq -0x130(%rbp), %rdi
movq -0x98(%rbp), %rcx
movb 0x8(%rcx), %dl
movb %dl, 0x8(%rax)
movq (%rcx), %rcx
movq %rcx, (%rax)
movl $0x9, %esi
callq 0x535f0
jmp 0x5993d
movq -0x118(%rbp), %rdi
callq 0x5c530
movq %rax, %rdi
callq 0x5ab60
movl %eax, -0xb0(%rbp)
cmpl $0x0, -0xb0(%rbp)
je 0x59a6b
movq -0x118(%rbp), %rdi
callq 0x5a440
movq %rax, %rdi
movl -0xb0(%rbp), %eax
movl %eax, %esi
callq 0x53770
jmp 0x59982
movq -0x10(%rbp), %rax
movq %rax, -0x140(%rbp)
movl -0xb0(%rbp), %eax
movl %eax, %edi
callq 0x5ccb0
movq %rax, -0x138(%rbp)
jmp 0x599a3
movq -0x140(%rbp), %rdi
movq -0x138(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rdx
leaq -0x70(%rbp), %rsi
callq 0x5cc60
jmp 0x599ca
leaq -0x70(%rbp), %rdi
callq 0x534d0
movq %rax, -0xd0(%rbp)
movq %rdx, -0xc8(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x534b0
movq -0x118(%rbp), %rdi
movq %rax, -0xc0(%rbp)
callq 0x5cce0
movq %rax, -0x148(%rbp)
jmp 0x59a09
movq -0x148(%rbp), %rdi
movq -0xc0(%rbp), %rsi
movl -0xb0(%rbp), %eax
movl %eax, %edx
callq 0xd0f0
jmp 0x59a6b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x71(%rbp), %rdi
callq 0xe180
jmp 0x59b54
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x59b4b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x59b3f
leaq -0xf1(%rbp), %rdi
movq %rdi, -0x150(%rbp)
callq 0xddb0
movq -0x150(%rbp), %rdx
leaq 0x1bb44(%rip), %rsi     # 0x755d0
leaq -0xf0(%rbp), %rdi
callq 0x10a30
jmp 0x59a9a
leaq -0xf0(%rbp), %rdi
callq 0x4ee60
jmp 0x59aa8
leaq -0xf0(%rbp), %rdi
callq 0xdac0
leaq -0xf1(%rbp), %rdi
callq 0xe180
movq -0x118(%rbp), %rdi
callq 0x5c9d0
jmp 0x59ace
movb $0x1, -0xa9(%rbp)
testb $0x1, -0xa9(%rbp)
jne 0x59b26
jmp 0x59b1a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x59b0c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0xdac0
leaq -0xf1(%rbp), %rdi
callq 0xe180
jmp 0x59b3f
movq -0x118(%rbp), %rdi
callq 0x59c40
leaq -0x70(%rbp), %rdi
callq 0x53920
movq -0x110(%rbp), %rax
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
movq -0x118(%rbp), %rdi
callq 0x59c40
leaq -0x70(%rbp), %rdi
callq 0x53920
movq -0x80(%rbp), %rdi
callq 0xd990
nopl (%rax)