// File: tsfn[P]doc2txt/src/Storage.cpp
// Function: read_msat(unsigned char*, unsigned int, unsigned char**, unsigned int*)
static bool read_msat(uchar *buf, uint buf_size, uchar **msat, uint *msat_size) {
  set<uint> vis;
  uint num_sec = 0, id = *(uint *)(buf + 0x44);
  for (; id < buf_size / 512 - 1; id = *(uint *)(buf + 512 + 512 * id + 508)) {
    if (vis.count(id)) {
      return false;
    }
    vis.insert(id);
    num_sec += 1;
  }
  *msat_size = 109 * 4 + num_sec * 512;
  if ((*msat = (uchar *)malloc(*msat_size)) == NULL) {
    return false;
  }
  memcpy(*msat, buf + 0x4C, 109 * 4);
  num_sec = 0;
  id = *(int *)(buf + 0x44);
  for (; id < buf_size / 512 - 1; id = *(int *)(buf + 512 + 512 * id + 508)) {
    memcpy(*msat + 436 + num_sec++ * 508, buf + 512 + 512 * id, 508);
  }
  return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x1f60
movl $0x0, -0x5c(%rbp)
movq -0x10(%rbp), %rax
movl 0x44(%rax), %eax
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %eax
movl -0x14(%rbp), %ecx
shrl $0x9, %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jae 0x1a79
leaq -0x58(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x1f80
movq %rax, -0x88(%rbp)
jmp 0x19ee
movq -0x88(%rbp), %rax
cmpq $0x0, %rax
je 0x1a25
movb $0x0, -0x1(%rbp)
movl $0x1, -0x70(%rbp)
jmp 0x1b56
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x2030
jmp 0x1b6d
leaq -0x58(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x1fe0
movb %dl, -0x91(%rbp)
movq %rax, -0x90(%rbp)
jmp 0x1a41
movb -0x91(%rbp), %al
movq -0x90(%rbp), %rcx
movq %rcx, -0x80(%rbp)
movb %al, -0x78(%rbp)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
movq -0x10(%rbp), %rax
movl -0x60(%rbp), %ecx
shll $0x9, %ecx
movl %ecx, %ecx
movl 0x3fc(%rax,%rcx), %eax
movl %eax, -0x60(%rbp)
jmp 0x19c4
movl -0x5c(%rbp), %ecx
shll $0x9, %ecx
addl $0x1b4, %ecx            # imm = 0x1B4
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x28(%rbp), %rax
movl (%rax), %eax
movl %eax, %edi
callq 0x1180
movq -0x20(%rbp), %rcx
movq %rax, (%rcx)
cmpq $0x0, %rax
jne 0x1ab5
movb $0x0, -0x1(%rbp)
movl $0x1, -0x70(%rbp)
jmp 0x1b56
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
addq $0x4c, %rsi
movl $0x1b4, %edx            # imm = 0x1B4
callq 0x10e0
movl $0x0, -0x5c(%rbp)
movq -0x10(%rbp), %rax
movl 0x44(%rax), %eax
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %eax
movl -0x14(%rbp), %ecx
shrl $0x9, %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jae 0x1b4b
movq -0x20(%rbp), %rax
movq (%rax), %rdi
addq $0x1b4, %rdi            # imm = 0x1B4
movl -0x5c(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x5c(%rbp)
imull $0x1fc, %eax, %eax      # imm = 0x1FC
movl %eax, %eax
addq %rax, %rdi
movq -0x10(%rbp), %rsi
addq $0x200, %rsi            # imm = 0x200
movl -0x60(%rbp), %eax
shll $0x9, %eax
movl %eax, %eax
addq %rax, %rsi
movl $0x1fc, %edx            # imm = 0x1FC
callq 0x10e0
movq -0x10(%rbp), %rax
movl -0x60(%rbp), %ecx
shll $0x9, %ecx
movl %ecx, %ecx
movl 0x3fc(%rax,%rcx), %eax
movl %eax, -0x60(%rbp)
jmp 0x1adf
movb $0x1, -0x1(%rbp)
movl $0x1, -0x70(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x2030
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xa0, %rsp
popq %rbp
retq
movq -0x68(%rbp), %rdi
callq 0x11d0
nopw %cs:(%rax,%rax)