// File: /workspace/github_cpp_makefile_star2_O3/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, %rbx
movq %rdi, %r14
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 0x231b2
xorps %xmm0, %xmm0
movups %xmm0, 0x28(%r14)
movups %xmm0, 0x18(%r14)
movups %xmm0, 0x8(%r14)
leaq 0x80(%rsp), %rsi
leaq 0xe0(%rsp), %rdx
movq %rbx, %rdi
callq 0x23288
leaq 0x11c97(%rip), %rdx     # 0x33792
leaq 0x118(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0x23495
leaq 0x8(%r14), %rax
movq %rax, 0x108(%rsp)
movq 0x118(%rsp), %rax
movq 0x20(%rax), %rdi
callq 0xba60
movq %r14, 0x8(%rsp)
movl %eax, (%r14)
leaq 0x58(%rsp), %rax
movb $0x0, 0x20(%rax)
leaq 0x140(%rsp), %r13
xorl %r14d, %r14d
leaq 0xe0(%rsp), %rbp
leaq 0x20(%rsp), %r12
leaq 0x130(%rsp), %r15
movq %rbx, 0x18(%rsp)
movq %rbx, %rdi
leaq 0x80(%rsp), %rsi
movq %rbp, %rdx
callq 0x23288
cmpq $0x0, 0xe8(%rsp)
setne %cl
testb %cl, %al
je 0x21cf5
movq %r12, %rdi
movq %rbp, %rsi
callq 0x210aa
movq 0x20(%rsp), %rax
movq %r13, 0x130(%rsp)
movq $0x0, 0x138(%rsp)
movb $0x0, 0x140(%rsp)
movq (%rax), %rdi
movq 0x8(%rax), %rsi
addq %rdi, %rsi
movq %r15, %rdx
movq %r13, %rbx
callq 0x244fa
movq %r15, %rdi
leaq 0x11f6d(%rip), %rsi     # 0x33b42
callq 0xb190
movl %eax, %r13d
movq 0x130(%rsp), %rdi
cmpq %rbx, %rdi
je 0x21bfa
movq 0x140(%rsp), %rsi
incq %rsi
callq 0xb600
testl %r13d, %r13d
je 0x21caa
movq 0x20(%rsp), %rax
leaq 0x140(%rsp), %rbx
movq %rbx, 0x130(%rsp)
movq $0x0, 0x138(%rsp)
movb $0x0, 0x140(%rsp)
movq (%rax), %rdi
movq 0x8(%rax), %rsi
addq %rdi, %rsi
movq %r15, %rdx
callq 0x244fa
movq %r15, %rdi
leaq 0x11d94(%rip), %rsi     # 0x339dc
callq 0xb190
movl %eax, %r13d
movq 0x130(%rsp), %rdi
cmpq %rbx, %rdi
je 0x21c6d
movq 0x140(%rsp), %rsi
incq %rsi
callq 0xb600
testl %r13d, %r13d
movq 0x18(%rsp), %rbx
jne 0x21ca0
movq 0x20(%rsp), %rax
movq 0x20(%rax), %rdi
callq 0xba60
testb $0x1, %r14b
movzbl %r14b, %r14d
movl $0x1, %ecx
cmovel %ecx, %r14d
cltq
movq %rax, 0x100(%rsp)
leaq 0x140(%rsp), %r13
jmp 0x21cca
movq 0x20(%rsp), %rsi
addq $0x20, %rsi
leaq 0x58(%rsp), %rdi
callq 0x2365e
leaq 0x140(%rsp), %r13
movq 0x18(%rsp), %rbx
movq 0x108(%rsp), %rdi
movq %r12, %rsi
callq 0x24532
movq 0x20(%rsp), %rsi
testq %rsi, %rsi
je 0x21b63
movq %r12, %rdi
callq 0x103c6
jmp 0x21b63
cmpb $0x1, 0x78(%rsp)
jne 0x21f5c
leaq 0x1120a(%rip), %rsi     # 0x32f11
leaq 0x58(%rsp), %rdi
callq 0xb190
testl %eax, %eax
je 0x21f5c
cmpb $0x1, 0x78(%rsp)
movq 0x8(%rsp), %r14
jne 0x2221b
leaq 0x11204(%rip), %rsi     # 0x32f34
leaq 0x58(%rsp), %rdi
callq 0xb190
testl %eax, %eax
jne 0x2221b
xorps %xmm0, %xmm0
leaq 0x40(%rsp), %rcx
movaps %xmm0, (%rcx)
xorl %eax, %eax
movq %rax, 0x10(%rcx)
leaq 0x130(%rsp), %rcx
movq %r13, (%rcx)
movq %rax, 0x8(%rcx)
movb $0x0, 0x10(%rcx)
leaq 0x80(%rsp), %r13
movq %rbx, %rdi
movq %r13, %rsi
leaq 0x130(%rsp), %rdx
callq 0x23288
cmpq $0x0, 0x138(%rsp)
setne %cl
testb %cl, %al
je 0x2207b
movq 0x130(%rsp), %rsi
leaq 0x20(%rsp), %rdi
leaq 0x17(%rsp), %rdx
callq 0xd9d2
movq 0x20(%rsp), %r15
callq 0xb090
movq %rax, %rbp
movl (%rax), %r14d
movl $0x0, (%rax)
movq %r15, %rdi
leaq 0x110(%rsp), %rsi
movl $0x10, %edx
callq 0xb920
movq 0x110(%rsp), %r12
subq %r15, %r12
je 0x22195
movq %rax, %rbx
movslq %ebx, %rax
cmpq %rbx, %rax
jne 0x221a1
movl (%rbp), %eax
cmpl $0x22, %eax
je 0x221a1
testl %eax, %eax
jne 0x21e0b
movl %r14d, (%rbp)
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rbp
cmpq %rbp, %rdi
je 0x21e27
movq 0x30(%rsp), %rsi
incq %rsi
callq 0xb600
cmpq 0x138(%rsp), %r12
movq 0x8(%rsp), %r14
jne 0x221ad
testl %ebx, %ebx
je 0x2203e
movq 0x18(%rsp), %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x23697
movq 0x90(%rsp), %r14
movq 0x48(%rsp), %rsi
addq %rbx, %rsi
subq 0x40(%rsp), %rsi
leaq 0x40(%rsp), %rdi
callq 0x23788
testq %rbx, %rbx
jle 0x21e98
movq 0x48(%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
ja 0x21e84
movq 0xa8(%rsp), %rax
cmpq %rax, 0x98(%rsp)
jae 0x21ec2
movq 0xc8(%rsp), %rcx
movq %rcx, 0x88(%rsp)
movq %rax, 0x98(%rsp)
movq 0x90(%rsp), %rcx
leaq (%rcx,%rbx), %rdx
movl %eax, %esi
subl %ecx, %esi
cmpq %rax, %rdx
cmovbeq %rbx, %rsi
movslq %esi, %rax
addq %rcx, %rax
movq %rax, 0x90(%rsp)
movl $0x2, %edx
movq 0x18(%rsp), %rdi
movq %r13, %rsi
callq 0x23697
movq 0xa8(%rsp), %rax
cmpq %rax, 0x98(%rsp)
jae 0x21f23
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 0x8(%rsp), %r14
movq 0x18(%rsp), %rbx
jmp 0x21d6e
testb $0x1, %r14b
je 0x221e4
leaq 0x80(%rsp), %rsi
movq %rbx, %rdi
movq 0x100(%rsp), %rbx
movq %rbx, %rdx
movq 0x8(%rsp), %r14
callq 0x23697
movq 0x90(%rsp), %rsi
leaq (%rsi,%rbx), %rdx
leaq 0x130(%rsp), %rdi
leaq 0x20(%rsp), %rcx
callq 0x23746
movq 0xa8(%rsp), %rax
cmpq %rax, 0x98(%rsp)
jae 0x21fce
movq 0xc8(%rsp), %rcx
movq %rcx, 0x88(%rsp)
movq %rax, 0x98(%rsp)
movq 0x90(%rsp), %rcx
leaq (%rcx,%rbx), %rdx
movl %eax, %esi
subl %ecx, %esi
cmpq %rax, %rdx
cmovbeq %rbx, %rsi
movslq %esi, %rax
addq %rcx, %rax
movq %rax, 0x90(%rsp)
movq 0x20(%r14), %rdi
movq 0x28(%r14), %rax
movq 0x30(%r14), %rsi
movaps 0x130(%rsp), %xmm0
movups %xmm0, 0x20(%r14)
movq 0x140(%rsp), %rcx
movq %rcx, 0x30(%r14)
movq %rdi, 0x130(%rsp)
movq %rax, 0x138(%rsp)
movq %rsi, 0x140(%rsp)
testq %rdi, %rdi
jne 0x220d8
jmp 0x220e0
leaq 0x20(%rsp), %rdx
movq %rbp, (%rdx)
movq $0x0, 0x8(%rdx)
movb $0x0, 0x10(%rdx)
leaq 0x80(%rsp), %rsi
movq 0x18(%rsp), %rdi
callq 0x23288
movq 0x20(%rsp), %rdi
cmpq %rbp, %rdi
je 0x2207b
movq 0x30(%rsp), %rsi
incq %rsi
callq 0xb600
movq 0x20(%r14), %rdi
movaps 0x40(%rsp), %xmm0
movq 0x50(%rsp), %rax
movq %rdi, 0x40(%rsp)
movups 0x28(%r14), %xmm1
movups %xmm0, 0x20(%r14)
movq %rax, 0x30(%r14)
movups %xmm1, 0x48(%rsp)
movq 0x130(%rsp), %rax
leaq 0x140(%rsp), %rcx
cmpq %rcx, %rax
je 0x220ce
movq 0x140(%rsp), %rsi
incq %rsi
movq %rax, %rdi
callq 0xb600
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x220e0
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0xb600
cmpb $0x1, 0x78(%rsp)
jne 0x22106
leaq 0x68(%rsp), %rax
movb $0x0, 0x10(%rax)
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x22106
movq 0x68(%rsp), %rsi
incq %rsi
callq 0xb600
leaq 0x118(%rsp), %rdi
callq 0x18772
leaq 0x24076(%rip), %rax     # 0x46190
movq %rax, 0x80(%rsp)
movq 0xc8(%rsp), %rdi
testq %rdi, %rdi
je 0x2213f
movq 0xd8(%rsp), %rsi
subq %rdi, %rsi
callq 0xb600
movq 0x24dd2(%rip), %rax     # 0x46f18
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 0x22180
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0xb600
movq %r14, %rax
addq $0x2a8, %rsp            # imm = 0x2A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xfec1(%rip), %rdi      # 0x3205d
callq 0xb3e0
leaq 0xfeb5(%rip), %rdi      # 0x3205d
callq 0xb9a0
movl $0x10, %edi
callq 0xb300
movq %rax, %rbx
leaq 0x10d7b(%rip), %rsi     # 0x32f3c
movq %rax, %rdi
callq 0xb270
movq 0x24e18(%rip), %rsi     # 0x46fe8
movq 0x24d71(%rip), %rdx     # 0x46f48
movq %rbx, %rdi
callq 0xbb60
jmp 0x222ba
movl $0x10, %edi
callq 0xb300
movq %rax, %rbx
leaq 0x10d22(%rip), %rsi     # 0x32f1a
movq %rax, %rdi
callq 0xb270
movq 0x24de1(%rip), %rsi     # 0x46fe8
movq 0x24d3a(%rip), %rdx     # 0x46f48
movq %rbx, %rdi
callq 0xbb60
jmp 0x222ba
leaq 0x130(%rsp), %rdi
callq 0xb8c0
leaq 0x10d25(%rip), %rsi     # 0x32f54
leaq 0x130(%rsp), %rdi
movl $0x24, %edx
callq 0xb730
cmpb $0x0, 0x78(%rsp)
je 0x222ba
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rdx
leaq 0x130(%rsp), %rdi
callq 0xb730
leaq 0x10d13(%rip), %rsi     # 0x32f79
movl $0x2, %edx
movq %rax, %rdi
callq 0xb730
movl $0x10, %edi
callq 0xb300
movq %rax, %rbx
leaq 0x138(%rsp), %rsi
leaq 0x20(%rsp), %rdi
callq 0xba80
movb $0x1, %bpl
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
callq 0xbaa0
xorl %ebp, %ebp
movq 0x24d3d(%rip), %rsi     # 0x46fe8
movq 0x24c96(%rip), %rdx     # 0x46f48
movq %rbx, %rdi
callq 0xbb60
callq 0x246cb
movq %rax, %r15
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x222dd
movq 0x30(%rsp), %rsi
incq %rsi
callq 0xb600
testb %bpl, %bpl
jne 0x222e7
jmp 0x22306
movq %rax, %r15
movq %rbx, %rdi
callq 0xb4b0
jmp 0x22306
movq %rax, %r15
movq 0x20(%rsp), %rdi
cmpq %rbp, %rdi
je 0x2237a
jmp 0x223d4
movq %rax, %r15
movq 0x24c53(%rip), %rsi     # 0x46f60
leaq 0x130(%rsp), %rdi
callq 0xb380
leaq 0x1a0(%rsp), %rdi
callq 0xb1f0
jmp 0x22425
jmp 0x22409
jmp 0x22409
movq %rax, %r15
movq %rbx, %rdi
callq 0xb4b0
jmp 0x22425
jmp 0x22348
movq %rax, %r15
jmp 0x2242a
jmp 0x22352
movq %rax, %r15
jmp 0x2245d
movq %rax, %r15
jmp 0x22472
jmp 0x22377
movq %rax, %r15
movq %rbx, %rdi
callq 0xb4b0
jmp 0x2237a
jmp 0x22377
jmp 0x22377
jmp 0x22377
movq %rax, %r15
movq 0x130(%rsp), %rdi
leaq 0x140(%rsp), %rax
cmpq %rax, %rdi
je 0x2239f
movq 0x140(%rsp), %rsi
incq %rsi
callq 0xb600
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x22425
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0xb600
jmp 0x22425
movq %rax, %r15
cmpl $0x0, (%rbp)
jne 0x223c5
movl %r14d, (%rbp)
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x2237a
movq 0x30(%rsp), %rsi
incq %rsi
callq 0xb600
jmp 0x2237a
jmp 0x223e7
jmp 0x22409
movq %rax, %r15
movq 0x130(%rsp), %rdi
cmpq %rbx, %rdi
je 0x22411
movq 0x140(%rsp), %rsi
incq %rsi
callq 0xb600
jmp 0x22411
movq %rax, %r15
jmp 0x22425
movq %rax, %r15
movq 0x20(%rsp), %rsi
testq %rsi, %rsi
je 0x22425
leaq 0x20(%rsp), %rdi
callq 0x103c6
movq 0x8(%rsp), %r14
cmpb $0x1, 0x78(%rsp)
jne 0x22450
leaq 0x68(%rsp), %rax
movb $0x0, 0x10(%rax)
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x22450
movq 0x68(%rsp), %rsi
incq %rsi
callq 0xb600
leaq 0x118(%rsp), %rdi
callq 0x18772
movq %r14, %rdi
callq 0xdbb6
leaq 0x80(%rsp), %rdi
callq 0x237b4
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x22497
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0xb600
movq %r15, %rdi
callq 0xbbb0
nop