// File: /workspace/github_c_makefile_star2_O2/negge[P]xlink/src/xlink.c
// Function: main
int main(int argc, char *argv[]) {
  xlink_binary bin;
  int c;
  int opt_index;
  unsigned int flags;
  char mapfile[256];
  xlink_binary_init(&bin);
  flags = 0;
  while ((c = getopt_long(argc, argv, OPTSTRING, OPTIONS, &opt_index)) != EOF) {
    switch (c) {
      case 'o' : {
        bin.output = optarg;
        break;
      }
      case 'e' : {
        bin.entry = optarg;
        break;
      }
      case 'i' : {
        bin.init = optarg;
        break;
      }
      case 'p' : {
        flags |= MOD_PACK;
        break;
      }
      case '1' : {
        flags |= MOD_ONE;
        break;
      }
      case 'L' : {
        flags |= MOD_LOW;
        break;
      }
      case 'C' : {
        flags |= MOD_CLAMP;
        break;
      }
      case 'E' : {
        flags |= MOD_EXIT;
        break;
      }
      case 'B' : {
        flags |= MOD_BASE;
        break;
      }
      case 'M' : {
        bin.hash_table_memory = atoi(optarg);
        break;
      }
      case 'd' : {
        flags |= MOD_DUMP;
        break;
      }
      case 'm' : {
        flags |= MOD_MAP;
        break;
      }
      case 's' : {
        flags |= MOD_SPLIT;
        break;
      }
      case 'c' : {
        flags |= MOD_CHECK;
        break;
      }
      case 'h' :
      default : {
        usage(argv[0]);
        return EXIT_FAILURE;
      }
    }
  }
  XLINK_ERROR(flags & MOD_PACK && flags & MOD_EXIT,
   ("Specified -E --exit with -p --pack but only valid for unpacked binaries"));
  XLINK_ERROR(bin.hash_table_memory & 1,
   ("Specified -M --memory size %i must be even", bin.hash_table_memory));
  XLINK_ERROR(flags & MOD_ONE && !(flags & MOD_PACK),
   ("Specified -1 --one without -p --pack but only valid for packed binaries"));
  XLINK_ERROR(flags & MOD_LOW && !(flags & MOD_PACK || flags & MOD_CHECK),
   ("Specified -L --low without -p --pack or -c --check command line option"));
  XLINK_ERROR(flags & MOD_CLAMP && !(flags & MOD_PACK || flags & MOD_CHECK),
   ("Specified -C --clamp without -p --pack or -c --check command line option"));
  if (flags & MOD_CHECK) {
    xlink_list bytes;
    xlink_list models;
    /* Read bytes from stdin */
    xlink_list_init(&bytes, sizeof(unsigned char), 0);
    while (!XLINK_FEOF(stdin)) {
      xlink_list_add_byte(&bytes, getc(stdin));
    }
    xlink_list_init(&models, sizeof(xlink_model), 0);
    /* Search for the best context to use for bytes */
    xlink_model_search(&models, &bytes);
    if (xlink_list_length(&models) > 0) {
      xlink_context ctx;
      xlink_bitstream bs;
      int size;
      /* Segment header has 4 weight bytes + n model bytes */
      printf("Required header: 4 weight bytes + %i model byte(s)\n",
       xlink_list_length(&models));
      xlink_model_set_state(&models,
       xlink_model_compute_packed_weights(&models));
      /* Create a context from models */
      xlink_context_init(&ctx, &models, 0, flags & MOD_LOW, flags & MOD_CLAMP);
      /* Create a bitstream for writing */
      xlink_bitstream_init(&bs);
      /* Encode bytes with the context and perfect hashing */
      xlink_bitstream_from_context(&bs, &ctx, &bytes);
      size = 8 + xlink_list_length(&models) + (bs.bits + 7)/8;
      printf("Perfect hashing: %i bits, %i bytes\n", bs.bits, (bs.bits + 7)/8);
      printf("Compressed size: %i bytes -> %2.3lf%% smaller\n", size,
       XLINK_RATIO(size, xlink_list_length(&bytes)));
      /* Encode bytes with the context and replacement hashing */
      printf("Using hash table size = %i\n", bin.hash_table_memory/2);
      xlink_context_set_fixed_capacity(&ctx, bin.hash_table_memory/2);
      xlink_bitstream_from_context(&bs, &ctx, &bytes);
      size = 8 + xlink_list_length(&models) + (bs.bits + 7)/8;
      printf("Replace hashing: %i bits, %i bytes\n", bs.bits, (bs.bits + 7)/8);
      printf("Compressed size: %i bytes -> %2.3lf%% smaller\n", size,
       XLINK_RATIO(size, xlink_list_length(&bytes)));
      xlink_context_clear(&ctx);
      xlink_bitstream_clear(&bs);
    }
    /* Clean up */
    xlink_list_clear(&bytes);
    xlink_list_clear(&models);
    return EXIT_SUCCESS;
  }
  if (optind == argc) {
    fprintf(stderr, "No <modules> specified!\n\n");
    usage(argv[0]);
    return EXIT_FAILURE;
  }
  if (!(flags & MOD_DUMP) && bin.output == NULL) {
    fprintf(stderr, "Output -o <program> is required!\n\n");
    usage(argv[0]);
    return EXIT_FAILURE;
  }
  if ((flags & MOD_MAP) && !(flags & MOD_DUMP)) {
    int len;
    len = strlen(bin.output);
    strcpy(mapfile, bin.output);
    if (len > 4 && strncasecmp(mapfile + len - 4, ".com", 4) == 0) {
      sprintf(mapfile + len - 4, "%s", ".map");
    }
    else {
      sprintf(mapfile + len, "%s", ".map");
    }
    bin.map = mapfile;
  }
  for (c = optind; c < argc; c++) {
    xlink_file file;
    xlink_file_init(&file, argv[c]);
    switch (file.buf[0]) {
      case OMF_THEADR :
      case OMF_LHEADR : {
        xlink_module *mod;
        mod = xlink_file_load_omf_module(&file, flags);
        XLINK_LIST_ADD(binary, module, &bin, mod);
        break;
      }
      case OMF_LIBHDR : {
        xlink_library *lib;
        lib = xlink_file_load_omf_library(&file, flags);
        XLINK_LIST_ADD(binary, library, &bin, lib);
        break;
      }
      default : {
        XLINK_ERROR(1,
         ("Unsupported file format, unknown record type %02X", file.buf[0]));
      }
    }
    xlink_file_clear(&file);
  }
  if (!(flags & MOD_DUMP)) {
    xlink_binary_link(&bin, flags);
  }
  xlink_binary_clear(&bin);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1e8, %rsp            # imm = 0x1E8
movq %rsi, %rbx
movl %edi, %r15d
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
movapd %xmm0, 0x30(%rsp)
movapd %xmm0, 0x40(%rsp)
movapd %xmm0, 0x50(%rsp)
movapd %xmm0, 0x60(%rsp)
andq $0x0, 0x80(%rsp)
movapd %xmm0, 0x70(%rsp)
leaq 0x2cbc(%rip), %rax      # 0x9594
movq %rax, 0x28(%rsp)
movl $0xc00000, 0x38(%rsp)   # imm = 0xC00000
movq $0x0, 0x10(%rsp)
movl $0xc00000, 0x8(%rsp)    # imm = 0xC00000
leaq 0x92c3(%rip), %r13      # 0xfbc0
leaq 0x1c(%rsp), %rbp
leaq 0x27db(%rip), %r12      # 0x90e4
xorl %r14d, %r14d
movq 0xc705(%rip), %rdx      # 0x13018
movl %r15d, %edi
movq %rbx, %rsi
movq %r13, %rcx
movq %rbp, %r8
callq 0x20b0
leal -0x63(%rax), %ecx
cmpl $0x10, %ecx
ja 0x693b
movslq (%r12,%rcx,4), %rax
addq %r12, %rax
jmpq *%rax
orl $0x8, %r14d
jmp 0x690c
leal -0x42(%rax), %ecx
cmpl $0xb, %ecx
ja 0x695c
leaq 0x276a(%rip), %rdx      # 0x90b4
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
orl $0x200, %r14d           # imm = 0x200
jmp 0x690c
cmpl $0x31, %eax
jne 0x6a07
orl $0x20, %r14d
jmp 0x690c
orl $0x2, %r14d
jmp 0x690c
movq 0x9660(%rip), %rax      # 0xffd8
movq (%rax), %rcx
movq %rcx, 0x10(%rsp)
movq %rcx, 0x20(%rsp)
jmp 0x690c
movq 0x964a(%rip), %rax      # 0xffd8
movq (%rax), %rax
movq %rax, 0x28(%rsp)
jmp 0x690c
movq 0x9636(%rip), %rax      # 0xffd8
movq (%rax), %rax
movq %rax, 0x30(%rsp)
jmp 0x690c
orl $0x1, %r14d
jmp 0x690c
orl $0x10, %r14d
jmp 0x690c
orl $0x4, %r14d
jmp 0x690c
orl $0x40, %r14d
jmp 0x690c
orl $0x80, %r14d
jmp 0x690c
orl $0x100, %r14d           # imm = 0x100
jmp 0x690c
movq 0x95e6(%rip), %rax      # 0xffd8
movq (%rax), %rdi
callq 0x21d0
movl %eax, 0x8(%rsp)
movl %eax, 0x38(%rsp)
jmp 0x690c
cmpl $-0x1, %eax
jne 0x6e56
movl %r14d, %eax
notl %eax
testw $0x110, %ax             # imm = 0x110
je 0x6e85
testb $0x1, 0x8(%rsp)
jne 0x6e8e
movl %r14d, %eax
andl $0x30, %eax
cmpl $0x20, %eax
je 0x6e9b
movl %r14d, %eax
andl $0x58, %eax
cmpl $0x40, %eax
je 0x6ea4
movl $0x80, %ebp
movl %r14d, %eax
andl $0x98, %eax
cmpl %ebp, %eax
je 0x6ead
testb $0x8, %r14b
jne 0x6bba
movq 0x9562(%rip), %rax      # 0xffd0
movslq (%rax), %r13
cmpl %r15d, %r13d
je 0x6e25
testb $0x1, %r14b
sete %al
cmpq $0x0, 0x10(%rsp)
sete %cl
andb %al, %cl
cmpb $0x1, %cl
je 0x6e3a
movl %r14d, %eax
andl $0x3, %eax
cmpl $0x2, %eax
jne 0x6b16
movq 0x10(%rsp), %r12
movq %r12, %rdi
callq 0x20a0
movq %rax, %rbp
leaq 0xe0(%rsp), %rdi
movq %r12, %rsi
callq 0x2050
cmpl $0x5, %ebp
jl 0x6aed
movl %ebp, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
leaq (%rsp,%rax), %r12
addq $0xdc, %r12
leaq 0x39ff(%rip), %rsi      # 0xa4dd
pushq $0x4
popq %rdx
movq %r12, %rdi
callq 0x2150
testl %eax, %eax
je 0x6afb
movslq %ebp, %rax
leaq (%rsp,%rax), %r12
addq $0xe0, %r12
movb $0x0, 0x4(%r12)
movl $0x70616d2e, (%r12)     # imm = 0x70616D2E
leaq 0xe0(%rsp), %rax
movq %rax, 0x40(%rsp)
movslq %r15d, %rbp
leaq 0xc0(%rsp), %r15
leaq 0x20(%rsp), %r12
cmpq %rbp, %r13
jge 0x6e04
movq (%rbx,%r13,8), %rsi
movq %r15, %rdi
callq 0x7634
movq 0xd0(%rsp), %rax
movzbl (%rax), %esi
cmpl $0x80, %esi
je 0x6b62
cmpl $0xf0, %esi
je 0x6b87
cmpl $0x82, %esi
jne 0x6e75
movq %r15, %rdi
movl %r14d, %esi
callq 0x4651
movl 0x50(%rsp), %ecx
incl %ecx
movl %ecx, 0x8(%rax)
movq %r12, 0x10(%rax)
movq %r12, %rdi
movq %rax, %rsi
callq 0x31e2
jmp 0x6baa
movq %r15, %rdi
movl %r14d, %esi
callq 0x532c
movl 0x60(%rsp), %ecx
incl %ecx
movl %ecx, 0x8(%rax)
movq %r12, 0x10(%rax)
movq %r12, %rdi
movq %rax, %rsi
callq 0x3276
movq %r15, %rdi
callq 0x76e5
incq %r13
jmp 0x6b26
movl %r14d, %r15d
andl $0x40, %r15d
andl %r14d, %ebp
leaq 0x90(%rsp), %rbx
pushq $0x1
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x82a8
movq 0x93e8(%rip), %r12      # 0xffc8
leaq 0xe0(%rsp), %r14
movq (%r12), %rdi
callq 0x2220
movq (%r12), %rsi
movl %eax, %edi
callq 0x2170
cmpl $-0x1, %eax
je 0x6c1e
movq (%r12), %rdi
callq 0x2220
movb %al, 0xe0(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x838e
jmp 0x6be8
leaq 0xa8(%rsp), %r14
pushq $0xc
popq %rsi
xorl %ebx, %ebx
movq %r14, %rdi
xorl %edx, %edx
callq 0x82a8
leaq 0x90(%rsp), %rsi
movq %r14, %rdi
callq 0x5782
movq %r14, %rdi
callq 0x82d7
testl %eax, %eax
jle 0x6de8
leaq 0xa8(%rsp), %r12
movq %r12, %rdi
callq 0x82d7
leaq 0x37c0(%rip), %rdi      # 0xa42c
movl %eax, %esi
xorl %eax, %eax
callq 0x20c0
movq %r12, %rdi
callq 0x770a
movq %r12, %rdi
movl %eax, %esi
callq 0x7780
leaq 0xe0(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
xorl %edx, %edx
movl %r15d, %ecx
movl %ebp, %r8d
callq 0x79da
leaq 0xc0(%rsp), %r15
movq %r15, %rdi
callq 0x6ee0
leaq 0x90(%rsp), %r13
movq %r15, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x58ac
movq %r12, %rdi
callq 0x82d7
movl %eax, %ecx
movl 0x18(%r15), %esi
leal 0x7(%rsi), %eax
pushq $0x8
popq %rdi
cltd
idivl %edi
leal (%rcx,%rax), %ebp
addl $0x8, %ebp
leaq 0x343f(%rip), %rdi      # 0xa12b
movl %eax, %edx
xorl %eax, %eax
callq 0x20c0
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0x10(%rsp)
movq %r13, %rdi
callq 0x82d7
cvtsi2sd %eax, %xmm0
movsd 0x10(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd 0x25b3(%rip), %xmm0     # 0x92d0
subsd %xmm1, %xmm0
mulsd 0x25af(%rip), %xmm0     # 0x92d8
leaq 0x341f(%rip), %rdi      # 0xa14f
movl %ebp, %esi
movb $0x1, %al
callq 0x20c0
movl 0x8(%rsp), %ebp
sarl %ebp
leaq 0x371a(%rip), %rdi      # 0xa460
movl %ebp, %esi
xorl %eax, %eax
callq 0x20c0
movq %r14, %rdi
movl %ebp, %esi
callq 0x7a4c
movq %r15, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x58ac
movq %r12, %rdi
callq 0x82d7
movl %eax, %ecx
movl 0x18(%r15), %esi
leal 0x7(%rsi), %eax
cltd
pushq $0x8
popq %rdi
idivl %edi
leal (%rcx,%rax), %ebp
addl $0x8, %ebp
leaq 0x36f1(%rip), %rdi      # 0xa47c
movl %eax, %edx
xorl %eax, %eax
callq 0x20c0
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0x8(%rsp)
movq %r13, %rdi
callq 0x82d7
cvtsi2sd %eax, %xmm0
movsd 0x8(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd 0x2514(%rip), %xmm0     # 0x92d0
subsd %xmm1, %xmm0
mulsd 0x2510(%rip), %xmm0     # 0x92d8
leaq 0x3380(%rip), %rdi      # 0xa14f
movl %ebp, %esi
movb $0x1, %al
callq 0x20c0
movq %r14, %rdi
callq 0x7a88
movq %r15, %rdi
callq 0x6ef4
leaq 0x90(%rsp), %rdi
callq 0x82cf
leaq 0xa8(%rsp), %rdi
callq 0x82cf
jmp 0x6e61
testb $0x1, %r14b
jne 0x6e17
leaq 0x20(%rsp), %rdi
movl %r14d, %esi
callq 0x5eb3
leaq 0x20(%rsp), %rdi
callq 0x29bf
xorl %ebx, %ebx
jmp 0x6e61
movq 0x91cc(%rip), %rax      # 0xfff8
movq (%rax), %rcx
leaq 0x366a(%rip), %rdi      # 0xa4a0
pushq $0x19
jmp 0x6e4d
movq 0x91b7(%rip), %rax      # 0xfff8
movq (%rax), %rcx
leaq 0x366f(%rip), %rdi      # 0xa4ba
pushq $0x22
popq %rsi
pushq $0x1
popq %rdx
callq 0x2200
movq (%rbx), %rdi
callq 0x6ec3
pushq $0x1
popq %rbx
movl %ebx, %eax
addq $0x1e8, %rsp            # imm = 0x1E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x366b(%rip), %rdi      # 0xa4e7
xorl %eax, %eax
callq 0x7514
jmp 0x6ebb
leaq 0x3455(%rip), %rdi      # 0xa2e1
jmp 0x6eb4
leaq 0x3494(%rip), %rdi      # 0xa329
movl 0x8(%rsp), %esi
jmp 0x6e7c
leaq 0x34b2(%rip), %rdi      # 0xa354
jmp 0x6eb4
leaq 0x34f1(%rip), %rdi      # 0xa39c
jmp 0x6eb4
leaq 0x352f(%rip), %rdi      # 0xa3e3
xorl %eax, %eax
callq 0x7514
pushq $-0x1
popq %rdi
callq 0x21f0