// File: /workspace/github_cpp_makefile_star2_O3/4n6ist[P]usn_analytics/lib/usnjrnl.cpp
// Function: UsnJrnl::WriteAllRecords(char*, bool)
int UsnJrnl::WriteAllRecords(char *odname, bool lt) {

  FILE *fp_ofraw;
  string ofraw;
  ofraw = string(odname) + SEP + "usn_parse_all.csv";

  if((fp_ofraw = fopen(ofraw.c_str(), "w")) == NULL) {
    perror("Output All Raw File Error");
    exit(EXIT_FAILURE);
  } 

  uint64_t usn_num = usn_set.size();
  printf("%8lu corrupt records skipped\n", corrupt_offset_set.size());
  printf("%8llu records found\n", usn_num);
  fprintf(fp_ofreport, "%8lu corrupt records skipped\n", corrupt_offset_set.size());
  fprintf(fp_ofreport, "%8llu records\n", usn_num);   

  // USN Sort & Deduplication
  sort(usn_set.begin(), usn_set.end());
  usn_set.erase(std::unique(usn_set.begin(), usn_set.end()), usn_set.end());
  if (usn_num != usn_set.size()) {
    printf("%8llu duplicate records found\n", usn_num - usn_set.size()); 
    printf("%8lu unique records found\n", usn_set.size()); 
    fprintf(fp_ofreport, "%8llu duplicate records\n", usn_num - usn_set.size()); 
    fprintf(fp_ofreport, "%8lu unique records\n", usn_set.size()); 
  }

  WriteAllHeader(fp_ofraw, lt);
  printf("Write all records");

  uint64_t usn_set_size = usn_set.size();
  uint64_t i=1;
  uint64_t progress = usn_set_size / 10;

  UsnRecord* ur = 0;
  ur = new UsnRecord(fp_in);

  for(uint64_t x: usn_set) {
    ur->ReadParseWriteRecord(fp_ofraw, usn_table[x]);
    if (i >= progress) {
  	  printf(".");
      progress += usn_set_size / 10;
    }
    ++i;
  }
  
  printf("Done\n");
  delete ur;
  fclose(fp_ofraw);
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movl %edx, %ebp
movq %rdi, %r14
leaq 0x28(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x88(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x8e9c
leaq 0xb88c(%rip), %rax      # 0x14279
movsbl (%rax), %r8d
leaq 0x88(%rsp), %rdi
movq 0x8(%rdi), %rsi
movl $0x1, %ecx
xorl %edx, %edx
callq 0x3490
leaq 0x58(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x8a30
movq %rdx, 0x48(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x58(%rsp)
jmp 0x8a37
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq 0x8(%rax), %rdx
leaq 0x48(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x6b51(%rip), %rsi      # 0xf5ab
callq 0x34a0
leaq 0x78(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
movq %r14, 0x8(%rsp)
je 0x8a8b
movq %rdx, 0x68(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x78(%rsp)
jmp 0x8a91
movups (%rcx), %xmm0
movups %xmm0, (%rbx)
movq 0x8(%rax), %rdx
leaq 0x68(%rsp), %r14
movq %rdx, 0x8(%r14)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x18(%rsp), %rdi
movq %r14, %rsi
callq 0x3300
movq (%r14), %rdi
cmpq %rbx, %rdi
je 0x8acf
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x3230
movq 0x48(%rsp), %rdi
cmpq %r15, %rdi
movq 0x8(%rsp), %rbx
je 0x8aeb
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x3230
leaq 0x98(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8b0c
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x3230
movq 0x18(%rsp), %rdi
leaq 0x6e8a(%rip), %rsi      # 0xf9a2
callq 0x32d0
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x8de0
movq 0x28(%rbx), %r15
movq 0x40(%rbx), %rsi
subq 0x20(%rbx), %r15
sarq $0x3, %r15
subq 0x38(%rbx), %rsi
sarq $0x3, %rsi
leaq 0x65a2(%rip), %r12      # 0xf0ec
movq %r12, %rdi
xorl %eax, %eax
callq 0x3040
leaq 0x65af(%rip), %rdi      # 0xf10a
movq %r15, %rsi
xorl %eax, %eax
callq 0x3040
movq 0x18(%rbx), %rdi
movq 0x40(%rbx), %rdx
subq 0x38(%rbx), %rdx
sarq $0x3, %rdx
movq %r12, %rsi
xorl %eax, %eax
callq 0x3350
movq 0x18(%rbx), %rdi
leaq 0x6595(%rip), %rsi      # 0xf11f
movq %r15, %rdx
xorl %eax, %eax
callq 0x3350
movq 0x20(%rbx), %r12
movq 0x28(%rbx), %r13
cmpq %r13, %r12
je 0x8c17
movq %r13, %rax
subq %r12, %rax
sarq $0x3, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r12, %rdi
movq %r13, %rsi
callq 0x9c04
movq %r12, %rdi
movq %r13, %rsi
callq 0x9ced
movq 0x20(%rbx), %r12
movq 0x28(%rbx), %rax
cmpq %rax, %r12
je 0x8c2c
leaq 0x8(%r12), %rcx
cmpq %rax, %rcx
je 0x8c2c
movq -0x8(%rcx), %rdx
leaq 0x8(%rcx), %rsi
cmpq (%rcx), %rdx
movq %rsi, %rcx
jne 0x8be0
leaq -0x10(%rsi), %rcx
cmpq %rax, %rsi
je 0x8c1c
movq %rdx, %rdi
movq (%rsi), %rdx
cmpq %rdx, %rdi
je 0x8c11
movq %rdx, 0x8(%rcx)
addq $0x8, %rcx
addq $0x8, %rsi
jmp 0x8bf9
movq %r12, %rax
jmp 0x8c2c
addq $0x8, %rcx
cmpq %rax, %rcx
je 0x8c2c
movq %rcx, 0x28(%rbx)
movq %rcx, %rax
subq %r12, %rax
sarq $0x3, %rax
movq %r15, %rsi
subq %rax, %rsi
je 0x8ca5
leaq 0x64ec(%rip), %rdi      # 0xf12e
xorl %eax, %eax
callq 0x3040
movq 0x28(%rbx), %rsi
subq 0x20(%rbx), %rsi
sarq $0x3, %rsi
leaq 0x64f1(%rip), %rdi      # 0xf14d
xorl %eax, %eax
callq 0x3040
movq 0x18(%rbx), %rdi
movq 0x28(%rbx), %rax
subq 0x20(%rbx), %rax
sarq $0x3, %rax
subq %rax, %r15
leaq 0x64eb(%rip), %rsi      # 0xf168
movq %r15, %rdx
xorl %eax, %eax
callq 0x3350
movq 0x18(%rbx), %rdi
movq 0x28(%rbx), %rdx
subq 0x20(%rbx), %rdx
sarq $0x3, %rdx
leaq 0x64e3(%rip), %rsi      # 0xf181
xorl %eax, %eax
callq 0x3350
movzbl %bpl, %edx
movq 0x10(%rsp), %rsi
callq 0x875e
leaq 0x691d(%rip), %rdi      # 0xf5d7
xorl %eax, %eax
callq 0x3040
movq 0x28(%rbx), %rax
subq 0x20(%rbx), %rax
sarq $0x3, %rax
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
mulq %rcx
movq %rdx, %rbp
movl $0x80, %edi
callq 0x3220
movq %rax, 0x38(%rsp)
movq %rax, %r15
movq 0x10(%rbx), %rsi
movq %rax, %rdi
callq 0xbb04
movq 0x20(%rbx), %r12
movq 0x28(%rbx), %r14
cmpq %r14, %r12
je 0x8d70
shrq $0x3, %rbp
addq $0x68, 0x8(%rsp)
movl $0x1, %ebx
xorl %r13d, %r13d
movq %rbp, 0x40(%rsp)
movq -0x8(%r12,%rbx,8), %rax
movq %rax, 0x68(%rsp)
movq 0x8(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x8eda
movq (%rax), %rdx
movq %r15, %rdi
movq 0x10(%rsp), %rsi
callq 0xc06a
cmpq %rbp, %rbx
jb 0x8d5c
movl $0x2e, %edi
callq 0x3340
addq 0x40(%rsp), %rbp
incq %rbx
leaq (%r12,%r13), %rax
addq $0x8, %rax
addq $0x8, %r13
cmpq %r14, %rax
jne 0x8d1f
leaq 0x68b9(%rip), %rdi      # 0xf630
callq 0x33d0
movq 0x60(%r15), %rdi
movq 0x38(%rsp), %rax
addq $0x70, %rax
cmpq %rax, %rdi
je 0x8d99
movq (%rax), %rsi
incq %rsi
callq 0x3230
movl $0x80, %esi
movq %r15, %rdi
callq 0x3230
movq 0x10(%rsp), %rdi
callq 0x3210
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x8dcc
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x3230
xorl %eax, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3539
movq %rax, %rbx
movl $0x80, %esi
movq %r15, %rdi
jmp 0x8e2f
jmp 0x8e3a
movq %rax, %rbx
movq 0x48(%rsp), %rdi
cmpq %r15, %rdi
je 0x8e13
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x3230
jmp 0x8e13
movq %rax, %rbx
leaq 0x98(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8e3d
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x3230
jmp 0x8e3d
jmp 0x8e3a
jmp 0x8e3a
movq %rax, %rbx
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x8e59
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x3230
movq %rbx, %rdi
callq 0x3460