// File: /workspace/github_cpp_makefile_star2_O1/kztomita[P]http-dump/hpack_decoder.cc
// Function: hpack::hpack_decoder::decode_representation(hpack::decoding_context&)
hpack_decoder::decoded_result hpack_decoder::decode_representation(decoding_context& context) {

  if (!buffer_view_.test_range(decode_pos_, 1)) {
    return decoded_result(std::nullopt, true);
  }

  int top_byte = buffer_view_.at(decode_pos_);

  if (top_byte & 0x80) {
    // 0b1...
    // Indexed Header Field Representation
    auto index = fetch_integer(7);
    return decoded_result(hpack_table_at(*context.dynamic_table, index),
                          false);
  } else if ((top_byte & 0xc0) == 0x40) {
    // 0b01...
    // Literal Header Field with Incremental Indexing
    auto index = fetch_integer(6);
    header_type header = fetch_header(context, index);
    context.dynamic_table->add(header);
    return decoded_result(std::move(header),
                          false);
  } else if ((top_byte & 0xf0) == 0x00) {
    // 0b0000...
    // Literal Header Field without Indexing
    auto index = fetch_integer(4);
    return decoded_result(fetch_header(context, index),
                          false);
  } else if ((top_byte & 0xf0) == 0x10) {
    // 0b0001...
    // Literal Header Field Never Indexed
    auto index = fetch_integer(4);
    return decoded_result(fetch_header(context, index),
                          false);
  } else if ((top_byte & 0xe0) == 0x20) {
    // 0b001...
    // Dynamic Table Size Update
    // このエントリはコマンドなのでヘッダはない
    auto max_size = fetch_integer(5);
    context.dynamic_table->set_maximum_table_size(max_size);
    return decoded_result(std::nullopt, false);
  }

  throw std::runtime_error("Unknown representation.");
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r15
movq %rdi, %rbx
movq 0x10(%rsi), %rsi
cmpq %rsi, 0x8(%r15)
jbe 0x299f9
movq %rdx, %r14
movq %r15, %rdi
callq 0x296f6
testb %al, %al
js 0x29a06
cmpb $0x40, %al
jae 0x29a66
movl %eax, %ecx
andb $0x30, %cl
cmpb $0x10, %cl
je 0x299bb
movzbl %cl, %ecx
testl %ecx, %ecx
jne 0x29b52
movq 0x10(%r15), %rsi
movl $0x4, %edx
movq %r15, %rdi
callq 0x29c74
addq %rdx, 0x10(%r15)
movslq %eax, %rcx
movq %rsp, %r12
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x29eb6
leaq 0x10(%rbx), %rcx
movq %rcx, (%rbx)
movq (%r12), %rdx
leaq 0x10(%rsp), %rax
jmp 0x29aaa
movb $0x0, 0x40(%rbx)
movb $0x1, 0x48(%rbx)
jmp 0x29bfd
movq 0x10(%r15), %rsi
movl $0x7, %edx
movq %r15, %rdi
callq 0x29c74
addq %rdx, 0x10(%r15)
movq (%r14), %rsi
movslq %eax, %rdx
movq %rsp, %r14
movq %r14, %rdi
callq 0x2a72e
movb $0x0, 0x40(%rbx)
movb 0x40(%r14), %al
cmpb $0x1, %al
jne 0x29b49
leaq 0x10(%rbx), %rcx
movq %rcx, (%rbx)
leaq 0x10(%rsp), %rdx
movq -0x10(%rdx), %rsi
cmpq %rdx, %rsi
je 0x29b84
movq %rsi, (%rbx)
movq 0x10(%rsp), %rcx
movq %rcx, 0x10(%rbx)
jmp 0x29b8a
movq 0x10(%r15), %rsi
movl $0x6, %edx
movq %r15, %rdi
callq 0x29c74
addq %rdx, 0x10(%r15)
movslq %eax, %rcx
movq %rsp, %r12
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x29eb6
movq (%r14), %rdi
movq %r12, %rsi
callq 0x2a4d0
leaq 0x10(%rbx), %rcx
movq %rcx, (%rbx)
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdx
cmpq %rax, %rdx
je 0x29abd
movq %rdx, (%rbx)
movq 0x10(%rsp), %rcx
movq %rcx, 0x10(%rbx)
jmp 0x29ac3
movups (%rax), %xmm0
movups %xmm0, (%rcx)
leaq 0x30(%rsp), %rcx
movq -0x28(%rcx), %rdx
movq %rdx, 0x8(%rbx)
movq %rax, -0x30(%rcx)
movq $0x0, -0x28(%rcx)
movb $0x0, -0x20(%rcx)
leaq 0x30(%rbx), %rdx
movq %rdx, 0x20(%rbx)
movq -0x10(%rcx), %rsi
cmpq %rcx, %rsi
je 0x29b00
movq %rsi, 0x20(%rbx)
movq 0x30(%rsp), %rdx
movq %rdx, 0x30(%rbx)
jmp 0x29b06
movups (%rcx), %xmm0
movups %xmm0, (%rdx)
movq 0x28(%rsp), %rdx
movq %rdx, 0x28(%rbx)
movq %rcx, 0x20(%rsp)
movq $0x0, 0x28(%rsp)
xorl %ecx, %ecx
movb %cl, 0x30(%rsp)
movb $0x1, 0x40(%rbx)
movb %cl, 0x48(%rbx)
movq (%rsp), %rdi
cmpq %rax, %rdi
je 0x29bfd
movq 0x10(%rsp), %rsi
incq %rsi
callq 0xb600
jmp 0x29bfd
movb $0x0, 0x48(%rbx)
jmp 0x29bfd
cmpb $0x20, %al
jb 0x29c0c
movq 0x10(%r15), %rsi
movl $0x5, %edx
movq %r15, %rdi
callq 0x29c74
addq %rdx, 0x10(%r15)
movq (%r14), %rdi
movslq %eax, %rsi
callq 0x2a41a
xorl %eax, %eax
movb %al, 0x40(%rbx)
movb %al, 0x48(%rbx)
jmp 0x29bfd
movups (%rdx), %xmm0
movups %xmm0, (%rcx)
leaq 0x30(%rsp), %rcx
movq -0x28(%rcx), %rsi
movq %rsi, 0x8(%rbx)
movq %rdx, -0x30(%rcx)
movq $0x0, -0x28(%rcx)
movb $0x0, -0x20(%rcx)
leaq 0x30(%rbx), %rdx
movq %rdx, 0x20(%rbx)
movq -0x10(%rcx), %rsi
cmpq %rcx, %rsi
je 0x29bc7
movq %rsi, 0x20(%rbx)
movq 0x30(%rsp), %rdx
movq %rdx, 0x30(%rbx)
jmp 0x29bcd
movups (%rcx), %xmm0
movups %xmm0, (%rdx)
movq 0x28(%rsp), %rdx
movq %rdx, 0x28(%rbx)
movq %rcx, 0x20(%rsp)
movq $0x0, 0x28(%rsp)
xorl %ecx, %ecx
movb %cl, 0x30(%rsp)
movb $0x1, 0x40(%rbx)
movb %cl, 0x48(%rbx)
testb %al, %al
je 0x29bfd
movq %rsp, %rdi
callq 0x2a1fa
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movl $0x10, %edi
callq 0xb300
movq %rax, %rbx
leaq 0xac86(%rip), %rsi      # 0x348a6
movq %rax, %rdi
callq 0xb270
movq 0x1e3c1(%rip), %rsi     # 0x47ff0
movq 0x1e31a(%rip), %rdx     # 0x47f50
movq %rbx, %rdi
callq 0xbb60
movq %rax, %r14
movq %rbx, %rdi
callq 0xb4b0
jmp 0x29c56
movq %rax, %r14
movq %rsp, %rdi
callq 0x19c44
movq %r14, %rdi
callq 0xbbb0