// File: /workspace/github_c_makefile_star2_O1/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 0x6584
movq (%r15), %rdx
movq $0x0, (%rsp)
leaq 0x2bdf(%rip), %rsi      # 0x9143
leaq 0x312a(%rip), %rcx      # 0x9695
leaq 0x313c(%rip), %r9       # 0x96ae
movq %r14, %rdi
movq %rdx, %r8
xorl %eax, %eax
callq 0x3510
jmp 0x6734
movq %rdi, %r13
movl $0x1, %ebp
movl $0x1, %eax
cmpl $0x3, %r12d
jne 0x65b6
movq 0x8(%r15), %rdi
leaq 0x308a(%rip), %rsi      # 0x962c
callq 0x3320
xorl %ebp, %ebp
testl %eax, %eax
setne %bpl
movl $0x2, %eax
subl %ebp, %eax
movl %eax, %ebx
movq (%r15,%rbx,8), %rdx
leaq 0x18(%rsp), %rcx
movq %r14, %rdi
movq %r13, %rsi
callq 0x3060
testl %eax, %eax
jne 0x6734
movq %rbx, 0x20(%rsp)
movq 0x18(%rsp), %rax
cmpl $0x0, 0x10(%rax)
je 0x66b0
movq 0x20(%rsp), %rbx
leal 0x2(%rbx), %eax
cmpl %r12d, %eax
jle 0x66cc
movabsq $0x4000000000000000, %rax # imm = 0x4000000000000000
movq %rax, 0x10(%rsp)
movl %ebp, 0x2c(%rsp)
movq 0x10(%rsp), %rdx
xorl %r12d, %r12d
testq %rdx, %rdx
jle 0x668c
leaq 0x30(%rsp), %rbx
xorl %r12d, %r12d
movl $0x1000, %eax           # imm = 0x1000
cmpq %rax, %rdx
cmovgeq %rax, %rdx
movq 0x18(%rsp), %rax
movq (%rax), %rcx
movl $0x1, %esi
movq %rbx, %rbp
movq %rbx, %rdi
callq 0x3120
movq %rax, %r13
movq 0x18(%rsp), %rax
movq (%rax), %rdi
callq 0x3110
testl %eax, %eax
jne 0x6764
testq %r13, %r13
je 0x668c
movb $0x0, 0x30(%rsp,%r13)
movq %r14, %rdi
movq %rbp, %rsi
xorl %edx, %edx
xorl %eax, %eax
callq 0x3510
movq %rbp, %rbx
movq 0x10(%rsp), %rdx
addq %r13, %r12
subq %r13, %rdx
movq %rdx, 0x10(%rsp)
jg 0x6621
cmpl $0x0, 0x2c(%rsp)
jne 0x66a9
testq %r12, %r12
jle 0x66a9
movq (%r14), %rax
cmpb $0xa, -0x1(%rax,%r12)
jne 0x66a9
movb $0x0, -0x1(%rax,%r12)
xorl %eax, %eax
jmp 0x6739
movq 0x20(%rsp), %rax
movq (%r15,%rax,8), %rdx
leaq 0x2a60(%rip), %rsi      # 0x9120
leaq 0x2e0b(%rip), %rcx      # 0x94d2
movq %r14, %rdi
jmp 0x672a
callq 0x3630
movq (%rax), %rax
movq 0x8(%r15,%rbx,8), %r12
movsbq (%r12), %rcx
testb $0x8, 0x1(%rax,%rcx,2)
jne 0x674b
movabsq $0x4000000000000000, %rax # imm = 0x4000000000000000
movq %rax, 0x10(%rsp)
movq %r12, %rdi
callq 0x3190
leaq 0x2f2a(%rip), %rsi      # 0x962d
movq %r12, %rdi
movq %rax, %rdx
callq 0x30b0
testl %eax, %eax
je 0x67ad
leaq 0x2f39(%rip), %rsi      # 0x9656
leaq 0x2f41(%rip), %rcx      # 0x9665
movq %r14, %rdi
movq %r12, %rdx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x3510
movl $0x1, %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 %r12, %rsi
callq 0x3480
testl %eax, %eax
jne 0x6734
jmp 0x6608
movq %r14, %rdi
callq 0x3270
movq 0x20(%rsp), %rax
movq (%r15,%rax,8), %r15
movq %r14, %rdi
callq 0x31b0
leaq 0x2d6a(%rip), %rsi      # 0x94ee
leaq 0x2a60(%rip), %rcx      # 0x91eb
movq %r14, %rdi
movq %r15, %rdx
movq %rax, %r8
xorl %r9d, %r9d
xorl %eax, %eax
callq 0x3510
movq 0x18(%rsp), %rax
movq (%rax), %rdi
callq 0x33a0
jmp 0x6734
xorl %ebp, %ebp
jmp 0x6608