// File: cpottamus[P]btree_lab/disksystem.cc
// Function: DiskSystem::InitFromConfigFile()
ERROR_T DiskSystem::InitFromConfigFile()
{
  string configname = diskfilestem + ".config";
  string dataname = diskfilestem + ".data";
  string bitmapname = diskfilestem + ".bitmap";
  
  if (configfilefd) { fclose(configfilefd); }
  
  if ((configfilefd = fopen(configname.c_str(),"r+"))==0) { 
    return ERROR_NOFILE;
  }

  int rc = ReadConfig();
  
  if (rc) { 
    return rc;
  }

  rc=SanityCheckConfig();

  if (rc) { 
    return rc;
  }

  if (datafilefd) { fclose(datafilefd);}

  if ((datafilefd = fopen(dataname.c_str(),"r+"))==0) { 
    return ERROR_NOFILE;
  }


  if (bitmapfilefd) { fclose(bitmapfilefd);}

  if ((bitmapfilefd = fopen(bitmapname.c_str(),"r+"))==0) { 
    return ERROR_NOFILE;
  }
  
  rc = ReadBitMap();

  if (rc) { 
    return rc;
  }

  return ERROR_NOERROR;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rsi
movq %rsi, -0x98(%rbp)
addq $0x28, %rsi
movq %rsi, -0x90(%rbp)
leaq 0xb3a5(%rip), %rdx      # 0x10371
leaq -0x30(%rbp), %rdi
callq 0x6870
movq -0x90(%rbp), %rsi
leaq 0xb396(%rip), %rdx      # 0x10379
leaq -0x50(%rbp), %rdi
callq 0x6870
jmp 0x4fee
movq -0x98(%rbp), %rsi
addq $0x28, %rsi
leaq 0xb37f(%rip), %rdx      # 0x1037f
leaq -0x80(%rbp), %rdi
callq 0x6870
jmp 0x500b
movq -0x98(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x5069
movq -0x98(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x3200
jmp 0x502b
jmp 0x5069
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x5298
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x528f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x3120
jmp 0x528f
leaq -0x30(%rbp), %rdi
callq 0x30a0
movq %rax, %rdi
leaq 0xb30b(%rip), %rsi      # 0x10387
callq 0x32e0
movq %rax, -0xa0(%rbp)
jmp 0x508a
movq -0xa0(%rbp), %rax
movq -0x98(%rbp), %rcx
movq %rax, 0x18(%rcx)
cmpq $0x0, %rax
jne 0x50b8
movl $0xfffffff3, -0x4(%rbp) # imm = 0xFFFFFFF3
movl $0x1, -0x84(%rbp)
jmp 0x5268
movq -0x98(%rbp), %rdi
callq 0x5700
movl %eax, -0xa4(%rbp)
jmp 0x50cc
movl -0xa4(%rbp), %eax
movl %eax, -0x88(%rbp)
cmpl $0x0, -0x88(%rbp)
je 0x50f9
movl -0x88(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x84(%rbp)
jmp 0x5268
movq -0x98(%rbp), %rdi
callq 0x5660
movl %eax, -0xa8(%rbp)
jmp 0x510d
movl -0xa8(%rbp), %eax
movl %eax, -0x88(%rbp)
cmpl $0x0, -0x88(%rbp)
je 0x513a
movl -0x88(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x84(%rbp)
jmp 0x5268
movq -0x98(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x515c
movq -0x98(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x3200
jmp 0x515a
jmp 0x515c
leaq -0x50(%rbp), %rdi
callq 0x30a0
movq %rax, %rdi
leaq 0xb218(%rip), %rsi      # 0x10387
callq 0x32e0
movq %rax, -0xb0(%rbp)
jmp 0x517d
movq -0xb0(%rbp), %rax
movq -0x98(%rbp), %rcx
movq %rax, 0x10(%rcx)
cmpq $0x0, %rax
jne 0x51ab
movl $0xfffffff3, -0x4(%rbp) # imm = 0xFFFFFFF3
movl $0x1, -0x84(%rbp)
jmp 0x5268
movq -0x98(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x51cd
movq -0x98(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x3200
jmp 0x51cb
jmp 0x51cd
leaq -0x80(%rbp), %rdi
callq 0x30a0
movq %rax, %rdi
leaq 0xb1a7(%rip), %rsi      # 0x10387
callq 0x32e0
movq %rax, -0xb8(%rbp)
jmp 0x51ee
movq -0xb8(%rbp), %rax
movq -0x98(%rbp), %rcx
movq %rax, 0x20(%rcx)
cmpq $0x0, %rax
jne 0x5219
movl $0xfffffff3, -0x4(%rbp) # imm = 0xFFFFFFF3
movl $0x1, -0x84(%rbp)
jmp 0x5268
movq -0x98(%rbp), %rdi
callq 0x5ae0
movl %eax, -0xbc(%rbp)
jmp 0x522d
movl -0xbc(%rbp), %eax
movl %eax, -0x88(%rbp)
cmpl $0x0, -0x88(%rbp)
je 0x5257
movl -0x88(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x84(%rbp)
jmp 0x5268
movl $0x0, -0x4(%rbp)
movl $0x1, -0x84(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x3120
leaq -0x50(%rbp), %rdi
callq 0x3120
leaq -0x30(%rbp), %rdi
callq 0x3120
movl -0x4(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq
leaq -0x50(%rbp), %rdi
callq 0x3120
leaq -0x30(%rbp), %rdi
callq 0x3120
movq -0x58(%rbp), %rdi
callq 0x3400
nopw (%rax,%rax)