// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jb 0x65b3
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xbc(%rbp)
testl %eax, %eax
je 0x6307
jmp 0x62f7
movl -0xbc(%rbp), %eax
subl $0x1, %eax
je 0x6362
jmp 0x65b1
movq -0x10(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x6356
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x6356
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x6356
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x20f0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rdi
callq 0x62c0
movl %eax, -0x4(%rbp)
jmp 0x65d5
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x65d5
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x641d
movq -0x10(%rbp), %rax
movl 0x10(%rax), %edi
leaq -0xa0(%rbp), %rsi
callq 0x2340
cmpl $-0x1, %eax
jne 0x63aa
callq 0x2060
movl (%rax), %edi
callq 0x2320
movq %rax, %rdx
xorl %eax, %eax
movl %eax, %edi
leaq 0x51d5(%rip), %rsi      # 0xb578
movb $0x0, %al
callq 0x50e0
movl -0x88(%rbp), %eax
andl $0xf000, %eax           # imm = 0xF000
cmpl $0x8000, %eax           # imm = 0x8000
jne 0x640f
movq -0x70(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x2220
movq -0x10(%rbp), %rcx
movq %rax, 0x8(%rcx)
cmpq $0x0, %rax
jne 0x63fd
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdx
xorl %eax, %eax
movl %eax, %edi
leaq 0x5195(%rip), %rsi      # 0xb58b
movb $0x0, %al
callq 0x50e0
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
jmp 0x641b
movq -0x10(%rbp), %rax
movq $-0x1, 0x30(%rax)
jmp 0x641d
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jb 0x64d5
movq -0x10(%rbp), %rax
cmpq $0x0, 0x28(%rax)
je 0x6461
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl $0x2000, %ecx           # imm = 0x2000
cqto
idivq %rcx
addq $0x1, %rax
shlq $0xd, %rax
movq %rax, -0xc8(%rbp)
jmp 0x646f
movl $0x2000, %eax           # imm = 0x2000
movq %rax, -0xc8(%rbp)
jmp 0x646f
movq -0xc8(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0xb0(%rbp), %rsi
callq 0x2240
movq %rax, -0xa8(%rbp)
cmpq $0x0, %rax
jne 0x64b7
movq -0xb0(%rbp), %rdx
xorl %eax, %eax
movl %eax, %edi
leaq 0x50db(%rip), %rsi      # 0xb58b
movb $0x0, %al
callq 0x50e0
movq -0xa8(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0xb0(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
jmp 0x64d7
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x28(%rcx), %rax
ja 0x65af
movq -0x10(%rbp), %rax
movl 0x10(%rax), %edi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x10(%rbp), %rax
addq 0x18(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdx
movq -0x10(%rbp), %rax
subq 0x18(%rax), %rdx
callq 0x2190
movq %rax, -0xb8(%rbp)
cmpq $0x0, -0xb8(%rbp)
jle 0x653f
movq -0xb8(%rbp), %rcx
movq -0x10(%rbp), %rax
addq 0x18(%rax), %rcx
movq %rcx, 0x18(%rax)
jmp 0x6576
cmpq $0x0, -0xb8(%rbp)
jge 0x6574
callq 0x2060
cmpl $0x4, (%rax)
je 0x6574
callq 0x2060
movl (%rax), %edi
callq 0x2320
movq %rax, %rdx
xorl %eax, %eax
movl %eax, %edi
leaq 0x5037(%rip), %rsi      # 0xb5a4
movb $0x0, %al
callq 0x50e0
jmp 0x6576
cmpq $0x0, -0xb8(%rbp)
je 0x6592
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x30(%rcx), %rax
jne 0x65aa
movq -0x10(%rbp), %rax
movl $0x0, (%rax)
movq -0x10(%rbp), %rdi
callq 0x62c0
movl %eax, -0x4(%rbp)
jmp 0x65d5
jmp 0x64d7
jmp 0x65b1
jmp 0x65b3
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rdx
movq 0x28(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x28(%rdx)
movzbl (%rax,%rcx), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)