// File: /workspace/github_cpp_makefile_star2_O1/williewillus[P]panda_scratchpad/src/utils/Tester.cpp
// Function: Tester::GetChangeData(int)
int Tester::GetChangeData(const int fd) {
  // Need to read a 64-bit value, switch it to big endian to figure out how much
  // we need to read, read that new data amount, and add it all to a buffer.
  while (true) {
    // Get the next DiskMod size.
    uint64_t buf;
    const int read_res = read(fd, (void *) &buf, sizeof(uint64_t));
    if (read_res < 0) {
      return read_res;
    } else if (read_res == 0) {
      // No more data to read.
      break;
    }

    uint64_t next_chunk_size = be64toh(buf);

    // Read the next DiskMod.
    shared_ptr<char> data(new char[next_chunk_size], [](char *c) {delete[] c;});
    memcpy(data.get(), (void *) &buf, sizeof(uint64_t));
    unsigned long long int read_data = sizeof(uint64_t);
    while (read_data < next_chunk_size) {
      const int res = read(fd, data.get() + read_data,
          next_chunk_size - read_data);
      if (res <= 0) {
        // We shouldn't find a size for a DiskMod without the rest of the
        // DiskMod.
        return -1;
      }
      read_data += res;
    }

    DiskMod mod;
    const int res = DiskMod::Deserialize(data, mod);
    if (res < 0) {
      return res;
    }

    if (mod.mod_type == DiskMod::kCheckpointMod) {
      // We found a checkpoint, so switch to a new set of DiskMods.
      cout << "Found a checkpoint" << endl;
      mods_.push_back(vector<DiskMod>());
    } else {
      if (mods_.empty()) {
        // We're just starting, so give us a place to put the mods.
        mods_.push_back(vector<DiskMod>());
      }
      // Just append this DiskMod to the end of the last set of DiskMods.
      mods_.back().push_back(mod);
    }
  }

  return SUCCESS;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movl %esi, %ebx
movq %rdi, -0x70(%rbp)
leaq 0xf8(%rdi), %rax
movq %rax, -0x58(%rbp)
leaq -0x30(%rbp), %r14
movl $0x8, %edx
movl %ebx, %edi
movq %r14, %rsi
callq 0x5620
testl %eax, %eax
js 0xfb7b
je 0xfb89
movq -0x30(%rbp), %r13
movq %r13, %r12
bswapq %r12
movq %r12, %rdi
callq 0x5030
movq %rax, %r14
movl $0x18, %edi
callq 0x54a0
movabsq $0x100000001, %rcx      # imm = 0x100000001
movq %rcx, 0x8(%rax)
leaq 0xc21a(%rip), %rcx      # 0x1bd38
movq %rcx, (%rax)
movq %rax, -0x38(%rbp)
movq %r14, 0x10(%rax)
movq %r13, (%r14)
movl $0x8, %r13d
movq %r12, %rdx
subq %r13, %rdx
jbe 0xfb94
leaq (%r14,%r13), %rsi
movl %ebx, %edi
callq 0x5620
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
testl %eax, %eax
movl $0x0, %edx
cmovleq %rdx, %rcx
addq %rcx, %r13
testl %eax, %eax
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmovlel %eax, %r15d
jg 0xfb32
movl $0x1, %r12d
leaq -0x30(%rbp), %r14
movq -0x38(%rbp), %r13
jmp 0xfd1b
movl $0x1, %r12d
movl %eax, %r15d
jmp 0xfd23
movl $0x3, %r12d
jmp 0xfd23
leaq -0x170(%rbp), %rdi
callq 0x9e18
movq %r14, -0x68(%rbp)
movq -0x38(%rbp), %r13
movq %r13, -0x60(%rbp)
movq 0xc40d(%rip), %rax      # 0x1bfc0
cmpb $0x0, (%rax)
movq -0x70(%rbp), %r12
je 0xfbc2
incl 0x8(%r13)
jmp 0xfbc7
lock
incl 0x8(%r13)
leaq -0x68(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0x9b9a
movl %eax, %r14d
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0xfbe8
callq 0x8af0
testl %r14d, %r14d
js 0xfc78
cmpl $0x6, -0x150(%rbp)
jne 0xfc87
movl $0x12, %edx
movq 0xc3be(%rip), %rdi      # 0x1bfc8
leaq 0x5717(%rip), %rsi      # 0x15328
callq 0x54f0
leaq -0x30(%rbp), %r14
movq 0xc3a7(%rip), %rcx      # 0x1bfc8
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x5470
movsbl %al, %esi
movq 0xc389(%rip), %rdi      # 0x1bfc8
callq 0x5040
movq %rax, %rdi
callq 0x5300
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x58(%rbp), %rdi
leaq -0x50(%rbp), %r12
movq %r12, %rsi
callq 0x10546
movq %r12, %rdi
callq 0x8a5e
xorl %r12d, %r12d
jmp 0xfcdd
movl $0x1, %r12d
movl %r14d, %r15d
leaq -0x30(%rbp), %r14
jmp 0xfcdd
movq 0xf8(%r12), %rax
cmpq 0x100(%r12), %rax
leaq -0x30(%rbp), %r14
jne 0xfcc2
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x58(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x10546
leaq -0x50(%rbp), %rdi
callq 0x8a5e
movq 0x100(%r12), %rdi
addq $-0x18, %rdi
xorl %r12d, %r12d
leaq -0x170(%rbp), %rsi
callq 0xbfa2
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0xfcf2
callq 0x5460
movq -0xa8(%rbp), %rdi
testq %rdi, %rdi
je 0xfd03
callq 0x8af0
movq -0x170(%rbp), %rdi
leaq -0x160(%rbp), %rax
cmpq %rax, %rdi
je 0xfd1b
callq 0x5460
movq %r13, %rdi
callq 0x8af0
testl %r12d, %r12d
je 0xfacd
cmpl $0x1, %r12d
je 0xfd35
xorl %r15d, %r15d
movl %r15d, %eax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xfd4c
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x8a5e
jmp 0xfd72
movq %rax, %rbx
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0xfd72
callq 0x8af0
jmp 0xfd72
jmp 0xfda7
movq %rax, %rbx
leaq -0x170(%rbp), %rdi
callq 0xbfde
jmp 0xfdaa
movq %rax, %rdi
callq 0x51d0
movq %r14, %rdi
callq 0x5540
callq 0x5640
movq %rax, %rbx
callq 0x5710
jmp 0xfdb3
movq %rax, %rdi
callq 0x8002
movq %rax, %rbx
movq -0x38(%rbp), %rdi
callq 0x8af0
movq %rbx, %rdi
callq 0x57c0
nop