// File: /workspace/github_c_makefile_star2_O2/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 0x636d
movq (%r15), %rdx
andq $0x0, (%rsp)
leaq 0x1df9(%rip), %rsi      # 0x8143
leaq 0x2368(%rip), %rcx      # 0x86b9
leaq 0x237a(%rip), %r9       # 0x86d2
movq %r14, %rdi
movq %rdx, %r8
xorl %eax, %eax
callq 0x3500
pushq $0x1
popq %rbp
jmp 0x64e6
movq %rdi, %r13
pushq $0x1
popq %rbp
movl %ebp, %ecx
movl %ebp, %eax
cmpl $0x3, %r12d
jne 0x6399
movq 0x8(%r15), %rdi
leaq 0x22c8(%rip), %rsi      # 0x8650
callq 0x3310
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
pushq $0x2
popq %rax
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 0x64e6
movq 0x20(%rsp), %rax
cmpl $0x0, 0x10(%rax)
je 0x6463
leal 0x2(%rbx), %eax
cmpl %r12d, %eax
jbe 0x647a
movq %rbx, 0x28(%rsp)
movabsq $0x4000000000000000, %r12 # imm = 0x4000000000000000
movq %r12, 0x10(%rsp)
movl $0x1000, %r13d          # imm = 0x1000
xorl %ebx, %ebx
testq %r12, %r12
jle 0x64fa
cmpq %r13, %r12
cmovaeq %r13, %r12
movq 0x20(%rsp), %rax
movq (%rax), %rcx
leaq 0x30(%rsp), %rdi
pushq $0x1
popq %rsi
movq %r12, %rdx
callq 0x3120
movq %rax, %rbp
movq 0x20(%rsp), %rax
movq (%rax), %rdi
callq 0x3110
testl %eax, %eax
jne 0x653c
testq %rbp, %rbp
je 0x64fa
movb $0x0, 0x30(%rsp,%rbp)
movq %r14, %rdi
leaq 0x30(%rsp), %rsi
xorl %edx, %edx
xorl %eax, %eax
callq 0x3500
movq 0x10(%rsp), %r12
subq %rbp, %r12
movq %r12, 0x10(%rsp)
addq %rbp, %rbx
jmp 0x63f2
movq (%r15,%rbx,8), %rdx
leaq 0x1cb2(%rip), %rsi      # 0x8120
leaq 0x2081(%rip), %rcx      # 0x84f6
movq %r14, %rdi
jmp 0x64dc
callq 0x3620
movq (%rax), %rax
movq 0x8(%r15,%rbx,8), %r13
movsbq (%r13), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
jne 0x6519
movabsq $0x4000000000000000, %r12 # imm = 0x4000000000000000
movq %r12, 0x10(%rsp)
movq %r13, %rdi
callq 0x3190
leaq 0x219c(%rip), %rsi      # 0x8651
movq %r13, %rdi
movq %rax, %rdx
callq 0x30b0
testl %eax, %eax
je 0x6588
leaq 0x21ab(%rip), %rsi      # 0x867a
leaq 0x21b3(%rip), %rcx      # 0x8689
movq %r14, %rdi
movq %r13, %rdx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x3500
movl %ebp, %eax
addq $0x1038, %rsp           # imm = 0x1038
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebp, %ebp
cmpl $0x0, 0x1c(%rsp)
jne 0x64e6
testq %rbx, %rbx
jle 0x64e6
movq (%r14), %rax
cmpb $0xa, -0x1(%rax,%rbx)
jne 0x64e6
movb $0x0, -0x1(%rax,%rbx)
jmp 0x64e6
leaq 0x10(%rsp), %rdx
movq %r14, %rdi
movq %r13, %rsi
callq 0x3470
testl %eax, %eax
jne 0x64e6
movq %rbx, 0x28(%rsp)
movq 0x10(%rsp), %r12
jmp 0x63ea
movq %r14, %rdi
callq 0x3260
movq 0x28(%rsp), %rax
movq (%r15,%rax,8), %r15
movq %r14, %rdi
callq 0x31b0
leaq 0x1fb6(%rip), %rsi      # 0x8512
leaq 0x1c88(%rip), %rcx      # 0x81eb
movq %r14, %rdi
movq %r15, %rdx
movq %rax, %r8
xorl %r9d, %r9d
xorl %eax, %eax
callq 0x3500
movq 0x20(%rsp), %rax
movq (%rax), %rdi
callq 0x3390
jmp 0x6365
movq %rbx, 0x28(%rsp)
movl $0x0, 0x1c(%rsp)
jmp 0x63ea