// File: /workspace/github_c_makefile_star2_O1/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)
movq $0x0, 0x30(%rsp)
movl $0x1, %edi
movl $0x48, %esi
callq 0x3130
testq %rax, %rax
je 0xaf1f
movq %rax, %r12
leaq -0x6af2(%rip), %rax     # 0x43b8
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 0x4f9b
movq %rax, %rbx
movq 0x10(%r15), %rax
testq %rax, %rax
je 0xaf2e
movq %rax, 0x8(%r12)
leaq 0x10(%rsp), %r15
movq $0x0, 0x20(%r15)
movq 0x18(%rbx), %rsi
leaq 0xefd3(%rip), %rdi      # 0x19ed0
movq %rbp, %rdx
movq %r13, %rcx
movq %r15, %r8
movq %r14, %r9
callq 0x799a
cmpb $0x0, (%r14)
movq 0x20(%r15), %rdi
je 0xaf40
callq 0x3aeb
jmp 0xaf2e
movq 0xe24a(%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 0xaf98
xorl %eax, %eax
xorl %ecx, %ecx
xorl %edx, %edx
cmpq $0x0, 0x8(%rdi)
sete %dl
leaq 0x28(%r12,%rdx,8), %rdx
movq %rdi, %rsi
cmoveq %rcx, %rsi
cmoveq %rax, %rcx
cmoveq %rdi, %rax
leaq 0x20(%rcx), %r8
testq %rcx, %rcx
cmoveq %rdx, %r8
movq %rdi, (%r8)
movq 0x30(%rsp), %rcx
movq 0x20(%rcx), %rcx
movq %rcx, 0x30(%rsp)
movq $0x0, 0x20(%rdi)
movq 0x30(%rsp), %rdi
movq %rsi, %rcx
testq %rdi, %rdi
jne 0xaf49
movq 0x30(%r12), %rax
testq %rax, %rax
je 0xafc7
cmpq $0x0, 0x20(%rax)
je 0xafc7
movq 0x8(%rsp), %rax
movl 0x28(%rax), %edx
leaq 0x7ea6(%rip), %rsi      # 0x12e5e
movq %r14, %rdi
xorl %eax, %eax
callq 0x3200
jmp 0xaf2e
movq 0x20(%rbx), %rbx
leaq 0x122c(%rip), %rax      # 0xc1fe
movq %rax, 0x10(%r12)
jmp 0xaf2e