// File: /workspace/github_c_makefile_star2_O3/haxlang[P]hax/haxUnixAZ.c
// Function: Hax_ReadCmd
int
Hax_ReadCmd(
    ClientData clientData,		/* Unix ClientData */
    Hax_Interp *interp,			/* Current interpreter. */
    int argc,				/* Number of arguments. */
    char **argv				/* Argument strings. */)
{
    UnixClientData *clientDataPtr;
    OpenFile *filePtr;
    long int bytesLeft, bytesRead, count;
#define READ_BUF_SIZE 4096
    char buffer[READ_BUF_SIZE+1];
    int newline, i;

    if ((argc != 2) && (argc != 3)) {
	Hax_AppendResult(interp, "wrong # args: should be \"", argv[0],
		" fileId ?numBytes?\" or \"", argv[0],
		" ?-nonewline? fileId\"", (char *) NULL);
	return HAX_ERROR;
    }
    i = 1;
    newline = 1;
    if ((argc == 3) && (strcmp(argv[1], "-nonewline") == 0)) {
	newline = 0;
	i++;
    }

    clientDataPtr = (UnixClientData *) clientData;
    if (HaxGetOpenFile(interp, clientDataPtr, argv[i], &filePtr) != HAX_OK) {
	return HAX_ERROR;
    }
    if (!filePtr->readable) {
	Hax_AppendResult(interp, "\"", argv[i],
		"\" wasn't opened for reading", (char *) NULL);
	return HAX_ERROR;
    }

    /*
     * Compute how many bytes to read, and see whether the final
     * newline should be dropped.
     */

    if ((argc >= (i + 2)) && isdigit(argv[i+1][0])) {
	if (Hax_GetLong(interp, argv[i+1], &bytesLeft) != HAX_OK) {
	    return HAX_ERROR;
	}
    } else {
	bytesLeft = 1LL<<62;

	/*
	 * The code below provides backward compatibility for an
	 * archaic earlier version of this command.
	 */

	if (argc >= (i + 2)) {
	    if (strncmp(argv[i+1], "nonewline", strlen(argv[i+1])) == 0) {
		newline = 0;
	    } else {
		Hax_AppendResult(interp, "bad argument \"", argv[i+1],
			"\": should be \"nonewline\"", (char *) NULL);
		return HAX_ERROR;
	    }
	}
    }

    /*
     * Read the file in one or more chunks.
     */

    bytesRead = 0;
    while (bytesLeft > 0) {
	count = READ_BUF_SIZE;
	if (bytesLeft < READ_BUF_SIZE) {
	    count = bytesLeft;
	}
	count = fread(buffer, 1, count, filePtr->f);
	if (ferror(filePtr->f)) {
	    Hax_ResetResult(interp);
	    Hax_AppendResult(interp, "error reading \"", argv[i],
		    "\": ", Hax_UnixError(interp), (char *) NULL);
	    clearerr(filePtr->f);
	    return HAX_ERROR;
	}
	if (count == 0) {
	    break;
	}
	buffer[count] = 0;
	Hax_AppendResult(interp, buffer, (char *) NULL);
	bytesLeft -= count;
	bytesRead += count;
    }
    if ((newline == 0) && (bytesRead > 0)
	    && (interp->result[bytesRead-1] == '\n')) {
	interp->result[bytesRead-1] = 0;
    }
    return HAX_OK;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1038, %rsp           # imm = 0x1038
movq %rcx, %r15
movl %edx, %r12d
movq %rsi, %r14
leal -0x4(%r12), %eax
cmpl $-0x3, %eax
ja 0x646b
movq (%r15), %rdx
movq $0x0, (%rsp)
leaq 0x1cfd(%rip), %rsi      # 0x8143
leaq 0x226c(%rip), %rcx      # 0x86b9
leaq 0x227e(%rip), %r9       # 0x86d2
movq %r14, %rdi
movq %rdx, %r8
xorl %eax, %eax
callq 0x3510
movl $0x1, %ebp
jmp 0x660d
movq %rdi, %r13
movl $0x1, %ebp
movl $0x1, %ecx
movl $0x1, %eax
cmpl $0x3, %r12d
jne 0x64a1
movq 0x8(%r15), %rdi
leaq 0x21c2(%rip), %rsi      # 0x8650
callq 0x3320
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
movl $0x2, %eax
subl %ecx, %eax
movl %ecx, 0x1c(%rsp)
movl %eax, %ebx
movq (%r15,%rbx,8), %rdx
leaq 0x20(%rsp), %rcx
movq %r14, %rdi
movq %r13, %rsi
callq 0x3060
testl %eax, %eax
jne 0x660d
movq 0x20(%rsp), %rax
cmpl $0x0, 0x10(%rax)
je 0x658e
leal 0x2(%rbx), %eax
cmpl %r12d, %eax
jbe 0x65a5
movabsq $0x4000000000000000, %r12 # imm = 0x4000000000000000
movq %r12, 0x10(%rsp)
movq %rbx, 0x28(%rsp)
leaq 0x30(%rsp), %rdi
xorl %ebx, %ebx
movl $0x1000, %eax           # imm = 0x1000
cmpq %rax, %r12
cmovaeq %rax, %r12
movq 0x20(%rsp), %rax
movq (%rax), %rcx
movl $0x1, %esi
movq %rdi, %r13
movq %r12, %rdx
callq 0x3120
movq %rax, %rbp
movq 0x20(%rsp), %rax
movq (%rax), %rdi
callq 0x3110
testl %eax, %eax
jne 0x6647
testq %rbp, %rbp
je 0x6563
movb $0x0, 0x30(%rsp,%rbp)
movq %r14, %rdi
movq %r13, %rsi
xorl %edx, %edx
xorl %eax, %eax
callq 0x3510
movq %r13, %rdi
movq 0x10(%rsp), %r12
addq %rbp, %rbx
subq %rbp, %r12
movq %r12, 0x10(%rsp)
jg 0x64f9
xorl %ebp, %ebp
cmpl $0x0, 0x1c(%rsp)
jne 0x660d
testq %rbx, %rbx
jle 0x660d
movq (%r14), %rax
cmpb $0xa, -0x1(%rax,%rbx)
jne 0x660d
movb $0x0, -0x1(%rax,%rbx)
jmp 0x660d
movq (%r15,%rbx,8), %rdx
leaq 0x1b87(%rip), %rsi      # 0x8120
leaq 0x1f56(%rip), %rcx      # 0x84f6
movq %r14, %rdi
jmp 0x6603
callq 0x3630
movq (%rax), %rax
movq 0x8(%r15,%rbx,8), %r13
movsbq (%r13), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
jne 0x6621
movabsq $0x4000000000000000, %r12 # imm = 0x4000000000000000
movq %r12, 0x10(%rsp)
movq %r13, %rdi
callq 0x3190
leaq 0x2075(%rip), %rsi      # 0x8651
movq %r13, %rdi
movq %rax, %rdx
callq 0x30b0
testl %eax, %eax
je 0x6693
leaq 0x2084(%rip), %rsi      # 0x867a
leaq 0x208c(%rip), %rcx      # 0x8689
movq %r14, %rdi
movq %r13, %rdx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x3510
movl %ebp, %eax
addq $0x1038, %rsp           # imm = 0x1038
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x10(%rsp), %rdx
movq %r14, %rdi
movq %r13, %rsi
callq 0x3480
testl %eax, %eax
jne 0x660d
movq 0x10(%rsp), %r12
testq %r12, %r12
jg 0x64ed
xorl %ebp, %ebp
jmp 0x660d
movq %r14, %rdi
callq 0x3270
movq 0x28(%rsp), %rax
movq (%r15,%rax,8), %r15
movq %r14, %rdi
callq 0x31b0
leaq 0x1eab(%rip), %rsi      # 0x8512
leaq 0x1b7d(%rip), %rcx      # 0x81eb
movq %r14, %rdi
movq %r15, %rdx
movq %rax, %r8
xorl %r9d, %r9d
xorl %eax, %eax
callq 0x3510
movq 0x20(%rsp), %rax
movq (%rax), %rdi
callq 0x33a0
jmp 0x6461
movl $0x0, 0x1c(%rsp)
jmp 0x64ed