// File: /workspace/github_cpp_makefile_star2_O1/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, 0x90(%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 0x6721
movq %rdx, %r12
shrq $0x3, %r12
leaq 0x80(%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 0x8e42
leaq 0xdecf(%rip), %rax      # 0x14281
movsbl (%rax), %r8d
movq 0xc0(%rsp), %rsi
movl $0x1, %ecx
movq %r14, %rdi
xorl %edx, %edx
callq 0x34a0
movq %rbx, 0x70(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x63f3
movq %rdx, 0x70(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x80(%rsp)
jmp 0x63f9
movups (%rcx), %xmm0
movups %xmm0, (%rbx)
leaq 0x40(%rsp), %rbx
movq 0x8(%rax), %rdx
movq %rdx, 0x78(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x70(%rsp), %rdi
leaq 0x8f46(%rip), %rsi      # 0xf368
callq 0x34b0
movq %rbp, 0x10(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x644a
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x6451
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 0x90(%rsp), %rax
movq 0x50(%rax), %rax
imulq $0xca, %r13, %rbp
movq 0xa(%rax,%rbp), %rsi
leaq 0x50(%rsp), %rdi
movl 0xc(%rsp), %edx
callq 0xc977
movq 0x10(%rsp), %rcx
movl $0xf, %esi
leaq 0x20(%rsp), %rax
cmpq %rax, %rcx
je 0x64a8
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %r8
movq 0x58(%rsp), %rdx
leaq (%rdx,%r8), %rax
cmpq %rsi, %rax
jbe 0x64d6
movl $0xf, %esi
leaq 0x60(%rsp), %rdi
cmpq %rdi, 0x50(%rsp)
je 0x64d1
movq 0x60(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x64e7
movq 0x50(%rsp), %rsi
leaq 0x10(%rsp), %rdi
callq 0x30b0
jmp 0x64f5
leaq 0x50(%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 0x6515
movq %rdx, 0x30(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x40(%rsp)
jmp 0x651b
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 0x8f3e(%rip), %rsi      # 0xf482
callq 0x34b0
leaq 0xf8(%rsp), %r14
movq %r14, 0xe8(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x657d
movq %rdx, 0xe8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xf8(%rsp)
jmp 0x6584
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 0x65d1
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x3230
movq 0x30(%rsp), %rdi
cmpq %rbx, %rdi
leaq 0xb8(%rsp), %r14
je 0x65f0
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x3230
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x660c
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x3230
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x6628
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3230
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x664a
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x3230
movq 0xb8(%rsp), %rdi
leaq 0xc8(%rsp), %rax
cmpq %rax, %rdi
je 0x666f
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x3230
movq 0x98(%rsp), %rdi
leaq 0x9325(%rip), %rsi      # 0xf9a3
callq 0x32d0
testq %rax, %rax
je 0x6766
movq %rax, %rbx
movq %rax, %rsi
movl 0xc(%rsp), %edx
callq 0x6158
cmpq %r15, %r13
jae 0x6703
xorl %r14d, %r14d
movq 0x90(%rsp), %rax
movq 0x50(%rax), %rdi
addq %rbp, %rdi
movq %rbx, %rsi
callq 0xc288
leaq (%r14,%r13), %rax
cmpq %r12, %rax
jbe 0x66d5
movl $0x2e, %edi
callq 0x3340
addq 0xe0(%rsp), %r12
leaq 0x1(%r14), %rax
leaq (%r14,%r13), %rcx
incq %rcx
cmpq %r15, %rcx
jae 0x66f8
addq $0xca, %rbp
cmpq $0xf423f, %r14          # imm = 0xF423F
movq %rax, %r14
jb 0x66a3
addq %rax, %r13
leaq 0xb8(%rsp), %r14
movq %rbx, %rdi
callq 0x3210
cmpq %r15, %r13
leaq 0x80(%rsp), %rbx
leaq 0x20(%rsp), %rbp
jb 0x6396
leaq 0x8f08(%rip), %rdi      # 0xf630
callq 0x33e0
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0x6752
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 0x350a
jmp 0x6827
movq %rax, %rbx
jmp 0x67fe
movq %rax, %rbx
jmp 0x67dc
movq %rax, %rbx
jmp 0x67c0
movq %rax, %rbx
jmp 0x67a4
movq %rbx, %rcx
movq %rax, %rbx
movq 0x30(%rsp), %rdi
cmpq %rcx, %rdi
je 0x67a4
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x3230
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x67c0
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x3230
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x67dc
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x3230
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x67fe
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x3230
movq 0xb8(%rsp), %rdi
leaq 0xc8(%rsp), %rax
cmpq %rax, %rdi
je 0x682a
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x3230
jmp 0x682a
jmp 0x6827
movq %rax, %rbx
leaq 0xa8(%rsp), %rax
movq 0x98(%rsp), %rdi
cmpq %rax, %rdi
je 0x684f
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x3230
movq %rbx, %rdi
callq 0x3470
nop