// File: /workspace/github_c_makefile_star2_O1/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
movq %rsi, %r14
cmpl $0x2, %edi
jl 0x2587
movl %edi, %ebx
movl $0x1, %r12d
xorl %r15d, %r15d
xorl %eax, %eax
movq $0x0, 0x8(%rsp)
movq (%r14,%r12,8), %rbp
movzbl (%rbp), %ecx
cmpl $0x2d, %ecx
je 0x253d
cmpl $0x2b, %ecx
jne 0x2553
movq $0x0, 0x640(%rsp)
callq 0x2040
movq %rax, %r13
movl $0x0, (%rax)
incq %rbp
movq %rbp, %rdi
leaq 0x640(%rsp), %rsi
xorl %edx, %edx
callq 0x2260
cmpl $0x0, (%r13)
jne 0x26ba
movq 0x640(%rsp), %rcx
cmpb $0x0, (%rcx)
je 0x2570
jmp 0x26ba
movzbl 0x1(%rbp), %ecx
cmpl $0x67, %ecx
jg 0x2560
testl %ecx, %ecx
jne 0x26dc
movq %rbp, %r15
jmp 0x2570
testq %r15, %r15
movq %rbp, %r15
je 0x2570
jmp 0x26c5
movb $0x1, %dl
movq %rdx, 0x8(%rsp)
cmpl $0x76, %ecx
jne 0x26cd
incq %r12
cmpq %r12, %rbx
jne 0x24df
movq %rax, (%rsp)
movq 0x8(%rsp), %rbx
jmp 0x2594
xorl %ebx, %ebx
movq $0x0, (%rsp)
xorl %r15d, %r15d
leaq 0x10(%rsp), %rdi
callq 0x4304
testb $0x1, %bl
je 0x25a8
movb $0x1, 0x12(%rsp)
testq %r15, %r15
je 0x269a
leaq 0x4a97(%rip), %rsi      # 0x704f
movq %r15, %rdi
callq 0x2150
testl %eax, %eax
je 0x25d2
movq 0x8(%r14), %rdi
callq 0x32f2
jmp 0x2688
xorl %r14d, %r14d
movl $0x4000, %ebx           # imm = 0x4000
xorl %r12d, %r12d
xorl %r13d, %r13d
movq 0x79f1(%rip), %rax      # 0x9fd8
movq (%rax), %rcx
movl $0x1, %esi
movl $0x1000, %edx           # imm = 0x1000
leaq 0x640(%rsp), %rdi
callq 0x2090
testq %rax, %rax
je 0x2653
movq %rax, %rbp
leaq (%rax,%r12), %r15
cmpq %r13, %r15
jbe 0x2636
testq %r13, %r13
leaq (%r13,%r13), %r13
cmoveq %rbx, %r13
cmpq %r13, %r15
ja 0x2612
movq %r14, %rdi
movq %r13, %rsi
callq 0x2200
testq %rax, %rax
je 0x265e
movq %rax, %r14
addq %r14, %r12
movq %r12, %rdi
leaq 0x640(%rsp), %rsi
movq %rbp, %rdx
callq 0x21b0
xorl %eax, %eax
movq %r15, %r12
jmp 0x2658
movl $0x3, %eax
testl %eax, %eax
je 0x25e0
jmp 0x266d
callq 0x233f
movl $0x1, %eax
xorl %r14d, %r14d
jmp 0x2658
cmpl $0x3, %eax
je 0x2678
xorl %r12d, %r12d
xorl %r14d, %r14d
testq %r14, %r14
je 0x26f8
movq %r14, %rdi
movq %r12, %rsi
callq 0x327c
testq %rax, %rax
je 0x26f8
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x4324
leaq 0x10(%rsp), %rdi
movq (%rsp), %rsi
callq 0x4526
addq $0x1648, %rsp           # imm = 0x1648
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
movq %r12, %rsi
callq 0x22ea
movq %r14, %rdi
callq 0x2318
cmpl $0x68, %ecx
jne 0x26ed
movq (%r14), %rdi
callq 0x2734
jmp 0x26e6
cmpl $0x56, %ecx
jne 0x26ed
callq 0x2702
xorl %edi, %edi
callq 0x2290
movq %r14, %rdi
movq %rbp, %rsi
callq 0x22c0
movl $0x1, %edi
callq 0x2290