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

  DiskSystem disk(argv[1]);
  SIZE_T blocksize = disk.GetBlockSize();

  vector<Block> b;

  for (unsigned i=0;i<numblocks;i++) { 
    Block block(blocksize);
    for (unsigned j=0;j<blocksize;j++) { 
      cin >> block.data[j];
    }
    b.push_back(block);
  }


  ERROR_T rc= disk.Write(blocknum, numblocks, b, reqtime);

  if (rc!=ERROR_NOERROR) { 
    cerr << "Error "<< rc << " occured.\n";
    return -1;
  } else {
    cerr << "Your data was successfully written.\n";
  }
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x4, -0x8(%rbp)
jge 0x262e
callq 0x25e0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x22a0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x2350
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x2350
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x140(%rbp)
leaq -0xc1(%rbp), %rdi
movq %rdi, -0x138(%rbp)
callq 0x23b0
movq -0x140(%rbp), %rsi
movq -0x138(%rbp), %rdx
leaq -0xc0(%rbp), %rdi
callq 0x2960
jmp 0x268c
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 0x3ff0
jmp 0x26cd
leaq -0xc0(%rbp), %rdi
callq 0x2100
leaq -0xc1(%rbp), %rdi
callq 0x2220
leaq -0xa0(%rbp), %rdi
callq 0x59a0
movl %eax, -0x144(%rbp)
jmp 0x26f9
movl -0x144(%rbp), %eax
movl %eax, -0xd8(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x2a10
movl $0x0, -0xf4(%rbp)
movl -0xf4(%rbp), %eax
cmpl -0x18(%rbp), %eax
jae 0x2854
movl -0xd8(%rbp), %esi
leaq -0x120(%rbp), %rdi
callq 0x39d0
jmp 0x273e
movl $0x0, -0x124(%rbp)
movl -0x124(%rbp), %eax
cmpl -0xd8(%rbp), %eax
jae 0x281f
movq -0x118(%rbp), %rsi
movl -0x124(%rbp), %eax
addq %rax, %rsi
movq 0x6867(%rip), %rdi      # 0x8fd8
callq 0x2260
jmp 0x2778
jmp 0x277a
movl -0x124(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x124(%rbp)
jmp 0x2748
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0x27bd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x2100
leaq -0xc1(%rbp), %rdi
callq 0x2220
jmp 0x2951
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0x2945
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
jmp 0x2939
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd0(%rbp)
movl %eax, -0xd4(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x3c90
jmp 0x2939
leaq -0xf0(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x2a30
jmp 0x2834
leaq -0x120(%rbp), %rdi
callq 0x3c90
movl -0xf4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf4(%rbp)
jmp 0x271b
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
leaq -0xa0(%rbp), %rdi
leaq -0xf0(%rbp), %rcx
leaq -0x20(%rbp), %r8
callq 0x5690
movl %eax, -0x148(%rbp)
jmp 0x2879
movl -0x148(%rbp), %eax
movl %eax, -0x128(%rbp)
cmpl $0x0, -0x128(%rbp)
je 0x28ed
movq 0x675b(%rip), %rdi      # 0x8ff0
leaq 0x379d(%rip), %rsi      # 0x6039
callq 0x21b0
movq %rax, -0x150(%rbp)
jmp 0x28aa
movq -0x150(%rbp), %rdi
movl -0x128(%rbp), %esi
callq 0x2390
movq %rax, -0x158(%rbp)
jmp 0x28c5
movq -0x158(%rbp), %rdi
leaq 0x376d(%rip), %rsi      # 0x6040
callq 0x21b0
jmp 0x28da
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x12c(%rbp)
jmp 0x2915
movq 0x66fc(%rip), %rdi      # 0x8ff0
leaq 0x3750(%rip), %rsi      # 0x604b
callq 0x21b0
jmp 0x2902
jmp 0x2904
movl $0x0, -0x4(%rbp)
movl $0x1, -0x12c(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x2aa0
leaq -0xa0(%rbp), %rdi
callq 0x4860
movl -0x4(%rbp), %eax
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
leaq -0xf0(%rbp), %rdi
callq 0x2aa0
leaq -0xa0(%rbp), %rdi
callq 0x4860
movq -0xd0(%rbp), %rdi
callq 0x23a0
nopl (%rax)