// File: /workspace/github_c_makefile_star2_O1/tyabu12[P]pl0compiler/codegen.c
// Function: readCode
int readCode(FILE *fp) {
struct {
  const char *name;
  OpCode opCode;
  int flag;
} static const opTbl[] = {
  { "lit", lit, 1 },
  { "opr", opr, 3 },
  { "lod", lod, 2 },
  { "sto", sto, 2 },
  { "cal", cal, 2 },
  { "ret", ret, 2 },
  { "ict", ict, 1 },
  { "jmp", jmp, 1 },
  { "jpc", jpc, 1 },
  { NULL, } /* 番兵 */
};
struct {
  const char *name;
  Operator optr;
} static const optrTbl[] = {
  { "neg",  neg  },
  { "add",  add  },
  { "sub",  sub  },
  { "mul",  mul  },
  { "div",  div  },
  { "odd",  odd  },
  { "eq",   eq   },
  { "lseq", lseq },
  { "ls",   ls   },
  { "greq", greq },
  { "gr",   gr   },
  { "neq",  neq  },
  { "rd",   rd   },
  { "wrt",  wrt  },
  { "wrl",  wrl  },
  { NULL, } /* 番兵 */
};
    char str[256];
    char *p;
    int op, optr, i;
    for (i = 0; fgets(str, 256, fp) != NULL; i++) {
        p = str;
        /* 行番号のスキップ */
        while (*p != ':' && *p != '\0') p++;
        if (*p == ':') p++;
        while (*p == ' ' && *p != '\0') p++;
        if (*p == '\0') return 1;
        /* 命令語をテーブルから検索 */
        for (op = 0; opTbl[op].name != NULL; op++) {
            if (strncmp(opTbl[op].name, p, 3) == 0)
                break;
        }
        if (opTbl[op].name == NULL) {
            fprintf(stderr, "Unknown op: %s\n", str);
            return 1;
        }
        code[i].opCode = opTbl[op].opCode;
        /* 命令語の形式毎に処理 */
        switch (opTbl[op].flag) {
        case 1:
            sscanf(p+4, "%d", &code[i].u.value);
            break;
        case 2:
            sscanf(p+4, "%d,%d",
                &code[i].u.addr.level, &code[i].u.addr.addr);
            break;
        case 3:
            for (optr = 0; optrTbl[optr].name != NULL; optr++) {
                if (strncmp(optrTbl[optr].name, p+4,
                  strlen(optrTbl[optr].name)) == 0)
                    break;
            }
            if (optrTbl[optr].name == NULL) {
                fprintf(stderr, "Unknown operator: %s\n", str);
                return 1;
            }
            code[i].u.optr = optrTbl[optr].optr;
            break;
        }
    }
    cIndex = i;
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rdi, %rbx
leaq 0x10(%rsp), %r12
movq %r12, %rdi
movl $0x100, %esi            # imm = 0x100
movq %rbx, %rdx
callq 0x20e0
xorl %ecx, %ecx
movl $0x0, %r15d
testq %rax, %rax
je 0x2867
leaq 0x14(%rsp), %rbp
leaq 0x2ab9(%rip), %rdi      # 0x5155
leaq 0x538d(%rip), %r14      # 0x7a30
xorl %r15d, %r15d
movq %r12, %r13
movzbl (%r13), %eax
testl %eax, %eax
je 0x26bf
cmpl $0x3a, %eax
je 0x26bf
incq %r13
incq %rbp
jmp 0x26a9
xorl %ecx, %ecx
cmpb $0x3a, %al
sete %cl
addq %rcx, %r13
addq %rcx, %rbp
movzbl (%r13), %eax
cmpl $0x20, %eax
jne 0x26de
incq %r13
incq %rbp
jmp 0x26cc
testl %eax, %eax
je 0x288d
movq %rbx, 0x8(%rsp)
movl $0x3, %edx
movq %r13, %rsi
callq 0x2040
testl %eax, %eax
je 0x2736
xorl %ecx, %ecx
leaq 0x10(%rcx), %rbx
cmpq $0x90, %rbx
je 0x2870
movq 0x10(%rcx,%r14), %r12
movl $0x3, %edx
movq %r12, %rdi
movq %r13, %rsi
callq 0x2040
movq %rbx, %rcx
testl %eax, %eax
jne 0x26fe
testq %r12, %r12
sete %al
addq %r14, %rbx
jmp 0x273b
xorl %eax, %eax
movq %r14, %rbx
testb %al, %al
jne 0x2870
leaq (%r15,%r15,2), %rax
leaq 0x59a2(%rip), %rcx      # 0x80f0
leaq (%rcx,%rax,4), %r13
movl 0x8(%rbx), %ecx
movl 0xc(%rbx), %eax
movl %ecx, (%r13)
cmpl $0x1, %eax
je 0x2805
cmpl $0x2, %eax
movq 0x8(%rsp), %rbx
leaq 0x10(%rsp), %r12
je 0x27e7
cmpl $0x3, %eax
jne 0x283d
movl $0x3, %edx
leaq 0x2aad(%rip), %rdi      # 0x5236
movq %rbp, %rsi
callq 0x2040
testl %eax, %eax
je 0x281f
xorl %ecx, %ecx
leaq 0x10(%rcx), %rbx
cmpq $0xf0, %rbx
je 0x28a6
leaq 0x531d(%rip), %rax      # 0x7ad0
movq 0x10(%rcx,%rax), %r12
movq %r12, %rdi
callq 0x2080
movq %r12, %rdi
movq %rbp, %rsi
movq %rax, %rdx
callq 0x2040
movq %rbx, %rcx
testl %eax, %eax
jne 0x279b
testq %r12, %r12
sete %al
leaq 0x52ee(%rip), %rcx      # 0x7ad0
addq %rcx, %rbx
jmp 0x2828
leaq 0x4(%r13), %rdx
addq $0x8, %r13
movq %rbp, %rdi
leaq 0x2990(%rip), %rsi      # 0x5189
movq %r13, %rcx
xorl %eax, %eax
callq 0x2130
jmp 0x283d
addq $0x4, %r13
movq %rbp, %rdi
leaq 0x2979(%rip), %rsi      # 0x518c
movq %r13, %rdx
xorl %eax, %eax
callq 0x2130
jmp 0x2833
xorl %eax, %eax
leaq 0x52a8(%rip), %rbx      # 0x7ad0
testb %al, %al
jne 0x28a6
movl 0x8(%rbx), %eax
movl %eax, 0x4(%r13)
movq 0x8(%rsp), %rbx
leaq 0x10(%rsp), %r12
incq %r15
movq %r12, %rdi
movl $0x100, %esi            # imm = 0x100
movq %rbx, %rdx
callq 0x20e0
testq %rax, %rax
leaq 0x14(%rsp), %rbp
leaq 0x28f6(%rip), %rdi      # 0x5155
jne 0x26a6
xorl %ecx, %ecx
movl %r15d, 0x586a(%rip)     # 0x80d8
jmp 0x2892
movq 0x5779(%rip), %rax      # 0x7ff0
movq (%rax), %rdi
leaq 0x28f8(%rip), %rsi      # 0x5179
leaq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x2110
movl $0x1, %ecx
movl %ecx, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x5743(%rip), %rax      # 0x7ff0
movq (%rax), %rdi
leaq 0x28d8(%rip), %rsi      # 0x518f
jmp 0x2881