// File: /workspace/github_c_makefile_star2_O3/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 0x2d7b(%rip), %rax      # 0xa594
movq %rax, 0x18(%rsp)
movl $0xc00000, 0x28(%rsp)   # imm = 0xC00000
movq $0x0, 0x8(%rsp)
movl $0xc00000, (%rsp)       # imm = 0xC00000
leaq 0x8383(%rip), %r13      # 0xfbc0
leaq 0x7c(%rsp), %rbp
leaq 0x289b(%rip), %r12      # 0xa0e4
xorl %ebx, %ebx
movq 0xb7c6(%rip), %rdx      # 0x13018
movl %r14d, %edi
movq %r15, %rsi
movq %r13, %rcx
movq %rbp, %r8
callq 0x20b0
cmpl $0x62, %eax
jle 0x7882
addl $-0x63, %eax
cmpl $0x10, %eax
ja 0x7dea
movslq (%r12,%rax,4), %rax
addq %r12, %rax
jmpq *%rax
orl $0x8, %ebx
jmp 0x784b
leal -0x42(%rax), %ecx
cmpl $0xb, %ecx
ja 0x78a2
leaq 0x2823(%rip), %rdx      # 0xa0b4
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
orl $0x200, %ebx            # imm = 0x200
jmp 0x784b
cmpl $0x31, %eax
jne 0x7941
orl $0x20, %ebx
jmp 0x784b
orl $0x40, %ebx
jmp 0x784b
orl $0x100, %ebx            # imm = 0x100
jmp 0x784b
orl $0x80, %ebx
jmp 0x784b
movq 0x870c(%rip), %rax      # 0xffd8
movq (%rax), %rdi
callq 0x21d0
movl %eax, (%rsp)
movl %eax, 0x28(%rsp)
jmp 0x784b
orl $0x4, %ebx
jmp 0x784b
orl $0x1, %ebx
jmp 0x784b
movq 0x86e1(%rip), %rax      # 0xffd8
movq (%rax), %rax
movq %rax, 0x18(%rsp)
jmp 0x784b
orl $0x10, %ebx
jmp 0x784b
movq 0x86c5(%rip), %rax      # 0xffd8
movq (%rax), %rax
movq %rax, 0x20(%rsp)
jmp 0x784b
orl $0x2, %ebx
jmp 0x784b
movq 0x86a9(%rip), %rax      # 0xffd8
movq (%rax), %rcx
movq %rcx, 0x8(%rsp)
movq %rcx, 0x10(%rsp)
jmp 0x784b
cmpl $-0x1, %eax
jne 0x7dea
movl %ebx, %eax
notl %eax
testl $0x110, %eax            # imm = 0x110
je 0x7e17
testb $0x1, (%rsp)
jne 0x7e20
movl %ebx, %eax
andl $0x30, %eax
cmpl $0x20, %eax
je 0x7e33
movl %ebx, %eax
andl $0x58, %eax
cmpl $0x40, %eax
je 0x7e3c
movl $0x80, %ebp
movl %ebx, %eax
andl $0x98, %eax
cmpl %ebp, %eax
je 0x7e45
testb $0x8, %bl
jne 0x7b65
movq 0x862d(%rip), %rax      # 0xffd0
movslq (%rax), %rbp
cmpl %ebp, %r14d
je 0x7df4
testb $0x1, %bl
sete %al
cmpq $0x0, 0x8(%rsp)
sete %cl
andb %al, %cl
cmpb $0x1, %cl
je 0x7dfe
movl %ebx, %eax
andl $0x3, %eax
cmpl $0x2, %eax
jne 0x7a4d
movq 0x8(%rsp), %r12
movq %r12, %rdi
callq 0x20a0
movq %rax, %r13
leaq 0xd0(%rsp), %rdi
movq %r12, %rsi
callq 0x2050
cmpl $0x5, %r13d
jl 0x7a24
movl %r13d, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
leaq (%rsp,%rax), %r12
addq $0xcc, %r12
leaq 0x3aca(%rip), %rsi      # 0xb4dd
movl $0x4, %edx
movq %r12, %rdi
callq 0x2150
testl %eax, %eax
je 0x7a32
movslq %r13d, %rax
leaq (%rsp,%rax), %r12
addq $0xd0, %r12
movb $0x0, 0x4(%r12)
movl $0x70616d2e, (%r12)     # imm = 0x70616D2E
leaq 0xd0(%rsp), %rax
movq %rax, 0x30(%rsp)
cmpl %ebp, %r14d
jle 0x7b42
leaq (%r15,%rbp,8), %rax
movq %rax, (%rsp)
subl %ebp, %r14d
xorl %ebp, %ebp
leaq 0x98(%rsp), %r15
movq (%rsp), %rax
movq (%rax,%rbp,8), %rsi
movq %r15, %rdi
callq 0x8558
movq 0xa8(%rsp), %rax
movzbl (%rax), %esi
cmpl $0x80, %esi
je 0x7aa2
cmpl $0xf0, %esi
je 0x7ada
cmpl $0x82, %esi
jne 0x7e0e
movq %r15, %rdi
movl %ebx, %esi
callq 0x4c62
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 0x7b0a
movq %r15, %rdi
movl %ebx, %esi
callq 0x5e5a
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 0x8540
movq %rax, (%r13)
movslq (%r15), %rcx
movq %r12, -0x8(%rax,%rcx,8)
leaq 0x98(%rsp), %r15
movq %r15, %rdi
callq 0x8612
incq %rbp
cmpl %ebp, %r14d
jne 0x7a6b
testb $0x1, %bl
jne 0x7b53
leaq 0x10(%rsp), %rdi
movl %ebx, %esi
callq 0x6bb7
leaq 0x10(%rsp), %rdi
callq 0x2bf3
xorl %r14d, %r14d
jmp 0x7dd5
leaq 0x80(%rsp), %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x948c
movq 0x8448(%rip), %r12      # 0xffc8
movq (%r12), %rdi
callq 0x2220
movq (%r12), %rsi
movl %eax, %edi
callq 0x2170
cmpl $-0x1, %eax
je 0x7bdd
leaq 0x80(%rsp), %r14
leaq 0xd0(%rsp), %r15
movq (%r12), %rdi
callq 0x2220
movb %al, 0xd0(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x957e
movq (%r12), %rdi
callq 0x2220
movq (%r12), %rsi
movl %eax, %edi
callq 0x2170
cmpl $-0x1, %eax
jne 0x7ba9
leaq 0xb8(%rsp), %r15
xorl %r14d, %r14d
movl $0xc, %esi
movq %r15, %rdi
xorl %edx, %edx
callq 0x948c
leaq 0x80(%rsp), %rsi
movq %r15, %rdi
callq 0x63f6
movq %r15, %rdi
callq 0x94be
testl %eax, %eax
jle 0x7dbb
movl %ebx, %r15d
andl $0x40, %r15d
andl %ebx, %ebp
leaq 0xb8(%rsp), %r12
movq %r12, %rdi
callq 0x94be
leaq 0x37f5(%rip), %rdi      # 0xb42c
movl %eax, %esi
xorl %eax, %eax
callq 0x20c0
movq %r12, %rdi
callq 0x86b8
movq %r12, %rdi
movl %eax, %esi
callq 0x8759
leaq 0xd0(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
xorl %edx, %edx
movl %r15d, %ecx
movl %ebp, %r8d
callq 0x89b0
leaq 0x98(%rsp), %r15
movq %r15, %rdi
callq 0x7e60
leaq 0x80(%rsp), %r13
movq %r15, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x6537
movq %r12, %rdi
callq 0x94be
movl 0x18(%r15), %esi
leal 0x7(%rsi), %ecx
leal 0xe(%rsi), %edx
testl %ecx, %ecx
cmovnsl %ecx, %edx
sarl $0x3, %edx
leal (%rax,%rdx), %ebp
addl $0x8, %ebp
leaq 0x3471(%rip), %rdi      # 0xb12b
xorl %eax, %eax
callq 0x20c0
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0x8(%rsp)
movq %r13, %rdi
callq 0x94be
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd 0x8(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd 0x25e4(%rip), %xmm0     # 0xa2d0
subsd %xmm1, %xmm0
mulsd 0x25e0(%rip), %xmm0     # 0xa2d8
leaq 0x3450(%rip), %rdi      # 0xb14f
movl %ebp, %esi
movb $0x1, %al
callq 0x20c0
movl (%rsp), %ebp
sarl %ebp
leaq 0x374c(%rip), %rdi      # 0xb460
movl %ebp, %esi
xorl %eax, %eax
callq 0x20c0
movq %rbx, %rdi
movl %ebp, %esi
callq 0x8a43
movq %r15, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x6537
movq %r12, %rdi
callq 0x94be
movl 0x18(%r15), %esi
leal 0x7(%rsi), %ecx
leal 0xe(%rsi), %edx
testl %ecx, %ecx
cmovnsl %ecx, %edx
sarl $0x3, %edx
leal (%rax,%rdx), %ebp
addl $0x8, %ebp
leaq 0x3720(%rip), %rdi      # 0xb47c
xorl %eax, %eax
callq 0x20c0
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
movsd %xmm0, (%rsp)
movq %r13, %rdi
callq 0x94be
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd (%rsp), %xmm1
divsd %xmm0, %xmm1
movsd 0x2541(%rip), %xmm0     # 0xa2d0
subsd %xmm1, %xmm0
mulsd 0x253d(%rip), %xmm0     # 0xa2d8
leaq 0x33ad(%rip), %rdi      # 0xb14f
movl %ebp, %esi
movb $0x1, %al
callq 0x20c0
movq %rbx, %rdi
callq 0x8a85
movq %r15, %rdi
callq 0x7e76
leaq 0x80(%rsp), %rdi
callq 0x94b6
leaq 0xb8(%rsp), %rdi
callq 0x94b6
movl %r14d, %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 0x7e06
movq %r15, %rdi
callq 0x228f
jmp 0x7e06
movq %r15, %rdi
callq 0x2250
movl $0x1, %r14d
jmp 0x7dd5
leaq 0x36d2(%rip), %rdi      # 0xb4e7
jmp 0x7e2a
leaq 0x34c3(%rip), %rdi      # 0xb2e1
jmp 0x7e4c
leaq 0x3502(%rip), %rdi      # 0xb329
movl (%rsp), %esi
xorl %eax, %eax
callq 0x22ef
jmp 0x7e53
leaq 0x351a(%rip), %rdi      # 0xb354
jmp 0x7e4c
leaq 0x3559(%rip), %rdi      # 0xb39c
jmp 0x7e4c
leaq 0x3597(%rip), %rdi      # 0xb3e3
xorl %eax, %eax
callq 0x22ef
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x21f0
nopl (%rax)