// File: /workspace/github_c_makefile_star2_O2/haxlang[P]hax/haxUnixUtil.c
// Function: HaxMakeFileTable
void
HaxMakeFileTable(
    Hax_Interp *interp,
    UnixClientData *clientDataPtr,
				/* Unix ClientData whose table of
				 * files is to be manipulated. */
    int index			/* Make sure table is large enough to
				 * hold at least this index. */)
{
    Hax_Memoryp *memoryp;

    memoryp = Hax_GetMemoryp(interp);

    /*
     * If the table doesn't even exist, then create it and initialize
     * entries for standard files.
     */

    if (clientDataPtr->numFiles == 0) {
	OpenFile *filePtr;
	int i;

	if (index < 2) {
	    clientDataPtr->numFiles = 3;
	} else {
	    clientDataPtr->numFiles = index+1;
	}
	clientDataPtr->filePtrArray = (OpenFile **) ckalloc(memoryp, (unsigned)
		((clientDataPtr->numFiles)*sizeof(OpenFile *)));
	for (i = clientDataPtr->numFiles-1; i >= 0; i--) {
	    clientDataPtr->filePtrArray[i] = NULL;
	}

	filePtr = (OpenFile *) ckalloc(memoryp, sizeof(OpenFile));
	filePtr->f = stdin;
	filePtr->f2 = NULL;
	filePtr->readable = 1;
	filePtr->writable = 0;
	filePtr->numPids = 0;
	filePtr->pidPtr = NULL;
	filePtr->errorId = -1;
	clientDataPtr->filePtrArray[0] = filePtr;

	filePtr = (OpenFile *) ckalloc(memoryp, sizeof(OpenFile));
	filePtr->f = stdout;
	filePtr->f2 = NULL;
	filePtr->readable = 0;
	filePtr->writable = 1;
	filePtr->numPids = 0;
	filePtr->pidPtr = NULL;
	filePtr->errorId = -1;
	clientDataPtr->filePtrArray[1] = filePtr;

	filePtr = (OpenFile *) ckalloc(memoryp, sizeof(OpenFile));
	filePtr->f = stderr;
	filePtr->f2 = NULL;
	filePtr->readable = 0;
	filePtr->writable = 1;
	filePtr->numPids = 0;
	filePtr->pidPtr = NULL;
	filePtr->errorId = -1;
	clientDataPtr->filePtrArray[2] = filePtr;
    } else if (index >= clientDataPtr->numFiles) {
	int newSize;
	OpenFile **newPtrArray;
	int i;

	newSize = index+1;
	newPtrArray = (OpenFile **) ckalloc(memoryp, (unsigned)
		((newSize)*sizeof(OpenFile *)));
	memcpy(newPtrArray, clientDataPtr->filePtrArray,
		clientDataPtr->numFiles*sizeof(OpenFile *));
	for (i = clientDataPtr->numFiles; i < newSize; i++) {
	    newPtrArray[i] = NULL;
	}
	ckfree(memoryp, (char *) clientDataPtr->filePtrArray);
	clientDataPtr->numFiles = newSize;
	clientDataPtr->filePtrArray = newPtrArray;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %r15d
movq %rsi, %rbx
callq 0x3530
movq %rax, %r14
movl (%rbx), %eax
testl %eax, %eax
je 0x7ab6
cmpl %r15d, %eax
jg 0x7be8
leal 0x1(%r15), %ebp
leal 0x8(,%r15,8), %esi
leaq 0x1860(%rip), %rdx      # 0x92da
movq %r14, %rdi
movl $0x39a, %ecx            # imm = 0x39A
callq 0x34b0
movq %rax, %r12
movq 0x8(%rbx), %rsi
movslq (%rbx), %rdx
shlq $0x3, %rdx
movq %rax, %rdi
callq 0x33b0
movslq (%rbx), %rax
movslq %r15d, %rcx
cmpq %rcx, %rax
jg 0x7bca
andq $0x0, (%r12,%rax,8)
incq %rax
jmp 0x7aa3
leal 0x1(%r15), %eax
cmpl $0x2, %r15d
pushq $0x3
popq %rsi
cmovgel %eax, %esi
movl %esi, (%rbx)
shll $0x3, %esi
leaq 0x180a(%rip), %rdx      # 0x92da
movq %r14, %rdi
movl $0x371, %ecx            # imm = 0x371
callq 0x34b0
movq %rax, 0x8(%rbx)
movl (%rbx), %eax
testl %eax, %eax
jle 0x7af6
movq 0x8(%rbx), %rcx
andq $0x0, -0x8(%rcx,%rax,8)
decq %rax
jmp 0x7ae3
leaq 0x17dd(%rip), %r15      # 0x92da
pushq $0x30
popq %r12
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
movl $0x376, %ecx            # imm = 0x376
callq 0x34b0
movq 0x44a5(%rip), %rcx      # 0xbfc0
movq (%rcx), %rcx
movq %rcx, (%rax)
andq $0x0, 0x8(%rax)
movq $0x1, 0x10(%rax)
andl $0x0, 0x18(%rax)
andq $0x0, 0x20(%rax)
orl $-0x1, 0x28(%rax)
movq 0x8(%rbx), %rcx
movq %rax, (%rcx)
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
movl $0x380, %ecx            # imm = 0x380
callq 0x34b0
movq 0x445c(%rip), %rcx      # 0xbfb8
movq (%rcx), %rcx
movq %rcx, (%rax)
andq $0x0, 0x8(%rax)
movabsq $0x100000000, %r13      # imm = 0x100000000
movq %r13, 0x10(%rax)
andl $0x0, 0x18(%rax)
andq $0x0, 0x20(%rax)
orl $-0x1, 0x28(%rax)
movq 0x8(%rbx), %rcx
movq %rax, 0x8(%rcx)
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
movl $0x38a, %ecx            # imm = 0x38A
callq 0x34b0
movq 0x444c(%rip), %rcx      # 0xbff0
movq (%rcx), %rcx
movq %rcx, (%rax)
andq $0x0, 0x8(%rax)
movq %r13, 0x10(%rax)
andl $0x0, 0x18(%rax)
andq $0x0, 0x20(%rax)
orl $-0x1, 0x28(%rax)
movq 0x8(%rbx), %rcx
movq %rax, 0x10(%rcx)
jmp 0x7be8
movq 0x8(%rbx), %rsi
leaq 0x1705(%rip), %rdx      # 0x92da
movq %r14, %rdi
movl $0x3a0, %ecx            # imm = 0x3A0
callq 0x31f0
movl %ebp, (%rbx)
movq %r12, 0x8(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq