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

  uint64_t usnmain_set_size = usnmain_set.size();
  uint64_t split_size = 1000000;
  uint64_t progress = usnmain_set_size / 10;

  FILE *fp_ofmain;
  string ofmain;
  
  for(uint64_t i=0; i < usnmain_set_size;) {

    ofmain = string(odname) + SEP + "usn_analytics_records-" + parse_datetime_iso8601(usnmain_set[i].timestamp_i, lt) + ".csv";

    if((fp_ofmain = fopen(ofmain.c_str(), "w")) == NULL) {
      perror("Output Records File Error");
      exit(EXIT_FAILURE);
    }
    WriteBundledHeader(fp_ofmain, lt);
    for(uint64_t j=0; i < usnmain_set_size && j < split_size; i++, j++) {    
      usnmain_set[i].WriteBundledRecord(fp_ofmain);
      if (i > progress) {
        printf(".");
        progress += usnmain_set_size / 10;
      }
    }
    fclose(fp_ofmain);

  }
  
  printf("Done\n");
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movl %edx, %ecx
movq %rsi, 0x18(%rsp)
movq 0x58(%rdi), %rax
movq %rdi, 0x8(%rsp)
subq 0x50(%rdi), %rax
movl $0xca, %esi
cqto
idivq %rsi
xorl %r15d, %r15d
pushq $0xa
popq %rsi
movq %rax, 0x10(%rsp)
xorl %edx, %edx
divq %rsi
movq %rax, %r12
leaq 0x38(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x48(%rsp), %r14
leaq 0x68(%rsp), %r13
leaq 0xa8(%rsp), %rbx
movzbl %cl, %eax
movl %eax, 0x4(%rsp)
movq %r12, 0x20(%rsp)
cmpq 0x10(%rsp), %r15
jae 0x54e7
movq %r14, %rdi
movq 0x18(%rsp), %rsi
leaq 0x3(%rsp), %rdx
callq 0x7072
leaq 0xcf08(%rip), %rax      # 0x12299
movsbl (%rax), %edx
movq %r13, %rdi
movq %r14, %rsi
callq 0x7050
movq %rbx, %rbp
movq %rbx, %rdi
movq %r13, %rsi
leaq 0x6fb9(%rip), %rdx      # 0xc368
callq 0x7031
movq 0x8(%rsp), %rax
movq 0x50(%rax), %rax
imulq $0xca, %r15, %rbx
movq 0xa(%rax,%rbx), %rsi
leaq 0x88(%rsp), %r14
movq %r14, %rdi
movl 0x4(%rsp), %edx
callq 0xa7cb
leaq 0xc8(%rsp), %r13
movq %r13, %rdi
movq %rbp, %rsi
movq %r14, %rdx
callq 0x71b8
leaq 0xe8(%rsp), %r14
movq %r14, %rdi
movq %r13, %rsi
leaq 0x707a(%rip), %rdx      # 0xc482
callq 0x7031
leaq 0x28(%rsp), %rdi
movq %r14, %rsi
callq 0x3320
movq %r14, %rdi
callq 0x3100
movq %r13, %rdi
callq 0x3100
leaq 0x88(%rsp), %rdi
callq 0x3100
movq %rbp, %rdi
callq 0x3100
leaq 0x68(%rsp), %rdi
callq 0x3100
leaq 0x48(%rsp), %rdi
callq 0x3100
movq 0x28(%rsp), %rdi
leaq 0x7543(%rip), %rsi      # 0xc9a2
callq 0x32f0
testq %rax, %rax
je 0x5511
movq %rax, %rbp
movq %rax, %rsi
movl 0x4(%rsp), %edx
callq 0x5198
xorl %r14d, %r14d
leaq (%r15,%r14), %r13
cmpq 0x10(%rsp), %r13
jae 0x54c5
cmpq $0xf4240, %r14          # imm = 0xF4240
jae 0x54c5
movq 0x8(%rsp), %rax
movq 0x50(%rax), %rdi
addq %rbx, %rdi
movq %rbp, %rsi
callq 0xa14c
cmpq %r12, %r13
jbe 0x54b9
pushq $0x2e
popq %rdi
callq 0x3370
addq 0x20(%rsp), %r12
incq %r14
addq $0xca, %rbx
jmp 0x547f
movq %rbp, %rdi
callq 0x3250
movq %r13, %r15
leaq 0x48(%rsp), %r14
leaq 0x68(%rsp), %r13
leaq 0xa8(%rsp), %rbx
jmp 0x536d
leaq 0x7142(%rip), %rdi      # 0xc630
callq 0x33f0
leaq 0x28(%rsp), %rdi
callq 0x3100
xorl %eax, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6e67(%rip), %rdi      # 0xc37f
callq 0x31f0
pushq $0x1
popq %rdi
callq 0x3310
movq %rax, %rbx
jmp 0x553f
movq %rax, %rbx
jmp 0x554c
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0x3100
leaq 0x88(%rsp), %rdi
callq 0x3100
leaq 0xa8(%rsp), %rdi
callq 0x3100
jmp 0x5560
jmp 0x557d
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x3100
jmp 0x5571
jmp 0x557d
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x3100
jmp 0x5580
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x3100
movq %rbx, %rdi
callq 0x3480