// File: /workspace/github_cpp_makefile_star2_O2/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 $-0x1, %rsi
je 0x248ee
cmpq %rsi, 0x8(%r15)
jbe 0x248ee
movq %rdx, %r14
movq %r15, %rdi
callq 0x24574
testb %al, %al
js 0x248f8
cmpb $0x40, %al
jae 0x2492d
movl %eax, %ecx
andb $0x30, %cl
cmpb $0x10, %cl
je 0x248bb
movzbl %cl, %ecx
testl %ecx, %ecx
jne 0x24980
pushq $0x4
popq %rsi
movq %r15, %rdi
callq 0x249f4
movslq %eax, %rcx
movq %rsp, %r12
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x24c3c
movq %rbx, %rdi
movq %r12, %rsi
callq 0x25056
movb $0x0, 0x48(%rbx)
movq %r12, %rdi
jmp 0x2496c
movb $0x0, 0x40(%rbx)
movb $0x1, 0x48(%rbx)
jmp 0x24971
pushq $0x7
popq %rsi
movq %r15, %rdi
callq 0x249f4
movq (%r14), %rsi
movslq %eax, %rdx
movq %rsp, %r14
movq %r14, %rdi
callq 0x25389
movq %rbx, %rdi
movq %r14, %rsi
callq 0x25026
movb $0x0, 0x48(%rbx)
movq %r14, %rdi
callq 0x24eea
jmp 0x24971
pushq $0x6
popq %rsi
movq %r15, %rdi
callq 0x249f4
movslq %eax, %rcx
movq %rsp, %r12
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x24c3c
movq (%r14), %rdi
movq %r12, %rsi
callq 0x251f6
movq %rsp, %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x25056
movb $0x0, 0x48(%rbx)
movq %r14, %rdi
callq 0x17960
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
cmpb $0x20, %al
jb 0x249a4
pushq $0x5
popq %rsi
movq %r15, %rdi
callq 0x249f4
movq (%r14), %rdi
movslq %eax, %rsi
callq 0x25148
xorl %eax, %eax
movb %al, 0x40(%rbx)
movb %al, 0x48(%rbx)
jmp 0x24971
pushq $0x10
popq %rdi
callq 0xb330
movq %rax, %rbx
leaq 0x8ef0(%rip), %rsi      # 0x2d8a6
movq %rax, %rdi
callq 0xb270
movq 0x21623(%rip), %rsi     # 0x45fe8
movq 0x2157c(%rip), %rdx     # 0x45f48
movq %rbx, %rdi
callq 0xbb50
movq %rax, %r14
movq %rbx, %rdi
callq 0xb4d0
jmp 0x249ec
movq %rax, %r14
movq %rsp, %rdi
callq 0x17960
movq %r14, %rdi
callq 0xbba0