// File: 4n6ist[P]usn_analytics/lib/usnjrnl.cpp
// Function: UsnJrnl::GetAllUsnOffset()
int UsnJrnl::GetAllUsnOffset() {
  int result;
  uint64_t progress = file_size / 10; 
  offset = 0;  
    
  while(offset <= file_size-sizeof(USN_RECORD_V2)) {
    
    if(offset >= progress) {
      printf(".");
      progress += file_size / 10;
    }

    UsnRecord* ur = new UsnRecord(fp_in);
    result = ur->IsValidRecord(offset);

    if(result == NOT_RECORD) {
      offset += 8;
      delete ur;
      continue;
    } else if(result == V2_RECORD) {
	    usn_set.push_back(ur->usn_record.Usn);
	    usn_table[ur->usn_record.Usn] = offset;
	  } else if(result == CORRUPT_RECORD) {
      corrupt_offset_set.push_back(offset);
    } else if (result == V3_RECORD) {
      printf("USN_RECORD_V3 found at offset %lld, skip\n", offset);
	  } else if (result == V4_RECORD) {
      printf("USN_RECORD_V4 found at offset %lld, skip\n", offset);
	  } 
	  offset += ur->usn_record.RecordLength;
    delete ur;
  }
  printf("Done\n");
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
movq (%rax), %rax
movl $0xa, %ecx
xorl %edx, %edx
divq %rcx
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, -0x18(%rbp)
movq $0x0, 0x8(%rax)
movq -0x38(%rbp), %rcx
movq 0x8(%rcx), %rax
movq (%rcx), %rcx
subq $0x3c, %rcx
cmpq %rcx, %rax
ja 0x3e43
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
cmpq -0x18(%rbp), %rax
jb 0x3cc1
leaq 0x18ae6(%rip), %rdi     # 0x1c787
movb $0x0, %al
callq 0x3060
movq -0x38(%rbp), %rax
movq (%rax), %rax
movl $0xa, %ecx
xorl %edx, %edx
divq %rcx
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movl $0x80, %edi
callq 0x3340
movq %rax, %rdi
movq -0x38(%rbp), %rax
movq %rdi, %rcx
movq %rcx, -0x40(%rbp)
movq 0x10(%rax), %rsi
callq 0x16410
jmp 0x3ce4
movq -0x38(%rbp), %rax
movq -0x40(%rbp), %rcx
movq %rcx, -0x20(%rbp)
movq -0x20(%rbp), %rdi
movq 0x8(%rax), %rsi
callq 0x16450
movl %eax, -0xc(%rbp)
cmpl $-0x1, -0xc(%rbp)
jne 0x3d5f
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rcx
addq $0x8, %rcx
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
je 0x3d3b
movq -0x48(%rbp), %rdi
callq 0xa4b0
movq -0x48(%rbp), %rdi
movl $0x80, %esi
callq 0x3350
jmp 0x3c74
movq -0x40(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x80, %esi
callq 0x3350
jmp 0x3e59
cmpl $0x2, -0xc(%rbp)
jne 0x3da8
movq -0x38(%rbp), %rdi
addq $0x20, %rdi
movq -0x20(%rbp), %rsi
addq $0x10, %rsi
addq $0x18, %rsi
callq 0xa4d0
movq -0x38(%rbp), %rdi
movq 0x8(%rdi), %rax
movq %rax, -0x50(%rbp)
addq $0x68, %rdi
movq -0x20(%rbp), %rsi
addq $0x10, %rsi
addq $0x18, %rsi
callq 0xa540
movq -0x50(%rbp), %rcx
movq %rcx, (%rax)
jmp 0x3e04
cmpl $-0x2, -0xc(%rbp)
jne 0x3dc4
movq -0x38(%rbp), %rsi
movq %rsi, %rdi
addq $0x38, %rdi
addq $0x8, %rsi
callq 0xa4d0
jmp 0x3e02
cmpl $0x3, -0xc(%rbp)
jne 0x3de2
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0x182bf(%rip), %rdi     # 0x1c098
movb $0x0, %al
callq 0x3060
jmp 0x3e00
cmpl $0x4, -0xc(%rbp)
jne 0x3dfe
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0x182cb(%rip), %rdi     # 0x1c0c2
movb $0x0, %al
callq 0x3060
jmp 0x3e00
jmp 0x3e02
jmp 0x3e04
jmp 0x3e06
movq -0x38(%rbp), %rax
movq -0x20(%rbp), %rcx
movl 0x10(%rcx), %ecx
addq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, %rax
je 0x3e3e
movq -0x58(%rbp), %rdi
callq 0xa4b0
movq -0x58(%rbp), %rdi
movl $0x80, %esi
callq 0x3350
jmp 0x3c74
leaq 0x185c7(%rip), %rdi     # 0x1c411
movb $0x0, %al
callq 0x3060
xorl %eax, %eax
addq $0x60, %rsp
popq %rbp
retq
movq -0x28(%rbp), %rdi
callq 0x35c0
nopw %cs:(%rax,%rax)