// File: /workspace/github_c_makefile_star2_O3/minoki[P]icfpc2006/run_threaded.c
// Function: main
int main(int argc, char *argv[])
{
    if (argc <= 1) {
        fprintf(stderr, "Usage: %s file.um\n", argv[0]);
        return 1;
    }
    void *rawprogram = NULL;
    size_t rawprogsize = 0;
    {
        FILE *f = fopen(argv[1], "rb");
        assert(f != NULL);
        int seekresult = fseek(f, 0, SEEK_END);
        assert(seekresult == 0);
        long size = ftell(f);
        assert(size >= 0);
        rawprogsize = size;
        seekresult = fseek(f, 0, SEEK_SET);
        assert(seekresult == 0);
        rawprogram = malloc(rawprogsize);
        assert(rawprogram != NULL);
        size_t result = fread(rawprogram, 1, rawprogsize, f);
        assert(result == rawprogsize);
        fclose(f);
    }
    assert(rawprogsize % 4 == 0);
    struct array *arr0 = malloc(sizeof(uint32_t) + rawprogsize);
    assert(arr0 != NULL);
    arr0->length = rawprogsize / 4;
    {
        uint8_t *rawprogram_ = (uint8_t *)rawprogram;
        for (size_t i = 0; i < rawprogsize / 4; ++i) {
            uint32_t a = (uint32_t)rawprogram_[4 * i];
            uint32_t b = (uint32_t)rawprogram_[4 * i + 1];
            uint32_t c = (uint32_t)rawprogram_[4 * i + 2];
            uint32_t d = (uint32_t)rawprogram_[4 * i + 3];
            arr0->data[i] = (a << 24) | (b << 16) | (c << 8) | d;
        }
        free(rawprogram);
    }

    fprintf(stderr, "Loaded program. size=%zu bytes\n", rawprogsize);

    size_t pc = 0;
    uint32_t reg[8] = {0};
    struct array **arr = calloc(1, sizeof(struct array *));
    arr[0] = arr0;
    size_t arraycount = 1;
    uint32_t *freelist = NULL, *freelist_end = NULL;
    uint32_t freelist_capacity = 0;

    static void * const operations[16] = {
        &&OP_CondMove,
        &&OP_ArrayIndex,
        &&OP_ArrayAmendment,
        &&OP_Add,
        &&OP_Mul,
        &&OP_Div,
        &&OP_NotAnd,
        &&OP_Halt,
        &&OP_Alloc,
        &&OP_Abandon,
        &&OP_Output,
        &&OP_Input,
        &&OP_LoadProgram,
        &&OP_Orthography,
        &&OP_Invalid,
        &&OP_Invalid,
    };
    uint32_t op = 0;
    while (1) {
#define JUMP()                                  \
        do {                                    \
            op = arr0->data[pc];                \
            goto *operations[op >> 28];         \
        } while (0)
        JUMP();
    OP_CondMove:
        {
            uint32_t a = (op >> 6) & 7;
            uint32_t b = (op >> 3) & 7;
            uint32_t c = op & 7;
            if (reg[c] != 0) {
                reg[a] = reg[b];
            }
            ++pc;
            JUMP();
        }
    OP_ArrayIndex:
        {
            uint32_t a = (op >> 6) & 7;
            uint32_t b = (op >> 3) & 7;
            uint32_t c = op & 7;
            uint32_t i = reg[b];
            assert(i < arraycount);
            struct array *ai = arr[i];
            assert(ai != NULL);
            assert(reg[c] < ai->length);
            reg[a] = ai->data[reg[c]];
            ++pc;
            JUMP();
        }
    OP_ArrayAmendment:
        {
            uint32_t a = (op >> 6) & 7;
            uint32_t b = (op >> 3) & 7;
            uint32_t c = op & 7;
            uint32_t i = reg[a];
            assert(i < arraycount);
            struct array *ai = arr[i];
            assert(ai != NULL);
            assert(reg[b] < ai->length);
            ai->data[reg[b]] = reg[c];
            ++pc;
            JUMP();
        }
    OP_Add:
        {
            uint32_t a = (op >> 6) & 7;
            uint32_t b = (op >> 3) & 7;
            uint32_t c = op & 7;
            reg[a] = reg[b] + reg[c];
            ++pc;
            JUMP();
        }
    OP_Mul:
        {
            uint32_t a = (op >> 6) & 7;
            uint32_t b = (op >> 3) & 7;
            uint32_t c = op & 7;
            reg[a] = reg[b] * reg[c];
            ++pc;
            JUMP();
        }
    OP_Div:
        {
            uint32_t a = (op >> 6) & 7;
            uint32_t b = (op >> 3) & 7;
            uint32_t c = op & 7;
            assert(reg[c] != 0);
            reg[a] = reg[b] / reg[c];
            ++pc;
            JUMP();
        }
    OP_NotAnd:
        {
            uint32_t a = (op >> 6) & 7;
            uint32_t b = (op >> 3) & 7;
            uint32_t c = op & 7;
            reg[a] = ~(reg[b] & reg[c]);
            ++pc;
            JUMP();
        }
    OP_Halt:
        fflush(stdout);
        fprintf(stderr, "HALT\n");
        return 0;
    OP_Alloc:
        {
            uint32_t b = (op >> 3) & 7;
            uint32_t c = op & 7;
            uint32_t capacity = reg[c];
            uint32_t i = 0;
            if (freelist_end == freelist) {
                i = arraycount;
                ++arraycount;
                arr = realloc(arr, sizeof(struct array *) * arraycount);
                assert(arr != NULL);
            } else {
                i = *(--freelist_end);
                *freelist_end = 0;
            }
            struct array *newarr = calloc(1 + capacity, sizeof(uint32_t));
            assert(newarr != NULL);
            newarr->length = capacity;
            arr[i] = newarr;
            reg[b] = i;
            ++pc;
            JUMP();
        }
    OP_Abandon:
        {
            uint32_t c = op & 7;
            uint32_t i = reg[c];
            assert(i < arraycount);
            assert(i != 0);
            assert(arr[i] != NULL);
            free(arr[i]);
            arr[i] = NULL;
            if (freelist_end - freelist == freelist_capacity) {
                uint32_t freelist_new_capacity = freelist_capacity == 0 ? 32 : freelist_capacity * 2;
                freelist = realloc(freelist, freelist_new_capacity * sizeof(uint32_t));
                memset(freelist + freelist_capacity, 0, (freelist_new_capacity - freelist_capacity) * sizeof(uint32_t));
                freelist_end = freelist + freelist_capacity;
                freelist_capacity = freelist_new_capacity;
            }
            *freelist_end++ = i;
            ++pc;
            JUMP();
        }
    OP_Output:
        {
            uint32_t c = op & 7;
            assert(reg[c] <= 255);
            putchar(reg[c]);
            ++pc;
            JUMP();
        }
    OP_Input:
        {
            uint32_t c = op & 7;
            fflush(stdout);
            int ch = getchar();
            if (ch == EOF) {
                reg[c] = (uint32_t)(-1);
            } else {
                assert(0 <= ch && ch <= 255);
                reg[c] = (uint32_t)ch;
            }
            ++pc;
            JUMP();
        }
    OP_LoadProgram:
        {
            uint32_t b = (op >> 3) & 7;
            uint32_t c = op & 7;
            uint32_t i = reg[b];
            if (UNLIKELY(i != 0)) {
                assert(i < arraycount);
                assert(arr[i] != NULL);
                uint32_t length = arr[i]->length;
                struct array *newprogram = malloc((length + 1) * sizeof(uint32_t));
                assert(newprogram != NULL);
                memcpy(newprogram, arr[i], (length + 1) * sizeof(uint32_t));
                free(arr0);
                arr0 = newprogram;
                arr[0] = newprogram;
            }
            pc = reg[c];
            assert(pc < arr0->length);
            JUMP();
        }
    OP_Orthography:
        {
            uint32_t a = (op >> 25) & 7;
            uint32_t value = op & ((UINT32_C(1) << 25) - 1);
            reg[a] = value;
            ++pc;
            JUMP();
        }
    OP_Invalid:
        {
            fprintf(stderr, "Invalid Instruction: %08X\n", op);
            abort();
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
cmpl $0x1, %edi
jg 0x1291
movq %rsi, %rdi
callq 0x1160
movl $0x1, %eax
jmp 0x17af
movq 0x8(%rsi), %rdi
leaq 0xd7b(%rip), %rsi       # 0x2017
callq 0x1130
testq %rax, %rax
je 0x19af
movq %rax, %rbx
movq %rax, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x1110
testl %eax, %eax
jne 0x19ce
movq %rbx, %rdi
callq 0x10d0
testq %rax, %rax
js 0x19ed
movq %rax, %r14
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x1110
testl %eax, %eax
jne 0x1a0c
movq %r14, %rdi
callq 0x10f0
testq %rax, %rax
je 0x1a2b
movq %rax, %r15
movl $0x1, %esi
movq %rax, %rdi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x1060
cmpq %r14, %rax
jne 0x1a4a
movq %rbx, %rdi
callq 0x1070
testb $0x3, %r14b
jne 0x1a69
leaq 0x4(%r14), %rdi
callq 0x10f0
testq %rax, %rax
je 0x1a88
movq %rax, %rbx
movq %r14, %rax
shrq $0x2, %rax
movl %eax, (%rbx)
testq %r14, %r14
je 0x1365
xorl %ecx, %ecx
movl (%r15,%rcx,4), %edx
bswapl %edx
movl %edx, 0x4(%rbx,%rcx,4)
incq %rcx
cmpq %rcx, %rax
jne 0x1353
movq %r15, %rdi
callq 0x1030
movq 0x2c7c(%rip), %rax      # 0x3ff0
movq (%rax), %rdi
leaq 0xd31(%rip), %rsi       # 0x20af
movq %r14, %rdx
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x10c0
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movaps %xmm0, 0x10(%rsp)
movl $0x1, %eax
movq %rax, 0x20(%rsp)
movl $0x1, %edi
movl $0x8, %esi
callq 0x10a0
movq %rax, %r13
movq %rbx, (%rax)
movq %rbx, %rax
addq $0x4, %rax
leaq 0x299c(%rip), %r15      # 0x3d60
movq $0x0, 0x30(%rsp)
movq $0x0, 0x38(%rsp)
xorl %ebp, %ebp
movl (%rax), %r12d
movl %r12d, %eax
shrl $0x1c, %eax
jmpq *(%r15,%rax,8)
movl %r12d, %eax
andl $0x7, %eax
cmpl $0x0, (%rsp,%rax,4)
je 0x166e
movl %r12d, %eax
shrl %eax
andl $0x1c, %eax
movl (%rsp,%rax), %eax
jmp 0x1662
movl %r12d, %eax
andl $0x1ffffff, %eax        # imm = 0x1FFFFFF
shrl $0x17, %r12d
jmp 0x1666
andl $0x7, %r12d
movl (%rsp,%r12,4), %edi
cmpl $0x100, %edi            # imm = 0x100
jae 0x17de
callq 0x1040
jmp 0x166e
movl %r12d, %eax
andl $0x7, %eax
movl %r12d, %ecx
shrl %ecx
andl $0x1c, %ecx
movl (%rsp,%rax,4), %eax
imull (%rsp,%rcx), %eax
jmp 0x1662
movl %r12d, %eax
shrl %eax
andl $0x1c, %eax
movl (%rsp,%rax), %eax
testq %rax, %rax
jne 0x1722
andl $0x7, %r12d
movl %r12d, %eax
movl (%rsp,%rax,4), %ebp
cmpl (%rbx), %ebp
jb 0x1671
jmp 0x18d6
movq %r13, %r15
andl $0x7, %r12d
movl (%rsp,%r12,4), %r13d
cmpq %r13, 0x20(%rsp)
jbe 0x17fd
testl %r13d, %r13d
je 0x18f5
movq (%r15,%r13,8), %rdi
testq %rdi, %rdi
je 0x1914
callq 0x1030
movq $0x0, (%r15,%r13,8)
movq 0x30(%rsp), %r12
movq 0x38(%rsp), %rdi
subq %rdi, %r12
movq %r12, %rax
sarq $0x2, %rax
movl %r14d, %ecx
cmpq %rcx, %rax
jne 0x167e
movq %rbx, 0x28(%rsp)
movq %r14, %rbx
addl %r14d, %r14d
testl %ebx, %ebx
movl $0x20, %eax
cmovel %eax, %r14d
leaq (,%r14,4), %rsi
callq 0x1120
movq %rax, 0x38(%rsp)
addq %rax, %r12
movl %r14d, %edx
subl %ebx, %edx
movq 0x28(%rsp), %rbx
shlq $0x2, %rdx
movq %r12, %rdi
xorl %esi, %esi
callq 0x1090
jmp 0x1683
movq 0x2aaf(%rip), %rax      # 0x3fd0
movq (%rax), %rdi
callq 0x1100
callq 0x10b0
cmpl $-0x1, %eax
je 0x1698
cmpl $0x100, %eax            # imm = 0x100
jb 0x169d
jmp 0x1971
movl %r12d, %eax
shrl $0x4, %eax
andl $0x1c, %eax
movl (%rsp,%rax), %eax
cmpq %rax, 0x20(%rsp)
jbe 0x185a
movq (%r13,%rax,8), %rax
testq %rax, %rax
je 0x183b
movl %r12d, %ecx
shrl $0x3, %ecx
andl $0x7, %ecx
movl (%rsp,%rcx,4), %ecx
cmpl (%rax), %ecx
jae 0x1952
andl $0x7, %r12d
movl (%rsp,%r12,4), %edx
movl %edx, 0x4(%rax,%rcx,4)
jmp 0x166e
movq %rbx, 0x28(%rsp)
movl %r12d, %eax
andl $0x7, %eax
movl (%rsp,%rax,4), %ebx
movq 0x30(%rsp), %rax
cmpq 0x38(%rsp), %rax
je 0x16a9
movq %r14, 0x40(%rsp)
movl -0x4(%rax), %r14d
movl $0x0, -0x4(%rax)
leaq -0x4(%rax), %r15
movq %r15, 0x30(%rsp)
jmp 0x16da
movl %r12d, %eax
andl $0x7, %eax
movl %r12d, %ecx
shrl %ecx
andl $0x1c, %ecx
movl (%rsp,%rax,4), %eax
addl (%rsp,%rcx), %eax
jmp 0x1662
movl %r12d, %eax
shrl %eax
andl $0x1c, %eax
movl (%rsp,%rax), %eax
cmpq %rax, 0x20(%rsp)
jbe 0x181c
movq (%r13,%rax,8), %rax
testq %rax, %rax
je 0x1879
movl %r12d, %ecx
andl $0x7, %ecx
movl (%rsp,%rcx,4), %ecx
cmpl (%rax), %ecx
jae 0x1933
shrl $0x6, %r12d
andl $0x7, %r12d
movl 0x4(%rax,%rcx,4), %eax
movl %eax, (%rsp,%r12,4)
jmp 0x166e
movl %r12d, %eax
andl $0x7, %eax
movl (%rsp,%rax,4), %ecx
testl %ecx, %ecx
je 0x1898
movl %r12d, %eax
shrl %eax
andl $0x1c, %eax
movl (%rsp,%rax), %eax
xorl %edx, %edx
divl %ecx
jmp 0x1662
movl %r12d, %eax
andl $0x7, %eax
movl %r12d, %ecx
shrl %ecx
andl $0x1c, %ecx
movl (%rsp,%rax,4), %eax
andl (%rsp,%rcx), %eax
notl %eax
shrl $0x4, %r12d
andl $0x1c, %r12d
movl %eax, (%rsp,%r12)
incq %rbp
leaq (%rbx,%rbp,4), %rax
addq $0x4, %rax
jmp 0x13d8
movq 0x30(%rsp), %r12
movl %r13d, (%r12)
addq $0x4, %r12
movq %r12, 0x30(%rsp)
incq %rbp
movq %r15, %r13
jmp 0x1716
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
andl $0x7, %r12d
movl %r12d, %ecx
movl %eax, (%rsp,%rcx,4)
jmp 0x166e
movq %r14, 0x40(%rsp)
movq 0x20(%rsp), %r14
leaq 0x8(,%r14,8), %rsi
movq %r13, %rdi
callq 0x1120
testq %rax, %rax
je 0x1990
movq %rax, %r13
movq %r14, %rax
incq %rax
movq %rax, 0x20(%rsp)
leal 0x1(%rbx), %edi
movl $0x4, %esi
callq 0x10a0
testq %rax, %rax
je 0x18b7
shrl $0x3, %r12d
andl $0x7, %r12d
movl %ebx, (%rax)
movl %r14d, %ecx
movq %rax, (%r13,%rcx,8)
movl %r12d, %eax
movl %r14d, (%rsp,%rax,4)
incq %rbp
movq 0x40(%rsp), %r14
movq 0x28(%rsp), %rbx
leaq 0x2643(%rip), %r15      # 0x3d60
jmp 0x1671
cmpq %rax, 0x20(%rsp)
jbe 0x1aa7
movq (%r13,%rax,8), %rbp
testq %rbp, %rbp
je 0x1ac6
movl (%rbp), %edi
incl %edi
shlq $0x2, %rdi
movq %rdi, 0x28(%rsp)
callq 0x10f0
testq %rax, %rax
je 0x1ae5
movq %rax, %rdi
movq %rbp, %rsi
movq 0x28(%rsp), %rdx
movq %rax, %rbp
callq 0x10e0
movq %rbx, %rdi
callq 0x1030
movq %rbp, (%r13)
movq %rbp, %rbx
jmp 0x1462
movq 0x284b(%rip), %rax      # 0x3fd0
movq (%rax), %rdi
callq 0x1100
movq 0x285c(%rip), %rax      # 0x3ff0
movq (%rax), %rcx
leaq 0x97f(%rip), %rdi       # 0x211d
movl $0x5, %esi
movl $0x1, %edx
callq 0x1140
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x282b(%rip), %rax      # 0x3ff0
movq (%rax), %rdi
leaq 0x9c1(%rip), %rsi       # 0x2190
movl %r12d, %edx
xorl %eax, %eax
callq 0x10c0
callq 0x1050
leaq 0x963(%rip), %rdi       # 0x2148
leaq 0x838(%rip), %rsi       # 0x2024
leaq 0x840(%rip), %rcx       # 0x2033
movl $0xdb, %edx
callq 0x1080
leaq 0x8cb(%rip), %rdi       # 0x20cf
leaq 0x819(%rip), %rsi       # 0x2024
leaq 0x821(%rip), %rcx       # 0x2033
movl $0xc8, %edx
callq 0x1080
leaq 0x8ac(%rip), %rdi       # 0x20cf
leaq 0x7fa(%rip), %rsi       # 0x2024
leaq 0x802(%rip), %rcx       # 0x2033
movl $0x6e, %edx
callq 0x1080
leaq 0x89c(%rip), %rdi       # 0x20de
leaq 0x7db(%rip), %rsi       # 0x2024
leaq 0x7e3(%rip), %rcx       # 0x2033
movl $0x7e, %edx
callq 0x1080
leaq 0x86e(%rip), %rdi       # 0x20cf
leaq 0x7bc(%rip), %rsi       # 0x2024
leaq 0x7c4(%rip), %rcx       # 0x2033
movl $0x7c, %edx
callq 0x1080
leaq 0x85e(%rip), %rdi       # 0x20de
leaq 0x79d(%rip), %rsi       # 0x2024
leaq 0x7a5(%rip), %rcx       # 0x2033
movl $0x70, %edx
callq 0x1080
leaq 0x872(%rip), %rdi       # 0x2111
leaq 0x77e(%rip), %rsi       # 0x2024
leaq 0x786(%rip), %rcx       # 0x2033
movl $0x9b, %edx
callq 0x1080
leaq 0x865(%rip), %rdi       # 0x2123
leaq 0x75f(%rip), %rsi       # 0x2024
leaq 0x767(%rip), %rcx       # 0x2033
movl $0xbd, %edx
callq 0x1080
leaq 0x8a1(%rip), %rdi       # 0x217e
leaq 0x740(%rip), %rsi       # 0x2024
leaq 0x748(%rip), %rcx       # 0x2033
movl $0xff, %edx
callq 0x1080
leaq 0x836(%rip), %rdi       # 0x2132
leaq 0x721(%rip), %rsi       # 0x2024
leaq 0x729(%rip), %rcx       # 0x2033
movl $0xc9, %edx
callq 0x1080
leaq 0x81e(%rip), %rdi       # 0x2139
leaq 0x702(%rip), %rsi       # 0x2024
leaq 0x70a(%rip), %rcx       # 0x2033
movl $0xca, %edx
callq 0x1080
leaq 0x7af(%rip), %rdi       # 0x20e9
leaq 0x6e3(%rip), %rsi       # 0x2024
leaq 0x6eb(%rip), %rcx       # 0x2033
movl $0x71, %edx
callq 0x1080
leaq 0x7a4(%rip), %rdi       # 0x20fd
leaq 0x6c4(%rip), %rsi       # 0x2024
leaq 0x6cc(%rip), %rcx       # 0x2033
movl $0x7f, %edx
callq 0x1080
leaq 0x7de(%rip), %rdi       # 0x2156
leaq 0x6a5(%rip), %rsi       # 0x2024
leaq 0x6ad(%rip), %rcx       # 0x2033
movl $0xe8, %edx
callq 0x1080
leaq 0x78f(%rip), %rdi       # 0x2126
leaq 0x686(%rip), %rsi       # 0x2024
leaq 0x68e(%rip), %rcx       # 0x2033
movl $0xb7, %edx
callq 0x1080
leaq 0x664(%rip), %rdi       # 0x201a
leaq 0x667(%rip), %rsi       # 0x2024
leaq 0x66f(%rip), %rcx       # 0x2033
movl $0x1b, %edx
callq 0x1080
leaq 0x675(%rip), %rdi       # 0x204a
leaq 0x648(%rip), %rsi       # 0x2024
leaq 0x650(%rip), %rcx       # 0x2033
movl $0x1d, %edx
callq 0x1080
leaq 0x666(%rip), %rdi       # 0x205a
leaq 0x629(%rip), %rsi       # 0x2024
leaq 0x631(%rip), %rcx       # 0x2033
movl $0x1f, %edx
callq 0x1080
leaq 0x637(%rip), %rdi       # 0x204a
leaq 0x60a(%rip), %rsi       # 0x2024
leaq 0x612(%rip), %rcx       # 0x2033
movl $0x22, %edx
callq 0x1080
leaq 0x632(%rip), %rdi       # 0x2064
leaq 0x5eb(%rip), %rsi       # 0x2024
leaq 0x5f3(%rip), %rcx       # 0x2033
movl $0x24, %edx
callq 0x1080
leaq 0x626(%rip), %rdi       # 0x2077
leaq 0x5cc(%rip), %rsi       # 0x2024
leaq 0x5d4(%rip), %rcx       # 0x2033
movl $0x26, %edx
callq 0x1080
leaq 0x61d(%rip), %rdi       # 0x208d
leaq 0x5ad(%rip), %rsi       # 0x2024
leaq 0x5b5(%rip), %rcx       # 0x2033
movl $0x29, %edx
callq 0x1080
leaq 0x613(%rip), %rdi       # 0x20a2
leaq 0x58e(%rip), %rsi       # 0x2024
leaq 0x596(%rip), %rcx       # 0x2033
movl $0x2b, %edx
callq 0x1080
leaq 0x621(%rip), %rdi       # 0x20cf
leaq 0x56f(%rip), %rsi       # 0x2024
leaq 0x577(%rip), %rcx       # 0x2033
movl $0xf4, %edx
callq 0x1080
leaq 0x66c(%rip), %rdi       # 0x2139
leaq 0x550(%rip), %rsi       # 0x2024
leaq 0x558(%rip), %rcx       # 0x2033
movl $0xf5, %edx
callq 0x1080
leaq 0x67f(%rip), %rdi       # 0x216b
leaq 0x531(%rip), %rsi       # 0x2024
leaq 0x539(%rip), %rcx       # 0x2033
movl $0xf8, %edx
callq 0x1080