// File: williewillus[P]panda_scratchpad/src/wrapper/wrapper.cpp
// Function: wrapper::RecordCmFsOps::CmOpenCommon(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, bool, int)
void RecordCmFsOps::CmOpenCommon(const int fd, const string &pathname,
    const bool exists, const int flags) {
  fd_map_.insert({fd, pathname});

  if (!exists || (flags & O_TRUNC)) {
    // We only want to record this op if we changed something on the file
    // system.

    DiskMod mod;

    // Need something like stat() because umask could affect the file
    // permissions.
    const int post_stat_res = fns_->FnStat(pathname.c_str(),
        &mod.post_mod_stats);
    if (post_stat_res < 0) {
      // TODO(ashmrtn): Some sort of warning here?
      return;
    }

    mod.directory_mod = S_ISDIR(mod.post_mod_stats.st_mode);

    if (!exists) {
      mod.mod_type = DiskMod::kCreateMod;
      mod.mod_opts = DiskMod::kNoneOpt;
    } else {
      mod.mod_type = DiskMod::kDataMetadataMod;
      mod.mod_opts = DiskMod::kTruncateOpt;
    }

    mod.path = pathname;

    mods_.push_back(mod);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1e0, %rsp            # imm = 0x1E0
movb %cl, %al
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
andb $0x1, %al
movb %al, -0x19(%rbp)
movl %r8d, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x1c0(%rbp)
addq $0x8, %rax
movq %rax, -0x1b8(%rbp)
movq -0x18(%rbp), %rdx
leaq -0x48(%rbp), %rdi
movq %rdi, -0x1b0(%rbp)
leaq -0xc(%rbp), %rsi
callq 0x13ea0
movq -0x1b8(%rbp), %rdi
movq -0x1b0(%rbp), %rsi
callq 0x13e60
movb %dl, -0x1a1(%rbp)
movq %rax, -0x1a0(%rbp)
jmp 0xff21
movb -0x1a1(%rbp), %al
movq -0x1a0(%rbp), %rcx
movq %rcx, -0x68(%rbp)
movb %al, -0x60(%rbp)
leaq -0x48(%rbp), %rdi
callq 0xcb30
testb $0x1, -0x19(%rbp)
je 0xff55
movl -0x20(%rbp), %eax
andl $0x200, %eax            # imm = 0x200
cmpl $0x0, %eax
je 0x10121
leaq -0x168(%rbp), %rdi
callq 0xe650
movq -0x1c0(%rbp), %rax
movq 0x90(%rax), %rax
movq %rax, -0x1d8(%rbp)
movq -0x18(%rbp), %rdi
callq 0x6220
movq %rax, -0x1d0(%rbp)
leaq -0x191(%rbp), %rdi
movq %rdi, -0x1c8(%rbp)
callq 0x68b0
movq -0x1d0(%rbp), %rsi
movq -0x1c8(%rbp), %rdx
leaq -0x190(%rbp), %rdi
callq 0x6670
jmp 0xffb5
movq -0x1d8(%rbp), %rdi
leaq -0x140(%rbp), %rdx
movq (%rdi), %rax
movq 0x88(%rax), %rax
leaq -0x190(%rbp), %rsi
callq *%rax
movl %eax, -0x1dc(%rbp)
jmp 0xffde
leaq -0x190(%rbp), %rdi
callq 0x69d8
leaq -0x191(%rbp), %rdi
callq 0x6590
movl -0x1dc(%rbp), %eax
movl %eax, -0x16c(%rbp)
cmpl $0x0, -0x16c(%rbp)
jge 0x1006b
movl $0x1, -0x198(%rbp)
jmp 0x100eb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x48(%rbp), %rdi
callq 0xcb30
jmp 0x1012a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x1005a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x190(%rbp), %rdi
callq 0x69d8
leaq -0x191(%rbp), %rdi
callq 0x6590
jmp 0x10113
movl -0x128(%rbp), %eax
andl $0xf000, %eax           # imm = 0xF000
cmpl $0x4000, %eax           # imm = 0x4000
sete %al
andb $0x1, %al
movb %al, -0xb0(%rbp)
testb $0x1, -0x19(%rbp)
jne 0x100a2
movl $0x0, -0x148(%rbp)
movl $0x0, -0x144(%rbp)
jmp 0x100b6
movl $0x1, -0x148(%rbp)
movl $0x1, -0x144(%rbp)
movq -0x18(%rbp), %rsi
leaq -0x168(%rbp), %rdi
callq 0x6060
jmp 0x100c8
movq -0x1c0(%rbp), %rdi
addq $0x78, %rdi
leaq -0x168(%rbp), %rsi
callq 0x13df0
jmp 0x100e1
movl $0x0, -0x198(%rbp)
leaq -0x168(%rbp), %rdi
callq 0xbf60
movl -0x198(%rbp), %eax
testl %eax, %eax
je 0x10105
jmp 0x10103
jmp 0x10121
jmp 0x10121
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x168(%rbp), %rdi
callq 0xbf60
jmp 0x1012a
addq $0x1e0, %rsp            # imm = 0x1E0
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0x68a0
nopw %cs:(%rax,%rax)