// File: /workspace/github_c_makefile_star2_O0/afi-lambda[P]a_little_smalltalk/src/unixio.c
// Function: ioPrimitive
object ioPrimitive(int number, object *arguments)
{
    int i, j;
    char *p, buffer[1024];
    object returnedObject;

    returnedObject = nilobj;

    i = intValue(arguments[0]);

    switch (number)
    {
    case 0: /* file open */
        i = intValue(arguments[0]);
        p = charPtr(arguments[1]);
        if (streq(p, "stdin"))
            fp[i] = stdin;
        else if (streq(p, "stdout"))
            fp[i] = stdout;
        else if (streq(p, "stderr"))
            fp[i] = stderr;
        else
        {
            fp[i] = fopen(p, charPtr(arguments[2]));
        }
        if (fp[i] == NULL)
            returnedObject = nilobj;
        else
            returnedObject = newInteger(i);
        break;

    case 1: /* file close - recover slot */
        if (fp[i])
            fclose(fp[i]);
        fp[i] = NULL;
        break;

    case 2: /* file size */
    case 3: /* file in */
        if (fp[i])
            fileIn(fp[i], true);
        break;

    case 4: /* get character */
        sysError("file operation not implemented yet", "");

    case 5: /* get string */
        if (!fp[i])
            break;
        j = 0;
        buffer[j] = '\0';
        while (1)
        {
            if (fgets(&buffer[j], 512, fp[i]) == NULL)
                return (nilobj); /* end of file */
            if (fp[i] == stdin)
            {
                /* delete the newline */
                j = strlen(buffer);
                if (buffer[j - 1] == '\n')
                    buffer[j - 1] = '\0';
            }
            j = strlen(buffer) - 1;
            if (buffer[j] != '\\')
                break;
            /* else we loop again */
        }
        returnedObject = newStString(buffer);
        break;

    case 7: /* write an object image */
        if (fp[i])
            imageWrite(fp[i]);
        returnedObject = trueobj;
        break;

    case 8: /* print no return */
    case 9: /* print string */
        if (!fp[i])
            break;
        fputs(charPtr(arguments[1]), fp[i]);
        if (number == 8)
            fflush(fp[i]);
        else
            fputc('\n', fp[i]);
        break;

    default:
        sysError("unknown primitive", "filePrimitive");
    }

    return (returnedObject);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x450, %rsp            # imm = 0x450
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movw $0x0, -0x422(%rbp)
movq -0x10(%rbp), %rax
movswl (%rax), %edi
callq 0x3470
movl %eax, -0x14(%rbp)
movl -0x8(%rbp), %eax
movq %rax, -0x430(%rbp)
subq $0x9, %rax
ja 0xbcbc
movq -0x430(%rbp), %rax
leaq 0x1378(%rip), %rcx      # 0xcba4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rax
movswl (%rax), %edi
callq 0x3470
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movw 0x2(%rax), %ax
leaq 0x1e05d(%rip), %rcx     # 0x298b0
movw %ax, (%rcx)
movswl %ax, %edi
callq 0x2fb0
cmpl $0x0, %eax
je 0xb88d
leaq 0x1e046(%rip), %rax     # 0x298b0
movswl (%rax), %eax
sarl %eax
movslq %eax, %rcx
leaq 0x49e7(%rip), %rax      # 0x10260
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x438(%rbp)
jmp 0xb8b5
leaq 0x1e01c(%rip), %rax     # 0x298b0
movswl (%rax), %eax
sarl %eax
movslq %eax, %rcx
leaq 0x49bd(%rip), %rax      # 0x10260
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x438(%rbp)
movq -0x438(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
leaq 0x1343(%rip), %rsi      # 0xcc0e
callq 0x2150
cmpl $0x0, %eax
jne 0xb8f3
movq 0x36fc(%rip), %rax      # 0xefd8
movq (%rax), %rdx
movslq -0x14(%rbp), %rcx
leaq 0x20816(%rip), %rax     # 0x2c100
movq %rdx, (%rax,%rcx,8)
jmp 0xb9fe
movq -0x20(%rbp), %rdi
leaq 0x1316(%rip), %rsi      # 0xcc14
callq 0x2150
cmpl $0x0, %eax
jne 0xb926
movq 0x36c1(%rip), %rax      # 0xefd0
movq (%rax), %rdx
movslq -0x14(%rbp), %rcx
leaq 0x207e3(%rip), %rax     # 0x2c100
movq %rdx, (%rax,%rcx,8)
jmp 0xb9fc
movq -0x20(%rbp), %rdi
leaq 0x12ea(%rip), %rsi      # 0xcc1b
callq 0x2150
cmpl $0x0, %eax
jne 0xb959
movq 0x36b6(%rip), %rax      # 0xeff8
movq (%rax), %rdx
movslq -0x14(%rbp), %rcx
leaq 0x207b0(%rip), %rax     # 0x2c100
movq %rdx, (%rax,%rcx,8)
jmp 0xb9fa
movq -0x20(%rbp), %rax
movq %rax, -0x440(%rbp)
movq -0x10(%rbp), %rax
movw 0x4(%rax), %ax
leaq 0x1df3d(%rip), %rcx     # 0x298b0
movw %ax, (%rcx)
movswl %ax, %edi
callq 0x2fb0
cmpl $0x0, %eax
je 0xb9ad
leaq 0x1df26(%rip), %rax     # 0x298b0
movswl (%rax), %eax
sarl %eax
movslq %eax, %rcx
leaq 0x48c7(%rip), %rax      # 0x10260
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x448(%rbp)
jmp 0xb9d5
leaq 0x1defc(%rip), %rax     # 0x298b0
movswl (%rax), %eax
sarl %eax
movslq %eax, %rcx
leaq 0x489d(%rip), %rax      # 0x10260
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x448(%rbp)
movq -0x440(%rbp), %rdi
movq -0x448(%rbp), %rsi
callq 0x21b0
movq %rax, %rdx
movslq -0x14(%rbp), %rcx
leaq 0x2070a(%rip), %rax     # 0x2c100
movq %rdx, (%rax,%rcx,8)
jmp 0xb9fc
jmp 0xb9fe
movslq -0x14(%rbp), %rcx
leaq 0x206f7(%rip), %rax     # 0x2c100
cmpq $0x0, (%rax,%rcx,8)
jne 0xba1b
movw $0x0, -0x422(%rbp)
jmp 0xba2a
movl -0x14(%rbp), %edi
callq 0x34a0
movw %ax, -0x422(%rbp)
jmp 0xbccf
movslq -0x14(%rbp), %rcx
leaq 0x206c6(%rip), %rax     # 0x2c100
cmpq $0x0, (%rax,%rcx,8)
je 0xba55
movslq -0x14(%rbp), %rcx
leaq 0x206b4(%rip), %rax     # 0x2c100
movq (%rax,%rcx,8), %rdi
callq 0x2080
movslq -0x14(%rbp), %rcx
leaq 0x206a0(%rip), %rax     # 0x2c100
movq $0x0, (%rax,%rcx,8)
jmp 0xbccf
movslq -0x14(%rbp), %rcx
leaq 0x20688(%rip), %rax     # 0x2c100
cmpq $0x0, (%rax,%rcx,8)
je 0xba98
movslq -0x14(%rbp), %rcx
leaq 0x20676(%rip), %rax     # 0x2c100
movq (%rax,%rcx,8), %rdi
movl $0x1, %esi
callq 0x8020
jmp 0xbccf
leaq 0x117e(%rip), %rdi      # 0xcc22
leaq 0xc0a(%rip), %rsi       # 0xc6b5
callq 0x63f0
movslq -0x14(%rbp), %rcx
leaq 0x20645(%rip), %rax     # 0x2c100
cmpq $0x0, (%rax,%rcx,8)
jne 0xbac7
jmp 0xbccf
movl $0x0, -0x18(%rbp)
movslq -0x18(%rbp), %rax
movb $0x0, -0x420(%rbp,%rax)
movslq -0x18(%rbp), %rax
leaq -0x420(%rbp), %rdi
addq %rax, %rdi
movslq -0x14(%rbp), %rcx
leaq 0x2060d(%rip), %rax     # 0x2c100
movq (%rax,%rcx,8), %rdx
movl $0x200, %esi            # imm = 0x200
callq 0x2110
cmpq $0x0, %rax
jne 0xbb12
movw $0x0, -0x2(%rbp)
jmp 0xbcda
movslq -0x14(%rbp), %rcx
leaq 0x205e3(%rip), %rax     # 0x2c100
movq (%rax,%rcx,8), %rax
movq 0x34b0(%rip), %rcx      # 0xefd8
cmpq (%rcx), %rax
jne 0xbb63
leaq -0x420(%rbp), %rdi
callq 0x2090
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
subl $0x1, %eax
cltq
movsbl -0x420(%rbp,%rax), %eax
cmpl $0xa, %eax
jne 0xbb61
movl -0x18(%rbp), %eax
subl $0x1, %eax
cltq
movb $0x0, -0x420(%rbp,%rax)
jmp 0xbb63
leaq -0x420(%rbp), %rdi
callq 0x2090
subq $0x1, %rax
movl %eax, -0x18(%rbp)
movslq -0x18(%rbp), %rax
movsbl -0x420(%rbp,%rax), %eax
cmpl $0x5c, %eax
je 0xbb89
jmp 0xbb8e
jmp 0xbada
leaq -0x420(%rbp), %rdi
callq 0x45d0
movw %ax, -0x422(%rbp)
jmp 0xbccf
movslq -0x14(%rbp), %rcx
leaq 0x2054f(%rip), %rax     # 0x2c100
cmpq $0x0, (%rax,%rcx,8)
je 0xbbcc
movslq -0x14(%rbp), %rcx
leaq 0x2053d(%rip), %rax     # 0x2c100
movq (%rax,%rcx,8), %rdi
callq 0xb660
leaq 0x1e41f(%rip), %rax     # 0x29ff2
movw (%rax), %ax
movw %ax, -0x422(%rbp)
jmp 0xbccf
movslq -0x14(%rbp), %rcx
leaq 0x20513(%rip), %rax     # 0x2c100
cmpq $0x0, (%rax,%rcx,8)
jne 0xbbf9
jmp 0xbccf
movq -0x10(%rbp), %rax
movw 0x2(%rax), %ax
leaq 0x1dca8(%rip), %rcx     # 0x298b0
movw %ax, (%rcx)
movswl %ax, %edi
callq 0x2fb0
cmpl $0x0, %eax
je 0xbc42
leaq 0x1dc91(%rip), %rax     # 0x298b0
movswl (%rax), %eax
sarl %eax
movslq %eax, %rcx
leaq 0x4632(%rip), %rax      # 0x10260
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x450(%rbp)
jmp 0xbc6a
leaq 0x1dc67(%rip), %rax     # 0x298b0
movswl (%rax), %eax
sarl %eax
movslq %eax, %rcx
leaq 0x4608(%rip), %rax      # 0x10260
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x450(%rbp)
movq -0x450(%rbp), %rdi
movslq -0x14(%rbp), %rcx
leaq 0x20484(%rip), %rax     # 0x2c100
movq (%rax,%rcx,8), %rsi
callq 0x20c0
cmpl $0x8, -0x8(%rbp)
jne 0xbca1
movslq -0x14(%rbp), %rcx
leaq 0x2046a(%rip), %rax     # 0x2c100
movq (%rax,%rcx,8), %rdi
callq 0x2190
jmp 0xbcba
movslq -0x14(%rbp), %rcx
leaq 0x20454(%rip), %rax     # 0x2c100
movq (%rax,%rcx,8), %rsi
movl $0xa, %edi
callq 0x20f0
jmp 0xbccf
leaq 0x7fc(%rip), %rdi       # 0xc4bf
leaq 0xf7b(%rip), %rsi       # 0xcc45
callq 0x63f0
movw -0x422(%rbp), %ax
movw %ax, -0x2(%rbp)
movw -0x2(%rbp), %ax
addq $0x450, %rsp            # imm = 0x450
popq %rbp
retq