// File: tomfunkhouser[P]gaps/apps/img2pd/img2pd.cpp
// Function: main
int main(int argc, char **argv)
{
  // Parse program arguments
  if (!ParseArgs(argc, argv)) exit(-1);

  // Print message
  RNTime start_time;
  start_time.Read();
  if (print_verbose) {
    printf("Adding images to %s\n", output_pixel_database_filename);
    fflush(stdout);
  }

  // Allocate pixel database
  R2PixelDatabase pd;
    
  // Open pixel database for writing
  if (!pd.OpenFile(output_pixel_database_filename, "w+")) {
    RNFail("Unable to open initial pixel database %s\n", output_pixel_database_filename);
    exit(-1);
  }

  // Add images to pixel database
  for (int i = 0; i < input_image_filenames.NEntries(); i++) {
    const char *image_filename = input_image_filenames.Kth(i);
    if (!AddImageToPixelDatabase(pd, image_filename)) exit(-1);
  }
  
  // Add lists of images to pixel database
  for (int i = 0; i < input_list_filenames.NEntries(); i++) {
    const char *list_filename = input_list_filenames.Kth(i);
    if (!AddListToPixelDatabase(pd, list_filename)) exit(-1);
  }
  
  // Add directories of images to pixel database
  for (int i = 0; i < input_image_directories.NEntries(); i++) {
    const char *image_directory = input_image_directories.Kth(i);
    if (!AddDirectoryToPixelDatabase(pd, image_directory)) exit(-1);
  }

  // Close pixel database
  if (!pd.CloseFile()) {
    RNFail("Unable to close initial pixel database %s\n", output_pixel_database_filename);
    exit(-1);
  }

  // Print message
  if (print_verbose) {
    printf("  Time = %.2f\n", start_time.Elapsed());
    printf("  # Images = %d\n", image_count);
    fflush(stdout);
  }

  // Return success
  return 0;
}

// Assembly:
subq $0x118, %rsp            # imm = 0x118
movl $0x0, 0x114(%rsp)
movl %edi, 0x110(%rsp)
movq %rsi, 0x108(%rsp)
movl 0x110(%rsp), %edi
movq 0x108(%rsp), %rsi
callq 0x6a80
cmpl $0x0, %eax
jne 0x6734
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x5470
leaq 0xf8(%rsp), %rdi
callq 0x3dca0
leaq 0xf8(%rsp), %rdi
callq 0x71b0
cmpl $0x0, 0xb8d43(%rip)     # 0xbf498
je 0x677b
movq 0xb8d42(%rip), %rsi     # 0xbf4a0
leaq 0x9989f(%rip), %rdi     # 0xa0004
movb $0x0, %al
callq 0x5060
movq 0xb883d(%rip), %rax     # 0xbefb0
movq (%rax), %rdi
callq 0x5440
leaq 0x98(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x72d0
movq 0x50(%rsp), %rdi
movq 0xb8d07(%rip), %rsi     # 0xbf4a0
leaq 0x99879(%rip), %rdx     # 0xa0019
callq 0x8440
movl %eax, 0x5c(%rsp)
jmp 0x67ab
movl 0x5c(%rsp), %eax
cmpl $0x0, %eax
jne 0x67fb
movq 0xb8ce5(%rip), %rsi     # 0xbf4a0
leaq 0x9985a(%rip), %rdi     # 0xa001c
xorl %eax, %eax
callq 0x424c0
jmp 0x67cb
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x5470
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x90(%rsp)
movl %eax, 0x8c(%rsp)
leaq 0x98(%rsp), %rdi
callq 0x7450
jmp 0x6a73
movl $0x0, 0x88(%rsp)
movl 0x88(%rsp), %eax
movl %eax, 0x48(%rsp)
leaq 0xb8c50(%rip), %rdi     # 0xbf468
callq 0x71d0
movl %eax, 0x4c(%rsp)
jmp 0x6823
movl 0x48(%rsp), %eax
movl 0x4c(%rsp), %ecx
cmpl %ecx, %eax
jge 0x689c
movl 0x88(%rsp), %esi
leaq 0xb8c2b(%rip), %rdi     # 0xbf468
callq 0x71e0
movq %rax, 0x40(%rsp)
jmp 0x6849
movq 0x40(%rsp), %rax
movq %rax, 0x80(%rsp)
movq 0x80(%rsp), %rsi
leaq 0x98(%rsp), %rdi
callq 0x6e90
movl %eax, 0x3c(%rsp)
jmp 0x6871
movl 0x3c(%rsp), %eax
cmpl $0x0, %eax
jne 0x6884
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x5470
jmp 0x6886
movl 0x88(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x88(%rsp)
jmp 0x6806
movl $0x0, 0x7c(%rsp)
movl 0x7c(%rsp), %eax
movl %eax, 0x34(%rsp)
leaq 0xb8bc5(%rip), %rdi     # 0xbf478
callq 0x71d0
movl %eax, 0x38(%rsp)
jmp 0x68be
movl 0x34(%rsp), %eax
movl 0x38(%rsp), %ecx
cmpl %ecx, %eax
jge 0x6928
movl 0x7c(%rsp), %esi
leaq 0xb8ba3(%rip), %rdi     # 0xbf478
callq 0x71e0
movq %rax, 0x28(%rsp)
jmp 0x68e1
movq 0x28(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x70(%rsp), %rsi
leaq 0x98(%rsp), %rdi
callq 0x6f90
movl %eax, 0x24(%rsp)
jmp 0x6903
movl 0x24(%rsp), %eax
cmpl $0x0, %eax
jne 0x6916
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x5470
jmp 0x6918
movl 0x7c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x7c(%rsp)
jmp 0x68a4
movl $0x0, 0x6c(%rsp)
movl 0x6c(%rsp), %eax
movl %eax, 0x1c(%rsp)
leaq 0xb8b49(%rip), %rdi     # 0xbf488
callq 0x71d0
movl %eax, 0x20(%rsp)
jmp 0x694a
movl 0x1c(%rsp), %eax
movl 0x20(%rsp), %ecx
cmpl %ecx, %eax
jge 0x69b4
movl 0x6c(%rsp), %esi
leaq 0xb8b27(%rip), %rdi     # 0xbf488
callq 0x71e0
movq %rax, 0x10(%rsp)
jmp 0x696d
movq 0x10(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x60(%rsp), %rsi
leaq 0x98(%rsp), %rdi
callq 0x7060
movl %eax, 0xc(%rsp)
jmp 0x698f
movl 0xc(%rsp), %eax
cmpl $0x0, %eax
jne 0x69a2
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x5470
jmp 0x69a4
movl 0x6c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x6c(%rsp)
jmp 0x6930
leaq 0x98(%rsp), %rdi
callq 0x8620
movl %eax, 0x8(%rsp)
jmp 0x69c7
movl 0x8(%rsp), %eax
cmpl $0x0, %eax
jne 0x69f1
movq 0xb8ac9(%rip), %rsi     # 0xbf4a0
leaq 0x99668(%rip), %rdi     # 0xa0046
xorl %eax, %eax
callq 0x424c0
jmp 0x69e7
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x5470
cmpl $0x0, 0xb8aa0(%rip)     # 0xbf498
je 0x6a4c
leaq 0xf8(%rsp), %rdi
callq 0x3dd60
movsd %xmm0, (%rsp)
jmp 0x6a0e
movsd (%rsp), %xmm0
leaq 0x99657(%rip), %rdi     # 0xa0071
movb $0x1, %al
callq 0x5060
jmp 0x6a23
movl 0xb8a7f(%rip), %esi     # 0xbf4a8
leaq 0x99650(%rip), %rdi     # 0xa0080
xorl %eax, %eax
callq 0x5060
jmp 0x6a39
movq 0xb8570(%rip), %rax     # 0xbefb0
movq (%rax), %rdi
callq 0x5440
jmp 0x6a4a
jmp 0x6a4c
movl $0x0, 0x114(%rsp)
leaq 0x98(%rsp), %rdi
callq 0x7450
movl 0x114(%rsp), %eax
addq $0x118, %rsp            # imm = 0x118
retq
movq 0x90(%rsp), %rdi
callq 0x5690