// File: /workspace/github_c_makefile_star2_O1/hsjoihs[P]c-compiler/codegen_expression.c
// Function: print_address_of_lvalue_or_struct_or_union
void print_address_of_lvalue_or_struct_or_union(struct PrinterState *ptr_prs,
                                                const struct Expr *ref_expr,
                                                const char *msg)
{
	const struct Expr expr = *ref_expr;
	switch (expr.category) {
	case CONDITIONAL_EXPR: {
		int label1 = get_new_label_name(ptr_prs);
		int label2 = get_new_label_name(ptr_prs);

		print_expression(ptr_prs, expr.ptr1);
		gen_if_zero_jmp_nbyte(
		    size_of_basic(&expr.ptr1->details.type,
		                  "condition of conditional expression"),
		    label1, 0);

		if (!is_struct_or_union(&expr.ptr2->details.type)) {
			simple_error("the conditional operator is used as lvalue");
		}

		print_address_of_lvalue_or_struct_or_union(
		    ptr_prs, expr.ptr2, "true branch of ternary operator");
		gen_jump(label2, "ternary operator");
		gen_label(label1);
		print_address_of_lvalue_or_struct_or_union(
		    ptr_prs, expr.ptr3, "false branch of ternary operator");
		gen_label(label2);
		gen_discard2nd();
		return;
	}
	case STRUCT_OR_UNION_ASSIGNMENT_EXPR: {
		print_address_of_lvalue(
		    ptr_prs, expr.ptr1, "left hand of struct assignment");
		print_address_of_lvalue_or_struct_or_union(
		    ptr_prs, expr.ptr2, "right hand of struct assignment");
		int size = expr.size_info_for_struct_or_union_assign;
		gen_copy_1st_struct_or_union_to_2nd_and_discard(size);
		print_address_of_lvalue(
		    ptr_prs, expr.ptr1, "left hand of struct assignment");
		return;
	}
	case FPCALL_EXPR_RETURNING_INTEGER_CLASS: {
		print_expression(ptr_prs, expr.ptr1);
		pass_args(ptr_prs, &expr.args);
		gen_pop_to_reg_8byte("r11");

		int size = expr.size_info_for_struct_or_union_assign;
		gen_raw_call_partA();
		gen_call_reg_and_assign_integerclass_struct_or_union_or_union_to_local(
		    "r11", expr.local_var_offset, size);
		gen_push_address_of_local(expr.local_var_offset);
		return;
	}
	case FPCALL_EXPR_RETURNING_MEMORY_CLASS: {
		print_expression(ptr_prs, expr.ptr1);
		pass_args(ptr_prs, &expr.args);
		gen_pop_to_reg_8byte("r11");

		/* call a function that returns a void */
		gen_raw_call_partA();
		gen_call_reg_and_push_ret_of_nbyte(4, "r11");
		gen_discard();

		gen_push_address_of_local(expr.local_var_offset);
		return;
	}
	case FUNCCALL_EXPR_RETURNING_INTEGER_CLASS: {

		pass_args(ptr_prs, &expr.args);

		int size = expr.size_info_for_struct_or_union_assign;
		gen_raw_call_partA();
		gen_call_and_assign_integerclass_struct_or_union_to_local(
		    expr.global_var_name, expr.local_var_offset, size);
		gen_push_address_of_local(expr.local_var_offset);
		return;
	}
	case FUNCCALL_EXPR_RETURNING_MEMORY_CLASS: {

		int arg_stacksize = count_args(&expr.args) * 8;
		if (arg_stacksize % 16 != 0) {
			unsupported("misaligned stack");
		}
		gen_raw_call_partA();
		pass_args(ptr_prs, &expr.args);

		/* call a function that returns a void */
		gen_push_ret_of_nbyte(4, expr.global_var_name, arg_stacksize);
		gen_discard();

		gen_push_address_of_local(expr.local_var_offset);
		return;
	}
	case LOCAL_VAR_: {
		gen_push_address_of_local(expr.local_var_offset);

		return;
	}
	case GLOBAL_VAR_: {
		gen_push_address_of_global(expr.global_var_name);

		return;
	}
	case UNARY_OP_EXPR:
		if (expr.unary_operator == UNARY_OP_ASTERISK) {
			print_expression(ptr_prs, expr.ptr1);
			return;
		} else {
			simple_error("the only unary operator that can create "
			             "lvalue is `*`\n");
		}
	case VOID_EXPR:
		fprintf(stderr, "context: %s\n", msg);
		simple_error("doesn't seem like an lvalue; it is a void expr.\n");
	case COMMA_EXPR: {
		print_expression_or_addr_of_struct_or_union(
		    ptr_prs, expr.ptr1, "struct as the first operand of comma");

		if (!is_struct_or_union(&expr.ptr2->details.type)) {
			simple_error(
			    "either the result of comma expression is used as an "
			    "lvalue, or the comma expression is used as if it were a "
			    "struct/union though the second operand of comma isn't.\n");
		}
		print_address_of_lvalue_or_struct_or_union(
		    ptr_prs, expr.ptr2, "struct/union as the second operand of comma");

		gen_discard2nd();
		return;
	}
	default:
		fprintf(stderr, "context: %s\n", msg);
		simple_error("doesn't seem like an lvalue or a struct\n");
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x100, %rsp            # imm = 0x100
movq %rdx, %r14
movq %rdi, %rbx
leaq -0x120(%rbp), %r15
movl $0x100, %edx            # imm = 0x100
movq %r15, %rdi
callq 0x1100
movl 0xa0(%r15), %eax
decl %eax
cmpl $0x18, %eax
ja 0x4cd3
leaq 0xa243(%rip), %rcx      # 0xec40
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x70(%rbp), %rsi
leaq 0xa508(%rip), %rdx      # 0xef19
movq %rbx, %rdi
callq 0x566e
movq -0x68(%rbp), %r14
movq %r14, %rdi
callq 0x9516
testl %eax, %eax
je 0x4ca3
leaq 0xa5ae(%rip), %rdx      # 0xefe2
movq %rbx, %rdi
movq %r14, %rsi
callq 0x49b8
jmp 0x4b23
leaq -0x40(%rbp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5546
movl 0x18(%r14), %ebx
callq 0xbd16
movq -0x10(%r14), %rdi
movl 0x10(%r14), %r14d
movl %r14d, %esi
movl %ebx, %edx
callq 0xb2ca
jmp 0x4c84
movq -0x50(%rbp), %rdi
addq $0x100, %rsp            # imm = 0x100
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0xa893
movq %rbx, %rdi
callq 0x245c
movl %eax, %r15d
movq %rbx, %rdi
callq 0x245c
movl %eax, %r14d
movq -0x70(%rbp), %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0x4cdb
leaq 0xa316(%rip), %rsi      # 0xedcd
movq %r12, %rdi
callq 0x9529
movl %eax, %edi
movl %r15d, %esi
xorl %edx, %edx
callq 0xaaa9
movq -0x68(%rbp), %r12
movq %r12, %rdi
callq 0x9516
testl %eax, %eax
je 0x4caf
leaq 0xa336(%rip), %rdx      # 0xee1c
movq %rbx, %rdi
movq %r12, %rsi
callq 0x49b8
leaq 0xa354(%rip), %rsi      # 0xee4c
movl %r14d, %edi
callq 0xaa5b
movl %r15d, %edi
callq 0xac08
movq -0x60(%rbp), %rsi
leaq 0xa329(%rip), %rdx      # 0xee3c
movq %rbx, %rdi
callq 0x49b8
movl %r14d, %edi
callq 0xac08
addq $0x100, %rsp            # imm = 0x100
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0xad85
leaq -0x40(%rbp), %r15
movq %r15, %rdi
callq 0x55f3
movl %eax, %r14d
testb $0x1, %r14b
jne 0x4cbb
shll $0x3, %r14d
callq 0xbd16
movq %rbx, %rdi
movq %r15, %rsi
callq 0x5546
movq -0x50(%rbp), %rsi
movl $0x4, %edi
movl %r14d, %edx
callq 0xa8e7
callq 0xad5d
movl -0x30(%rbp), %edi
jmp 0x4c87
movq -0x70(%rbp), %r14
leaq 0xa2d0(%rip), %r15      # 0xee5d
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x4990
movq -0x68(%rbp), %rsi
leaq 0xa2d6(%rip), %rdx      # 0xee7c
movq %rbx, %rdi
callq 0x49b8
movl -0x28(%rbp), %edi
callq 0xb4f7
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
addq $0x100, %rsp            # imm = 0x100
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x4990
cmpl $0x7, -0x78(%rbp)
jne 0x4cc7
movq -0x70(%rbp), %rsi
movq %rbx, %rdi
addq $0x100, %rsp            # imm = 0x100
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x4cdb
leaq -0x40(%rbp), %r14
movq -0x30(%r14), %rsi
movq %rbx, %rdi
callq 0x4cdb
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5546
leaq 0xa282(%rip), %rbx      # 0xee9c
movq %rbx, %rdi
callq 0xb1a9
callq 0xbd16
movl $0x4, %edi
movq %rbx, %rsi
callq 0xa996
callq 0xad5d
movl 0x10(%r14), %edi
jmp 0x4c87
leaq -0x40(%rbp), %r14
movq -0x30(%r14), %rsi
movq %rbx, %rdi
callq 0x4cdb
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5546
leaq 0xa23b(%rip), %rbx      # 0xee9c
movq %rbx, %rdi
callq 0xb1a9
movl 0x18(%r14), %r15d
callq 0xbd16
movl 0x10(%r14), %r14d
movq %rbx, %rdi
movl %r14d, %esi
movl %r15d, %edx
callq 0xb3f8
movl %r14d, %edi
addq $0x100, %rsp            # imm = 0x100
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0xa7b8
movq %r14, %rdi
callq 0x1544
leaq 0xa294(%rip), %rdi      # 0xef3e
callq 0x9492
leaq 0xa13b(%rip), %rdi      # 0xedf1
callq 0x9492
leaq 0xa1de(%rip), %rdi      # 0xeea0
callq 0x94cd
leaq 0xa1e3(%rip), %rdi      # 0xeeb1
callq 0x9492
movq %r14, %rdi
callq 0x156f