// File: /workspace/github_cpp_makefile_star2_O1/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 0x8e42
leaq 0xb8cc(%rip), %rax      # 0x14281
movsbl (%rax), %r8d
leaq 0x88(%rsp), %rdi
movq 0x8(%rdi), %rsi
movl $0x1, %ecx
xorl %edx, %edx
callq 0x34a0
leaq 0x58(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x89f8
movq %rdx, 0x48(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x58(%rsp)
jmp 0x89ff
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 0x6b89(%rip), %rsi      # 0xf5ab
callq 0x34b0
leaq 0x78(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
movq %r14, %r12
cmpq %rcx, %rdx
je 0x8a51
movq %rdx, 0x68(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x78(%rsp)
jmp 0x8a57
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 0x8a95
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x3230
movq 0x48(%rsp), %rdi
cmpq %r15, %rdi
movq %r12, %rbx
je 0x8aaf
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x3230
leaq 0x98(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8ad0
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x3230
movq 0x18(%rsp), %rdi
leaq 0x6ec7(%rip), %rsi      # 0xf9a3
callq 0x32d0
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x8d81
movq 0x28(%rbx), %r15
movq 0x40(%rbx), %rsi
subq 0x20(%rbx), %r15
sarq $0x3, %r15
subq 0x38(%rbx), %rsi
sarq $0x3, %rsi
leaq 0x65de(%rip), %r12      # 0xf0ec
movq %r12, %rdi
xorl %eax, %eax
callq 0x3040
leaq 0x65eb(%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 0x3360
movq 0x18(%rbx), %rdi
leaq 0x65d1(%rip), %rsi      # 0xf11f
movq %r15, %rdx
xorl %eax, %eax
callq 0x3360
movq 0x20(%rbx), %r12
movq 0x28(%rbx), %r13
cmpq %r13, %r12
je 0x8b92
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 0x9b9d
movq %r12, %rdi
movq %r13, %rsi
callq 0x9c86
movq 0x20(%rbx), %rdi
movq 0x28(%rbx), %rsi
callq 0x9f1b
movq 0x28(%rbx), %rcx
cmpq %rcx, %rax
je 0x8bbe
movq 0x28(%rbx), %rdx
movq %rdx, %rsi
subq %rcx, %rsi
addq %rsi, %rax
cmpq %rax, %rdx
je 0x8bbe
movq %rax, 0x28(%rbx)
movq 0x28(%rbx), %rax
subq 0x20(%rbx), %rax
sarq $0x3, %rax
movq %r15, %rsi
subq %rax, %rsi
je 0x8c3c
leaq 0x6555(%rip), %rdi      # 0xf12e
xorl %eax, %eax
callq 0x3040
movq 0x28(%rbx), %rsi
subq 0x20(%rbx), %rsi
sarq $0x3, %rsi
leaq 0x655a(%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 0x6554(%rip), %rsi      # 0xf168
movq %r15, %rdx
xorl %eax, %eax
callq 0x3360
movq 0x18(%rbx), %rdi
movq 0x28(%rbx), %rdx
subq 0x20(%rbx), %rdx
sarq $0x3, %rdx
leaq 0x654c(%rip), %rsi      # 0xf181
xorl %eax, %eax
callq 0x3360
movzbl %bpl, %edx
movq 0x10(%rsp), %rsi
callq 0x8726
leaq 0x6986(%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, %rdi
movq 0x10(%rbx), %rsi
movq %rax, 0x8(%rsp)
callq 0xbb00
movq 0x20(%rbx), %r12
movq 0x28(%rbx), %r14
cmpq %r14, %r12
je 0x8d0a
movq %rbx, %r15
shrq $0x3, %rbp
addq $0x68, %r15
movl $0x1, %ebx
xorl %r13d, %r13d
movq %rbp, 0x40(%rsp)
movq -0x8(%r12,%rbx,8), %rax
movq %rax, 0x68(%rsp)
movq %r15, %rdi
leaq 0x68(%rsp), %rsi
callq 0x8e80
movq (%rax), %rdx
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0xc066
cmpq %rbp, %rbx
jb 0x8cf6
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 0x8cb9
leaq 0x691f(%rip), %rdi      # 0xf630
callq 0x33e0
movq 0x8(%rsp), %rax
movq 0x60(%rax), %rdi
movq 0x38(%rsp), %rax
addq $0x70, %rax
cmpq %rax, %rdi
je 0x8d38
movq (%rax), %rsi
incq %rsi
callq 0x3230
movl $0x80, %esi
movq 0x8(%rsp), %rdi
callq 0x3230
movq 0x10(%rsp), %rdi
callq 0x3210
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x8d6d
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 0x3549
movq %rax, %rbx
movl $0x80, %esi
movq 0x8(%rsp), %rdi
jmp 0x8dd4
jmp 0x8ddf
jmp 0x8ddf
movq %rax, %rbx
movq 0x48(%rsp), %rdi
cmpq %r15, %rdi
je 0x8db8
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x3230
jmp 0x8db8
movq %rax, %rbx
leaq 0x98(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8de2
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x3230
jmp 0x8de2
jmp 0x8ddf
jmp 0x8ddf
movq %rax, %rbx
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x8dfe
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x3230
movq %rbx, %rdi
callq 0x3470