// File: /workspace/github_c_makefile_star2_O3/martincameron[P]towntalk/towntalk.c
// Function: parse_switch_statement
static struct element* parse_switch_statement( struct element *elem,
	struct function *func, struct variables *vars, struct statement *prev, char *message ) {
	struct expression expr;
	struct element *next = elem->next;
	struct statement block = { 0 }, *cas, *def;
	struct block_statement *stmt = calloc( 1, sizeof( struct block_statement ) );
	if( stmt ) {
		stmt->stmt.dispose = dispose_block_statement;
		prev->next = &stmt->stmt;
		expr.next = NULL;
		next = parse_expression( next, func, vars, &expr, message );
		if( expr.next ) {
			stmt->stmt.source = expr.next;
			block.next = NULL;
			parse_keywords( switch_stmts, next->child, func, vars, &block, message );
			if( message[ 0 ] == 0 ) {
				cas = def = NULL;
				while( block.next ) {
					if( block.next->source ) {
						if( cas ) {
							cas->next = block.next;
							cas = cas->next;
						} else {
							stmt->if_block = cas = block.next;
						}
						block.next = block.next->next;
						cas->next = NULL;
					} else {
						if( def ) {
							def->next = block.next;
							def = def->next;
						} else {
							stmt->else_block = def = block.next;
						}
						block.next = block.next->next;
						def->next = NULL;
					}
				}
				if( stmt->else_block == NULL || stmt->else_block->next == NULL ) {
					next = next->next;
					stmt->stmt.execute = execute_switch_statement;
				} else {
					sprintf( message, "Duplicate default block in switch statement on line %d.", elem->line );
				}
			} else {
				dispose_statements( block.next );
			}
		}
	} else {
		strcpy( message, OUT_OF_MEMORY );
	}
	return next;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r8, %r14
movq %rcx, %r15
movq %rdx, %r13
movq %rsi, %rbp
movq %rdi, 0x8(%rsp)
movq 0x20(%rdi), %rbx
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movl $0x1, %edi
movl $0x48, %esi
callq 0x3130
testq %rax, %rax
je 0xad57
movq %rax, %r12
leaq -0x695b(%rip), %rax     # 0x4387
movq %rax, 0x18(%r12)
movq %r12, 0x20(%r15)
leaq 0x38(%rsp), %r15
movq $0x0, 0x10(%r15)
movq %rbx, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %r15, %rcx
movq %r14, %r8
callq 0x4f62
movq %rax, %rbx
movq 0x10(%r15), %rax
testq %rax, %rax
je 0xad66
movq %rax, 0x8(%r12)
leaq 0x10(%rsp), %r15
movq $0x0, 0x20(%r15)
movq 0x18(%rbx), %rsi
leaq 0xf19b(%rip), %rdi      # 0x19ed0
movq %rbp, %rdx
movq %r13, %rcx
movq %r15, %r8
movq %r14, %r9
callq 0x7850
cmpb $0x0, (%r14)
movq 0x20(%r15), %rdi
je 0xad78
callq 0x3abb
jmp 0xad66
movq 0xe412(%rip), %rsi      # 0x19170
movq %r14, %rdi
callq 0x3070
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %rdi, %rdi
je 0xaddb
xorl %eax, %eax
xorl %ecx, %ecx
cmpq $0x0, 0x8(%rdi)
je 0xad98
testq %rcx, %rcx
je 0xada8
movq %rdi, 0x20(%rcx)
movq 0x30(%rsp), %rdx
jmp 0xadb0
testq %rax, %rax
je 0xadb5
movq %rdi, 0x20(%rax)
movq 0x30(%rsp), %rdx
jmp 0xadbd
movq %rdi, 0x28(%r12)
movq %rdi, %rdx
movq %rdi, %rcx
jmp 0xadc0
movq %rdi, 0x30(%r12)
movq %rdi, %rdx
movq %rdi, %rax
movq 0x20(%rdx), %rdx
movq %rdx, 0x30(%rsp)
movq $0x0, 0x20(%rdi)
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
jne 0xad81
movq 0x30(%r12), %rax
testq %rax, %rax
je 0xae0a
cmpq $0x0, 0x20(%rax)
je 0xae0a
movq 0x8(%rsp), %rax
movl 0x28(%rax), %edx
leaq 0x805f(%rip), %rsi      # 0x12e5a
movq %r14, %rdi
xorl %eax, %eax
callq 0x3200
jmp 0xad66
movq 0x20(%rbx), %rbx
leaq 0x119a(%rip), %rax      # 0xbfaf
movq %rax, 0x10(%r12)
jmp 0xad66