// File: /workspace/github_c_makefile_star2_O0/kyz[P]amostools/listamos.c
// Function: main
int main(int argc, char *argv[]) {
    uint8_t *buf;
    size_t len;
    int i;

    if (argc < 2) {
        printf("List AMOS source code as plain text.\n");
        printf("Usage: %s [options] <Filename.AMOS>\n", argv[0]);
        printf("Options:\n"
               "  -e extension     use this extension in its default slot\n"
               "  -eN=extension    use this extension in slot N\n"
               "  -c config        read extension filenames from config\n"
               "  -d dir           ...and extension files are in this dir\n");
        return 0;
    }

    i = read_extensions(argc, argv);
    read_config_extensions(argc, argv);
    read_default_extensions();

    /* list source file(s) */
    for (; i < argc; i++) {
        if ((buf = read_file(argv[i], &len))) {
            if (len >= 34 && amos_leek(buf) == 0x414D4F53) {
                uint32_t srclen = amos_leek(&buf[16]);
                if (srclen > (len - 20)) srclen = len - 20;
                int err = AMOS_print_source(&buf[20], srclen, stdout, table);
                if (err & 4) {
                    fprintf(stderr, "%s: missing extension instruction(s) - "
                            "are the correct extensions loaded?\n", argv[i]);
                }
            }
            else {
                fprintf(stderr, "%s: not an AMOS source file\n", argv[i]);
            }
            free(buf);
        }
    }
        
    AMOS_free_tokens(table);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x2, -0x8(%rbp)
jge 0x3739
leaq 0xad7(%rip), %rdi       # 0x41da
movb $0x0, %al
callq 0x10f0
movq -0x10(%rbp), %rax
movq (%rax), %rsi
leaq 0xae8(%rip), %rdi       # 0x4200
movb $0x0, %al
callq 0x10f0
leaq 0xaff(%rip), %rdi       # 0x4225
movb $0x0, %al
callq 0x10f0
movl $0x0, -0x4(%rbp)
jmp 0x38c0
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
callq 0x3010
movl %eax, -0x24(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
callq 0x3150
callq 0x3610
movl -0x24(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x38ad
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq -0x20(%rbp), %rsi
callq 0x12d0
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x389d
cmpq $0x22, -0x20(%rbp)
jb 0x3870
movq -0x18(%rbp), %rax
movzbl (%rax), %eax
shll $0x18, %eax
movq -0x18(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movq -0x18(%rbp), %rcx
movzbl 0x2(%rcx), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movq -0x18(%rbp), %rcx
movzbl 0x3(%rcx), %ecx
orl %ecx, %eax
cmpl $0x414d4f53, %eax       # imm = 0x414D4F53
jne 0x3870
movq -0x18(%rbp), %rax
movzbl 0x10(%rax), %eax
shll $0x18, %eax
movq -0x18(%rbp), %rcx
movzbl 0x11(%rcx), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movq -0x18(%rbp), %rcx
movzbl 0x12(%rcx), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movq -0x18(%rbp), %rcx
movzbl 0x13(%rcx), %ecx
orl %ecx, %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
movq -0x20(%rbp), %rcx
subq $0x14, %rcx
cmpq %rcx, %rax
jbe 0x3819
movq -0x20(%rbp), %rax
subq $0x14, %rax
movl %eax, -0x28(%rbp)
movq -0x18(%rbp), %rdi
addq $0x14, %rdi
movl -0x28(%rbp), %eax
movl %eax, %esi
movq 0x27ab(%rip), %rax      # 0x5fd8
movq (%rax), %rdx
leaq 0x5eb9(%rip), %rcx      # 0x96f0
callq 0x1480
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x386e
movq 0x27a7(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
leaq 0xaa4(%rip), %rsi       # 0x430b
movb $0x0, %al
callq 0x1150
jmp 0x3894
movq 0x2781(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
leaq 0xac9(%rip), %rsi       # 0x4356
movb $0x0, %al
callq 0x1150
movq -0x18(%rbp), %rdi
callq 0x1040
jmp 0x389f
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x3759
leaq 0x5e3c(%rip), %rdi      # 0x96f0
callq 0x2e80
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq