// File: /workspace/github_c_makefile_star2_O1/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 %r14
pushq %rbx
subq $0x90, %rsp
movq %rdi, %rbx
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq 0x18(%rbx), %rax
cmpq %rax, 0x28(%rbx)
jb 0x4f61
movl (%rbx), %ecx
testl %ecx, %ecx
jne 0x4e44
testq %rax, %rax
jne 0x4f75
movq 0x8(%rbx), %rdi
testq %rdi, %rdi
je 0x4f75
cmpb $0x0, (%rdi)
je 0x4f75
callq 0x20e0
movq %rax, 0x18(%rbx)
jmp 0x4e06
cmpl $0x1, %ecx
jne 0x4f61
cmpq $0x0, 0x8(%rbx)
jne 0x4eac
movl 0x10(%rbx), %edi
movq %rsp, %rsi
callq 0x2320
cmpl $-0x1, %eax
je 0x4fa9
movl $0xf000, %eax           # imm = 0xF000
andl 0x18(%rsp), %eax
cmpl $0x8000, %eax           # imm = 0x8000
jne 0x4e9c
movq 0x30(%rsp), %r14
movq %r14, 0x30(%rbx)
movq %r14, %rdi
callq 0x21f0
movq %rax, 0x8(%rbx)
movl $0x20, %ecx
testq %rax, %rax
jne 0x4ea8
jmp 0x4f96
movq $-0x1, %r14
movl $0x30, %ecx
movq %r14, (%rbx,%rcx)
movq 0x28(%rbx), %rax
cmpq 0x20(%rbx), %rax
jb 0x4efc
testq %rax, %rax
je 0x4ed9
leaq 0x1fff(%rax), %r14
testq %rax, %rax
cmovnsq %rax, %r14
andq $-0x2000, %r14          # imm = 0xE000
addq $0x2000, %r14           # imm = 0x2000
jmp 0x4edf
movl $0x2000, %r14d          # imm = 0x2000
movq 0x8(%rbx), %rdi
movq %r14, %rsi
callq 0x2220
testq %rax, %rax
je 0x4f96
movq %rax, 0x8(%rbx)
movq %r14, 0x20(%rbx)
movq 0x18(%rbx), %rax
cmpq 0x28(%rbx), %rax
ja 0x4f61
movl 0x10(%rbx), %edi
movq 0x8(%rbx), %rsi
addq %rax, %rsi
movq 0x20(%rbx), %rdx
subq %rax, %rdx
callq 0x2170
movq %rax, %r14
testq %rax, %rax
jle 0x4f2a
addq %r14, 0x18(%rbx)
jmp 0x4f38
jns 0x4f38
callq 0x2060
movl (%rax), %edi
cmpl $0x4, %edi
jne 0x4f83
testq %r14, %r14
je 0x4f49
movq 0x18(%rbx), %rcx
movb $0x1, %al
cmpq 0x30(%rbx), %rcx
jne 0x4f5b
movl $0x0, (%rbx)
movq %rbx, %rdi
callq 0x4df3
movl %eax, %ebp
xorl %eax, %eax
testb %al, %al
jne 0x4efc
jmp 0x4f75
movq 0x8(%rbx), %rax
movq 0x28(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x28(%rbx)
movzbl (%rax,%rcx), %ebp
movl %ebp, %eax
addq $0x90, %rsp
popq %rbx
popq %r14
popq %rbp
retq
callq 0x2300
leaq 0x35dd(%rip), %rsi      # 0x856c
xorl %edi, %edi
movq %rax, %rdx
jmp 0x4fa2
leaq 0x35b6(%rip), %rsi      # 0x8553
xorl %edi, %edi
movq %r14, %rdx
xorl %eax, %eax
callq 0x4388
callq 0x2060
movl (%rax), %edi
callq 0x2300
leaq 0x3584(%rip), %rsi      # 0x8540
jmp 0x4f8f