// File: kztomita[P]http-dump/http_header.cc
// Function: create_http_header_from_header_line_or_null(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
http_header_ptr create_http_header_from_header_line_or_null(const std::string& line) {
  // 改行コード削除
  std::string stripped;
  std::copy_if(line.begin(), line.end(), std::back_inserter(stripped),
               [](char c){return c != '\r' && c != '\n' ;});

  auto pos = stripped.find(":");
  if (pos == std::string::npos) {
    return http_header_ptr();      // null
  }

  auto stripped_view = std::string_view(stripped);

  auto name = std::string_view(stripped_view.substr(0, pos));
  name = string_util::trim(name, " ");

  auto value = line.substr(pos + 1, stripped_view.size() - pos - 1);
  value = string_util::trim(value, " ");

  return std::make_unique<http_header>(std::string(name), std::string(value));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x190, %rsp            # imm = 0x190
movq %rdi, -0x148(%rbp)
movq %rdi, %rax
movq %rax, -0x140(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x30(%rbp), %rdi
movq %rdi, -0x138(%rbp)
callq 0xd510
movq -0x10(%rbp), %rdi
callq 0xd330
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
callq 0xdf30
movq -0x138(%rbp), %rdi
movq %rax, -0x40(%rbp)
callq 0x4db70
movq %rax, -0x130(%rbp)
jmp 0x4d5c3
movq -0x130(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x4d890
movq %rax, -0x150(%rbp)
jmp 0x4d5e8
movq -0x150(%rbp), %rax
movq %rax, -0x60(%rbp)
leaq -0x30(%rbp), %rdi
leaq 0x28162(%rip), %rsi     # 0x75760
xorl %eax, %eax
movl %eax, %edx
callq 0xd050
movq %rax, -0x68(%rbp)
cmpq $-0x1, -0x68(%rbp)
jne 0x4d63b
movq -0x148(%rbp), %rdi
callq 0x4dba0
movl $0x1, -0x6c(%rbp)
jmp 0x4d861
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x4d87a
leaq -0x30(%rbp), %rdi
callq 0xdf20
movq %rax, -0x80(%rbp)
movq %rdx, -0x78(%rbp)
movq -0x68(%rbp), %rdx
xorl %eax, %eax
movl %eax, %esi
leaq -0x80(%rbp), %rdi
callq 0x4dbd0
movq %rdx, -0x160(%rbp)
movq %rax, -0x158(%rbp)
jmp 0x4d66d
movq -0x160(%rbp), %rax
movq -0x158(%rbp), %rcx
movq %rcx, -0x90(%rbp)
movq %rax, -0x88(%rbp)
leaq 0x28212(%rip), %rsi     # 0x758a2
leaq -0x90(%rbp), %rdi
callq 0x4dc60
movq %rdx, -0x170(%rbp)
movq %rax, -0x168(%rbp)
jmp 0x4d6ac
movq -0x170(%rbp), %rax
movq -0x168(%rbp), %rcx
movq %rcx, -0xa0(%rbp)
movq %rax, -0x98(%rbp)
movups -0xa0(%rbp), %xmm0
movaps %xmm0, -0x90(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x180(%rbp)
movq -0x68(%rbp), %rax
incq %rax
movq %rax, -0x178(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x4dcb0
movq -0x180(%rbp), %rsi
movq -0x178(%rbp), %rdx
movq -0x68(%rbp), %rcx
notq %rcx
addq %rax, %rcx
leaq -0xc0(%rbp), %rdi
callq 0xde20
jmp 0x4d71e
leaq 0x2817d(%rip), %rdx     # 0x758a2
leaq -0xe0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x4dcd0
jmp 0x4d73a
leaq -0xc0(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
movq %rsi, -0x190(%rbp)
callq 0xd790
movq -0x190(%rbp), %rdi
callq 0xdac0
leaq -0x101(%rbp), %rdi
movq %rdi, -0x188(%rbp)
callq 0xddb0
movq -0x188(%rbp), %rdx
leaq -0x100(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x21ed0
jmp 0x4d78f
leaq -0x128(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0xd1e0
jmp 0x4d7a4
movq -0x148(%rbp), %rdi
leaq -0x100(%rbp), %rsi
leaq -0x128(%rbp), %rdx
callq 0x4dd50
jmp 0x4d7c0
leaq -0x128(%rbp), %rdi
callq 0xdac0
leaq -0x100(%rbp), %rdi
callq 0xdac0
leaq -0x101(%rbp), %rdi
callq 0xe180
movl $0x1, -0x6c(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0xdac0
jmp 0x4d861
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x4d853
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x4d847
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x4d83b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x128(%rbp), %rdi
callq 0xdac0
leaq -0x100(%rbp), %rdi
callq 0xdac0
leaq -0x101(%rbp), %rdi
callq 0xe180
leaq -0xc0(%rbp), %rdi
callq 0xdac0
jmp 0x4d87a
leaq -0x30(%rbp), %rdi
callq 0xdac0
movq -0x140(%rbp), %rax
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
leaq -0x30(%rbp), %rdi
callq 0xdac0
movq -0x50(%rbp), %rdi
callq 0xd990
nopl (%rax)