// File: 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
movq %rsp, %rbp
subq $0x180, %rsp            # imm = 0x180
movb %dl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
andb $0x1, %al
movb %al, -0x11(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x148(%rbp)
addq $0x50, %rdi
callq 0xaf20
movq %rax, -0x20(%rbp)
movq $0xf4240, -0x28(%rbp)   # imm = 0xF4240
movq -0x20(%rbp), %rax
movl $0xa, %ecx
xorl %edx, %edx
divq %rcx
movq %rax, -0x30(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x34b0
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x70bc
movq -0x10(%rbp), %rax
movq %rax, -0x158(%rbp)
leaq -0x101(%rbp), %rdi
movq %rdi, -0x150(%rbp)
callq 0x35d0
movq -0x158(%rbp), %rsi
movq -0x150(%rbp), %rdx
leaq -0x100(%rbp), %rdi
callq 0xa400
jmp 0x6da5
leaq 0x20595(%rip), %rax     # 0x27341
movsbl (%rax), %edx
leaq -0xe0(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0xa3b0
jmp 0x6dc4
leaq 0x1559f(%rip), %rdx     # 0x1c36a
leaq -0xc0(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0xa360
jmp 0x6de0
movq -0x148(%rbp), %rdi
addq $0x50, %rdi
movq -0x60(%rbp), %rsi
callq 0xaf90
movq 0xa(%rax), %rsi
movzbl -0x11(%rbp), %edx
andl $0x1, %edx
leaq -0x138(%rbp), %rdi
callq 0x17a40
jmp 0x6e0d
leaq -0xa0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
leaq -0x138(%rbp), %rdx
callq 0xaa80
jmp 0x6e29
leaq 0x1565d(%rip), %rdx     # 0x1c48d
leaq -0x80(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0xa360
jmp 0x6e42
leaq -0x58(%rbp), %rdi
movq %rdi, -0x168(%rbp)
leaq -0x80(%rbp), %rsi
movq %rsi, -0x170(%rbp)
callq 0x3450
movq -0x170(%rbp), %rdi
callq 0x31d0
leaq -0xa0(%rbp), %rdi
callq 0x31d0
leaq -0x138(%rbp), %rdi
callq 0x31d0
leaq -0xc0(%rbp), %rdi
callq 0x31d0
leaq -0xe0(%rbp), %rdi
callq 0x31d0
leaq -0x100(%rbp), %rdi
callq 0x31d0
leaq -0x101(%rbp), %rdi
callq 0x33c0
movq -0x168(%rbp), %rdi
callq 0x3120
movq %rax, %rdi
leaq 0x15c67(%rip), %rsi     # 0x1cb2e
callq 0x3420
movq %rax, -0x160(%rbp)
jmp 0x6ed5
movq -0x160(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
jne 0x6fdf
leaq 0x15490(%rip), %rdi     # 0x1c381
callq 0x32a0
jmp 0x6ef8
movl $0x1, %edi
callq 0x3440
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x110(%rbp)
movl %eax, -0x114(%rbp)
jmp 0x6fb7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x110(%rbp)
movl %eax, -0x114(%rbp)
jmp 0x6fab
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x110(%rbp)
movl %eax, -0x114(%rbp)
jmp 0x6f9f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x110(%rbp)
movl %eax, -0x114(%rbp)
jmp 0x6f93
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x110(%rbp)
movl %eax, -0x114(%rbp)
jmp 0x6f87
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x110(%rbp)
movl %eax, -0x114(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x31d0
leaq -0x138(%rbp), %rdi
callq 0x31d0
leaq -0xc0(%rbp), %rdi
callq 0x31d0
leaq -0xe0(%rbp), %rdi
callq 0x31d0
leaq -0x100(%rbp), %rdi
callq 0x31d0
leaq -0x101(%rbp), %rdi
callq 0x33c0
jmp 0x70e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x110(%rbp)
movl %eax, -0x114(%rbp)
jmp 0x70e0
movq -0x148(%rbp), %rdi
movq -0x38(%rbp), %rsi
movzbl -0x11(%rbp), %edx
andl $0x1, %edx
callq 0x6ba0
jmp 0x6ff8
movq $0x0, -0x140(%rbp)
movq -0x60(%rbp), %rcx
xorl %eax, %eax
cmpq -0x20(%rbp), %rcx
movb %al, -0x171(%rbp)
jae 0x7029
movq -0x140(%rbp), %rax
cmpq -0x28(%rbp), %rax
setb %al
movb %al, -0x171(%rbp)
movb -0x171(%rbp), %al
testb $0x1, %al
jne 0x7035
jmp 0x70ac
movq -0x148(%rbp), %rdi
addq $0x50, %rdi
movq -0x60(%rbp), %rsi
callq 0xaf90
movq %rax, %rdi
movq -0x38(%rbp), %rsi
callq 0x16e80
jmp 0x7057
movq -0x60(%rbp), %rax
cmpq -0x30(%rbp), %rax
jbe 0x7087
leaq 0x1571f(%rip), %rdi     # 0x1c787
xorl %eax, %eax
callq 0x3060
jmp 0x7071
movq -0x20(%rbp), %rax
movl $0xa, %ecx
xorl %edx, %edx
divq %rcx
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x7089
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
movq -0x140(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x140(%rbp)
jmp 0x7003
movq -0x38(%rbp), %rdi
callq 0x3330
jmp 0x70b7
jmp 0x6d5d
leaq 0x1534e(%rip), %rdi     # 0x1c411
xorl %eax, %eax
callq 0x3060
jmp 0x70cc
leaq -0x58(%rbp), %rdi
callq 0x31d0
xorl %eax, %eax
addq $0x180, %rsp            # imm = 0x180
popq %rbp
retq
leaq -0x58(%rbp), %rdi
callq 0x31d0
movq -0x110(%rbp), %rdi
callq 0x35c0
nopw %cs:(%rax,%rax)