// File: /workspace/github_c_makefile_star2_O3/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 0x3540
movq %rax, %r14
movl (%rbx), %eax
testl %eax, %eax
je 0x7c6e
cmpl %r15d, %eax
jg 0x7d8f
leal 0x1(%r15), %ebp
leal 0x8(,%r15,8), %esi
leaq 0x16d0(%rip), %rdx      # 0x92da
movq %r14, %rdi
movl $0x39a, %ecx            # imm = 0x39A
callq 0x34c0
movq %rax, %r12
movq 0x8(%rbx), %rsi
movslq (%rbx), %rdx
shlq $0x3, %rdx
movq %rax, %rdi
callq 0x33c0
movslq (%rbx), %rax
cmpl %eax, %r15d
jl 0x7c4b
leaq (%r12,%rax,8), %rdi
subl %eax, %r15d
leaq 0x8(,%r15,8), %rdx
xorl %esi, %esi
callq 0x3250
movq 0x8(%rbx), %rsi
leaq 0x1684(%rip), %rdx      # 0x92da
movq %r14, %rdi
movl $0x3a0, %ecx            # imm = 0x3A0
callq 0x31f0
movl %ebp, (%rbx)
movq %r12, 0x8(%rbx)
jmp 0x7d8f
leal 0x1(%r15), %eax
cmpl $0x2, %r15d
movl $0x3, %esi
cmovgel %eax, %esi
movl %esi, (%rbx)
shll $0x3, %esi
leaq 0x1650(%rip), %rdx      # 0x92da
movq %r14, %rdi
movl $0x371, %ecx            # imm = 0x371
callq 0x34c0
movq %rax, 0x8(%rbx)
movslq (%rbx), %rax
testq %rax, %rax
jle 0x7cbc
incq %rax
movq 0x8(%rbx), %rcx
movq $0x0, -0x10(%rcx,%rax,8)
decq %rax
cmpq $0x1, %rax
ja 0x7ca6
leaq 0x1617(%rip), %r15      # 0x92da
movl $0x30, %esi
movq %r14, %rdi
movq %r15, %rdx
movl $0x376, %ecx            # imm = 0x376
callq 0x34c0
movq 0x42e1(%rip), %rcx      # 0xbfc0
movq (%rcx), %rcx
movq %rcx, (%rax)
xorl %r12d, %r12d
movq %r12, 0x8(%rax)
movq $0x1, 0x10(%rax)
movl %r12d, 0x18(%rax)
movq %r12, 0x20(%rax)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, 0x28(%rax)
movq 0x8(%rbx), %rcx
movq %rax, (%rcx)
movl $0x30, %esi
movq %r14, %rdi
movq %r15, %rdx
movl $0x380, %ecx            # imm = 0x380
callq 0x34c0
movq 0x4291(%rip), %rcx      # 0xbfb8
movq (%rcx), %rcx
movq %rcx, (%rax)
movq %r12, 0x8(%rax)
movabsq $0x100000000, %r13      # imm = 0x100000000
movq %r13, 0x10(%rax)
movl %r12d, 0x18(%rax)
movq %r12, 0x20(%rax)
movl %ebp, 0x28(%rax)
movq 0x8(%rbx), %rcx
movq %rax, 0x8(%rcx)
movl $0x30, %esi
movq %r14, %rdi
movq %r15, %rdx
movl $0x38a, %ecx            # imm = 0x38A
callq 0x34c0
movq 0x4282(%rip), %rcx      # 0xbff0
movq (%rcx), %rcx
movq %rcx, (%rax)
movq %r12, 0x8(%rax)
movq %r13, 0x10(%rax)
movl %r12d, 0x18(%rax)
movq %r12, 0x20(%rax)
movl %ebp, 0x28(%rax)
movq 0x8(%rbx), %rcx
movq %rax, 0x10(%rcx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq