// File: /workspace/github_c_makefile_star2_O0/martincameron[P]towntalk/ttasm.c
// Function: parse_leta
static struct element* parse_leta( struct element *elem, struct function *func, struct instruction *output, char *message ) {
	/*
		opcode      x y z imm : mnemonic
		letai_v     x 0 z imm : let [ x imm ] = z;
		letav_i     x y 0 imm : let [ x y ] = imm;
		letav_v     x y z   0 : let [ x y ] = z;
		letap_v     x y z   0 : let [ x y++ ] = z;
	*/
	int idx;
	char *str;
	struct element *next = elem->next, *child = next->child;
	if( child && child->next && child->next->next == NULL ) {
		idx = get_local_variable( func, child, "", message );
		if( idx >= 0 ) {
			output->x = idx;
			str = child->next->str.string;
			if( str[ 0 ] == '-' || ( str[ 0 ] >= '0' && str[ 0 ] <= '9' ) ) {
				/* letai_v */
				if( parse_number( str, &output->imm ) ) {
					next = next->next->next;
					idx = get_local_variable( func, next, "", message );
					if( idx >= 0 ) {
						output->opcode = LETAI_V;
						output->z = idx;
					} else {
						next = NULL;
					}
				} else {
					sprintf( message, "Invalid immediate '%.64s' at line %d.", child->next->str.string, child->next->line );
					next = NULL;
				}
			} else {
				idx = get_local_variable( func, child->next, "", NULL );
				if( idx >= 0 ) {
					output->y = idx;
					next = next->next->next;
					str = next->str.string;
					if( str[ 0 ] == '-' || ( str[ 0 ] >= '0' && str[ 0 ] <= '9' ) ) {
						/* letav_i */
						if( parse_number( str, &output->imm ) ) {
							output->opcode = LETAV_I;
						} else {
							sprintf( message, "Invalid immediate '%.64s' at line %d.", next->str.string, next->line );
							next = NULL;
						}
					} else {
						/* letav_v */
						idx = get_local_variable( func, next, "", message );
						if( idx >= 0 ) {
							output->z = idx;
							output->opcode = LETAV_V;
						} else {
							next = NULL;
						}
					}
				} else {
					/* letap_v */
					idx = get_local_variable( func, child->next, "++", message );
					if( idx >= 0 ) {
						output->y = idx;
						next = next->next->next;
						idx = get_local_variable( func, next, "", message );
						if( idx >= 0 ) {
							output->z = idx;
							output->opcode = LETAP_V;
						} else {
							next = NULL;
						}
					} else {
						next = NULL;
					}
				}
			}
		} else {
			next = NULL;
		}
	} else {
		sprintf( message, "Invalid index expression on line %d.", next->line );
		next = NULL;
	}
	return next;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x1a203
movq -0x40(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x1a203
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rax
cmpq $0x0, 0x20(%rax)
jne 0x1a203
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x20(%rbp), %rcx
leaq 0x10e6(%rip), %rdx      # 0x1b056
callq 0x1a960
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jl 0x1a1f9
movl -0x24(%rbp), %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x1(%rax)
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
je 0x19fca
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x30, %eax
jl 0x1a066
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x39, %eax
jg 0x1a066
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x4, %rsi
callq 0x5d90
cmpl $0x0, %eax
je 0x1a030
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x20(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x20(%rbp), %rcx
leaq 0x1053(%rip), %rdx      # 0x1b056
callq 0x1a960
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jl 0x1a026
movq -0x18(%rbp), %rax
movb $0xd, (%rax)
movl -0x24(%rbp), %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x3(%rax)
jmp 0x1a02e
movq $0x0, -0x38(%rbp)
jmp 0x1a061
movq -0x20(%rbp), %rdi
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x8(%rax), %rdx
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rax
movl 0x28(%rax), %ecx
leaq 0x2935(%rip), %rsi      # 0x1c987
movb $0x0, %al
callq 0x31f0
movq $0x0, -0x38(%rbp)
jmp 0x1a1f7
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rsi
leaq 0xfdd(%rip), %rdx       # 0x1b056
xorl %eax, %eax
movl %eax, %ecx
callq 0x1a960
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jl 0x1a16a
movl -0x24(%rbp), %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x2(%rax)
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x20(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
je 0x1a0db
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x30, %eax
jl 0x1a125
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x39, %eax
jg 0x1a125
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x4, %rsi
callq 0x5d90
cmpl $0x0, %eax
je 0x1a0fa
movq -0x18(%rbp), %rax
movb $0xc, (%rax)
jmp 0x1a123
movq -0x20(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x38(%rbp), %rax
movl 0x28(%rax), %ecx
leaq 0x2873(%rip), %rsi      # 0x1c987
movb $0x0, %al
callq 0x31f0
movq $0x0, -0x38(%rbp)
jmp 0x1a165
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x20(%rbp), %rcx
leaq 0xf1e(%rip), %rdx       # 0x1b056
callq 0x1a960
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jl 0x1a15b
movl -0x24(%rbp), %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x3(%rax)
movq -0x18(%rbp), %rax
movb $0xe, (%rax)
jmp 0x1a163
movq $0x0, -0x38(%rbp)
jmp 0x1a165
jmp 0x1a1f5
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x20(%rbp), %rcx
leaq 0x1aad(%rip), %rdx      # 0x1bc2e
callq 0x1a960
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jl 0x1a1eb
movl -0x24(%rbp), %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x2(%rax)
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x20(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x20(%rbp), %rcx
leaq 0xe98(%rip), %rdx       # 0x1b056
callq 0x1a960
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jl 0x1a1e1
movl -0x24(%rbp), %eax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x3(%rax)
movq -0x18(%rbp), %rax
movb $0xf, (%rax)
jmp 0x1a1e9
movq $0x0, -0x38(%rbp)
jmp 0x1a1f3
movq $0x0, -0x38(%rbp)
jmp 0x1a1f5
jmp 0x1a1f7
jmp 0x1a201
movq $0x0, -0x38(%rbp)
jmp 0x1a224
movq -0x20(%rbp), %rdi
movq -0x38(%rbp), %rax
movl 0x28(%rax), %edx
leaq 0x1847(%rip), %rsi      # 0x1ba5c
movb $0x0, %al
callq 0x31f0
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nop