// File: /workspace/github_cpp_makefile_star2_O1/kztomita[P]http-dump/./socket.h
// Function: http_response read_response<sync_stream_wrapper>(sync_stream_wrapper&)
http_response read_response(SyncReadStream& socket) {
  namespace asio = boost::asio;

  std::string line;
  asio::streambuf receive_buffer;

  http_response r;

  // Status Line読み込み
  read_line(socket, receive_buffer, line);
  auto elements = string_util::split(line, " ");
  r.code_ = std::atoi(elements[1].c_str());

  // ヘッダー読み込み
  std::optional<std::string> transfer_encoding;
  std::optional<std::size_t> content_length;

  while (true) {
    if (!read_line(socket, receive_buffer, line)) {
      break;
    }
    if (line.size() == 0) {
      // ヘッダー終了
      break;
    }
    auto h = create_http_header_from_header_line(line);

    if (string_util::tolower(h->key) == "transfer-encoding") {
      transfer_encoding = h->value;
    } else if (string_util::tolower(h->key) == "content-length") {
      content_length = std::atoi(h->value.c_str());
    }

    r.headers_.push_back(std::move(h));
  }

  // payload読み込み

  if (!transfer_encoding ||
      transfer_encoding == "identity") {
    if (!content_length) {
      throw std::runtime_error("Content-Length not found.");
    }
    std::size_t length = content_length.value();

    fill_streambuf(socket, receive_buffer, length);
    const char* data = asio::buffer_cast<const char*>(receive_buffer.data());
    http_response::payload_type payload(data, data + length);
    receive_buffer.consume(length);

    using std::swap;
    swap(r.payload_, payload);
  } else if (transfer_encoding == "chunked") {
    http_response::payload_type payload;
    std::string line;
    while (read_line(socket, receive_buffer, line)) {
      if (line.size() == 0) {
        break;
      }
      std::size_t pos;
      std::size_t chunk_size = std::stoi(line.c_str(), &pos, 16);
      if (pos != line.size()) {
        throw std::runtime_error("Can't parse chunk size.");
      }
      if (chunk_size == 0) {
        // \r\n読み捨て
        std::string l;
        read_line(socket, receive_buffer, l);
        break;
      }

      fill_streambuf(socket, receive_buffer, chunk_size);
      const char* data = asio::buffer_cast<const char*>(receive_buffer.data());
      payload.resize(payload.size() + chunk_size);
      std::copy(data, data + chunk_size, payload.end() - chunk_size);
      receive_buffer.consume(chunk_size);

      // \r\n読み捨て
      fill_streambuf(socket, receive_buffer, 2);
      receive_buffer.consume(2);
    }

    using std::swap;
    swap(r.payload_, payload);
  } else {
    std::ostringstream msg;
    msg << "Unsupported Transfer-Encoding type ("
        << transfer_encoding.value()
        << ").";
    throw std::runtime_error(msg.str());
  }

  return r;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2a8, %rsp            # imm = 0x2A8
movq %rsi, %r12
movq %rdi, %rbx
leaq 0xf0(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x80(%rsp), %rdi
leaq 0x130(%rsp), %rdx
movq $-0x1, %rsi
callq 0x233ae
xorps %xmm0, %xmm0
movups %xmm0, 0x28(%rbx)
movups %xmm0, 0x18(%rbx)
movups %xmm0, 0x8(%rbx)
leaq 0x80(%rsp), %rsi
leaq 0xe0(%rsp), %rdx
movq %r12, %rdi
callq 0x23480
leaq 0x12b52(%rip), %rdx     # 0x34792
leaq 0x118(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x2369d
leaq 0x8(%rbx), %rax
movq %rax, 0x108(%rsp)
movq 0x118(%rsp), %rax
movq 0x20(%rax), %rdi
callq 0xba60
movq %rbx, (%rsp)
movl %eax, (%rbx)
leaq 0x58(%rsp), %rax
movb $0x0, 0x20(%rax)
leaq 0x140(%rsp), %rbp
xorl %r14d, %r14d
leaq 0xe0(%rsp), %rbx
leaq 0x10(%rsp), %r13
leaq 0x130(%rsp), %r15
movq %r12, 0x50(%rsp)
movq %r12, %rdi
leaq 0x80(%rsp), %rsi
movq %rbx, %rdx
callq 0x23480
cmpq $0x0, 0xe8(%rsp)
setne %cl
testb %cl, %al
je 0x21e34
movq %r13, %rdi
movq %rbx, %rsi
callq 0x211de
movq 0x10(%rsp), %rax
movq %rbp, 0x130(%rsp)
movq $0x0, 0x138(%rsp)
movb $0x0, 0x140(%rsp)
movq (%rax), %rdi
movq 0x8(%rax), %rsi
addq %rdi, %rsi
movq %r15, %rdx
movq %rbp, %r12
callq 0x2474a
movq %r15, %rdi
leaq 0x12e2a(%rip), %rsi     # 0x34b42
callq 0xb190
movl %eax, %ebp
movq 0x130(%rsp), %rdi
cmpq %r12, %rdi
je 0x21d3c
movq 0x140(%rsp), %rsi
incq %rsi
callq 0xb600
testl %ebp, %ebp
je 0x21de9
movq 0x10(%rsp), %rax
leaq 0x140(%rsp), %r12
movq %r12, 0x130(%rsp)
movq $0x0, 0x138(%rsp)
movb $0x0, 0x140(%rsp)
movq (%rax), %rdi
movq 0x8(%rax), %rsi
addq %rdi, %rsi
movq %r15, %rdx
callq 0x2474a
movq %r15, %rdi
leaq 0x12c53(%rip), %rsi     # 0x349dc
callq 0xb190
movl %eax, %ebp
movq 0x130(%rsp), %rdi
cmpq %r12, %rdi
je 0x21dad
movq 0x140(%rsp), %rsi
incq %rsi
callq 0xb600
testl %ebp, %ebp
movq 0x50(%rsp), %r12
jne 0x21ddf
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rdi
callq 0xba60
cltq
movq %rax, 0x100(%rsp)
testb $0x1, %r14b
movzbl %r14b, %r14d
movl $0x1, %eax
cmovel %eax, %r14d
leaq 0x140(%rsp), %rbp
jmp 0x21e09
movq 0x10(%rsp), %rsi
addq $0x20, %rsi
leaq 0x58(%rsp), %rdi
callq 0x23846
leaq 0x140(%rsp), %rbp
movq 0x50(%rsp), %r12
movq 0x108(%rsp), %rdi
movq %r13, %rsi
callq 0x24782
movq 0x10(%rsp), %rsi
testq %rsi, %rsi
je 0x21ca6
movq %r13, %rdi
callq 0x10490
jmp 0x21ca6
cmpb $0x1, 0x78(%rsp)
jne 0x22156
leaq 0x120cb(%rip), %rsi     # 0x33f11
leaq 0x58(%rsp), %rdi
callq 0xb190
testl %eax, %eax
je 0x22156
cmpb $0x1, 0x78(%rsp)
jne 0x2237c
leaq 0x120ca(%rip), %rsi     # 0x33f34
leaq 0x58(%rsp), %rdi
callq 0xb190
testl %eax, %eax
jne 0x2237c
xorps %xmm0, %xmm0
leaq 0x30(%rsp), %rcx
movaps %xmm0, (%rcx)
xorl %eax, %eax
movq %rax, 0x10(%rcx)
leaq 0x130(%rsp), %rcx
movq %rbp, (%rcx)
movq %rax, 0x8(%rcx)
movb $0x0, 0x10(%rcx)
leaq 0x20(%rsp), %r14
movq (%rsp), %rbx
movq %r12, %rdi
leaq 0x80(%rsp), %rsi
leaq 0x130(%rsp), %rdx
callq 0x23480
cmpq $0x0, 0x138(%rsp)
setne %cl
testb %cl, %al
je 0x220f4
movq %r14, %r13
movq 0x130(%rsp), %rsi
leaq 0x10(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0xda18
movq 0x10(%rsp), %r12
callq 0xb090
movq %rax, %rbx
movl (%rax), %r14d
movl $0x0, (%rax)
movq %r12, %rdi
leaq 0x110(%rsp), %rsi
movl $0x10, %edx
callq 0xb920
movq 0x110(%rsp), %rbp
subq %r12, %rbp
je 0x222f6
movq %rax, %r15
movslq %r15d, %rax
cmpq %r15, %rax
jne 0x22302
movl (%rbx), %eax
cmpl $0x22, %eax
je 0x22302
testl %eax, %eax
movq 0x50(%rsp), %r12
jne 0x21f51
movl %r14d, (%rbx)
movq 0x10(%rsp), %rdi
movq %r13, %r14
cmpq %r13, %rdi
je 0x21f6b
movq 0x20(%rsp), %rsi
incq %rsi
callq 0xb600
cmpq 0x138(%rsp), %rbp
movq (%rsp), %rbx
jne 0x2230e
testl %r15d, %r15d
leaq 0x140(%rsp), %rbp
je 0x220ac
movslq %r15d, %rbx
movq %r12, %rdi
leaq 0x80(%rsp), %rsi
movq %rbx, %rdx
callq 0x2387f
movq 0x90(%rsp), %r14
movq 0x38(%rsp), %rsi
addq %rbx, %rsi
subq 0x30(%rsp), %rsi
leaq 0x30(%rsp), %rdi
callq 0x23970
testq %rbx, %rbx
jle 0x21fea
movq 0x38(%rsp), %rax
subq %rbx, %rax
leaq 0x1(%rbx), %rcx
xorl %edx, %edx
movb (%r14,%rdx), %sil
movb %sil, (%rax,%rdx)
decq %rcx
incq %rdx
cmpq $0x1, %rcx
jg 0x21fd6
movq 0xa8(%rsp), %rax
cmpq %rax, 0x98(%rsp)
jae 0x22014
movq 0xc8(%rsp), %rcx
movq %rcx, 0x88(%rsp)
movq %rax, 0x98(%rsp)
movq 0x90(%rsp), %rcx
addq %rcx, %rbx
movl %eax, %edx
subl %ecx, %edx
cmpq %rax, %rbx
movq %r15, %rax
cmovaq %rdx, %rax
cltq
addq %rcx, %rax
movq %rax, 0x90(%rsp)
movl $0x2, %edx
movq %r12, %rdi
leaq 0x80(%rsp), %rsi
callq 0x2387f
movq 0xa8(%rsp), %rax
cmpq %rax, 0x98(%rsp)
jae 0x22079
movq 0xc8(%rsp), %rcx
movq %rcx, 0x88(%rsp)
movq %rax, 0x98(%rsp)
movq 0x90(%rsp), %rcx
leaq 0x2(%rcx), %rdx
movl %eax, %esi
subl %ecx, %esi
cmpq %rax, %rdx
movslq %esi, %rax
movl $0x2, %edx
cmovbeq %rdx, %rax
addq %rcx, %rax
movq %rax, 0x90(%rsp)
movq (%rsp), %rbx
movq %r13, %r14
jmp 0x220eb
movq %r14, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movb $0x0, 0x20(%rsp)
movq %r12, %rdi
leaq 0x80(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x23480
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x220eb
movq 0x20(%rsp), %rsi
incq %rsi
callq 0xb600
testl %r15d, %r15d
jne 0x21ea9
movups 0x20(%rbx), %xmm0
movq 0x30(%rbx), %rax
movq 0x30(%rsp), %rcx
movq %rcx, 0x20(%rbx)
movq 0x38(%rsp), %rcx
movq %rcx, 0x28(%rbx)
movq 0x40(%rsp), %rcx
movq %rcx, 0x30(%rbx)
movaps %xmm0, 0x30(%rsp)
movq %rax, 0x40(%rsp)
movq 0x130(%rsp), %rdi
cmpq %rbp, %rdi
je 0x2213e
movq 0x140(%rsp), %rsi
incq %rsi
callq 0xb600
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x22241
movq 0x40(%rsp), %rsi
jmp 0x22239
testb $0x1, %r14b
je 0x22345
leaq 0x80(%rsp), %rsi
movq %r12, %rdi
movq 0x100(%rsp), %r14
movq %r14, %rdx
movq (%rsp), %rbx
callq 0x2387f
movq 0x90(%rsp), %rsi
leaq (%rsi,%r14), %rdx
leaq 0x130(%rsp), %rdi
leaq 0x10(%rsp), %rcx
callq 0x2392e
movq 0xa8(%rsp), %rax
cmpq %rax, 0x98(%rsp)
jae 0x221c7
movq 0xc8(%rsp), %rcx
movq %rcx, 0x88(%rsp)
movq %rax, 0x98(%rsp)
movq 0x90(%rsp), %rcx
leaq (%rcx,%r14), %rdx
movl %eax, %esi
subl %ecx, %esi
cmpq %rax, %rdx
cmovbeq %r14, %rsi
movslq %esi, %rax
addq %rcx, %rax
movq %rax, 0x90(%rsp)
movq 0x20(%rbx), %rdi
movq 0x28(%rbx), %rax
movq 0x30(%rbx), %rsi
movq 0x130(%rsp), %rcx
movq %rcx, 0x20(%rbx)
movq 0x138(%rsp), %rcx
movq %rcx, 0x28(%rbx)
movq 0x140(%rsp), %rcx
movq %rcx, 0x30(%rbx)
movq %rdi, 0x130(%rsp)
movq %rax, 0x138(%rsp)
movq %rsi, 0x140(%rsp)
testq %rdi, %rdi
je 0x22241
subq %rdi, %rsi
callq 0xb600
cmpb $0x1, 0x78(%rsp)
jne 0x22267
leaq 0x68(%rsp), %rax
movb $0x0, 0x10(%rax)
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x22267
movq 0x68(%rsp), %rsi
incq %rsi
callq 0xb600
leaq 0x118(%rsp), %rdi
callq 0x18866
leaq 0x24ed5(%rip), %rax     # 0x47150
movq %rax, 0x80(%rsp)
movq 0xc8(%rsp), %rdi
testq %rdi, %rdi
je 0x222a0
movq 0xd8(%rsp), %rsi
subq %rdi, %rsi
callq 0xb600
movq 0x25c79(%rip), %rax     # 0x47f20
addq $0x10, %rax
leaq 0xb8(%rsp), %rdi
movq %rax, -0x38(%rdi)
callq 0xb950
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x222e1
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0xb600
movq %rbx, %rax
addq $0x2a8, %rsp            # imm = 0x2A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x10d60(%rip), %rdi     # 0x3305d
callq 0xb3e0
leaq 0x10d54(%rip), %rdi     # 0x3305d
callq 0xb9a0
movl $0x10, %edi
callq 0xb300
movq %rax, %rbx
leaq 0x11c1a(%rip), %rsi     # 0x33f3c
movq %rax, %rdi
callq 0xb270
movq 0x25cbf(%rip), %rsi     # 0x47ff0
movq 0x25c18(%rip), %rdx     # 0x47f50
movq %rbx, %rdi
callq 0xbb60
jmp 0x2241b
movl $0x10, %edi
callq 0xb300
movq %rax, %rbx
leaq 0x11bc1(%rip), %rsi     # 0x33f1a
movq %rax, %rdi
callq 0xb270
movq 0x25c88(%rip), %rsi     # 0x47ff0
movq 0x25be1(%rip), %rdx     # 0x47f50
movq %rbx, %rdi
callq 0xbb60
jmp 0x2241b
leaq 0x130(%rsp), %rdi
callq 0xb8c0
leaq 0x11bc4(%rip), %rsi     # 0x33f54
leaq 0x130(%rsp), %rdi
movl $0x24, %edx
callq 0xb730
cmpb $0x0, 0x78(%rsp)
je 0x2241b
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rdx
leaq 0x130(%rsp), %rdi
callq 0xb730
leaq 0x11bb2(%rip), %rsi     # 0x33f79
movl $0x2, %edx
movq %rax, %rdi
callq 0xb730
movl $0x10, %edi
callq 0xb300
movq %rax, %rbx
leaq 0x138(%rsp), %rsi
leaq 0x10(%rsp), %rdi
callq 0xba80
movb $0x1, %bpl
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0xbaa0
xorl %ebp, %ebp
movq 0x25be4(%rip), %rsi     # 0x47ff0
movq 0x25b3d(%rip), %rdx     # 0x47f50
movq %rbx, %rdi
callq 0xbb60
callq 0x24915
movq %rax, %r15
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x22446
movq 0x20(%rsp), %rsi
incq %rsi
callq 0xb600
jmp 0x22446
movq %rax, %r15
movb $0x1, %bpl
testb %bpl, %bpl
je 0x22458
movq %rbx, %rdi
callq 0xb4b0
jmp 0x22458
movq %rax, %r15
movq 0x25b09(%rip), %rsi     # 0x47f68
leaq 0x130(%rsp), %rdi
callq 0xb380
leaq 0x1a0(%rsp), %rdi
callq 0xb1f0
jmp 0x22588
jmp 0x22563
jmp 0x22563
movq %rax, %r15
movq %rbx, %rdi
callq 0xb4b0
jmp 0x22588
jmp 0x2249a
movq %rax, %r15
jmp 0x2258c
jmp 0x224a4
movq %rax, %r15
jmp 0x225bf
movq %rax, %r15
jmp 0x225d4
movq %rax, %r15
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
jne 0x224f2
jmp 0x224ff
jmp 0x224d8
movq %rax, %r15
movq %rbx, %rdi
callq 0xb4b0
jmp 0x224ff
jmp 0x224d8
jmp 0x224d8
jmp 0x224d8
movq %rax, %r15
jmp 0x224ff
movq %rax, %r15
cmpl $0x0, (%rbx)
jne 0x224e8
movl %r14d, (%rbx)
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
je 0x224ff
movq 0x20(%rsp), %rsi
incq %rsi
callq 0xb600
movq 0x130(%rsp), %rdi
leaq 0x140(%rsp), %rax
cmpq %rax, %rdi
je 0x22524
movq 0x140(%rsp), %rsi
incq %rsi
callq 0xb600
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x22588
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0xb600
jmp 0x22588
jmp 0x22541
jmp 0x22563
movq %rax, %r15
movq 0x130(%rsp), %rdi
cmpq %r12, %rdi
je 0x2256b
movq 0x140(%rsp), %rsi
incq %rsi
callq 0xb600
jmp 0x2256b
movq %rax, %r15
jmp 0x22588
movq %rax, %r15
movq 0x10(%rsp), %rsi
testq %rsi, %rsi
je 0x2257f
leaq 0x10(%rsp), %rdi
callq 0x10490
movq $0x0, 0x10(%rsp)
movq (%rsp), %rbx
cmpb $0x1, 0x78(%rsp)
jne 0x225b2
leaq 0x68(%rsp), %rax
movb $0x0, 0x10(%rax)
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x225b2
movq 0x68(%rsp), %rsi
incq %rsi
callq 0xb600
leaq 0x118(%rsp), %rdi
callq 0x18866
movq %rbx, %rdi
callq 0xdbf6
leaq 0x80(%rsp), %rdi
callq 0x2399c
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x225f9
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0xb600
movq %r15, %rdi
callq 0xbbb0
nop