// File: /workspace/github_c_makefile_star2_O2/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 %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdi, %r14
leaq 0x8(%rsp), %r15
movl $0xf000, %ebp           # imm = 0xF000
movl $0x2000, %r13d          # imm = 0x2000
pushq $-0x1
popq %rbx
movq 0x18(%r14), %rcx
movq 0x28(%r14), %rax
cmpq %rcx, %rax
jb 0x4c6c
movl (%r14), %edx
cmpl $0x1, %edx
je 0x4b80
testl %edx, %edx
jne 0x4c6c
testq %rcx, %rcx
jne 0x4c7c
movq 0x8(%r14), %rdi
testq %rdi, %rdi
je 0x4c7c
cmpb $0x0, (%rdi)
je 0x4c7c
callq 0x20e0
movq %rax, 0x18(%r14)
jmp 0x4b35
cmpq $0x0, 0x8(%r14)
jne 0x4bd6
movl 0x10(%r14), %edi
movq %r15, %rsi
callq 0x2320
cmpl $-0x1, %eax
je 0x4cb6
movl 0x20(%rsp), %eax
andl %ebp, %eax
cmpl $0x8000, %eax           # imm = 0x8000
jne 0x4bcd
movq 0x38(%rsp), %r12
movq %r12, 0x30(%r14)
movq %r12, %rdi
callq 0x21f0
movq %rax, 0x8(%r14)
testq %rax, %rax
je 0x4ca8
movq %r12, 0x20(%r14)
jmp 0x4bd2
orq $-0x1, 0x30(%r14)
movq 0x28(%r14), %rax
cmpq 0x20(%r14), %rax
jb 0x4c15
testq %rax, %rax
je 0x4bf2
cqto
idivq %r13
movq %rax, %r12
shlq $0xd, %r12
addq %r13, %r12
jmp 0x4bf8
movl $0x2000, %r12d          # imm = 0x2000
movq 0x8(%r14), %rdi
movq %r12, %rsi
callq 0x2220
testq %rax, %rax
je 0x4ca8
movq %rax, 0x8(%r14)
movq %r12, 0x20(%r14)
movq 0x18(%r14), %rcx
movq 0x28(%r14), %rax
cmpq %rax, %rcx
ja 0x4c6c
movl 0x10(%r14), %edi
movq 0x8(%r14), %rsi
addq %rcx, %rsi
movq 0x20(%r14), %rdx
subq %rcx, %rdx
callq 0x2170
testq %rax, %rax
jle 0x4c4b
movq %rax, %rcx
addq 0x18(%r14), %rcx
movq %rcx, 0x18(%r14)
jmp 0x4c5d
jns 0x4c63
callq 0x2060
movl (%rax), %edi
cmpl $0x4, %edi
jne 0x4c90
movq 0x18(%r14), %rcx
cmpq 0x30(%r14), %rcx
jne 0x4c19
andl $0x0, (%r14)
jmp 0x4b35
movq 0x8(%r14), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x28(%r14)
movzbl (%rcx,%rax), %ebx
movl %ebx, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2300
leaq 0x28c8(%rip), %rsi      # 0x7564
xorl %edi, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0x4186
leaq 0x289c(%rip), %rsi      # 0x754b
xorl %edi, %edi
movq %r12, %rdx
jmp 0x4ca1
callq 0x2060
movl (%rax), %edi
callq 0x2300
leaq 0x286f(%rip), %rsi      # 0x7538
jmp 0x4c9c