// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x688, %rsp            # imm = 0x688
movl $0x0, 0x684(%rsp)
movl %edi, 0x680(%rsp)
movq %rsi, 0x678(%rsp)
movq $0x0, 0x670(%rsp)
movb $0x0, 0x66f(%rsp)
movq $0x0, 0x660(%rsp)
movl $0x1, 0x65c(%rsp)
movl 0x65c(%rsp), %eax
cmpl 0x680(%rsp), %eax
jge 0x2619
movq 0x678(%rsp), %rax
movslq 0x65c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0x2b, %eax
jne 0x24ba
movq $0x0, 0x650(%rsp)
callq 0x2040
movl $0x0, (%rax)
movq 0x678(%rsp), %rax
movslq 0x65c(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
addq $0x1, %rdi
leaq 0x650(%rsp), %rsi
xorl %edx, %edx
callq 0x2240
movq %rax, 0x660(%rsp)
callq 0x2040
cmpl $0x0, (%rax)
jne 0x2470
movq 0x650(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x24b5
movq 0xbb81(%rip), %rax      # 0xdff8
movq (%rax), %rdi
movq 0x678(%rsp), %rax
movq (%rax), %rdx
movq 0x678(%rsp), %rax
movslq 0x65c(%rsp), %rcx
movq (%rax,%rcx,8), %rcx
addq $0x1, %rcx
leaq 0x8b60(%rip), %rsi      # 0xb004
movb $0x0, %al
callq 0x2160
movl $0x1, %edi
callq 0x2270
jmp 0x2601
movq 0x678(%rsp), %rax
movslq 0x65c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x25ab
movq 0x678(%rsp), %rax
movslq 0x65c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movsbl 0x1(%rax), %eax
movl %eax, 0x4(%rsp)
testl %eax, %eax
je 0x254a
jmp 0x24fc
movl 0x4(%rsp), %eax
subl $0x56, %eax
je 0x251d
jmp 0x2507
movl 0x4(%rsp), %eax
subl $0x68, %eax
je 0x2529
jmp 0x2512
movl 0x4(%rsp), %eax
subl $0x76, %eax
je 0x2540
jmp 0x2568
callq 0x26f0
xorl %edi, %edi
callq 0x2270
movq 0x678(%rsp), %rax
movq (%rax), %rdi
callq 0x2730
xorl %edi, %edi
callq 0x2270
movb $0x1, 0x66f(%rsp)
jmp 0x25a9
movq 0x678(%rsp), %rax
movslq 0x65c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x670(%rsp)
jmp 0x25a9
movq 0xba89(%rip), %rax      # 0xdff8
movq (%rax), %rdi
movq 0x678(%rsp), %rax
movq (%rax), %rdx
movq 0x678(%rsp), %rax
movslq 0x65c(%rsp), %rcx
movq (%rax,%rcx,8), %rcx
leaq 0x8a84(%rip), %rsi      # 0xb01c
movb $0x0, %al
callq 0x2160
movl $0x1, %edi
callq 0x2270
jmp 0x25ff
cmpq $0x0, 0x670(%rsp)
je 0x25e3
movq 0xba3b(%rip), %rax      # 0xdff8
movq (%rax), %rdi
movq 0x678(%rsp), %rax
movq (%rax), %rdx
leaq 0x8a63(%rip), %rsi      # 0xb035
movb $0x0, %al
callq 0x2160
movl $0x1, %edi
callq 0x2270
movq 0x678(%rsp), %rax
movslq 0x65c(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x670(%rsp)
jmp 0x2601
jmp 0x2603
movl 0x65c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x65c(%rsp)
jmp 0x23dc
leaq 0x20(%rsp), %rdi
callq 0x6170
testb $0x1, 0x66f(%rsp)
je 0x2632
movb $0x1, 0x22(%rsp)
cmpq $0x0, 0x670(%rsp)
je 0x26d1
movq 0x670(%rsp), %rdi
leaq 0x89ff(%rip), %rsi      # 0xb04f
callq 0x2140
cmpl $0x0, %eax
jne 0x269a
movq $0x0, 0x10(%rsp)
leaq 0x10(%rsp), %rdi
callq 0x2760
movq %rax, 0x8(%rsp)
cmpq $0x0, 0x8(%rsp)
jne 0x2684
movl $0x1, %edi
callq 0x2270
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x3e60
movq %rax, 0x18(%rsp)
jmp 0x26b0
movq 0x678(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x3fa0
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x18(%rsp)
jne 0x26c2
movl $0x1, %edi
callq 0x2270
movq 0x18(%rsp), %rsi
leaq 0x20(%rsp), %rdi
callq 0x61b0
movq 0x660(%rsp), %rsi
leaq 0x20(%rsp), %rdi
callq 0x6670
addq $0x688, %rsp            # imm = 0x688
retq
nopl (%rax,%rax)