// File: /workspace/github_c_makefile_star2_O2/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
movslq %edi, %rbx
pushq $0x1
popq %r15
movq $0x0, (%rsp)
xorl %eax, %eax
xorl %ebp, %ebp
cmpq %rbx, %r15
jge 0x2467
movq (%r14,%r15,8), %r12
movzbl (%r12), %ecx
cmpl $0x2d, %ecx
je 0x2435
cmpl $0x2b, %ecx
jne 0x244f
andq $0x0, 0x640(%rsp)
callq 0x2040
movq %rax, %r13
andl $0x0, (%rax)
incq %r12
movq %r12, %rdi
leaq 0x640(%rsp), %rsi
xorl %edx, %edx
callq 0x2260
cmpl $0x0, (%r13)
jne 0x2592
movq 0x640(%rsp), %rcx
cmpb $0x0, (%rcx)
je 0x245f
jmp 0x2592
movzbl 0x1(%r12), %ecx
testl %ecx, %ecx
je 0x245c
movb $0x1, %dl
movq %rdx, (%rsp)
cmpl $0x76, %ecx
je 0x245f
jmp 0x25b6
testq %rbp, %rbp
movq %r12, %rbp
je 0x245f
jmp 0x25c7
movq %r12, %rbp
incq %r15
jmp 0x23d3
movq %rax, 0x8(%rsp)
leaq 0x10(%rsp), %rdi
callq 0x4004
testb $0x1, (%rsp)
je 0x2481
movb $0x1, 0x12(%rsp)
testq %rbp, %rbp
je 0x24b1
cmpb $0x2d, (%rbp)
jne 0x2492
cmpb $0x0, 0x1(%rbp)
je 0x24d2
movq 0x8(%r14), %rdi
callq 0x3153
testq %rax, %rax
je 0x258a
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x401d
leaq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x4214
addq $0x1648, %rsp           # imm = 0x1648
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq $0x0, (%rsp)
leaq 0x640(%rsp), %r14
movl $0x4000, %ebx           # imm = 0x4000
xorl %r15d, %r15d
xorl %ebp, %ebp
movq 0x8ae5(%rip), %rax      # 0xafd8
movq (%rax), %rcx
movl $0x1000, %edx           # imm = 0x1000
movq %r14, %rdi
pushq $0x1
popq %rsi
callq 0x2090
testq %rax, %rax
je 0x2558
movq %rax, %r12
leaq (%rax,%r15), %r13
cmpq %rbp, %r13
movq (%rsp), %rax
jbe 0x253e
cmpq %rbp, %r13
jbe 0x252e
testq %rbp, %rbp
leaq (%rbp,%rbp), %rbp
cmoveq %rbx, %rbp
jmp 0x251b
movq %rax, %rdi
movq %rbp, %rsi
callq 0x2200
testq %rax, %rax
je 0x256e
movq %rax, (%rsp)
addq %rax, %r15
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x21b0
movq %r13, %r15
jmp 0x24ec
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x258a
movq %r15, %rsi
callq 0x30e8
jmp 0x249b
movq 0x8a83(%rip), %rax      # 0xaff8
movq (%rax), %rcx
leaq 0x4aef(%rip), %rdi      # 0x706e
pushq $0x15
popq %rsi
pushq $0x1
popq %rdx
callq 0x22a0
pushq $0x1
popq %rdi
callq 0x2290
movq 0x8a5f(%rip), %rax      # 0xaff8
movq (%rax), %rdi
movq (%r14), %rdx
movq (%r14,%r15,8), %rcx
incq %rcx
leaq 0x4a57(%rip), %rsi      # 0x7004
xorl %eax, %eax
callq 0x2170
jmp 0x258a
cmpl $0x68, %ecx
je 0x25e4
cmpl $0x56, %ecx
jne 0x25f3
callq 0x260c
jmp 0x25ec
movq 0x8a2a(%rip), %rax      # 0xaff8
movq (%rax), %rdi
movq (%r14), %rdx
leaq 0x4a5a(%rip), %rsi      # 0x7035
xorl %eax, %eax
callq 0x2170
jmp 0x258a
movq (%r14), %rdi
callq 0x263e
xorl %edi, %edi
callq 0x2290
movq 0x89fe(%rip), %rax      # 0xaff8
movq (%rax), %rdi
movq (%r14), %rdx
leaq 0x4a15(%rip), %rsi      # 0x701c
movq %r12, %rcx
jmp 0x25ad