// File: /workspace/github_c_makefile_star2_O1/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 $0x1d8, %rsp            # imm = 0x1D8
movq %rsi, %r15
movl %edi, %r14d
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movapd %xmm0, 0x20(%rsp)
movapd %xmm0, 0x30(%rsp)
movapd %xmm0, 0x40(%rsp)
movapd %xmm0, 0x50(%rsp)
movapd %xmm0, 0x60(%rsp)
movq $0x0, 0x70(%rsp)
leaq 0x2d69(%rip), %rax      # 0xa594
movq %rax, 0x18(%rsp)
movl $0xc00000, 0x28(%rsp)   # imm = 0xC00000
xorl %ebx, %ebx
leaq 0x837f(%rip), %r12      # 0xfbc0
leaq 0x7c(%rsp), %r13
leaq 0x2897(%rip), %rbp      # 0xa0e4
movq 0xb7c4(%rip), %rdx      # 0x13018
movl %r14d, %edi
movq %r15, %rsi
movq %r12, %rcx
movq %r13, %r8
callq 0x20b0
cmpl $0x62, %eax
jle 0x7885
addl $-0x63, %eax
cmpl $0x10, %eax
ja 0x7e00
movslq (%rbp,%rax,4), %rax
addq %rbp, %rax
jmpq *%rax
orl $0x8, %ebx
jmp 0x784d
leal -0x42(%rax), %ecx
cmpl $0xb, %ecx
ja 0x78a5
leaq 0x2820(%rip), %rdx      # 0xa0b4
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
orl $0x200, %ebx            # imm = 0x200
jmp 0x784d
cmpl $0x31, %eax
jne 0x793c
orl $0x20, %ebx
jmp 0x784d
orl $0x40, %ebx
jmp 0x784d
orl $0x100, %ebx            # imm = 0x100
jmp 0x784d
orl $0x80, %ebx
jmp 0x784d
movq 0x8709(%rip), %rax      # 0xffd8
movq (%rax), %rdi
callq 0x21d0
movl %eax, 0x28(%rsp)
jmp 0x784d
orl $0x4, %ebx
jmp 0x784d
orl $0x1, %ebx
jmp 0x784d
movq 0x86e1(%rip), %rax      # 0xffd8
movq (%rax), %rax
movq %rax, 0x18(%rsp)
jmp 0x784d
orl $0x10, %ebx
jmp 0x784d
movq 0x86c5(%rip), %rax      # 0xffd8
movq (%rax), %rax
movq %rax, 0x20(%rsp)
jmp 0x784d
orl $0x2, %ebx
jmp 0x784d
movq 0x86a9(%rip), %rax      # 0xffd8
movq (%rax), %rax
movq %rax, 0x10(%rsp)
jmp 0x784d
cmpl $-0x1, %eax
jne 0x7e00
movl %ebx, %eax
notl %eax
testl $0x110, %eax            # imm = 0x110
je 0x7e2c
movl 0x28(%rsp), %esi
testb $0x1, %sil
jne 0x7e35
movl %ebx, %eax
andl $0x30, %eax
cmpl $0x20, %eax
je 0x7e45
movl %ebx, %eax
andl $0x58, %eax
cmpl $0x40, %eax
je 0x7e4e
movl $0x80, %r12d
movl %ebx, %eax
andl $0x98, %eax
cmpl %r12d, %eax
je 0x7e57
testb $0x8, %bl
jne 0x7b61
movq 0x862c(%rip), %rax      # 0xffd0
movslq (%rax), %r12
cmpl %r12d, %r14d
je 0x7e0a
testb $0x1, %bl
sete %al
movq 0x10(%rsp), %rbp
testq %rbp, %rbp
sete %cl
andb %al, %cl
cmpb $0x1, %cl
je 0x7e14
movl %ebx, %eax
andl $0x3, %eax
cmpl $0x2, %eax
jne 0x7a48
movq %rbp, %rdi
callq 0x20a0
movq %rax, %r13
leaq 0xd0(%rsp), %rdi
movq %rbp, %rsi
callq 0x2050
cmpl $0x5, %r13d
jl 0x7a22
movl %r13d, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
leaq (%rsp,%rax), %rbp
addq $0xcc, %rbp
leaq 0x3b04(%rip), %rsi      # 0xb515
movl $0x4, %edx
movq %rbp, %rdi
callq 0x2150
testl %eax, %eax
je 0x7a30
movslq %r13d, %rax
leaq (%rsp,%rax), %rbp
addq $0xd0, %rbp
movb $0x0, 0x4(%rbp)
movl $0x70616d2e, (%rbp)     # imm = 0x70616D2E
leaq 0xd0(%rsp), %rax
movq %rax, 0x30(%rsp)
cmpl %r12d, %r14d
jle 0x7b3f
leaq (%r15,%r12,8), %rax
movq %rax, 0x8(%rsp)
subl %r12d, %r14d
xorl %ebp, %ebp
leaq 0x98(%rsp), %r15
movq 0x8(%rsp), %rax
movq (%rax,%rbp,8), %rsi
movq %r15, %rdi
callq 0x8544
movq 0xa8(%rsp), %rax
movzbl (%rax), %esi
cmpl $0x80, %esi
je 0x7a9f
cmpl $0xf0, %esi
je 0x7ad7
cmpl $0x82, %esi
jne 0x7e23
movq %r15, %rdi
movl %ebx, %esi
callq 0x4c64
movq %rax, %r12
movl 0x40(%rsp), %eax
incl %eax
movl %eax, 0x8(%r12)
leaq 0x10(%rsp), %rax
movq %rax, 0x10(%r12)
movl 0x40(%rsp), %eax
incl %eax
movl %eax, 0x40(%rsp)
leaq 0x38(%rsp), %r13
leaq 0x40(%rsp), %r15
jmp 0x7b07
movq %r15, %rdi
movl %ebx, %esi
callq 0x5d84
movq %rax, %r12
movl 0x50(%rsp), %eax
incl %eax
movl %eax, 0x8(%r12)
leaq 0x10(%rsp), %rcx
movq %rcx, 0x10(%r12)
movl %eax, 0x50(%rsp)
leaq 0x48(%rsp), %r13
leaq 0x50(%rsp), %r15
movq (%r13), %rdi
movslq %eax, %rsi
shlq $0x3, %rsi
callq 0x852c
movq %rax, (%r13)
movslq (%r15), %rcx
movq %r12, -0x8(%rax,%rcx,8)
leaq 0x98(%rsp), %r15
movq %r15, %rdi
callq 0x85fe
incq %rbp
cmpl %ebp, %r14d
jne 0x7a67
testb $0x1, %bl
jne 0x7b50
leaq 0x10(%rsp), %rdi
movl %ebx, %esi
callq 0x6bb2
leaq 0x10(%rsp), %rdi
callq 0x2bf7
xorl %ebp, %ebp
jmp 0x7dec
leaq 0x80(%rsp), %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x92e8
movq 0x844c(%rip), %r13      # 0xffc8
movq (%r13), %rdi
callq 0x2220
movq (%r13), %rsi
movl %eax, %edi
callq 0x2170
cmpl $-0x1, %eax
je 0x7bd9
leaq 0x80(%rsp), %r14
leaq 0xd0(%rsp), %r15
movq (%r13), %rdi
callq 0x2220
movb %al, 0xd0(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x93e4
movq (%r13), %rdi
callq 0x2220
movq (%r13), %rsi
movl %eax, %edi
callq 0x2170
cmpl $-0x1, %eax
jne 0x7ba5
leaq 0xb8(%rsp), %r14
xorl %ebp, %ebp
movl $0xc, %esi
movq %r14, %rdi
xorl %edx, %edx
callq 0x92e8
leaq 0x80(%rsp), %rsi
movq %r14, %rdi
callq 0x6356
movq %r14, %rdi
callq 0x931a
testl %eax, %eax
jle 0x7dd2
movl %ebx, %r14d
andl $0x40, %r14d
andl %ebx, %r12d
leaq 0xb8(%rsp), %r15
movq %r15, %rdi
callq 0x931a
leaq 0x3831(%rip), %rdi      # 0xb464
movl %eax, %esi
xorl %eax, %eax
callq 0x20c0
movq %r15, %rdi
callq 0x8627
movq %r15, %rdi
movl %eax, %esi
callq 0x86c8
leaq 0xd0(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
xorl %edx, %edx
movl %r14d, %ecx
movl %r12d, %r8d
callq 0x8921
leaq 0x98(%rsp), %r14
movq %r14, %rdi
callq 0x7e70
leaq 0x80(%rsp), %r12
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x6497
movq %r15, %rdi
callq 0x931a
movl 0x18(%r14), %esi
leal 0x7(%rsi), %ecx
leal 0xe(%rsi), %edx
testl %ecx, %ecx
cmovnsl %ecx, %edx
sarl $0x3, %edx
leal (%rax,%rdx), %r13d
addl $0x8, %r13d
leaq 0x34ab(%rip), %rdi      # 0xb163
xorl %eax, %eax
callq 0x20c0
cvtsi2sd %r13d, %xmm0
movsd %xmm0, 0x8(%rsp)
movq %r12, %rdi
callq 0x931a
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd 0x8(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd 0x25e5(%rip), %xmm0     # 0xa2d0
subsd %xmm1, %xmm0
mulsd 0x25e1(%rip), %xmm0     # 0xa2d8
leaq 0x3489(%rip), %rdi      # 0xb187
movl %r13d, %esi
movb $0x1, %al
callq 0x20c0
movl 0x28(%rsp), %eax
movl %eax, %esi
shrl $0x1f, %esi
addl %eax, %esi
sarl %esi
leaq 0x377c(%rip), %rdi      # 0xb498
xorl %eax, %eax
callq 0x20c0
movl 0x28(%rsp), %eax
movl %eax, %esi
shrl $0x1f, %esi
addl %eax, %esi
sarl %esi
movq %rbx, %rdi
callq 0x89b4
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x6497
movq %r15, %rdi
callq 0x931a
movl 0x18(%r14), %esi
leal 0x7(%rsi), %ecx
leal 0xe(%rsi), %edx
testl %ecx, %ecx
cmovnsl %ecx, %edx
sarl $0x3, %edx
leal (%rax,%rdx), %r15d
addl $0x8, %r15d
leaq 0x3745(%rip), %rdi      # 0xb4b4
xorl %eax, %eax
callq 0x20c0
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
movsd %xmm0, 0x8(%rsp)
movq %r12, %rdi
callq 0x931a
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd 0x8(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd 0x252b(%rip), %xmm0     # 0xa2d0
subsd %xmm1, %xmm0
mulsd 0x2527(%rip), %xmm0     # 0xa2d8
leaq 0x33cf(%rip), %rdi      # 0xb187
movl %r15d, %esi
movb $0x1, %al
callq 0x20c0
movq %rbx, %rdi
callq 0x89f6
movq %r14, %rdi
callq 0x7e86
leaq 0x80(%rsp), %rdi
callq 0x9312
leaq 0xb8(%rsp), %rdi
callq 0x9312
movl %ebp, %eax
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
callq 0x22ce
jmp 0x7e1c
movq %r15, %rdi
callq 0x228f
jmp 0x7e1c
movq %r15, %rdi
callq 0x2250
movl $0x1, %ebp
jmp 0x7dec
leaq 0x36f5(%rip), %rdi      # 0xb51f
jmp 0x7e3c
leaq 0x34e6(%rip), %rdi      # 0xb319
jmp 0x7e5e
leaq 0x3525(%rip), %rdi      # 0xb361
xorl %eax, %eax
callq 0x22ef
jmp 0x7e65
leaq 0x3540(%rip), %rdi      # 0xb38c
jmp 0x7e5e
leaq 0x357f(%rip), %rdi      # 0xb3d4
jmp 0x7e5e
leaq 0x35bd(%rip), %rdi      # 0xb41b
xorl %eax, %eax
callq 0x22ef
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x21f0
nop