// File: enferex[P]fnplot/cs.cc
// Function: CS::initTrailer(unsigned char const*, unsigned long)
void CS::initTrailer(const uint8_t *data, size_t data_len)
{
    int i;
    char line[1024] = {0};
    pos_t pos = {0};

    pos.data = data;
    pos.data_len = data_len;
    pos.off = this->_hdr.trailer;

    if (!VALID(&pos))
      return;

    // Viewpaths
    getLine(&pos, line, sizeof(line));
    this->_trailer.n_viewpaths = atoi(line);
    for (i=0; i<this->_trailer.n_viewpaths; ++i) {
        getLine(&pos, line, sizeof(line));
        DBG("[%d of %d] Viewpath: %s", i+1, this->_trailer.n_viewpaths, line);
    }

    // Sources
    getLine(&pos, line, sizeof(line));
    this->_trailer.n_srcs = atoi(line);
    for (i=0; i<this->_trailer.n_srcs; ++i) {
        getLine(&pos, line, sizeof(line));
        DBG("[%d of %d] Sources: %s", i+1, this->_trailer.n_srcs, line);
    }

    // Includes
    getLine(&pos, line, sizeof(line));
    this->_trailer.n_incs = atoi(line);
    getLine(&pos, line, sizeof(line));
    for (i=0; i<this->_trailer.n_incs; ++i) {
        getLine(&pos, line, sizeof(line));
        DBG("[%d of %d] Includes: %s", i+1, this->_trailer.n_incs, line);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x440, %rsp            # imm = 0x440
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x440(%rbp)
leaq -0x420(%rbp), %rdi
xorl %esi, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x2150
leaq -0x438(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x2150
movq -0x440(%rbp), %rax
movq -0x10(%rbp), %rcx
movq %rcx, -0x428(%rbp)
movq -0x18(%rbp), %rcx
movq %rcx, -0x430(%rbp)
movq 0x10(%rax), %rax
movq %rax, -0x438(%rbp)
movq -0x438(%rbp), %rax
cmpq -0x430(%rbp), %rax
jbe 0x2cb5
jmp 0x2e08
leaq -0x420(%rbp), %rsi
leaq -0x438(%rbp), %rdi
movl $0x400, %edx            # imm = 0x400
callq 0x3760
leaq -0x420(%rbp), %rdi
callq 0x2380
movl %eax, %ecx
movq -0x440(%rbp), %rax
movl %ecx, 0x20(%rax)
movl $0x0, -0x1c(%rbp)
movq -0x440(%rbp), %rcx
movl -0x1c(%rbp), %eax
cmpl 0x20(%rcx), %eax
jge 0x2d1e
leaq -0x420(%rbp), %rsi
leaq -0x438(%rbp), %rdi
movl $0x400, %edx            # imm = 0x400
callq 0x3760
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x2cec
leaq -0x420(%rbp), %rsi
leaq -0x438(%rbp), %rdi
movl $0x400, %edx            # imm = 0x400
callq 0x3760
leaq -0x420(%rbp), %rdi
callq 0x2380
movl %eax, %ecx
movq -0x440(%rbp), %rax
movl %ecx, 0x30(%rax)
movl $0x0, -0x1c(%rbp)
movq -0x440(%rbp), %rcx
movl -0x1c(%rbp), %eax
cmpl 0x30(%rcx), %eax
jge 0x2d87
leaq -0x420(%rbp), %rsi
leaq -0x438(%rbp), %rdi
movl $0x400, %edx            # imm = 0x400
callq 0x3760
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x2d55
leaq -0x420(%rbp), %rsi
leaq -0x438(%rbp), %rdi
movl $0x400, %edx            # imm = 0x400
callq 0x3760
leaq -0x420(%rbp), %rdi
callq 0x2380
movl %eax, %ecx
movq -0x440(%rbp), %rax
movl %ecx, 0x40(%rax)
leaq -0x420(%rbp), %rsi
leaq -0x438(%rbp), %rdi
movl $0x400, %edx            # imm = 0x400
callq 0x3760
movl $0x0, -0x1c(%rbp)
movq -0x440(%rbp), %rcx
movl -0x1c(%rbp), %eax
cmpl 0x40(%rcx), %eax
jge 0x2e08
leaq -0x420(%rbp), %rsi
leaq -0x438(%rbp), %rdi
movl $0x400, %edx            # imm = 0x400
callq 0x3760
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x2dd6
addq $0x440, %rsp            # imm = 0x440
popq %rbp
retq
nopw %cs:(%rax,%rax)