// File: /workspace/github_c_makefile_star2_O3/hughbarney[P]zepl/lisp.c
// Function: streamGetc
int streamGetc(Stream * stream)
{
	if (stream->offset >= stream->length) {
		switch (stream->type) {
		case STREAM_TYPE_STRING:
			// set length if a string was given but its length has not been set
			if (!stream->length && stream->buffer && *stream->buffer) {
				stream->length = strlen(stream->buffer);
				return streamGetc(stream);
			}
			return EOF;

		case STREAM_TYPE_FILE:
			// if this is the first read, try to find the size of the file
			if (!stream->buffer) {
				struct stat st;

				if (fstat(stream->fd, &st) == -1)
					exception("fstat() failed, %s", strerror(errno));

				if (S_ISREG(st.st_mode)) {
					stream->size = st.st_size;

					if (!(stream->buffer = malloc(stream->size)))
						exception("out of memory, %ld bytes", (long)stream->size);

					stream->capacity = stream->size;
				} else
					stream->size = -1;
			}
			// resize buffer to nearest multiple of BUFSIZ if capacity exceeded
			if (stream->offset >= stream->capacity) {
				char *buffer;
				size_t capacity = stream->offset ? (stream->offset / BUFSIZ + 1) * BUFSIZ : BUFSIZ;

				if (!(buffer = realloc(stream->buffer, capacity)))
					exception("out of memory, %ld bytes", (long)capacity);

				stream->buffer = buffer;
				stream->capacity = capacity;
			}
			// read until offset reached
			while (stream->length <= stream->offset) {
				ssize_t nbytes = read(stream->fd, stream->buffer + stream->length,
						      stream->capacity - stream->length);

				if (nbytes > 0)
					stream->length += nbytes;
				else if (nbytes < 0 && errno != EINTR)
					exception("read() failed, %s", strerror(errno));

				if (nbytes == 0 || stream->length == stream->size) {
					stream->type = STREAM_TYPE_STRING;
					return streamGetc(stream);
				}
			}

			break;
		}
	}

	return (unsigned char)stream->buffer[stream->offset++];
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x90, %rsp
movq %rdi, %rbx
movq 0x18(%rdi), %rax
movq 0x28(%rdi), %r12
cmpq %rax, %r12
jae 0x4dfe
movq 0x8(%rbx), %rax
leaq 0x1(%r12), %rcx
movq %rcx, 0x28(%rbx)
movzbl (%rax,%r12), %ecx
movl %ecx, %eax
addq $0x90, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl (%rbx), %ecx
movq %rsp, %r14
movl $0xf000, %ebp           # imm = 0xF000
cmpl $0x1, %ecx
je 0x4e37
testl %ecx, %ecx
jne 0x4dda
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testq %rax, %rax
jne 0x4dec
movq 0x8(%rbx), %rdi
testq %rdi, %rdi
je 0x4dec
cmpb $0x0, (%rdi)
je 0x4dec
callq 0x20e0
movq %rax, 0x18(%rbx)
jmp 0x4f3a
cmpq $0x0, 0x8(%rbx)
jne 0x4e8f
movl 0x10(%rbx), %edi
movq %r14, %rsi
callq 0x2320
cmpl $-0x1, %eax
je 0x4f70
movl 0x18(%rsp), %eax
andl %ebp, %eax
cmpl $0x8000, %eax           # imm = 0x8000
jne 0x4e83
movq 0x30(%rsp), %r15
movq %r15, 0x30(%rbx)
movq %r15, %rdi
callq 0x21f0
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x4f62
movq %r15, 0x20(%rbx)
jmp 0x4e8b
movq $-0x1, 0x30(%rbx)
movq 0x28(%rbx), %r12
cmpq 0x20(%rbx), %r12
jb 0x4edc
testq %r12, %r12
je 0x4eb9
leaq 0x1fff(%r12), %r15
testq %r12, %r12
cmovnsq %r12, %r15
andq $-0x2000, %r15          # imm = 0xE000
addq $0x2000, %r15           # imm = 0x2000
jmp 0x4ebf
movl $0x2000, %r15d          # imm = 0x2000
movq 0x8(%rbx), %rdi
movq %r15, %rsi
callq 0x2220
testq %rax, %rax
je 0x4f62
movq %rax, 0x8(%rbx)
movq %r15, 0x20(%rbx)
movq 0x18(%rbx), %rax
movq 0x28(%rbx), %r12
cmpq %r12, %rax
ja 0x4dda
movl 0x10(%rbx), %edi
movq 0x8(%rbx), %rsi
addq %rax, %rsi
movq 0x20(%rbx), %rdx
subq %rax, %rdx
callq 0x2170
testq %rax, %rax
jle 0x4f12
addq 0x18(%rbx), %rax
movq %rax, 0x18(%rbx)
jmp 0x4f24
jns 0x4f2c
callq 0x2060
movl (%rax), %edi
cmpl $0x4, %edi
jne 0x4f4a
movq 0x18(%rbx), %rax
cmpq 0x30(%rbx), %rax
jne 0x4ee0
jmp 0x4f30
movq 0x18(%rbx), %rax
movl $0x0, (%rbx)
movq 0x28(%rbx), %r12
xorl %ecx, %ecx
cmpq %rax, %r12
jae 0x4e08
jmp 0x4dda
callq 0x2300
leaq 0x3616(%rip), %rsi      # 0x856c
xorl %edi, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0x4380
leaq 0x35ea(%rip), %rsi      # 0x8553
xorl %edi, %edi
movq %r15, %rdx
jmp 0x4f5b
callq 0x2060
movl (%rax), %edi
callq 0x2300
leaq 0x35bd(%rip), %rsi      # 0x8540
jmp 0x4f56