// File: /workspace/github_cpp_makefile_star2_O3/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 $0x20938, %rsp          # imm = 0x20938
movq %rcx, -0x38(%rbp)
movq %rdx, %r15
movq %rdi, -0x40(%rbp)
movq (%rsi), %r13
callq 0x2040
movq %rax, %r12
movl (%rax), %eax
movl %eax, -0x30(%rbp)
movl $0x0, (%r12)
leaq -0x20960(%rbp), %r14
movq %r13, %rdi
movq %r14, %rsi
movl $0xa, %edx
callq 0x22d0
cmpq %r13, (%r14)
je 0x3d09
movslq %eax, %rcx
cmpq %rax, %rcx
jne 0x3d15
movl (%r12), %ebx
cmpl $0x22, %ebx
je 0x3d15
movq %rax, -0x48(%rbp)
testl %ebx, %ebx
jne 0x39f8
movl -0x30(%rbp), %ebx
movl %ebx, (%r12)
movq (%r15), %r14
movl $0x0, (%r12)
leaq -0x20960(%rbp), %r13
movq %r14, %rdi
movq %r13, %rsi
movl $0xa, %edx
callq 0x22d0
cmpq %r14, (%r13)
je 0x3d21
movabsq $-0x100000000, %rdx     # imm = 0xFFFFFFFF00000000
leaq -0x80000000(%rax), %rcx
cmpq %rdx, %rcx
jb 0x3d2d
movl (%r12), %ecx
cmpl $0x22, %ecx
je 0x3d2d
testl %ecx, %ecx
jne 0x3a53
movl %ebx, (%r12)
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x3d39
movq (%rax), %rax
movq %rax, -0x38(%rbp)
leaq -0x250(%rbp), %rdi
movl $0x200, %edx            # imm = 0x200
xorl %esi, %esi
callq 0x2100
movl 0x169bc9(%rip), %r15d   # 0x16d650
testl %r15d, %r15d
jle 0x3ae4
leaq 0x105bcd(%rip), %rbx    # 0x109660
xorl %r12d, %r12d
leaq -0x554(%rbp), %r14
movq (%rbx), %rdx
movq -0x40(%rbp), %rax
cmpq 0x8(%rax), %rdx
jne 0x3ad5
testq %rdx, %rdx
je 0x3ac3
movq -0x40(%rbp), %rax
movq (%rax), %rsi
movq -0x8(%rbx), %rdi
callq 0x2200
testl %eax, %eax
jne 0x3ad5
movl -0x10(%rbx), %esi
movq %r14, %rdi
callq 0x2f2a
movl 0x169b7b(%rip), %r15d   # 0x16d650
incq %r12
movslq %r15d, %rax
addq $0x28, %rbx
cmpq %rax, %r12
jl 0x3a9d
movl $0x1f10, %edi           # imm = 0x1F10
callq 0x21f0
movq %rax, %r12
movl $0x1, (%rax)
movl $0x0, 0xb08(%rax)
movl $0x41, %ebx
leaq 0x105743(%rip), %r14    # 0x109250
movq -0x30(%rbp), %r15
movl -0x554(%rbp,%rbx,4), %edi
testl %edi, %edi
je 0x3b31
callq 0x3187
movl $0x400, %edx            # imm = 0x400
movq %r13, %rdi
movq %r14, %rsi
callq 0x2170
incq %rbx
addq $0x400, %r13            # imm = 0x400
cmpq $0xc1, %rbx
jne 0x3b11
movq -0x48(%rbp), %rax
testl %eax, %eax
jle 0x3b7e
addl %r15d, %eax
movslq %r15d, %rcx
leaq (%rcx,%rbp), %rdi
addq $-0x20960, %rdi         # imm = 0xFFFDF6A0
leal 0x1(%r15), %ecx
cmpl %ecx, %eax
cmovgl %eax, %ecx
notl %r15d
addl %ecx, %r15d
incq %r15
movq -0x38(%rbp), %rax
movzbl (%rax), %esi
movq %r15, %rdx
callq 0x2100
xorl %ebx, %ebx
leaq -0x960(%rbp), %r15
leaq 0x173b92(%rip), %r14    # 0x177720
leaq (%rbx,%rbp), %rsi
addq $-0x20960, %rsi         # imm = 0xFFFDF6A0
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 -0x964(%rbp,%rax), %cl
testb %cl, %cl
je 0x3bec
movb %cl, (%r13,%rax)
incq %rax
cmpq $0x404, %rax            # imm = 0x404
jne 0x3bd1
movslq 0x175b2d(%rip), %rcx    # 0x179720
leal 0x1(%rcx), %eax
movl %eax, 0x175b24(%rip)    # 0x179720
movq %r13, (%r14,%rcx,8)
cmpl $0x400, %eax            # imm = 0x400
jne 0x3c15
movq %r14, %rdi
callq 0x4644
movl 0x175b0b(%rip), %eax    # 0x179720
movl 0x105629(%rip), %ecx    # 0x109244
shll $0xa, %ecx
addl %eax, %ecx
movslq 0xb08(%r12), %rdx
leal 0x1(%rdx), %esi
movl %esi, 0xb08(%r12)
movl %ecx, 0x508(%r12,%rdx,4)
movq %rbx, %rdx
shrq $0x8, %rdx
movl %ecx, -0x250(%rbp,%rdx)
leaq 0x400(%rbx), %rcx
cmpq $0x1fc00, %rbx          # imm = 0x1FC00
movq %rcx, %rbx
jb 0x3b8e
leal 0x1(%rax), %edx
movl %edx, 0x175ab7(%rip)    # 0x179720
cltq
movq %r12, (%r14,%rax,8)
cmpl $0x400, %edx            # imm = 0x400
jne 0x3c89
leaq 0x173aa2(%rip), %rdi    # 0x177720
callq 0x4644
movl 0x175a97(%rip), %edx    # 0x179720
leaq 0x173a90(%rip), %rdi    # 0x177720
leaq -0x250(%rbp), %rsi
callq 0x37bc
movslq 0x1699ad(%rip), %rax    # 0x16d650
leaq 0x169a6e(%rip), %rbx    # 0x16d718
movl 0x173a68(%rip), %ecx    # 0x177718
leaq (%rax,%rax,4), %rax
leaq 0x105995(%rip), %rdx    # 0x109650
leaq (%rdx,%rax,8), %rdi
addq $0x8, %rdi
movl %ecx, -0x8(%rdi)
movq -0x40(%rbp), %rsi
callq 0x20f0
incl 0x16997b(%rip)          # 0x16d650
movl 0x105569(%rip), %eax    # 0x109244
shll $0xa, %eax
addl 0x175a3c(%rip), %eax    # 0x179720
movslq 0x173a2d(%rip), %rcx    # 0x177718
leal 0x1(%rcx), %edx
movl %edx, 0x173a24(%rip)    # 0x177718
movl %eax, (%rbx,%rcx,4)
addq $0x20938, %rsp          # imm = 0x20938
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2cc3(%rip), %rdi      # 0x69d3
callq 0x2110
leaq 0x2cb7(%rip), %rdi      # 0x69d3
callq 0x22f0
leaq 0x2cab(%rip), %rdi      # 0x69d3
callq 0x2110
leaq 0x2c9f(%rip), %rdi      # 0x69d3
callq 0x22f0
leaq 0x2cc2(%rip), %rdi      # 0x6a02
xorl %esi, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x2330
cmpl $0x0, (%r12)
jne 0x3d66
movl %ebx, (%r12)
jmp 0x3d66
cmpl $0x0, (%r12)
jne 0x3d66
movl -0x30(%rbp), %ecx
movl %ecx, (%r12)
movq %rax, %rdi
callq 0x23a0