// File: cpottamus[P]btree_lab/freebuffer.cc
// Function: main
int main(int argc, char *argv[])
{
  if (argc<5) { 
    usage();
    exit(-1);
  }
  SIZE_T cachesize=atoi(argv[2]);
  SIZE_T blocknum=atoi(argv[3]);
  SIZE_T numblocks=atoi(argv[4]);

  DiskSystem disk(argv[1]);
  BufferCache cache(&disk,cachesize);

  cache.Attach();

  for (unsigned i=blocknum;i<(blocknum+numblocks);i++) { 
    ERROR_T rc=cache.NotifyDeallocateBlock(i);
    if (rc!=ERROR_NOERROR) { 
      cerr << "Error " << rc <<" occured when notifying cache of allocation of block "<< i << endl;
      return -1;
    }
  }

  cache.Detach();

  cerr << "Deallocation done\n";

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1a0, %rsp            # imm = 0x1A0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x5, -0x8(%rbp)
jge 0x26ae
callq 0x2660
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x22e0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x2390
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x2390
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x2390
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x158(%rbp)
leaq -0xc1(%rbp), %rdi
movq %rdi, -0x150(%rbp)
callq 0x23f0
movq -0x158(%rbp), %rsi
movq -0x150(%rbp), %rdx
leaq -0xc0(%rbp), %rdi
callq 0x2990
jmp 0x271c
movq %rsp, %rax
movl $0x0, 0x10(%rax)
movl $0x0, 0x8(%rax)
movl $0x0, (%rax)
leaq -0xa0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
xorl %r9d, %r9d
xorps %xmm2, %xmm2
movl %r9d, %edx
movl %r9d, %ecx
movl %r9d, %r8d
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0x2ce0
jmp 0x275d
leaq -0xc0(%rbp), %rdi
callq 0x2120
leaq -0xc1(%rbp), %rdi
callq 0x2260
movl -0x14(%rbp), %edx
leaq -0x138(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x5a50
jmp 0x278d
leaq -0x138(%rbp), %rdi
callq 0x5c10
jmp 0x279b
movl -0x18(%rbp), %eax
movl %eax, -0x13c(%rbp)
movl -0x13c(%rbp), %eax
movl -0x18(%rbp), %ecx
addl -0x1c(%rbp), %ecx
cmpl %ecx, %eax
jae 0x2914
movl -0x13c(%rbp), %esi
leaq -0x138(%rbp), %rdi
callq 0x5d00
movl %eax, -0x15c(%rbp)
jmp 0x27d2
movl -0x15c(%rbp), %eax
movl %eax, -0x140(%rbp)
cmpl $0x0, -0x140(%rbp)
je 0x28fe
movq 0xb7fe(%rip), %rdi      # 0xdff0
leaq 0x6844(%rip), %rsi      # 0x903d
callq 0x21e0
movq %rax, -0x168(%rbp)
jmp 0x2807
movq -0x168(%rbp), %rdi
movl -0x140(%rbp), %esi
callq 0x23d0
movq %rax, -0x170(%rbp)
jmp 0x2822
movq -0x170(%rbp), %rdi
leaq 0x6814(%rip), %rsi      # 0x9044
callq 0x21e0
movq %rax, -0x178(%rbp)
jmp 0x283e
movq -0x178(%rbp), %rdi
movl -0x13c(%rbp), %esi
callq 0x2320
movq %rax, -0x180(%rbp)
jmp 0x2859
movq -0x180(%rbp), %rdi
movq 0xb761(%rip), %rsi      # 0xdfc8
callq 0x2230
jmp 0x286e
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x144(%rbp)
jmp 0x2948
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0x28b6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x2120
leaq -0xc1(%rbp), %rdi
callq 0x2260
jmp 0x2978
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0x296c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x5ac0
jmp 0x296c
jmp 0x2900
movl -0x13c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x13c(%rbp)
jmp 0x27a4
leaq -0x138(%rbp), %rdi
callq 0x5b20
jmp 0x2922
movq 0xb6c7(%rip), %rdi      # 0xdff0
leaq 0x674a(%rip), %rsi      # 0x907a
callq 0x21e0
jmp 0x2937
movl $0x0, -0x4(%rbp)
movl $0x1, -0x144(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x5ac0
leaq -0xa0(%rbp), %rdi
callq 0x3550
movl -0x4(%rbp), %eax
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbp
retq
leaq -0xa0(%rbp), %rdi
callq 0x3550
movq -0xd0(%rbp), %rdi
callq 0x23e0
nopw %cs:(%rax,%rax)
nop