#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(unsigned char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ process_func(int /*<<< orphan*/ *, unsigned long, int, int *,
                                unsigned char *, unsigned char *, int,
                                unsigned long, unsigned long);
int /*<<< orphan*/ strcmp(char *, char *);
int strlen(char const *);
unsigned long strtoul(char const *, char **, int);
int main(int ac, char **av) {
  unsigned long func = -1;
  const char *funcstr = NULL;
  unsigned char *opcode_buf = NULL;
  unsigned char *intrinsic_buf = NULL;
  long sz;
  int i = 0;
  int found = 0;
  int mode = 0;
  unsigned long opcode = -1;
  unsigned long intrinsic = -1;
  FILE *f;
  printf("Ultima 7 usecode disassembler v0.7\n\n");
  if (ac == 3) {
    if (!strcmp(av[1], "-o")) {
      char *stopstr;
      opcode = strtoul(av[2], &stopstr, 16);
      if (stopstr - av[2] < strlen(av[2]))
        opcode = -1;
      else
        mode = 4;
    } else if (!strcmp(av[1], "-i")) {
      char *stopstr;
      intrinsic = strtoul(av[2], &stopstr, 16);
      if (stopstr - av[2] < strlen(av[2]))
        intrinsic = -1;
      else
        mode = 5;
    }
  } else if (ac == 2) {
    if (!strcmp(av[1], "-l"))
      mode = 2;
    else if (!strcmp(av[1], "-c"))
      mode = 3;
    else {
      char *stopstr;
      funcstr = av[1];
      func = strtoul(funcstr, &stopstr, 16);
      if (stopstr - funcstr < strlen(funcstr))
        func = -1;
      else
        mode = 1;
    }
  }
  if (mode == 0) {
    printf("Usage:\n");
    printf("\tucdump -l - prints list of all present functions\n");
    printf("\tucdump -c - scans the whole usecode file for unknown opcodes\n");
    printf("\tucdump -o <hex number> - prints list of functions which use ");
    printf("the given opcode\n");
    printf("\tucdump -i <hex number> - prints list of functions which use ");
    printf("the given intrinsic function\n");
    printf("\tucdump <hex number> - disassembles single function to stdout\n");
    return -1;
  }
  if (mode != 2) {
    opcode_buf = (unsigned char *)malloc(256);
    intrinsic_buf = (unsigned char *)malloc(256);
    if ((opcode_buf == NULL) || (intrinsic_buf == NULL)) {
      free(opcode_buf);
      free(intrinsic_buf);
      printf("Out of memory\n");
      return -2;
    }
    memset(opcode_buf, 0, 256);
    memset(intrinsic_buf, 0, 256);
  }
  f = fopen("usecode", "r");
  if (f == NULL) {
    free(opcode_buf);
    free(intrinsic_buf);
    printf("Failed to open usecode file\n\n");
    return -2;
  }
  fseek(f, 0, SEEK_END);
  sz = ftell(f);
  fseek(f, 0, SEEK_SET);
  if (mode == 1)
    printf("Looking for function number %08lx\n\n", func);
  while (ftell(f) < sz) {
    process_func(f, func, i, &found, opcode_buf, intrinsic_buf, (mode == 3),
                 opcode, intrinsic);
    if (((mode != 4) && (mode != 5)) || found)
      i++;
    if ((mode == 4) || (mode == 5))
      found = 0;
  }
  if (func == -1) {
    if (ftell(f) != sz)
      printf("Problem, tell = %ld!\n", ftell(f));
    printf("Functions: %d\n", i);
  }
  if (((mode == 1) || (mode == 4)) && !found)
    printf("Function not found.\n");
  fclose(f);
  if ((mode == 1) || (mode == 3)) {
    if (opcode_buf) {
      int found = 0;
      for (i = 0; i < 255; i++)
        if (opcode_buf[i]) {
          if (!found) {
            printf("Undefined opcodes found\n");
            found = 1;
          }
          printf("0x%02x (%d times)\n", (unsigned)i, opcode_buf[i]);
        }
    }
    if (intrinsic_buf) {
      int found = 0;
      for (i = 0; i < 255; i++)
        if (intrinsic_buf[i]) {
          if (!found) {
            printf("Undefined intrinsic functions found\n");
            found = 1;
          }
          printf("0x%02x (%d times)\n", (unsigned)i, intrinsic_buf[i]);
        }
    }
  }
  free(opcode_buf);
  free(intrinsic_buf);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0xffffffffffffffff,-0x18(%rbp)
ff
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
movq   $0xffffffffffffffff,-0x50(%rbp)
ff
movq   $0xffffffffffffffff,-0x58(%rbp)
ff
lea    0xddb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpl   $0x3,-0x8(%rbp)
jne    1350 <main+0x190>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xde0(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    12be <main+0xfe>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x68(%rbp),%rsi
mov    $0x10,%edx
call   10e0 <strtoul@plt>
mov    %rax,-0x50(%rbp)
mov    -0x68(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    0x10(%rcx),%rcx
sub    %rcx,%rax
mov    %rax,-0x88(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x88(%rbp),%rax
movslq %ecx,%rcx
cmp    %rcx,%rax
jge    12b2 <main+0xf2>
movq   $0xffffffffffffffff,-0x50(%rbp)
ff
jmp    12b9 <main+0xf9>
movl   $0x4,-0x44(%rbp)
jmp    134b <main+0x18b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd5b(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    1346 <main+0x186>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x70(%rbp),%rsi
mov    $0x10,%edx
call   10e0 <strtoul@plt>
mov    %rax,-0x58(%rbp)
mov    -0x70(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    0x10(%rcx),%rcx
sub    %rcx,%rax
mov    %rax,-0x90(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x90(%rbp),%rax
movslq %ecx,%rcx
cmp    %rcx,%rax
jge    133a <main+0x17a>
movq   $0xffffffffffffffff,-0x58(%rbp)
ff
jmp    1341 <main+0x181>
movl   $0x5,-0x44(%rbp)
jmp    1346 <main+0x186>
jmp    134b <main+0x18b>
jmp    1426 <main+0x266>
cmpl   $0x2,-0x8(%rbp)
jne    1421 <main+0x261>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xcc2(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    1383 <main+0x1c3>
movl   $0x2,-0x44(%rbp)
jmp    141c <main+0x25c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xc9c(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    13ac <main+0x1ec>
movl   $0x3,-0x44(%rbp)
jmp    1417 <main+0x257>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x78(%rbp),%rsi
mov    $0x10,%edx
call   10e0 <strtoul@plt>
mov    %rax,-0x18(%rbp)
mov    -0x78(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x98(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x98(%rbp),%rax
movslq %ecx,%rcx
cmp    %rcx,%rax
jge    140b <main+0x24b>
movq   $0xffffffffffffffff,-0x18(%rbp)
ff
jmp    1412 <main+0x252>
movl   $0x1,-0x44(%rbp)
jmp    1417 <main+0x257>
jmp    141c <main+0x25c>
jmp    1421 <main+0x261>
jmp    1426 <main+0x266>
cmpl   $0x0,-0x44(%rbp)
jne    14ac <main+0x2ec>
lea    0xbfa(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xbf4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xc19(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xc4a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xc7a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xc7e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xcae(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xcbe(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1839 <main+0x679>
cmpl   $0x2,-0x44(%rbp)
je     1534 <main+0x374>
mov    $0x100,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    $0x100,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     14e8 <main+0x328>
cmpq   $0x0,-0x30(%rbp)
jne    1514 <main+0x354>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
lea    0xc95(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1839 <main+0x679>
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
mov    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
lea    0xc6a(%rip),%rdi
lea    0xc6b(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
jne    1582 <main+0x3c2>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
lea    0xc40(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1839 <main+0x679>
mov    -0x60(%rbp),%rdi
mov    0x2a5b(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    -0x60(%rbp),%rdi
call   1090 <ftell@plt>
mov    %rax,-0x38(%rbp)
mov    -0x60(%rbp),%rdi
mov    0x2a2a(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10c0 <fseek@plt>
cmpl   $0x1,-0x44(%rbp)
jne    15d3 <main+0x413>
mov    -0x18(%rbp),%rsi
lea    0xc01(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    15d8 <main+0x418>
mov    -0x60(%rbp),%rdi
call   1090 <ftell@plt>
cmp    -0x38(%rbp),%rax
jge    1671 <main+0x4b1>
mov    -0x60(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x3c(%rbp),%edx
mov    -0x28(%rbp),%r8
mov    -0x30(%rbp),%r9
cmpl   $0x3,-0x44(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%r11d
mov    -0x50(%rbp),%r10
mov    -0x58(%rbp),%rax
lea    -0x40(%rbp),%rcx
mov    %r11d,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   10b0 <process_func@plt>
cmpl   $0x4,-0x44(%rbp)
je     163e <main+0x47e>
cmpl   $0x5,-0x44(%rbp)
jne    1648 <main+0x488>
cmpl   $0x0,-0x40(%rbp)
je     1651 <main+0x491>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
cmpl   $0x4,-0x44(%rbp)
je     1665 <main+0x4a5>
cmpl   $0x5,-0x44(%rbp)
jne    166c <main+0x4ac>
movl   $0x0,-0x40(%rbp)
jmp    15d8 <main+0x418>
cmpq   $0xffffffffffffffff,-0x18(%rbp)
jne    16ba <main+0x4fa>
mov    -0x60(%rbp),%rdi
call   1090 <ftell@plt>
cmp    -0x38(%rbp),%rax
je     16a9 <main+0x4e9>
mov    -0x60(%rbp),%rdi
call   1090 <ftell@plt>
mov    %rax,%rsi
lea    0xb4f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x3c(%rbp),%esi
lea    0xb54(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpl   $0x1,-0x44(%rbp)
je     16ce <main+0x50e>
cmpl   $0x4,-0x44(%rbp)
jne    16e6 <main+0x526>
cmpl   $0x0,-0x40(%rbp)
jne    16e6 <main+0x526>
lea    0xb37(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x60(%rbp),%rdi
call   1040 <fclose@plt>
cmpl   $0x1,-0x44(%rbp)
je     1703 <main+0x543>
cmpl   $0x3,-0x44(%rbp)
jne    1820 <main+0x660>
cmpq   $0x0,-0x28(%rbp)
je     178f <main+0x5cf>
movl   $0x0,-0x7c(%rbp)
movl   $0x0,-0x3c(%rbp)
cmpl   $0xff,-0x3c(%rbp)
jge    178a <main+0x5ca>
mov    -0x28(%rbp),%rax
movslq -0x3c(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     1777 <main+0x5b7>
cmpl   $0x0,-0x7c(%rbp)
jne    175a <main+0x59a>
lea    0xadf(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x7c(%rbp)
mov    -0x3c(%rbp),%esi
mov    -0x28(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xad4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    177c <main+0x5bc>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    171c <main+0x55c>
jmp    178f <main+0x5cf>
cmpq   $0x0,-0x30(%rbp)
je     181b <main+0x65b>
movl   $0x0,-0x80(%rbp)
movl   $0x0,-0x3c(%rbp)
cmpl   $0xff,-0x3c(%rbp)
jge    1816 <main+0x656>
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     1803 <main+0x643>
cmpl   $0x0,-0x80(%rbp)
jne    17e6 <main+0x626>
lea    0xa7f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x80(%rbp)
mov    -0x3c(%rbp),%esi
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xa48(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1808 <main+0x648>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    17a8 <main+0x5e8>
jmp    181b <main+0x65b>
jmp    1820 <main+0x660>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
movl   $0x0,0xc(%rsp)
lea    0xefc(%rip),%rdi
call   1040 <puts@plt>
cmp    $0x2,%ebp
je     1288 <main+0xb8>
cmp    $0x3,%ebp
jne    132e <main+0x15e>
mov    0x8(%rbx),%rbp
lea    0xdec(%rip),%rsi
mov    %rbp,%rdi
call   1090 <strcmp@plt>
test   %eax,%eax
je     12fa <main+0x12a>
lea    0xdd8(%rip),%rsi
mov    %rbp,%rdi
call   1090 <strcmp@plt>
test   %eax,%eax
jne    132e <main+0x15e>
mov    0x10(%rbx),%rdi
lea    0x10(%rsp),%rsi
mov    $0x10,%edx
call   10f0 <strtoul@plt>
mov    %rax,%r13
mov    0x10(%rsp),%rbp
mov    0x10(%rbx),%rdi
sub    %rdi,%rbp
call   1060 <strlen@plt>
cltq
cmp    %rax,%rbp
jl     132e <main+0x15e>
mov    $0x5,%r12d
mov    $0xffffffffffffffff,%r15
movq   $0xffffffffffffffff,0x20(%rsp)
ff ff
jmp    13dc <main+0x20c>
mov    0x8(%rbx),%rbx
lea    0xd73(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcmp@plt>
test   %eax,%eax
je     139c <main+0x1cc>
lea    0xd5f(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcmp@plt>
movq   $0xffffffffffffffff,0x20(%rsp)
ff ff
test   %eax,%eax
je     13c0 <main+0x1f0>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x10,%edx
call   10f0 <strtoul@plt>
mov    %rax,%r15
mov    0x10(%rsp),%rbp
sub    %rbx,%rbp
mov    %rbx,%rdi
call   1060 <strlen@plt>
cltq
cmp    %rax,%rbp
jl     132e <main+0x15e>
mov    $0x1,%r12d
jmp    13d5 <main+0x205>
mov    0x10(%rbx),%rdi
lea    0x10(%rsp),%rsi
mov    $0x10,%edx
call   10f0 <strtoul@plt>
mov    %rax,0x20(%rsp)
mov    0x10(%rsp),%rbp
mov    0x10(%rbx),%rdi
sub    %rdi,%rbp
call   1060 <strlen@plt>
cltq
cmp    %rax,%rbp
jge    13c8 <main+0x1f8>
lea    0xe58(%rip),%rdi
call   1040 <puts@plt>
lea    0xe53(%rip),%rdi
call   1040 <puts@plt>
lea    0xe79(%rip),%rdi
call   1040 <puts@plt>
lea    0xcb3(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe9d(%rip),%rdi
call   1040 <puts@plt>
lea    0xcd7(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe94(%rip),%rdi
call   1040 <puts@plt>
lea    0xea5(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
jmp    16cf <main+0x4ff>
mov    $0x2,%r12d
mov    $0xffffffffffffffff,%r13
xor    %ebx,%ebx
movq   $0xffffffffffffffff,0x20(%rsp)
ff ff
mov    $0xffffffffffffffff,%r15
xor    %r14d,%r14d
jmp    1426 <main+0x256>
mov    $0x3,%r12d
jmp    13ce <main+0x1fe>
mov    $0x4,%r12d
mov    $0xffffffffffffffff,%r15
mov    $0xffffffffffffffff,%r13
mov    $0x100,%edi
call   10b0 <malloc@plt>
mov    %rax,%rbx
mov    $0x100,%edi
call   10b0 <malloc@plt>
mov    %rax,%r14
test   %rbx,%rbx
je     162b <main+0x45b>
test   %r14,%r14
je     162b <main+0x45b>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1080 <memset@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1080 <memset@plt>
lea    0xc5b(%rip),%rdi
lea    0xc5c(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
je     1644 <main+0x474>
mov    %rax,%rbp
mov    %r13,0x40(%rsp)
mov    %r15,0x28(%rsp)
mov    %r14,0x30(%rsp)
mov    %rbx,0x38(%rsp)
mov    0x2b88(%rip),%rax
mov    (%rax),%edx
xor    %r15d,%r15d
mov    %rbp,%rdi
xor    %esi,%esi
call   10d0 <fseek@plt>
mov    %rbp,%rdi
call   10a0 <ftell@plt>
mov    %rax,%r13
mov    0x2b57(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   10d0 <fseek@plt>
mov    %r12d,0x1c(%rsp)
cmp    $0x1,%r12d
jne    14ab <main+0x2db>
lea    0xbf3(%rip),%rdi
mov    0x28(%rsp),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbp,%rdi
call   10a0 <ftell@plt>
cmp    %r13,%rax
jge    1545 <main+0x375>
xor    %r14d,%r14d
mov    0x1c(%rsp),%ebx
cmp    $0x3,%ebx
sete   %r14b
and    $0xfffffffe,%ebx
xor    %r15d,%r15d
jmp    14f3 <main+0x323>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl %al,%eax
add    %eax,%r15d
mov    %rbp,%rdi
call   10a0 <ftell@plt>
cmp    %r13,%rax
jge    1545 <main+0x375>
cmp    $0x4,%ebx
setne  %r12b
sub    $0x8,%rsp
mov    %rbp,%rdi
mov    0x30(%rsp),%rsi
mov    %r15d,%edx
lea    0x14(%rsp),%rcx
mov    0x40(%rsp),%r8
mov    0x38(%rsp),%r9
push   0x48(%rsp)
push   0x30(%rsp)
push   %r14
call   10c0 <process_func@plt>
add    $0x20,%rsp
cmpl   $0x0,0xc(%rsp)
setne  %al
or     %r12b,%al
cmp    $0x4,%ebx
jne    14e0 <main+0x310>
movl   $0x0,0xc(%rsp)
jmp    14e0 <main+0x310>
cmpq   $0xffffffffffffffff,0x28(%rsp)
mov    0x38(%rsp),%rbx
mov    0x30(%rsp),%r14
mov    0x1c(%rsp),%r12d
jne    1593 <main+0x3c3>
mov    %rbp,%rdi
call   10a0 <ftell@plt>
cmp    %r13,%rax
je     1582 <main+0x3b2>
mov    %rbp,%rdi
call   10a0 <ftell@plt>
lea    0xb3e(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xb43(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
cmp    $0x1,%r12d
sete   %al
cmp    $0x4,%r12d
sete   %cl
or     %al,%cl
cmp    $0x1,%cl
jne    15bb <main+0x3eb>
cmpl   $0x0,0xc(%rsp)
jne    15bb <main+0x3eb>
lea    0xb5c(%rip),%rdi
call   1040 <puts@plt>
mov    %rbp,%rdi
call   1050 <fclose@plt>
and    $0xfffffffd,%r12d
cmp    $0x1,%r12d
jne    16bd <main+0x4ed>
test   %rbx,%rbx
je     1667 <main+0x497>
lea    0xb69(%rip),%r15
lea    0xaf3(%rip),%r12
xor    %ebp,%ebp
xor    %eax,%eax
jmp    1611 <main+0x441>
xchg   %ax,%ax
movzbl %cl,%edx
mov    %r12,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%eax
add    $0x1,%rbp
cmp    $0xff,%rbp
je     1667 <main+0x497>
movzbl (%rbx,%rbp,1),%ecx
test   %cl,%cl
je     1604 <main+0x434>
test   %eax,%eax
jne    15f0 <main+0x420>
mov    %r15,%rdi
call   1040 <puts@plt>
movzbl (%rbx,%rbp,1),%ecx
jmp    15f0 <main+0x420>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
lea    0xb3d(%rip),%rdi
jmp    165b <main+0x48b>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
lea    0xb07(%rip),%rdi
call   1040 <puts@plt>
mov    $0xfffffffe,%eax
jmp    16cf <main+0x4ff>
test   %r14,%r14
je     16bd <main+0x4ed>
lea    0xab3(%rip),%r15
lea    0xa61(%rip),%r12
xor    %ebp,%ebp
xor    %eax,%eax
jmp    16a1 <main+0x4d1>
movzbl %cl,%edx
mov    %r12,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%eax
add    $0x1,%rbp
cmp    $0xff,%rbp
je     16bd <main+0x4ed>
movzbl (%r14,%rbp,1),%ecx
test   %cl,%cl
je     1694 <main+0x4c4>
test   %eax,%eax
jne    1680 <main+0x4b0>
mov    %r15,%rdi
call   1040 <puts@plt>
movzbl (%r14,%rbp,1),%ecx
jmp    1680 <main+0x4b0>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"Ultima 7 usecode disassembler v0.7\0A\0A\00"
@.str.1 = [3 x i8] c"-o\00"
@.str.2 = [3 x i8] c"-i\00"
@.str.3 = [3 x i8] c"-l\00"
@.str.4 = [3 x i8] c"-c\00"
@.str.5 = [8 x i8] c"Usage:\0A\00"
@.str.6 = [51 x i8] c"\09ucdump -l - prints list of all present functions\0A\00"
@.str.7 = [63 x i8] c"\09ucdump -c - scans the whole usecode file for unknown opcodes\0A\00"
@.str.8 = [62 x i8] c"\09ucdump -o <hex number> - prints list of functions which use \00"
@.str.9 = [18 x i8] c"the given opcode\0A\00"
@.str.10 = [62 x i8] c"\09ucdump -i <hex number> - prints list of functions which use \00"
@.str.11 = [30 x i8] c"the given intrinsic function\0A\00"
@.str.12 = [63 x i8] c"\09ucdump <hex number> - disassembles single function to stdout\0A\00"
@.str.13 = [15 x i8] c"Out of memory\0A\00"
@.str.14 = [8 x i8] c"usecode\00"
@.str.15 = [2 x i8] c"r\00"
@.str.16 = [30 x i8] c"Failed to open usecode file\0A\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.17 = [36 x i8] c"Looking for function number %08lx\0A\0A\00"
@.str.18 = [22 x i8] c"Problem, tell = %ld!\0A\00"
@.str.19 = [15 x i8] c"Functions: %d\0A\00"
@.str.20 = [21 x i8] c"Function not found.\0A\00"
@.str.21 = [25 x i8] c"Undefined opcodes found\0A\00"
@.str.22 = [19 x i8] c"0x%02x (%d times)\0A\00"
@.str.23 = [37 x i8] c"Undefined intrinsic functions found\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i64
%15 = alloca i64
%16 = alloca i32*
%17 = alloca i8*
%18 = alloca i8*
%19 = alloca i8*
%20 = alloca i32
%21 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 -1, i64* %6
store i8* null, i8** %7
store i8* null, i8** %8
store i8* null, i8** %9
store i32 0, i32* %11
store i32 0, i32* %12
store i32 0, i32* %13
store i64 -1, i64* %14
store i64 -1, i64* %15
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%23 = load i32, i32* %4
%24 = icmp eq i32 %23, 3
br i1 %24, label %25, label %81
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @strcmp(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%30 = icmp ne i32 %29, 0
br i1 %30, label %52, label %31
31: ; preds = %25
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = call i64 @strtoul(i8* %34, i8** %17, i32 16)
store i64 %35, i64* %14
%36 = load i8*, i8** %17
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 2
%39 = load i8*, i8** %38
%40 = ptrtoint i8* %36 to i64
%41 = ptrtoint i8* %39 to i64
%42 = sub i64 %40, %41
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 2
%45 = load i8*, i8** %44
%46 = call i32 @strlen(i8* %45)
%47 = sext i32 %46 to i64
%48 = icmp slt i64 %42, %47
br i1 %48, label %49, label %50
49: ; preds = %31
store i64 -1, i64* %14
br label %51
50: ; preds = %31
store i32 4, i32* %13
br label %51
51: ; preds = %50, %49
br label %80
52: ; preds = %25
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 1
%55 = load i8*, i8** %54
%56 = call i32 @strcmp(i8* %55, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%57 = icmp ne i32 %56, 0
br i1 %57, label %79, label %58
58: ; preds = %52
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i64 2
%61 = load i8*, i8** %60
%62 = call i64 @strtoul(i8* %61, i8** %18, i32 16)
store i64 %62, i64* %15
%63 = load i8*, i8** %18
%64 = load i8**, i8*** %5
%65 = getelementptr inbounds i8*, i8** %64, i64 2
%66 = load i8*, i8** %65
%67 = ptrtoint i8* %63 to i64
%68 = ptrtoint i8* %66 to i64
%69 = sub i64 %67, %68
%70 = load i8**, i8*** %5
%71 = getelementptr inbounds i8*, i8** %70, i64 2
%72 = load i8*, i8** %71
%73 = call i32 @strlen(i8* %72)
%74 = sext i32 %73 to i64
%75 = icmp slt i64 %69, %74
br i1 %75, label %76, label %77
76: ; preds = %58
store i64 -1, i64* %15
br label %78
77: ; preds = %58
store i32 5, i32* %13
br label %78
78: ; preds = %77, %76
br label %79
79: ; preds = %78, %52
br label %80
80: ; preds = %79, %51
br label %119
81: ; preds = %2
%82 = load i32, i32* %4
%83 = icmp eq i32 %82, 2
br i1 %83, label %84, label %118
84: ; preds = %81
%85 = load i8**, i8*** %5
%86 = getelementptr inbounds i8*, i8** %85, i64 1
%87 = load i8*, i8** %86
%88 = call i32 @strcmp(i8* %87, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%89 = icmp ne i32 %88, 0
br i1 %89, label %91, label %90
90: ; preds = %84
store i32 2, i32* %13
br label %117
91: ; preds = %84
%92 = load i8**, i8*** %5
%93 = getelementptr inbounds i8*, i8** %92, i64 1
%94 = load i8*, i8** %93
%95 = call i32 @strcmp(i8* %94, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%96 = icmp ne i32 %95, 0
br i1 %96, label %98, label %97
97: ; preds = %91
store i32 3, i32* %13
br label %116
98: ; preds = %91
%99 = load i8**, i8*** %5
%100 = getelementptr inbounds i8*, i8** %99, i64 1
%101 = load i8*, i8** %100
store i8* %101, i8** %7
%102 = load i8*, i8** %7
%103 = call i64 @strtoul(i8* %102, i8** %19, i32 16)
store i64 %103, i64* %6
%104 = load i8*, i8** %19
%105 = load i8*, i8** %7
%106 = ptrtoint i8* %104 to i64
%107 = ptrtoint i8* %105 to i64
%108 = sub i64 %106, %107
%109 = load i8*, i8** %7
%110 = call i32 @strlen(i8* %109)
%111 = sext i32 %110 to i64
%112 = icmp slt i64 %108, %111
br i1 %112, label %113, label %114
113: ; preds = %98
store i64 -1, i64* %6
br label %115
114: ; preds = %98
store i32 1, i32* %13
br label %115
115: ; preds = %114, %113
br label %116
116: ; preds = %115, %97
br label %117
117: ; preds = %116, %90
br label %118
118: ; preds = %117, %81
br label %119
119: ; preds = %118, %80
%120 = load i32, i32* %13
%121 = icmp eq i32 %120, 0
br i1 %121, label %122, label %131
122: ; preds = %119
%123 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%124 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.6, i64 0, i64 0))
%125 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.7, i64 0, i64 0))
%126 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.8, i64 0, i64 0))
%127 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0))
%128 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.10, i64 0, i64 0))
%129 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.11, i64 0, i64 0))
%130 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.12, i64 0, i64 0))
store i32 -1, i32* %3
br label %322
131: ; preds = %119
%132 = load i32, i32* %13
%133 = icmp ne i32 %132, 2
br i1 %133, label %134, label %155
134: ; preds = %131
%135 = call i64 @malloc(i32 256)
%136 = inttoptr i64 %135 to i8*
store i8* %136, i8** %8
%137 = call i64 @malloc(i32 256)
%138 = inttoptr i64 %137 to i8*
store i8* %138, i8** %9
%139 = load i8*, i8** %8
%140 = icmp eq i8* %139, null
br i1 %140, label %144, label %141
141: ; preds = %134
%142 = load i8*, i8** %9
%143 = icmp eq i8* %142, null
br i1 %143, label %144, label %150
144: ; preds = %141, %134
%145 = load i8*, i8** %8
%146 = call i32 @free(i8* %145)
%147 = load i8*, i8** %9
%148 = call i32 @free(i8* %147)
%149 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.13, i64 0, i64 0))
store i32 -2, i32* %3
br label %322
150: ; preds = %141
%151 = load i8*, i8** %8
%152 = call i32 @memset(i8* %151, i32 0, i32 256)
%153 = load i8*, i8** %9
%154 = call i32 @memset(i8* %153, i32 0, i32 256)
br label %155
155: ; preds = %150, %131
%156 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.14, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.15, i64 0, i64 0))
store i32* %156, i32** %16
%157 = load i32*, i32** %16
%158 = icmp eq i32* %157, null
br i1 %158, label %159, label %165
159: ; preds = %155
%160 = load i8*, i8** %8
%161 = call i32 @free(i8* %160)
%162 = load i8*, i8** %9
%163 = call i32 @free(i8* %162)
%164 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.16, i64 0, i64 0))
store i32 -2, i32* %3
br label %322
165: ; preds = %155
%166 = load i32*, i32** %16
%167 = load i32, i32* @SEEK_END
%168 = call i32 @fseek(i32* %166, i32 0, i32 %167)
%169 = load i32*, i32** %16
%170 = call i64 @ftell(i32* %169)
store i64 %170, i64* %10
%171 = load i32*, i32** %16
%172 = load i32, i32* @SEEK_SET
%173 = call i32 @fseek(i32* %171, i32 0, i32 %172)
%174 = load i32, i32* %13
%175 = icmp eq i32 %174, 1
br i1 %175, label %176, label %179
176: ; preds = %165
%177 = load i64, i64* %6
%178 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.17, i64 0, i64 0), i64 %177)
br label %179
179: ; preds = %176, %165
br label %180
180: ; preds = %215, %179
%181 = load i32*, i32** %16
%182 = call i64 @ftell(i32* %181)
%183 = load i64, i64* %10
%184 = icmp slt i64 %182, %183
br i1 %184, label %185, label %216
185: ; preds = %180
%186 = load i32*, i32** %16
%187 = load i64, i64* %6
%188 = load i32, i32* %11
%189 = load i8*, i8** %8
%190 = load i8*, i8** %9
%191 = load i32, i32* %13
%192 = icmp eq i32 %191, 3
%193 = zext i1 %192 to i32
%194 = load i64, i64* %14
%195 = load i64, i64* %15
%196 = call i32 @process_func(i32* %186, i64 %187, i32 %188, i32* %12, i8* %189, i8* %190, i32 %193, i64 %194, i64 %195)
%197 = load i32, i32* %13
%198 = icmp ne i32 %197, 4
br i1 %198, label %199, label %202
199: ; preds = %185
%200 = load i32, i32* %13
%201 = icmp ne i32 %200, 5
br i1 %201, label %205, label %202
202: ; preds = %199, %185
%203 = load i32, i32* %12
%204 = icmp ne i32 %203, 0
br i1 %204, label %205, label %208
205: ; preds = %202, %199
%206 = load i32, i32* %11
%207 = add nsw i32 %206, 1
store i32 %207, i32* %11
br label %208
208: ; preds = %205, %202
%209 = load i32, i32* %13
%210 = icmp eq i32 %209, 4
br i1 %210, label %214, label %211
211: ; preds = %208
%212 = load i32, i32* %13
%213 = icmp eq i32 %212, 5
br i1 %213, label %214, label %215
214: ; preds = %211, %208
store i32 0, i32* %12
br label %215
215: ; preds = %214, %211
br label %180
216: ; preds = %180
%217 = load i64, i64* %6
%218 = icmp eq i64 %217, -1
br i1 %218, label %219, label %231
219: ; preds = %216
%220 = load i32*, i32** %16
%221 = call i64 @ftell(i32* %220)
%222 = load i64, i64* %10
%223 = icmp ne i64 %221, %222
br i1 %223, label %224, label %228
224: ; preds = %219
%225 = load i32*, i32** %16
%226 = call i64 @ftell(i32* %225)
%227 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.18, i64 0, i64 0), i64 %226)
br label %228
228: ; preds = %224, %219
%229 = load i32, i32* %11
%230 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.19, i64 0, i64 0), i32 %229)
br label %231
231: ; preds = %228, %216
%232 = load i32, i32* %13
%233 = icmp eq i32 %232, 1
br i1 %233, label %237, label %234
234: ; preds = %231
%235 = load i32, i32* %13
%236 = icmp eq i32 %235, 4
br i1 %236, label %237, label %242
237: ; preds = %234, %231
%238 = load i32, i32* %12
%239 = icmp ne i32 %238, 0
br i1 %239, label %242, label %240
240: ; preds = %237
%241 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.20, i64 0, i64 0))
br label %242
242: ; preds = %240, %237, %234
%243 = load i32*, i32** %16
%244 = call i32 @fclose(i32* %243)
%245 = load i32, i32* %13
%246 = icmp eq i32 %245, 1
br i1 %246, label %250, label %247
247: ; preds = %242
%248 = load i32, i32* %13
%249 = icmp eq i32 %248, 3
br i1 %249, label %250, label %317
250: ; preds = %247, %242
%251 = load i8*, i8** %8
%252 = icmp ne i8* %251, null
br i1 %252, label %253, label %283
253: ; preds = %250
store i32 0, i32* %20
store i32 0, i32* %11
br label %254
254: ; preds = %279, %253
%255 = load i32, i32* %11
%256 = icmp slt i32 %255, 255
br i1 %256, label %257, label %282
257: ; preds = %254
%258 = load i8*, i8** %8
%259 = load i32, i32* %11
%260 = sext i32 %259 to i64
%261 = getelementptr inbounds i8, i8* %258, i64 %260
%262 = load i8, i8* %261
%263 = icmp ne i8 %262, 0
br i1 %263, label %264, label %278
264: ; preds = %257
%265 = load i32, i32* %20
%266 = icmp ne i32 %265, 0
br i1 %266, label %269, label %267
267: ; preds = %264
%268 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.21, i64 0, i64 0))
store i32 1, i32* %20
br label %269
269: ; preds = %267, %264
%270 = load i32, i32* %11
%271 = load i8*, i8** %8
%272 = load i32, i32* %11
%273 = sext i32 %272 to i64
%274 = getelementptr inbounds i8, i8* %271, i64 %273
%275 = load i8, i8* %274
%276 = zext i8 %275 to i32
%277 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.22, i64 0, i64 0), i32 %270, i32 %276)
br label %278
278: ; preds = %269, %257
br label %279
279: ; preds = %278
%280 = load i32, i32* %11
%281 = add nsw i32 %280, 1
store i32 %281, i32* %11
br label %254
282: ; preds = %254
br label %283
283: ; preds = %282, %250
%284 = load i8*, i8** %9
%285 = icmp ne i8* %284, null
br i1 %285, label %286, label %316
286: ; preds = %283
store i32 0, i32* %21
store i32 0, i32* %11
br label %287
287: ; preds = %312, %286
%288 = load i32, i32* %11
%289 = icmp slt i32 %288, 255
br i1 %289, label %290, label %315
290: ; preds = %287
%291 = load i8*, i8** %9
%292 = load i32, i32* %11
%293 = sext i32 %292 to i64
%294 = getelementptr inbounds i8, i8* %291, i64 %293
%295 = load i8, i8* %294
%296 = icmp ne i8 %295, 0
br i1 %296, label %297, label %311
297: ; preds = %290
%298 = load i32, i32* %21
%299 = icmp ne i32 %298, 0
br i1 %299, label %302, label %300
300: ; preds = %297
%301 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.23, i64 0, i64 0))
store i32 1, i32* %21
br label %302
302: ; preds = %300, %297
%303 = load i32, i32* %11
%304 = load i8*, i8** %9
%305 = load i32, i32* %11
%306 = sext i32 %305 to i64
%307 = getelementptr inbounds i8, i8* %304, i64 %306
%308 = load i8, i8* %307
%309 = zext i8 %308 to i32
%310 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.22, i64 0, i64 0), i32 %303, i32 %309)
br label %311
311: ; preds = %302, %290
br label %312
312: ; preds = %311
%313 = load i32, i32* %11
%314 = add nsw i32 %313, 1
store i32 %314, i32* %11
br label %287
315: ; preds = %287
br label %316
316: ; preds = %315, %283
br label %317
317: ; preds = %316, %247
%318 = load i8*, i8** %8
%319 = call i32 @free(i8* %318)
%320 = load i8*, i8** %9
%321 = call i32 @free(i8* %320)
store i32 0, i32* %3
br label %322
322: ; preds = %317, %159, %144, %122
%323 = load i32, i32* %3
ret i32 %323
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"-o\00"
@.str.2 = [3 x i8] c"-i\00"
@.str.3 = [3 x i8] c"-l\00"
@.str.4 = [3 x i8] c"-c\00"
@.str.8 = [62 x i8] c"\09ucdump -o <hex number> - prints list of functions which use \00"
@.str.10 = [62 x i8] c"\09ucdump -i <hex number> - prints list of functions which use \00"
@.str.14 = [8 x i8] c"usecode\00"
@.str.15 = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.17 = [36 x i8] c"Looking for function number %08lx\0A\0A\00"
@.str.18 = [22 x i8] c"Problem, tell = %ld!\0A\00"
@.str.19 = [15 x i8] c"Functions: %d\0A\00"
@.str.22 = [19 x i8] c"0x%02x (%d times)\0A\00"
@str = [36 x i8] c"Ultima 7 usecode disassembler v0.7\0A\00"
@str.24 = [20 x i8] c"Function not found.\00"
@str.25 = [36 x i8] c"Undefined intrinsic functions found\00"
@str.26 = [24 x i8] c"Undefined opcodes found\00"
@str.27 = [29 x i8] c"Failed to open usecode file\0A\00"
@str.28 = [14 x i8] c"Out of memory\00"
@str.29 = [7 x i8] c"Usage:\00"
@str.30 = [50 x i8] c"\09ucdump -l - prints list of all present functions\00"
@str.31 = [62 x i8] c"\09ucdump -c - scans the whole usecode file for unknown opcodes\00"
@str.32 = [17 x i8] c"the given opcode\00"
@str.33 = [29 x i8] c"the given intrinsic function\00"
@str.34 = [62 x i8] c"\09ucdump <hex number> - disassembles single function to stdout\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
switch i32 %0, label %61 [
i32 3, label %9
i32 2, label %43
]
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @strcmp(i8* dereferenceable(1) %11, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %27
14: ; preds = %9
%15 = bitcast i8** %4 to i8*
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = call i64 @strtoul(i8* %17, i8** %4, i32 16)
%19 = load i8*, i8** %4
%20 = load i8*, i8** %16
%21 = ptrtoint i8* %19 to i64
%22 = ptrtoint i8* %20 to i64
%23 = sub i64 %21, %22
%24 = tail call i32 @strlen(i8* %20)
%25 = sext i32 %24 to i64
%26 = icmp slt i64 %23, %25
br i1 %26, label %61, label %70
27: ; preds = %9
%28 = tail call i32 @strcmp(i8* dereferenceable(1) %11, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %61
30: ; preds = %27
%31 = bitcast i8** %5 to i8*
%32 = getelementptr inbounds i8*, i8** %1, i64 2
%33 = load i8*, i8** %32
%34 = call i64 @strtoul(i8* %33, i8** %5, i32 16)
%35 = load i8*, i8** %5
%36 = load i8*, i8** %32
%37 = ptrtoint i8* %35 to i64
%38 = ptrtoint i8* %36 to i64
%39 = sub i64 %37, %38
%40 = tail call i32 @strlen(i8* %36)
%41 = sext i32 %40 to i64
%42 = icmp slt i64 %39, %41
br i1 %42, label %61, label %70
43: ; preds = %2
%44 = getelementptr inbounds i8*, i8** %1, i64 1
%45 = load i8*, i8** %44
%46 = tail call i32 @strcmp(i8* dereferenceable(1) %45, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%47 = icmp eq i32 %46, 0
br i1 %47, label %89, label %48
48: ; preds = %43
%49 = tail call i32 @strcmp(i8* dereferenceable(1) %45, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%50 = icmp eq i32 %49, 0
br i1 %50, label %70, label %51
51: ; preds = %48
%52 = bitcast i8** %6 to i8*
%53 = call i64 @strtoul(i8* %45, i8** %6, i32 16)
%54 = load i8*, i8** %6
%55 = ptrtoint i8* %54 to i64
%56 = ptrtoint i8* %45 to i64
%57 = sub i64 %55, %56
%58 = tail call i32 @strlen(i8* %45)
%59 = sext i32 %58 to i64
%60 = icmp slt i64 %57, %59
br i1 %60, label %61, label %70
61: ; preds = %51, %14, %30, %27, %2
%62 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.29, i64 0, i64 0))
%63 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.30, i64 0, i64 0))
%64 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @str.31, i64 0, i64 0))
%65 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @.str.8, i64 0, i64 0))
%66 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.32, i64 0, i64 0))
%67 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @.str.10, i64 0, i64 0))
%68 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.33, i64 0, i64 0))
%69 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @str.34, i64 0, i64 0))
br label %203
70: ; preds = %30, %14, %51, %48
%71 = phi i64 [ -1, %48 ], [ %53, %51 ], [ -1, %14 ], [ -1, %30 ]
%72 = phi i32 [ 3, %48 ], [ 1, %51 ], [ 4, %14 ], [ 5, %30 ]
%73 = phi i64 [ -1, %48 ], [ -1, %51 ], [ %18, %14 ], [ -1, %30 ]
%74 = phi i64 [ -1, %48 ], [ -1, %51 ], [ -1, %14 ], [ %34, %30 ]
%75 = tail call i64 @malloc(i32 256)
%76 = inttoptr i64 %75 to i8*
%77 = tail call i64 @malloc(i32 256)
%78 = inttoptr i64 %77 to i8*
%79 = icmp eq i64 %75, 0
%80 = icmp eq i64 %77, 0
%81 = select i1 %79, i1 true, i1 %80
br i1 %81, label %82, label %86
82: ; preds = %70
%83 = tail call i32 @free(i8* %76)
%84 = tail call i32 @free(i8* %78)
%85 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.28, i64 0, i64 0))
br label %203
86: ; preds = %70
%87 = tail call i32 @memset(i8* %76, i32 0, i32 256)
%88 = tail call i32 @memset(i8* %78, i32 0, i32 256)
br label %89
89: ; preds = %43, %86
%90 = phi i64 [ %74, %86 ], [ -1, %43 ]
%91 = phi i64 [ %73, %86 ], [ -1, %43 ]
%92 = phi i32 [ %72, %86 ], [ 2, %43 ]
%93 = phi i64 [ %71, %86 ], [ -1, %43 ]
%94 = phi i8* [ %76, %86 ], [ null, %43 ]
%95 = phi i8* [ %78, %86 ], [ null, %43 ]
%96 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.14, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.15, i64 0, i64 0))
%97 = icmp eq i32* %96, null
br i1 %97, label %98, label %102
98: ; preds = %89
%99 = tail call i32 @free(i8* %94)
%100 = tail call i32 @free(i8* %95)
%101 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.27, i64 0, i64 0))
br label %203
102: ; preds = %89
%103 = load i32, i32* @SEEK_END
%104 = tail call i32 @fseek(i32* %96, i32 0, i32 %103)
%105 = tail call i64 @ftell(i32* %96)
%106 = load i32, i32* @SEEK_SET
%107 = tail call i32 @fseek(i32* %96, i32 0, i32 %106)
%108 = icmp eq i32 %92, 1
br i1 %108, label %109, label %111
109: ; preds = %102
%110 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.17, i64 0, i64 0), i64 %93)
br label %111
111: ; preds = %109, %102
%112 = call i64 @ftell(i32* %96)
%113 = icmp slt i64 %112, %105
br i1 %113, label %114, label %132
114: ; preds = %111
%115 = icmp eq i32 %92, 3
%116 = zext i1 %115 to i32
%117 = and i32 %92, -2
%118 = icmp ne i32 %117, 4
%119 = icmp eq i32 %117, 4
br label %120
120: ; preds = %114, %129
%121 = phi i32 [ 0, %114 ], [ %127, %129 ]
%122 = call i32 @process_func(i32* %96, i64 %93, i32 %121, i32* %3, i8* %94, i8* %95, i32 %116, i64 %91, i64 %90)
%123 = load i32, i32* %3
%124 = icmp ne i32 %123, 0
%125 = select i1 %118, i1 true, i1 %124
%126 = zext i1 %125 to i32
%127 = add nuw nsw i32 %121, %126
br i1 %119, label %128, label %129
128: ; preds = %120
store i32 0, i32* %3
br label %129
129: ; preds = %120, %128
%130 = call i64 @ftell(i32* %96)
%131 = icmp slt i64 %130, %105
br i1 %131, label %120, label %132
132: ; preds = %129, %111
%133 = phi i32 [ 0, %111 ], [ %127, %129 ]
%134 = icmp eq i64 %93, -1
br i1 %134, label %135, label %143
135: ; preds = %132
%136 = call i64 @ftell(i32* %96)
%137 = icmp eq i64 %136, %105
br i1 %137, label %141, label %138
138: ; preds = %135
%139 = call i64 @ftell(i32* %96)
%140 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.18, i64 0, i64 0), i64 %139)
br label %141
141: ; preds = %138, %135
%142 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.19, i64 0, i64 0), i32 %133)
br label %143
143: ; preds = %141, %132
%144 = icmp eq i32 %92, 4
%145 = or i1 %108, %144
%146 = xor i1 %145, true
%147 = load i32, i32* %3
%148 = icmp ne i32 %147, 0
%149 = select i1 %146, i1 true, i1 %148
br i1 %149, label %152, label %150
150: ; preds = %143
%151 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.24, i64 0, i64 0))
br label %152
152: ; preds = %143, %150
%153 = call i32 @fclose(i32* %96)
%154 = and i32 %92, -3
%155 = icmp eq i32 %154, 1
br i1 %155, label %156, label %200
156: ; preds = %152
%157 = icmp eq i8* %94, null
br i1 %157, label %178, label %158
158: ; preds = %156, %174
%159 = phi i64 [ %176, %174 ], [ 0, %156 ]
%160 = phi i32 [ %175, %174 ], [ 0, %156 ]
%161 = getelementptr inbounds i8, i8* %94, i64 %159
%162 = load i8, i8* %161
%163 = icmp eq i8 %162, 0
br i1 %163, label %174, label %164
164: ; preds = %158
%165 = icmp eq i32 %160, 0
br i1 %165, label %166, label %169
166: ; preds = %164
%167 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.26, i64 0, i64 0))
%168 = load i8, i8* %161
br label %169
169: ; preds = %166, %164
%170 = phi i8 [ %168, %166 ], [ %162, %164 ]
%171 = zext i8 %170 to i32
%172 = trunc i64 %159 to i32
%173 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.22, i64 0, i64 0), i32 %172, i32 %171)
br label %174
174: ; preds = %158, %169
%175 = phi i32 [ 1, %169 ], [ %160, %158 ]
%176 = add nuw nsw i64 %159, 1
%177 = icmp eq i64 %176, 255
br i1 %177, label %178, label %158
178: ; preds = %174, %156
%179 = icmp eq i8* %95, null
br i1 %179, label %200, label %180
180: ; preds = %178, %196
%181 = phi i64 [ %198, %196 ], [ 0, %178 ]
%182 = phi i32 [ %197, %196 ], [ 0, %178 ]
%183 = getelementptr inbounds i8, i8* %95, i64 %181
%184 = load i8, i8* %183
%185 = icmp eq i8 %184, 0
br i1 %185, label %196, label %186
186: ; preds = %180
%187 = icmp eq i32 %182, 0
br i1 %187, label %188, label %191
188: ; preds = %186
%189 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.25, i64 0, i64 0))
%190 = load i8, i8* %183
br label %191
191: ; preds = %188, %186
%192 = phi i8 [ %190, %188 ], [ %184, %186 ]
%193 = zext i8 %192 to i32
%194 = trunc i64 %181 to i32
%195 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.22, i64 0, i64 0), i32 %194, i32 %193)
br label %196
196: ; preds = %180, %191
%197 = phi i32 [ 1, %191 ], [ %182, %180 ]
%198 = add nuw nsw i64 %181, 1
%199 = icmp eq i64 %198, 255
br i1 %199, label %200, label %180
200: ; preds = %196, %178, %152
%201 = call i32 @free(i8* %94)
%202 = call i32 @free(i8* %95)
br label %203
203: ; preds = %200, %98, %82, %61
%204 = phi i32 [ -1, %61 ], [ -2, %82 ], [ -2, %98 ], [ 0, %200 ]
ret i32 %204
}