// File: /workspace/github_cpp_makefile_star2_O1/jasperandrew[P]cs350-project2/./lab7.h
// Function: overwrite(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void overwrite(string filename, string howmany, string start, string c)
{
  //convert strings args to ints                                                                                                                                                                                                                              
  int copyNum =  stoi(howmany);
  int sByte = stoi(start);
  char *chr = &c.at(0);
  block_num blocknums[128] = {0};
  char bigBuffer[MAX_FILE_SZ];
  inode node;
  //get inode Block Num and file map index                                                                                                                                                                                                                   
  for(int i = 0; i < g_filemap_ctr; i++)
    {
      if(g_filemap[i].name == filename)
        {
	  node = readInode(g_filemap[i].num);
          //blockNum = g_imap.list[g_filemap[i].num];
        }
    }
  /*Block inode*/ 
  //inode node = readInode(blockNum);
  Block *inodeB = new Block(1);
  for(int i = 0; i < 128;i++)
    {
      if(node.datablocks[i])
	{
 	  readData(node.datablocks[i]);
	  memcpy(bigBuffer+(i*BLOCK_SZ), block_buffer, BLOCK_SZ);	  
	}
    }
  
  for(int j = sByte; j < copyNum+sByte;j++)
    {
      bigBuffer[j] = *chr;
    }
   

  for(int i = 0; i < MAX_FILE_SZ; i += BLOCK_SZ){
    
    char tmp_data[BLOCK_SZ] = {0};
    memcpy(tmp_data, bigBuffer+i, BLOCK_SZ); 

    Block *data_block = new Block(0);
    data_block->setData(tmp_data);

    wbuffer.addBlock(data_block);
    int block_number = BLOCK_SZ * current_segment + wbuffer.getNumBlocks();
    inodeB->addBlockNum(block_number);
    blocknums[i/BLOCK_SZ] = block_number;
  }

  wbuffer.addBlock(inodeB);
  wbuffer.addSegInfo(blocknums,wbuffer.getNumBlocks());

  for(int s; s<g_filemap_ctr; s++)
    {
      if (g_filemap[s].name == filename)
        {
          g_filemap[s].name == "";
          g_filemap[s].num == -1;
        }
    }

  g_filemap[g_filemap_ctr].num = g_imap.idx;
  g_filemap[g_filemap_ctr].name = filename;
  g_filemap_ctr++;
  

  g_imap.list[g_imap.idx++] = BLOCK_SZ * current_segment + wbuffer.getNumBlocks();
  return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x20928, %rsp          # imm = 0x20928
movq %rcx, %rbx
movq %rdx, %r15
movq %rdi, -0x38(%rbp)
movq (%rsi), %r13
callq 0x2040
movq %rax, %r12
movl (%rax), %eax
movl %eax, -0x30(%rbp)
movl $0x0, (%r12)
leaq -0x20950(%rbp), %r14
movq %r13, %rdi
movq %r14, %rsi
movl $0xa, %edx
callq 0x22d0
cmpq %r13, (%r14)
je 0x3c87
movslq %eax, %rcx
cmpq %rax, %rcx
jne 0x3c93
movl (%r12), %ecx
cmpl $0x22, %ecx
je 0x3c93
movq %rax, -0x40(%rbp)
testl %ecx, %ecx
jne 0x3975
movl -0x30(%rbp), %eax
movl %eax, (%r12)
movq (%r15), %r14
movl (%r12), %eax
movl %eax, -0x30(%rbp)
movl $0x0, (%r12)
leaq -0x20950(%rbp), %r13
movq %r14, %rdi
movq %r13, %rsi
movl $0xa, %edx
callq 0x22d0
cmpq %r14, (%r13)
je 0x3c9f
movq %rax, %r15
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
leaq -0x80000000(%r15), %rcx
cmpq %rax, %rcx
jb 0x3cab
movl (%r12), %eax
cmpl $0x22, %eax
je 0x3cab
testl %eax, %eax
jne 0x39dd
movl -0x30(%rbp), %eax
movl %eax, (%r12)
movq 0x8(%rbx), %rdx
testq %rdx, %rdx
je 0x3cb7
movq (%rbx), %rax
movq %rax, -0x30(%rbp)
leaq -0x240(%rbp), %rdi
movl $0x200, %edx            # imm = 0x200
xorl %esi, %esi
callq 0x2100
cmpl $0x0, 0x169c45(%rip)    # 0x16d650
jle 0x3a62
leaq 0x105c4c(%rip), %rbx    # 0x109660
xorl %r12d, %r12d
leaq -0x544(%rbp), %r14
movq (%rbx), %rdx
movq -0x38(%rbp), %rax
cmpq 0x8(%rax), %rdx
jne 0x3a4f
testq %rdx, %rdx
je 0x3a44
movq -0x38(%rbp), %rax
movq (%rax), %rsi
movq -0x8(%rbx), %rdi
callq 0x2200
testl %eax, %eax
jne 0x3a4f
movl -0x10(%rbx), %esi
movq %r14, %rdi
callq 0x2edc
incq %r12
movslq 0x169bf7(%rip), %rax    # 0x16d650
addq $0x28, %rbx
cmpq %rax, %r12
jl 0x3a1e
movl $0x1f10, %edi           # imm = 0x1F10
callq 0x21f0
movq %rax, %r12
movl $0x1, (%rax)
movl $0x0, 0xb08(%rax)
movl $0x41, %ebx
leaq 0x1057c5(%rip), %r14    # 0x109250
movl -0x544(%rbp,%rbx,4), %edi
testl %edi, %edi
je 0x3aab
callq 0x3139
movl $0x400, %edx            # imm = 0x400
movq %r13, %rdi
movq %r14, %rsi
callq 0x2170
incq %rbx
addq $0x400, %r13            # imm = 0x400
cmpq $0xc1, %rbx
jne 0x3a8b
movq -0x40(%rbp), %rax
testl %eax, %eax
jle 0x3af8
addl %r15d, %eax
movslq %r15d, %rcx
leaq (%rcx,%rbp), %rdi
addq $-0x20950, %rdi         # imm = 0xFFFDF6B0
leal 0x1(%r15), %ecx
cmpl %ecx, %eax
cmovgl %eax, %ecx
notl %r15d
addl %ecx, %r15d
incq %r15
movq -0x30(%rbp), %rax
movzbl (%rax), %esi
movq %r15, %rdx
callq 0x2100
xorl %ebx, %ebx
leaq -0x950(%rbp), %r15
leaq 0x173c18(%rip), %r14    # 0x177720
leaq (%rbx,%rbp), %rsi
addq $-0x20950, %rsi         # imm = 0xFFFDF6B0
movl $0x400, %edx            # imm = 0x400
movq %r15, %rdi
callq 0x2170
movl $0x1f10, %edi           # imm = 0x1F10
callq 0x21f0
movq %rax, %r13
movl $0x0, 0xb08(%rax)
movl $0x404, %edx            # imm = 0x404
movq %rax, %rdi
xorl %esi, %esi
callq 0x2100
movl $0x4, %eax
movb -0x954(%rbp,%rax), %cl
testb %cl, %cl
je 0x3b66
movb %cl, (%r13,%rax)
incq %rax
cmpq $0x404, %rax            # imm = 0x404
jne 0x3b4b
movslq 0x175bb3(%rip), %rax    # 0x179720
leal 0x1(%rax), %ecx
movl %ecx, 0x175baa(%rip)    # 0x179720
movq %r13, (%r14,%rax,8)
cmpl $0x400, %ecx            # imm = 0x400
jne 0x3b8a
movq %r14, %rdi
callq 0x45b4
movl 0x1056b4(%rip), %eax    # 0x109244
shll $0xa, %eax
addl 0x175b87(%rip), %eax    # 0x179720
movslq 0xb08(%r12), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0xb08(%r12)
movl %eax, 0x508(%r12,%rcx,4)
movq %rbx, %rcx
shrq $0x8, %rcx
movl %eax, -0x240(%rbp,%rcx)
leaq 0x400(%rbx), %rax
cmpq $0x1fc00, %rbx          # imm = 0x1FC00
movq %rax, %rbx
jb 0x3b08
movslq 0x175b40(%rip), %rax    # 0x179720
leal 0x1(%rax), %ecx
movl %ecx, 0x175b37(%rip)    # 0x179720
movq %r12, (%r14,%rax,8)
cmpl $0x400, %ecx            # imm = 0x400
jne 0x3c01
leaq 0x173b24(%rip), %rdi    # 0x177720
callq 0x45b4
movl 0x175b19(%rip), %edx    # 0x179720
leaq 0x173b12(%rip), %rdi    # 0x177720
leaq -0x240(%rbp), %rsi
callq 0x376a
movslq 0x169a2f(%rip), %rax    # 0x16d650
leaq 0x169af0(%rip), %rbx    # 0x16d718
movl 0x173aea(%rip), %ecx    # 0x177718
leaq (%rax,%rax,4), %rax
leaq 0x105a17(%rip), %rdx    # 0x109650
leaq (%rdx,%rax,8), %rdi
addq $0x8, %rdi
movl %ecx, -0x8(%rdi)
movq -0x38(%rbp), %rsi
callq 0x20f0
incl 0x1699fd(%rip)          # 0x16d650
movl 0x1055eb(%rip), %eax    # 0x109244
shll $0xa, %eax
addl 0x175abe(%rip), %eax    # 0x179720
movslq 0x173aaf(%rip), %rcx    # 0x177718
leal 0x1(%rcx), %edx
movl %edx, 0x173aa6(%rip)    # 0x177718
movl %eax, (%rbx,%rcx,4)
addq $0x20928, %rsp          # imm = 0x20928
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2d45(%rip), %rdi      # 0x69d3
callq 0x2110
leaq 0x2d39(%rip), %rdi      # 0x69d3
callq 0x22f0
leaq 0x2d2d(%rip), %rdi      # 0x69d3
callq 0x2110
leaq 0x2d21(%rip), %rdi      # 0x69d3
callq 0x22f0
leaq 0x2d44(%rip), %rdi      # 0x6a02
xorl %esi, %esi
xorl %eax, %eax
callq 0x2330
jmp 0x3cc9
cmpl $0x0, (%r12)
jne 0x3cd7
movl -0x30(%rbp), %ecx
movl %ecx, (%r12)
movq %rax, %rdi
callq 0x23a0