// File: /workspace/github_c_makefile_star2_O0/endeav0r[P]hsvm/src/assembler.c
// Function: assemble
uint16_t assemble (struct _token * tokens, unsigned char * mem)
{
    struct _labels labels;
    struct _label * label;
    struct _instruction ins;
    struct _token * next;
    struct _token * peek;
    int rule;
    int mem_i = 0;
    int copy_instruction = 0;
    uint16_t lval;

    labels.first = NULL;
    labels.last = NULL;

    // first pass to assemble
    next = tokens;
    while (next != NULL) {
        memset(&ins, 0, sizeof(struct _instruction));
        rule = match_rule(next);
        copy_instruction = 0;

        if (rule == -1) {
            fprintf(stderr, "couldn't match rule, line %d\n", next->line);
            for (peek = next;
                 (peek != NULL) && (peek->type != TOK_NEWLINE);
                 peek = peek->next) {
                fprintf(stderr, "%s ", token_str(peek));
            }
            fprintf(stderr, "\n");
            exit(-1);
        }

        switch (rule) {
        case RULE_MOV :
        case RULE_CMP :
            ins.opcode = next->type;
            peek = token_peek(next, 1);
            ins.operand_0 = peek->type;
            peek = token_peek(next, 3);
            ins.operand_1 = peek->type;
            copy_instruction = 1;
            break;

        case RULE_MOVLVAL    :
        case RULE_MOVLABEL   :
        case RULE_CMPLVAL    :
        case RULE_ADDLVAL    :
        case RULE_SUBLVAL    :
        case RULE_MULLVAL    :
        case RULE_DIVLVAL    :
        case RULE_MODLVAL    :
        case RULE_ANDLVAL    :
        case RULE_ORLVAL     :
        case RULE_XORLVAL    :
            if (next->type == OP_MOV) ins.opcode = OP_MOVLVAL;
            else if (next->type == OP_CMP) ins.opcode = OP_CMPLVAL;
            else if (next->type == OP_ADD) ins.opcode = OP_ADDLVAL;
            else if (next->type == OP_SUB) ins.opcode = OP_SUBLVAL;
            else if (next->type == OP_MUL) ins.opcode = OP_MULLVAL;
            else if (next->type == OP_DIV) ins.opcode = OP_DIVLVAL;
            else if (next->type == OP_MOD) ins.opcode = OP_MODLVAL;
            else if (next->type == OP_AND) ins.opcode = OP_ANDLVAL;
            else if (next->type == OP_OR ) ins.opcode = OP_ORLVAL;
            else if (next->type == OP_XOR) ins.opcode = OP_XORLVAL;
            peek = token_peek(next, 1);
            ins.operand_0 = peek->type;
            peek = token_peek(next, 3);
            lval = strtoul(peek->str, NULL, 0);
            lval = htons(lval);
            ins.lval = lval;
            copy_instruction = 1;
            break;

        case RULE_LOAD  :
        case RULE_STOR  :
        case RULE_LOADB :
        case RULE_STORB :
        case RULE_IN    :
        case RULE_OUT   :
        case RULE_PUSH  :
        case RULE_POP   :
            ins.opcode = next->type;
            if ((rule == RULE_STOR) || (rule == RULE_STORB))
                peek = token_peek(next, 3);
            else
                peek = token_peek(next, 1);
            ins.operand_0 = peek->type;
            copy_instruction = 1;
            break;

        case RULE_ADD :
        case RULE_SUB :
        case RULE_MUL :
        case RULE_DIV :
        case RULE_MOD :
        case RULE_AND :
        case RULE_OR  :
        case RULE_XOR :
            ins.opcode = next->type;
            peek = token_peek(next, 1);
            ins.operand_0 = peek->type;
            peek = token_peek(next, 3);
            ins.operand_1 = peek->type;
            peek = token_peek(next, 5);
            ins.operand_2 = peek->type;
            copy_instruction = 1;
            break;

        case RULE_JMP     :
        case RULE_JE      :
        case RULE_JNE     :
        case RULE_JL      :
        case RULE_JLE     :
        case RULE_JG      :
        case RULE_JGE     :
        case RULE_CALL    :
        case RULE_RET     :
        case RULE_HLT     :
        case RULE_SYSCALL :
        case RULE_NOP     :
        case RULE_PUSHLABEL :
            if (rule == RULE_PUSHLABEL)
                ins.opcode = OP_PUSHLVAL;
            else
                ins.opcode = next->type;
            copy_instruction = 1;
            break;

        case RULE_LOADR  :
        case RULE_STORR  :
        case RULE_LOADBR :
        case RULE_STORBR :
            if (rule == RULE_LOADR)
                ins.opcode = OP_LOADR;
            else if (rule == RULE_STORR)
                ins.opcode = OP_STORR;
            else if (rule == RULE_LOADBR)
                ins.opcode = OP_LOADBR;
            else if (rule == RULE_STORBR)
                ins.opcode = OP_STORBR;
            peek = token_peek(next, 1);
            ins.operand_0 = peek->type;
            peek = token_peek(next, 3);
            ins.operand_1 = peek->type;
            copy_instruction = 1;
            break;

        case RULE_PUSHLVAL :
        case RULE_JMPLVAL  :
        case RULE_JELVAL   :
        case RULE_JNELVAL  :
        case RULE_JLLVAL   :
        case RULE_JLELVAL  :
        case RULE_JGLVAL   :
        case RULE_JGELVAL  :
            if (rule == RULE_PUSHLVAL) ins.opcode = OP_PUSHLVAL;
            else ins.opcode = next->type;
            peek = token_peek(next, 1);
            lval = strtoul(peek->str, NULL, 0);
            lval = htons(lval);
            ins.lval = lval;
            copy_instruction = 1;
            break;

        case RULE_LABELNUM :
            labels_append(&labels, label_create(next->str, mem_i));

            peek = token_peek(next, 1);
            lval = strtoul(peek->str, NULL, 0);
            lval = htons(lval);
            memcpy(&(mem[mem_i]), &lval, 2);
            mem_i += 2;
            break;

        case RULE_LABELSTR :
            labels_append(&labels, label_create(next->str, mem_i));

            peek = token_peek(next, 1);
            memcpy(&(mem[mem_i]), peek->str, strlen(peek->str) + 1);
            mem_i += strlen(peek->str) + 1;
            break;

        case RULE_LABELLABEL :
            labels_append(&labels, label_create(next->str, mem_i));
            mem_i += 2;
            break;

        case RULE_LABEL :
            labels_append(&labels, label_create(next->str, mem_i));
            break;
        }

        if (copy_instruction) {
            memcpy(&(mem[mem_i]), &ins, sizeof(struct _instruction));
            mem_i += sizeof(struct _instruction);
        }
        next = advance_token(next, rule_size(rule));
    }

    // second pass to patch labels
    mem_i = 0;
    next = tokens;
    while (next != NULL) {
        rule = match_rule(next);
        switch (rule) {
        case RULE_JMP       :
        case RULE_JE        :
        case RULE_JNE       :
        case RULE_JL        :
        case RULE_JLE       :
        case RULE_JG        :
        case RULE_JGE       :
        case RULE_CALL      :
        case RULE_LOAD      :
        case RULE_LOADB     :
        case RULE_STOR      :
        case RULE_STORB     :
        case RULE_MOVLABEL  :
        case RULE_PUSHLABEL :

            if ((rule == RULE_LOAD) || (rule == RULE_MOVLABEL))
                peek = token_peek(next, 3);
            else
                peek = token_peek(next, 1);

            label = labels_search(&labels, peek->str);
            if (label == NULL) {
                fprintf(stderr, "could not find label: %s\n", peek->str);
                exit(-1);
            }

            memcpy(&ins, &(mem[mem_i]), sizeof(struct _instruction));

            ins.lval = label->location;
            if (    (rule == RULE_JMP)   || (rule == RULE_JE)  || (rule == RULE_JNE)
                 || (rule == RULE_JL)    || (rule == RULE_JLE)
                 || (rule == RULE_JG)    || (rule == RULE_JGE)
                 || (rule == RULE_CALL)) {
                ins.lval = ins.lval - mem_i - 4;
            }
            ins.lval = htons(ins.lval);

            memcpy(&(mem[mem_i]), &ins, sizeof(struct _instruction));

        case RULE_MOV       :
        case RULE_MOVLVAL   :
        case RULE_CMP       :
        case RULE_CMPLVAL   :
        case RULE_ADD       :
        case RULE_ADDLVAL   :
        case RULE_SUB       :
        case RULE_SUBLVAL   :
        case RULE_MUL       :
        case RULE_MULLVAL   :
        case RULE_DIV       :
        case RULE_DIVLVAL   :
        case RULE_MOD       :
        case RULE_MODLVAL   :
        case RULE_AND       :
        case RULE_ANDLVAL   :
        case RULE_OR        :
        case RULE_ORLVAL    :
        case RULE_XOR       :
        case RULE_XORLVAL   :
        case RULE_JMPLVAL   :
        case RULE_JELVAL    :
        case RULE_JNELVAL   :
        case RULE_JLLVAL    :
        case RULE_JLELVAL   :
        case RULE_JGLVAL    :
        case RULE_JGELVAL   :
        case RULE_CALLR     :
        case RULE_RET       :
        case RULE_LOADR     :
        case RULE_LOADBR    :
        case RULE_STORR     :
        case RULE_STORBR    :
        case RULE_IN        :
        case RULE_OUT       :
        case RULE_PUSH      :
        case RULE_PUSHLVAL  :
        case RULE_POP       :
        case RULE_HLT       :
        case RULE_SYSCALL   :
        case RULE_NOP       :
            mem_i += sizeof(struct _instruction);
            break;

        case RULE_LABELLABEL :
            peek = token_peek(next, 1);

            label = labels_search(&labels, peek->str);
            if (label == NULL) {
                fprintf(stderr, "could not find label: %s\n", peek->str);
                exit(-1);
            }
            ins.lval = htons(label->location);
            memcpy(&(mem[mem_i]), &(ins.lval), 2);

        case RULE_LABELNUM :
            mem_i += 2;
            break;

        case RULE_LABELSTR :
            peek = token_peek(next, 1);
            mem_i += strlen(peek->str) + 1;
            break;
        }
        next = advance_token(next, rule_size(rule));
    }

    return mem_i;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x2ccf
leaq -0x2c(%rbp), %rdi
xorl %esi, %esi
movl $0x4, %edx
callq 0x2140
movq -0x38(%rbp), %rdi
callq 0x2410
movl %eax, -0x44(%rbp)
movl $0x0, -0x4c(%rbp)
cmpl $-0x1, -0x44(%rbp)
jne 0x2816
movq 0x9880(%rip), %rax      # 0xbff8
movq (%rax), %rdi
movq -0x38(%rbp), %rax
movl 0x4(%rax), %edx
leaq 0x6a4f(%rip), %rsi      # 0x91d8
movb $0x0, %al
callq 0x21b0
movq -0x38(%rbp), %rax
movq %rax, -0x40(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x40(%rbp)
movb %al, -0x4f(%rbp)
je 0x27b1
movq -0x40(%rbp), %rax
cmpl $0x70, (%rax)
setne %al
movb %al, -0x4f(%rbp)
movb -0x4f(%rbp), %al
testb $0x1, %al
jne 0x27ba
jmp 0x27f4
movq 0x9837(%rip), %rax      # 0xbff8
movq (%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x40(%rbp), %rdi
callq 0x5db0
movq -0x58(%rbp), %rdi
movq %rax, %rdx
leaq 0x6a17(%rip), %rsi      # 0x91f6
movb $0x0, %al
callq 0x21b0
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x40(%rbp)
jmp 0x2798
movq 0x97fd(%rip), %rax      # 0xbff8
movq (%rax), %rdi
leaq 0x700d(%rip), %rsi      # 0x9812
movb $0x0, %al
callq 0x21b0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x22b0
movl -0x44(%rbp), %eax
movq %rax, -0x60(%rbp)
subq $0x3a, %rax
ja 0x2c8c
movq -0x60(%rbp), %rax
leaq 0x68ba(%rip), %rcx      # 0x90ec
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x38(%rbp), %rax
movl (%rax), %eax
movb %al, -0x2c(%rbp)
movq -0x38(%rbp), %rdi
movl $0x1, %esi
callq 0x2580
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl (%rax), %eax
movb %al, -0x2b(%rbp)
movq -0x38(%rbp), %rdi
movl $0x3, %esi
callq 0x2580
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl (%rax), %eax
movb %al, -0x2a(%rbp)
movl $0x1, -0x4c(%rbp)
jmp 0x2c8c
movq -0x38(%rbp), %rax
cmpl $0x51, (%rax)
jne 0x2898
movb $0x52, -0x2c(%rbp)
jmp 0x2932
movq -0x38(%rbp), %rax
cmpl $0x53, (%rax)
jne 0x28aa
movb $0x54, -0x2c(%rbp)
jmp 0x2930
movq -0x38(%rbp), %rax
cmpl $0x10, (%rax)
jne 0x28b9
movb $0x11, -0x2c(%rbp)
jmp 0x292e
movq -0x38(%rbp), %rax
cmpl $0x12, (%rax)
jne 0x28c8
movb $0x13, -0x2c(%rbp)
jmp 0x292c
movq -0x38(%rbp), %rax
cmpl $0x14, (%rax)
jne 0x28d7
movb $0x15, -0x2c(%rbp)
jmp 0x292a
movq -0x38(%rbp), %rax
cmpl $0x16, (%rax)
jne 0x28e6
movb $0x17, -0x2c(%rbp)
jmp 0x2928
movq -0x38(%rbp), %rax
cmpl $0x18, (%rax)
jne 0x28f5
movb $0x19, -0x2c(%rbp)
jmp 0x2926
movq -0x38(%rbp), %rax
cmpl $0x1a, (%rax)
jne 0x2904
movb $0x1b, -0x2c(%rbp)
jmp 0x2924
movq -0x38(%rbp), %rax
cmpl $0x1c, (%rax)
jne 0x2913
movb $0x1d, -0x2c(%rbp)
jmp 0x2922
movq -0x38(%rbp), %rax
cmpl $0x1e, (%rax)
jne 0x2920
movb $0x1f, -0x2c(%rbp)
jmp 0x2922
jmp 0x2924
jmp 0x2926
jmp 0x2928
jmp 0x292a
jmp 0x292c
jmp 0x292e
jmp 0x2930
jmp 0x2932
movq -0x38(%rbp), %rdi
movl $0x1, %esi
callq 0x2580
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl (%rax), %eax
movb %al, -0x2b(%rbp)
movq -0x38(%rbp), %rdi
movl $0x3, %esi
callq 0x2580
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x2290
movw %ax, -0x4e(%rbp)
movzwl -0x4e(%rbp), %edi
callq 0x2100
movw %ax, -0x4e(%rbp)
movw -0x4e(%rbp), %ax
movw %ax, -0x2a(%rbp)
movl $0x1, -0x4c(%rbp)
jmp 0x2c8c
movq -0x38(%rbp), %rax
movl (%rax), %eax
movb %al, -0x2c(%rbp)
cmpl $0x2a, -0x44(%rbp)
je 0x29ac
cmpl $0x2c, -0x44(%rbp)
jne 0x29c0
movq -0x38(%rbp), %rdi
movl $0x3, %esi
callq 0x2580
movq %rax, -0x40(%rbp)
jmp 0x29d2
movq -0x38(%rbp), %rdi
movl $0x1, %esi
callq 0x2580
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl (%rax), %eax
movb %al, -0x2b(%rbp)
movl $0x1, -0x4c(%rbp)
jmp 0x2c8c
movq -0x38(%rbp), %rax
movl (%rax), %eax
movb %al, -0x2c(%rbp)
movq -0x38(%rbp), %rdi
movl $0x1, %esi
callq 0x2580
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl (%rax), %eax
movb %al, -0x2b(%rbp)
movq -0x38(%rbp), %rdi
movl $0x3, %esi
callq 0x2580
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl (%rax), %eax
movb %al, -0x2a(%rbp)
movq -0x38(%rbp), %rdi
movl $0x5, %esi
callq 0x2580
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl (%rax), %eax
movb %al, -0x29(%rbp)
movl $0x1, -0x4c(%rbp)
jmp 0x2c8c
cmpl $0x32, -0x44(%rbp)
jne 0x2a59
movb $0x43, -0x2c(%rbp)
jmp 0x2a62
movq -0x38(%rbp), %rax
movl (%rax), %eax
movb %al, -0x2c(%rbp)
movl $0x1, -0x4c(%rbp)
jmp 0x2c8c
cmpl $0x27, -0x44(%rbp)
jne 0x2a7a
movb $0x31, -0x2c(%rbp)
jmp 0x2aa2
cmpl $0x2b, -0x44(%rbp)
jne 0x2a86
movb $0x35, -0x2c(%rbp)
jmp 0x2aa0
cmpl $0x29, -0x44(%rbp)
jne 0x2a92
movb $0x33, -0x2c(%rbp)
jmp 0x2a9e
cmpl $0x2d, -0x44(%rbp)
jne 0x2a9c
movb $0x37, -0x2c(%rbp)
jmp 0x2a9e
jmp 0x2aa0
jmp 0x2aa2
movq -0x38(%rbp), %rdi
movl $0x1, %esi
callq 0x2580
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl (%rax), %eax
movb %al, -0x2b(%rbp)
movq -0x38(%rbp), %rdi
movl $0x3, %esi
callq 0x2580
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl (%rax), %eax
movb %al, -0x2a(%rbp)
movl $0x1, -0x4c(%rbp)
jmp 0x2c8c
cmpl $0x31, -0x44(%rbp)
jne 0x2af0
movb $0x43, -0x2c(%rbp)
jmp 0x2af9
movq -0x38(%rbp), %rax
movl (%rax), %eax
movb %al, -0x2c(%rbp)
movq -0x38(%rbp), %rdi
movl $0x1, %esi
callq 0x2580
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x2290
movw %ax, -0x4e(%rbp)
movzwl -0x4e(%rbp), %edi
callq 0x2100
movw %ax, -0x4e(%rbp)
movw -0x4e(%rbp), %ax
movw %ax, -0x2a(%rbp)
movl $0x1, -0x4c(%rbp)
jmp 0x2c8c
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0x48(%rbp), %eax
movzwl %ax, %esi
callq 0x25c0
movq %rax, %rsi
leaq -0x20(%rbp), %rdi
callq 0x2640
movq -0x38(%rbp), %rdi
movl $0x1, %esi
callq 0x2580
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x2290
movw %ax, -0x4e(%rbp)
movzwl -0x4e(%rbp), %edi
callq 0x2100
movw %ax, -0x4e(%rbp)
movq -0x10(%rbp), %rax
movslq -0x48(%rbp), %rcx
movw -0x4e(%rbp), %dx
movw %dx, (%rax,%rcx)
movl -0x48(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x48(%rbp)
jmp 0x2c8c
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0x48(%rbp), %eax
movzwl %ax, %esi
callq 0x25c0
movq %rax, %rsi
leaq -0x20(%rbp), %rdi
callq 0x2640
movq -0x38(%rbp), %rdi
movl $0x1, %esi
callq 0x2580
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movslq -0x48(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x20f0
movq -0x70(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq %rax, %rdx
addq $0x1, %rdx
callq 0x21d0
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x20f0
movq %rax, %rcx
addq $0x1, %rcx
movslq -0x48(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x48(%rbp)
jmp 0x2c8c
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0x48(%rbp), %eax
movzwl %ax, %esi
callq 0x25c0
movq %rax, %rsi
leaq -0x20(%rbp), %rdi
callq 0x2640
movl -0x48(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x48(%rbp)
jmp 0x2c8c
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0x48(%rbp), %eax
movzwl %ax, %esi
callq 0x25c0
movq %rax, %rsi
leaq -0x20(%rbp), %rdi
callq 0x2640
cmpl $0x0, -0x4c(%rbp)
je 0x2cab
movq -0x10(%rbp), %rax
movslq -0x48(%rbp), %rcx
movl -0x2c(%rbp), %edx
movl %edx, (%rax,%rcx)
movslq -0x48(%rbp), %rax
addq $0x4, %rax
movl %eax, -0x48(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x78(%rbp)
movl -0x44(%rbp), %edi
callq 0x24f0
movq -0x78(%rbp), %rdi
movl %eax, %esi
callq 0x2540
movq %rax, -0x38(%rbp)
jmp 0x2739
movl $0x0, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x2ef3
movq -0x38(%rbp), %rdi
callq 0x2410
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq %rax, -0x80(%rbp)
subq $0x39, %rax
ja 0x2ec9
movq -0x80(%rbp), %rax
leaq 0x62f3(%rip), %rcx      # 0x9004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x26, -0x44(%rbp)
je 0x2d26
cmpl $0x2, -0x44(%rbp)
jne 0x2d3a
movq -0x38(%rbp), %rdi
movl $0x3, %esi
callq 0x2580
movq %rax, -0x40(%rbp)
jmp 0x2d4c
movq -0x38(%rbp), %rdi
movl $0x1, %esi
callq 0x2580
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rsi
leaq -0x20(%rbp), %rdi
callq 0x2690
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x2d92
movq 0x9289(%rip), %rax      # 0xbff8
movq (%rax), %rdi
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rdx
leaq 0x6479(%rip), %rsi      # 0x91fa
movb $0x0, %al
callq 0x21b0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x22b0
movq -0x10(%rbp), %rax
movslq -0x48(%rbp), %rcx
movl (%rax,%rcx), %eax
movl %eax, -0x2c(%rbp)
movq -0x28(%rbp), %rax
movw 0x8(%rax), %ax
movw %ax, -0x2a(%rbp)
cmpl $0x15, -0x44(%rbp)
je 0x2ddc
cmpl $0x17, -0x44(%rbp)
je 0x2ddc
cmpl $0x19, -0x44(%rbp)
je 0x2ddc
cmpl $0x1b, -0x44(%rbp)
je 0x2ddc
cmpl $0x1d, -0x44(%rbp)
je 0x2ddc
cmpl $0x1f, -0x44(%rbp)
je 0x2ddc
cmpl $0x21, -0x44(%rbp)
je 0x2ddc
cmpl $0x23, -0x44(%rbp)
jne 0x2dea
movzwl -0x2a(%rbp), %eax
subl -0x48(%rbp), %eax
subl $0x4, %eax
movw %ax, -0x2a(%rbp)
movzwl -0x2a(%rbp), %edi
callq 0x2100
movw %ax, -0x2a(%rbp)
movq -0x10(%rbp), %rax
movslq -0x48(%rbp), %rcx
movl -0x2c(%rbp), %edx
movl %edx, (%rax,%rcx)
movslq -0x48(%rbp), %rax
addq $0x4, %rax
movl %eax, -0x48(%rbp)
jmp 0x2ec9
movq -0x38(%rbp), %rdi
movl $0x1, %esi
callq 0x2580
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rsi
leaq -0x20(%rbp), %rdi
callq 0x2690
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x2e6d
movq 0x91ae(%rip), %rax      # 0xbff8
movq (%rax), %rdi
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rdx
leaq 0x639e(%rip), %rsi      # 0x91fa
movb $0x0, %al
callq 0x21b0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x22b0
movq -0x28(%rbp), %rax
movzwl 0x8(%rax), %edi
callq 0x2100
movw %ax, -0x2a(%rbp)
movq -0x10(%rbp), %rax
movslq -0x48(%rbp), %rcx
movw -0x2a(%rbp), %dx
movw %dx, (%rax,%rcx)
movl -0x48(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x48(%rbp)
jmp 0x2ec9
movq -0x38(%rbp), %rdi
movl $0x1, %esi
callq 0x2580
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x20f0
movq %rax, %rcx
addq $0x1, %rcx
movslq -0x48(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x48(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x88(%rbp)
movl -0x44(%rbp), %edi
callq 0x24f0
movq -0x88(%rbp), %rdi
movl %eax, %esi
callq 0x2540
movq %rax, -0x38(%rbp)
jmp 0x2cde
movl -0x48(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nop