// File: /workspace/github_c_makefile_star2_O0/martincameron[P]towntalk/ttasm.c
// Function: parse_instructions
static int parse_instructions( struct element *elem, struct function *func, struct instruction *output, struct label *labels, char *message ) {
	int count = 0;
	while( elem ) {
		if( elem->str.string[ elem->str.length - 1 ] == ':' ) {
			if( output == NULL ) {
				labels->next = new_label( elem, count, message );
				labels = labels->next;
				if( labels == NULL ) {
					break;
				}
			}
		} else if( strcmp( elem->str.string, "//" ) ) {
			if( is_keyword( elem->str.string, "let" ) ) {
				if( output ) {
					elem = parse_let( elem, func, &output[ count ], message );
				} else {
					elem = validate_let( elem, message );
				}
				if( elem == NULL ) {
					break;
				}
			} else if( is_keyword( elem->str.string, "jump" ) ) {
				if( output ) {
					elem = parse_jump( elem, func, labels->next, &output[ count ], message );
				} else {
					elem = validate_jump( elem, message );
				}
				if( elem == NULL ) {
					break;
				}
			} else if( is_keyword( elem->str.string, "halt" ) ) {
				if( output ) {
					output[ count ].opcode = HALT;
				}
			} else {
				sprintf( message, "Unrecognized opcode '%.64s' on line %d.", elem->str.string, elem->line );
				break;
			}
			if( elem->next && strcmp( ";", elem->next->str.string ) == 0 ) {
				elem = elem->next;
				count++;
			} else {
				sprintf( message, "Expected ';' after '%.64s' on line %d.", elem->str.string, elem->line );
				break;
			}
		}
		elem = elem->next;
	}
	if( message[ 0 ] ) {
		count = 0;
	} else {
		if( output ) {
			output[ count ].opcode = HALT;
		}
		count++;
	}
	return count;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x17c7b
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movl 0x10(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x3a, %eax
jne 0x17abd
cmpq $0x0, -0x18(%rbp)
jne 0x17ab8
movq -0x8(%rbp), %rdi
movl -0x2c(%rbp), %esi
movq -0x28(%rbp), %rdx
callq 0x19710
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x17ab6
jmp 0x17c7b
jmp 0x17ab8
jmp 0x17c6a
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x456c(%rip), %rsi      # 0x1c038
callq 0x3130
cmpl $0x0, %eax
je 0x17c68
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x4659(%rip), %rsi      # 0x1c142
callq 0x83b0
cmpl $0x0, %eax
je 0x17b42
cmpq $0x0, -0x18(%rbp)
je 0x17b20
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movslq -0x2c(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdx
movq -0x28(%rbp), %rcx
callq 0x19810
movq %rax, -0x8(%rbp)
jmp 0x17b31
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x19950
movq %rax, -0x8(%rbp)
cmpq $0x0, -0x8(%rbp)
jne 0x17b3d
jmp 0x17c7b
jmp 0x17c04
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x4daf(%rip), %rsi      # 0x1c900
callq 0x83b0
cmpl $0x0, %eax
je 0x17baf
cmpq $0x0, -0x18(%rbp)
je 0x17b90
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0x18(%rbp), %rcx
movslq -0x2c(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rcx
movq -0x28(%rbp), %r8
callq 0x19ab0
movq %rax, -0x8(%rbp)
jmp 0x17ba1
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x19c30
movq %rax, -0x8(%rbp)
cmpq $0x0, -0x8(%rbp)
jne 0x17bad
jmp 0x17c7b
jmp 0x17c02
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x4d47(%rip), %rsi      # 0x1c905
callq 0x83b0
cmpl $0x0, %eax
je 0x17bdd
cmpq $0x0, -0x18(%rbp)
je 0x17bdb
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movb $0x0, (%rax,%rcx,8)
jmp 0x17c00
movq -0x28(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x8(%rbp), %rax
movl 0x28(%rax), %ecx
leaq 0x4d13(%rip), %rsi      # 0x1c90a
movb $0x0, %al
callq 0x31f0
jmp 0x17c7b
jmp 0x17c02
jmp 0x17c04
movq -0x8(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x17c43
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x8(%rax), %rsi
leaq 0x436f(%rip), %rdi      # 0x1bf91
callq 0x3130
cmpl $0x0, %eax
jne 0x17c43
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x8(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x17c66
movq -0x28(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x8(%rbp), %rax
movl 0x28(%rax), %ecx
leaq 0x4cd5(%rip), %rsi      # 0x1c932
movb $0x0, %al
callq 0x31f0
jmp 0x17c7b
jmp 0x17c68
jmp 0x17c6a
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x8(%rbp)
jmp 0x17a53
movq -0x28(%rbp), %rax
cmpb $0x0, (%rax)
je 0x17c8d
movl $0x0, -0x2c(%rbp)
jmp 0x17ca9
cmpq $0x0, -0x18(%rbp)
je 0x17ca0
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movb $0x0, (%rax,%rcx,8)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)