// File: /workspace/github_c_makefile_star2_O2/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, %r13
leaq 0x14(%rsp), %rbx
leaq 0x10(%rsp), %r14
leaq 0x443a(%rip), %r12      # 0x6a30
pushq $0x3
popq %r15
movq $0x0, (%rsp)
movq %r14, %rdi
movl $0x100, %esi            # imm = 0x100
movq %r13, %rdx
callq 0x20d0
testq %rax, %rax
je 0x275a
movq %rbx, %rbp
movzbl (%r14), %eax
testl %eax, %eax
je 0x2633
cmpl $0x3a, %eax
je 0x2633
incq %r14
incq %rbp
jmp 0x261e
xorl %ecx, %ecx
cmpb $0x3a, %al
sete %cl
addq %rcx, %r14
addq %rcx, %rbp
movzbl (%r14), %eax
cmpl $0x20, %eax
jne 0x2651
incq %r14
incq %rbp
jmp 0x2640
testl %eax, %eax
je 0x2785
xorl %ecx, %ecx
leaq 0x10(%rcx), %rbx
cmpq $0xa0, %rbx
je 0x2768
movq (%rcx,%r12), %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x2040
movq %rbx, %rcx
testl %eax, %eax
jne 0x265b
imulq $0xc, (%rsp), %rcx
leaq 0x4a62(%rip), %rsi      # 0x70f0
leaq (%rsi,%rcx), %r14
movl -0x8(%rbx,%r12), %edx
movl -0x4(%rbx,%r12), %eax
movl %edx, (%rcx,%rsi)
cmpl $0x1, %eax
je 0x272f
cmpl $0x2, %eax
leaq 0x14(%rsp), %rbx
je 0x2711
cmpl $0x3, %eax
jne 0x274c
movq %r13, 0x8(%rsp)
xorl %ecx, %ecx
leaq 0x10(%rcx), %rbx
cmpq $0x100, %rbx            # imm = 0x100
je 0x279a
leaq 0x43f6(%rip), %rax      # 0x6ad0
movq (%rcx,%rax), %r13
movq %r13, %rdi
callq 0x2080
movq %r13, %rdi
movq %rbp, %rsi
movq %rax, %rdx
callq 0x2040
movq %rbx, %rcx
testl %eax, %eax
jne 0x26c2
leaq 0x43ce(%rip), %rax      # 0x6ad0
movl -0x8(%rbx,%rax), %eax
movl %eax, 0x4(%r14)
movq 0x8(%rsp), %r13
jmp 0x2747
leaq 0x4(%r14), %rdx
addq $0x8, %r14
movq %rbp, %rdi
leaq 0x1a42(%rip), %rsi      # 0x4165
movq %r14, %rcx
xorl %eax, %eax
callq 0x2120
jmp 0x274c
addq $0x4, %r14
movq %rbp, %rdi
leaq 0x1a2b(%rip), %rsi      # 0x4168
movq %r14, %rdx
xorl %eax, %eax
callq 0x2120
leaq 0x14(%rsp), %rbx
incq (%rsp)
leaq 0x10(%rsp), %r14
jmp 0x2602
movq (%rsp), %rax
movl %eax, 0x496c(%rip)      # 0x70d0
xorl %eax, %eax
jmp 0x2788
movq 0x4881(%rip), %rax      # 0x6ff0
movq (%rax), %rdi
leaq 0x19dc(%rip), %rsi      # 0x4155
leaq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x2100
pushq $0x1
popq %rax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x484f(%rip), %rax      # 0x6ff0
movq (%rax), %rdi
leaq 0x19c0(%rip), %rsi      # 0x416b
jmp 0x2779