// File: /workspace/github_c_makefile_star2_O3/moefh[P]hed/src/main.c
// Function: main
int main(int argc, char **argv)
{
  const char *filename = NULL;
  bool view_mode = false;
  unsigned long offset = 0;

  for (int i = 1; i < argc; i++) {
    if (argv[i][0] == '+') {
      char *end = NULL;
      errno = 0;
      offset = strtoul(argv[i] + 1, &end, 0);
      if (errno != 0 || *end != '\0') {
        fprintf(stderr, "%s: invalid offset: %s\n", argv[0], argv[i] + 1);
        exit(1);
      }
    } else if (argv[i][0] == '-') {
      switch (argv[i][1]) {
      case 'V': print_version(); exit(0);
      case 'h': print_help(argv[0]); exit(0);
      case 'v': view_mode = true; break;
      case '\0': filename = argv[i]; break;
      default:
        fprintf(stderr, "%s: unknown option '%s'\n", argv[0], argv[i]);
        exit(1);
      }
    } else {
      if (filename) {
        fprintf(stderr, "%s: too many files given\n", argv[0]);
        exit(1);
      }
      filename = argv[i];
    }
  }

  struct hed_editor editor;
  hed_init_editor(&editor);
  if (view_mode)
    editor.read_only = true;

  if (filename) {
    struct hed_file *file;
    if (strcmp(filename, "-") == 0) {
      size_t data_len = 0;
      uint8_t *data = read_stdin(&data_len);
      if (! data)
        exit(1);
      file = hed_new_file_from_data(data, data_len);
    } else
      file = hed_read_file(argv[1]);
    if (! file)
      exit(1);
    hed_add_file(&editor, file);
  }
  
  return hed_run_editor(&editor, offset);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1648, %rsp           # imm = 0x1648
cmpl $0x1, %edi
jle 0x25d0
movq %rsi, %r14
movl %edi, %ebx
movl $0x1, %r15d
xorl %r12d, %r12d
xorl %eax, %eax
movq $0x0, 0x8(%rsp)
movq (%r14,%r15,8), %r13
movzbl (%r13), %ecx
cmpl $0x2d, %ecx
je 0x253d
cmpl $0x2b, %ecx
jne 0x2554
movq $0x0, 0x640(%rsp)
callq 0x2040
movq %rax, %rbp
movl $0x0, (%rax)
incq %r13
movq %r13, %rdi
leaq 0x640(%rsp), %rsi
xorl %edx, %edx
callq 0x2260
cmpl $0x0, (%rbp)
jne 0x26cb
movq 0x640(%rsp), %rcx
cmpb $0x0, (%rcx)
je 0x2571
jmp 0x26cb
movzbl 0x1(%r13), %ecx
cmpl $0x67, %ecx
jg 0x2561
testl %ecx, %ecx
jne 0x26ed
movq %r13, %r12
jmp 0x2571
testq %r12, %r12
movq %r13, %r12
je 0x2571
jmp 0x26d6
movb $0x1, %dl
movq %rdx, 0x8(%rsp)
cmpl $0x76, %ecx
jne 0x26de
incq %r15
cmpq %r15, %rbx
jne 0x24df
movq %rax, (%rsp)
leaq 0x10(%rsp), %rdi
callq 0x4200
testb $0x1, 0x8(%rsp)
je 0x2597
movb $0x1, 0x12(%rsp)
testq %r12, %r12
je 0x25ca
cmpb $0x2d, (%r12)
jne 0x25ab
cmpb $0x0, 0x1(%r12)
je 0x25f8
movq 0x8(%r14), %rdi
callq 0x3289
testq %rax, %rax
je 0x26c1
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x4220
movq (%rsp), %rsi
jmp 0x25dc
leaq 0x10(%rsp), %rdi
callq 0x4200
xorl %esi, %esi
leaq 0x10(%rsp), %rdi
callq 0x4428
addq $0x1648, %rsp           # imm = 0x1648
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x79d9(%rip), %rax      # 0x9fd8
movq (%rax), %rcx
leaq 0x640(%rsp), %rdi
movl $0x1, %esi
movl $0x1000, %edx           # imm = 0x1000
callq 0x2090
testq %rax, %rax
je 0x26c1
movq %rax, %r12
xorl %r14d, %r14d
movl $0x4000, %ebx           # imm = 0x4000
xorl %r15d, %r15d
xorl %r13d, %r13d
leaq (%r15,%r12), %rbp
cmpq %r14, %rbp
jbe 0x265f
testq %r14, %r14
leaq (%r14,%r14), %r14
cmoveq %rbx, %r14
cmpq %r14, %rbp
ja 0x263c
movq %r13, %rdi
movq %r14, %rsi
callq 0x2200
movq %rax, %r13
testq %rax, %rax
je 0x26b4
addq %r13, %r15
movq %r15, %rdi
leaq 0x640(%rsp), %r15
movq %r15, %rsi
movq %r12, %rdx
callq 0x21b0
movq 0x7959(%rip), %rax      # 0x9fd8
movq (%rax), %rcx
movl $0x1, %esi
movl $0x1000, %edx           # imm = 0x1000
movq %r15, %rdi
callq 0x2090
movq %rax, %r12
movq %rbp, %r15
testq %rax, %rax
jne 0x2633
testq %r13, %r13
je 0x26c1
movq %r13, %rdi
movq %rbp, %rsi
callq 0x321c
jmp 0x25b4
leaq 0x640(%rsp), %rdi
callq 0x233f
movl $0x1, %edi
callq 0x2290
movq %r14, %rdi
movq %r15, %rsi
callq 0x22ea
movq %r14, %rdi
callq 0x2318
cmpl $0x68, %ecx
jne 0x26fe
movq (%r14), %rdi
callq 0x273b
jmp 0x26f7
cmpl $0x56, %ecx
jne 0x26fe
callq 0x2709
xorl %edi, %edi
callq 0x2290
movq %r14, %rdi
movq %r13, %rsi
callq 0x22c0