// File: /workspace/github_cpp_makefile_star2_O3/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, 0xd8(%rsp)
movq 0x58(%rdi), %rsi
movq %rdi, 0x70(%rsp)
movq 0x50(%rdi), %rdi
movq %rsi, %rax
subq %rdi, %rax
sarq %rax
movabsq $0x3a4c0a237c32b16d, %r15 # imm = 0x3A4C0A237C32B16D
imulq %rax, %r15
movabsq $-0x3333333333333333, %rdx # imm = 0xCCCCCCCCCCCCCCCD
movq %r15, %rax
mulq %rdx
leaq 0xa8(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
cmpq %rdi, %rsi
je 0x6718
movq %rdx, %r12
shrq $0x3, %r12
leaq 0x60(%rsp), %rbx
leaq 0x20(%rsp), %rbp
xorl %r13d, %r13d
leaq 0xb8(%rsp), %r14
movzbl %cl, %eax
movl %eax, 0xc(%rsp)
movq %r12, 0xe0(%rsp)
movq %r14, %rdi
movq 0xd8(%rsp), %rsi
leaq 0xb(%rsp), %rdx
callq 0x8e9c
leaq 0xdecb(%rip), %rax      # 0x14279
movsbl (%rax), %r8d
movq 0xc0(%rsp), %rsi
movl $0x1, %ecx
movq %r14, %rdi
xorl %edx, %edx
callq 0x3490
movq %rbx, 0x50(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x63ec
movq %rdx, 0x50(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x60(%rsp)
jmp 0x63f2
movups (%rcx), %xmm0
movups %xmm0, (%rbx)
leaq 0x40(%rsp), %rbx
movq 0x8(%rax), %rdx
movq %rdx, 0x58(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x50(%rsp), %rdi
leaq 0x8f4d(%rip), %rsi      # 0xf368
callq 0x34a0
movq %rbp, 0x10(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x6443
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x644a
movups (%rcx), %xmm0
movups %xmm0, (%rbp)
movq 0x8(%rax), %rdx
movq %rdx, 0x18(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x70(%rsp), %rax
movq 0x50(%rax), %rax
imulq $0xca, %r13, %rbp
movq 0xa(%rax,%rbp), %rsi
leaq 0x78(%rsp), %rdi
movl 0xc(%rsp), %edx
callq 0xc945
movq 0x10(%rsp), %rcx
movl $0xf, %edi
leaq 0x20(%rsp), %rax
cmpq %rax, %rcx
je 0x649e
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %r8
movq 0x78(%rsp), %rsi
movq 0x80(%rsp), %rdx
leaq (%rdx,%r8), %rax
cmpq %rdi, %rax
jbe 0x64d8
movl $0xf, %edi
leaq 0x88(%rsp), %r9
cmpq %r9, %rsi
je 0x64d3
movq 0x88(%rsp), %rdi
cmpq %rdi, %rax
jbe 0x64e4
leaq 0x10(%rsp), %rdi
callq 0x30b0
jmp 0x64f2
leaq 0x78(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3290
movq %rbx, 0x30(%rsp)
movq (%rax), %rdx
leaq 0x10(%rax), %rcx
cmpq %rcx, %rdx
je 0x6512
movq %rdx, 0x30(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x40(%rsp)
jmp 0x6518
movups (%rcx), %xmm0
movups %xmm0, (%rbx)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x38(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
leaq 0x30(%rsp), %rdi
leaq 0x8f41(%rip), %rsi      # 0xf482
callq 0x34a0
leaq 0xf8(%rsp), %r14
movq %r14, 0xe8(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x657a
movq %rdx, 0xe8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xf8(%rsp)
jmp 0x6581
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq 0x8(%rax), %rdx
movq %rdx, 0xf0(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x98(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x3300
movq 0xe8(%rsp), %rdi
cmpq %r14, %rdi
je 0x65ce
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x3230
movq 0x30(%rsp), %rdi
cmpq %rbx, %rdi
leaq 0xb8(%rsp), %r14
je 0x65ed
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x3230
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x660f
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x3230
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x662b
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3230
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x6647
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x3230
movq 0xb8(%rsp), %rdi
leaq 0xc8(%rsp), %rax
cmpq %rax, %rdi
je 0x666c
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x3230
movq 0x98(%rsp), %rdi
leaq 0x9327(%rip), %rsi      # 0xf9a2
callq 0x32d0
testq %rax, %rax
je 0x675d
movq %rax, %rbx
movq %rax, %rsi
movl 0xc(%rsp), %edx
callq 0x615a
cmpq %r15, %r13
jae 0x66fd
xorl %r14d, %r14d
movq 0x70(%rsp), %rax
movq 0x50(%rax), %rdi
addq %rbp, %rdi
movq %rbx, %rsi
callq 0xc28c
leaq (%r14,%r13), %rax
cmpq %r12, %rax
jbe 0x66cf
movl $0x2e, %edi
callq 0x3340
addq 0xe0(%rsp), %r12
leaq 0x1(%r14), %rax
leaq (%r14,%r13), %rcx
incq %rcx
cmpq %r15, %rcx
jae 0x66f2
addq $0xca, %rbp
cmpq $0xf423f, %r14          # imm = 0xF423F
movq %rax, %r14
jb 0x66a0
addq %rax, %r13
leaq 0xb8(%rsp), %r14
movq %rbx, %rdi
callq 0x3210
cmpq %r15, %r13
leaq 0x60(%rsp), %rbx
leaq 0x20(%rsp), %rbp
jb 0x6392
leaq 0x8f11(%rip), %rdi      # 0xf630
callq 0x33d0
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0x6749
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x3230
xorl %eax, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x34fa
jmp 0x681e
movq %rax, %rbx
jmp 0x67f5
movq %rax, %rbx
jmp 0x67d9
movq %rax, %rbx
jmp 0x67bd
movq %rax, %rbx
jmp 0x679b
movq %rbx, %rcx
movq %rax, %rbx
movq 0x30(%rsp), %rdi
cmpq %rcx, %rdi
je 0x679b
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x3230
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x67bd
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x3230
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x67d9
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3230
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x67f5
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x3230
movq 0xb8(%rsp), %rdi
leaq 0xc8(%rsp), %rax
cmpq %rax, %rdi
je 0x6821
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x3230
jmp 0x6821
jmp 0x681e
movq %rax, %rbx
leaq 0xa8(%rsp), %rax
movq 0x98(%rsp), %rdi
cmpq %rax, %rdi
je 0x6846
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x3230
movq %rbx, %rdi
callq 0x3460