// File: /workspace/github_cpp_makefile_star2_O1/williewillus[P]panda_scratchpad/src/wrapper/DiskMod.cpp
// Function: wrapper::DiskMod::Serialize(wrapper::DiskMod&, unsigned long long*)
shared_ptr<char> DiskMod::Serialize(DiskMod &dm, unsigned long long *size) {
  // Standard code to serialize the front part of the DiskMod.
  // Get a block large enough for this DiskMod.
  const uint64_t mod_size = dm.GetSerializeSize();
  if (size != nullptr) {
    *size = mod_size;
  }
  // TODO(ashmrtn): May want to split this if it is very large.
  shared_ptr<char> res_ptr(new (std::nothrow) char[mod_size],
      [](char *c) {delete[] c;});
  char *buf = res_ptr.get();
  if (buf == nullptr) {
    return res_ptr;
  }

  const uint64_t mod_size_be = htobe64(mod_size);
  memcpy(buf, &mod_size_be, sizeof(uint64_t));
  unsigned int buf_offset = sizeof(uint64_t);

  int res = SerializeHeader(buf, buf_offset, dm);
  if (res < 0) {
    return shared_ptr<char>(nullptr);
  }
  buf_offset += res;

  // kCheckpointMod and kSyncMod don't need anything done after the type.
  if (!(dm.mod_type == DiskMod::kCheckpointMod ||
      dm.mod_type == DiskMod::kSyncMod)) {
    res = SerializeChangeHeader(buf, buf_offset, dm);
    if (res < 0) {
      return shared_ptr<char>(nullptr);
    }

    if (dm.mod_type == DiskMod::kFsyncMod ||
        dm.mod_type == DiskMod::kCreateMod) {
      return res_ptr;
    }

    buf_offset += res;
    if (dm.directory_mod) {
      // We changed a directory, only put that down.
      res = SerializeDirectoryMod(buf, buf_offset, dm);
      if (res < 0) {
        return shared_ptr<char>(nullptr);
      }
      buf_offset += res;
    } else {
      // TODO(ashmrtn): *Technically* fallocate and friends can be called on a
      // directory file descriptor. The current code will not play well with
      // that.
      // We changed a file, only put that down.
      res = SerializeDataRange(buf, buf_offset, dm);
      if (res < 0) {
        return shared_ptr<char>(nullptr);
      }
      buf_offset += res;
    }
  }

  return res_ptr;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %rbx
movq %rsi, %rdi
callq 0x985c
movq %rax, %r13
testq %r14, %r14
je 0x98fb
movq %r13, (%r14)
movq 0x12686(%rip), %rsi     # 0x1bf88
movq %r13, %rdi
callq 0x5720
movq %rax, %r15
movl $0x18, %edi
callq 0x54a0
movq %rax, %r14
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, 0x8(%r14)
leaq 0x11e91(%rip), %rax     # 0x1b7c0
movq %rax, (%r14)
movq %r15, 0x10(%r14)
testq %r15, %r15
je 0x996e
bswapq %r13
movq %r13, (%r15)
movl 0x20(%r12), %r13d
movl %r13d, %eax
rolw $0x8, %ax
movl 0x24(%r12), %edx
movl %edx, %ecx
rolw $0x8, %cx
movw %ax, 0x8(%r15)
movw %cx, 0xa(%r15)
cmpl $0x6, %r13d
je 0x996e
cmpl $0x8, %r13d
jne 0x9997
movq %r15, (%rbx)
movq %r14, 0x8(%rbx)
xorl %r14d, %r14d
testq %r14, %r14
je 0x9985
movq %r14, %rdi
callq 0x8af0
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %edx, -0x2c(%rbp)
leaq 0xc(%r15), %rdi
movq (%r12), %rsi
movq 0x8(%r12), %rax
movq %rax, -0x40(%rbp)
leal 0x1(%rax), %edx
movq %rdx, -0x38(%rbp)
callq 0x53b0
movq -0x40(%rbp), %rsi
movb 0xb8(%r12), %al
movq -0x38(%rbp), %rcx
movb %al, 0xc(%r15,%rcx)
movl %esi, %ecx
addl $0x2, %ecx
js 0x9a46
cmpl $0x7, %r13d
je 0x996e
testl %r13d, %r13d
je 0x996e
testb %al, %al
jne 0x9a51
addl $0xe, %esi
movq 0xd0(%r12), %rax
bswapq %rax
movq %rax, (%r15,%rsi)
movq 0xd8(%r12), %rdx
movq %rdx, %rax
bswapq %rax
movq %rax, 0x8(%r15,%rsi)
cmpl $0x9, %r13d
sete %al
movl -0x2c(%rbp), %ecx
addl $-0x2, %ecx
cmpl $0x7, %ecx
setb %cl
orb %al, %cl
jne 0x996e
movq %r15, %rdi
addq %rsi, %rdi
addq $0x10, %rdi
movq 0xc0(%r12), %rsi
movq %rdx, %r12
callq 0x53b0
addl $0x10, %r12d
jns 0x996e
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
jmp 0x9978
leaq 0xb0ca(%rip), %rdi      # 0x14b22
leaq 0xb0da(%rip), %rsi      # 0x14b39
leaq 0xb0e7(%rip), %rcx      # 0x14b4d
movl $0xce, %edx
callq 0x52e0
movq %rax, %rdi
callq 0x51d0
testq %r15, %r15
je 0x9a85
movq %r15, %rdi
callq 0x5540
callq 0x5640
movq %rax, %rbx
callq 0x5710
movq %rbx, %rdi
callq 0x57c0
movq %rax, %rdi
callq 0x8002