// File: /workspace/github_c_makefile_star2_O2/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)
pushq $0x1
popq %rdi
pushq $0x48
popq %rsi
callq 0x3130
testq %rax, %rax
je 0xa5cc
movq %rax, %r12
leaq -0x6381(%rip), %rax     # 0x41de
movq %rax, 0x18(%r12)
movq %r12, 0x20(%r15)
leaq 0x38(%rsp), %r15
andq $0x0, 0x10(%r15)
movq %rbx, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %r15, %rcx
movq %r14, %r8
callq 0x4d6c
movq %rax, %rbx
movq 0x10(%r15), %rax
testq %rax, %rax
je 0xa5db
movq %rax, 0x8(%r12)
leaq 0x10(%rsp), %r8
andq $0x0, 0x20(%r8)
movq 0x18(%rbx), %rsi
leaq 0xe924(%rip), %rdi      # 0x18ed0
movq %rbp, %rdx
movq %r13, %rcx
movq %r14, %r9
callq 0x72d9
cmpb $0x0, (%r14)
je 0xa5ed
movq 0x30(%rsp), %rdi
callq 0x39e8
jmp 0xa5db
movq 0xdb9d(%rip), %rsi      # 0x18170
movq %r14, %rdi
callq 0x3070
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
xorl %edx, %edx
movq 0x30(%rsp), %rcx
testq %rcx, %rcx
je 0xa64a
cmpq $0x0, 0x8(%rcx)
je 0xa612
testq %rax, %rax
je 0xa622
movq %rcx, 0x20(%rax)
movq 0x30(%rsp), %rsi
jmp 0xa62a
testq %rdx, %rdx
je 0xa62f
movq %rcx, 0x20(%rdx)
movq 0x30(%rsp), %rsi
jmp 0xa637
movq %rcx, 0x28(%r12)
movq %rcx, %rsi
movq %rcx, %rax
jmp 0xa63a
movq %rcx, 0x30(%r12)
movq %rcx, %rsi
movq %rcx, %rdx
movq 0x20(%rsi), %rsi
movq %rsi, 0x30(%rsp)
andq $0x0, 0x20(%rcx)
jmp 0xa5f1
movq 0x30(%r12), %rax
testq %rax, %rax
je 0xa679
cmpq $0x0, 0x20(%rax)
je 0xa679
movq 0x8(%rsp), %rax
movl 0x28(%rax), %edx
leaq 0x7830(%rip), %rsi      # 0x11e9a
movq %r14, %rdi
xorl %eax, %eax
callq 0x3200
jmp 0xa5db
movq 0x20(%rbx), %rbx
leaq 0x100d(%rip), %rax      # 0xb691
movq %rax, 0x10(%r12)
jmp 0xa5db