// File: /workspace/github_c_makefile_star2_O0/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
subq $0x140, %rsp            # imm = 0x140
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rsi
leaq -0x118(%rbp), %rdi
movl $0x100, %edx            # imm = 0x100
callq 0x10e0
movl -0x78(%rbp), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x138(%rbp)
subl $0x18, %eax
ja 0x4f56
movq -0x138(%rbp), %rax
leaq 0xf09b(%rip), %rcx      # 0x13cac
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%rbp), %rdi
callq 0x12b0
movl %eax, -0x11c(%rbp)
movq -0x8(%rbp), %rdi
callq 0x12b0
movl %eax, -0x120(%rbp)
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x4f90
movq -0x68(%rbp), %rdi
leaq 0xf239(%rip), %rsi      # 0x13e89
callq 0xb280
movl %eax, %edi
movl -0x11c(%rbp), %esi
xorl %edx, %edx
callq 0xd550
movq -0x60(%rbp), %rdi
callq 0xb250
cmpl $0x0, %eax
jne 0x4c7e
leaq 0xf234(%rip), %rdi      # 0x13ead
callq 0xb150
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rsi
leaq 0xf24b(%rip), %rdx      # 0x13ed8
callq 0x4bc0
movl -0x120(%rbp), %edi
leaq 0xf269(%rip), %rsi      # 0x13f08
callq 0xd4f0
movl -0x11c(%rbp), %edi
callq 0xd6f0
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rsi
leaq 0xf23a(%rip), %rdx      # 0x13ef8
callq 0x4bc0
movl -0x120(%rbp), %edi
callq 0xd6f0
callq 0xd8b0
jmp 0x4f7e
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rsi
leaq 0xf232(%rip), %rdx      # 0x13f19
callq 0x4b30
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rsi
leaq 0xf23d(%rip), %rdx      # 0x13f38
callq 0x4bc0
movl -0x20(%rbp), %eax
movl %eax, -0x124(%rbp)
movl -0x124(%rbp), %edi
callq 0xe170
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rsi
leaq 0xf1f6(%rip), %rdx      # 0x13f19
callq 0x4b30
jmp 0x4f7e
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x4f90
movq -0x8(%rbp), %rdi
leaq -0x118(%rbp), %rsi
addq $0xe0, %rsi
callq 0x59c0
leaq 0xf200(%rip), %rdi      # 0x13f58
callq 0xdde0
movl -0x20(%rbp), %eax
movl %eax, -0x128(%rbp)
callq 0xeac0
movl -0x28(%rbp), %esi
movl -0x128(%rbp), %edx
leaq 0xf1dd(%rip), %rdi      # 0x13f58
callq 0xe0a0
movl -0x28(%rbp), %edi
callq 0xd1d0
jmp 0x4f7e
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x4f90
movq -0x8(%rbp), %rdi
leaq -0x118(%rbp), %rsi
addq $0xe0, %rsi
callq 0x59c0
leaq 0xf1a0(%rip), %rdi      # 0x13f58
callq 0xdde0
callq 0xeac0
movl $0x4, %edi
leaq 0xf18a(%rip), %rsi      # 0x13f58
callq 0xd400
callq 0xd880
movl -0x28(%rbp), %edi
callq 0xd1d0
jmp 0x4f7e
movq -0x8(%rbp), %rdi
leaq -0x118(%rbp), %rsi
addq $0xe0, %rsi
callq 0x59c0
movl -0x20(%rbp), %eax
movl %eax, -0x12c(%rbp)
callq 0xeac0
movq -0x48(%rbp), %rdi
movl -0x28(%rbp), %esi
movl -0x12c(%rbp), %edx
callq 0xdf50
movl -0x28(%rbp), %edi
callq 0xd1d0
jmp 0x4f7e
leaq -0x118(%rbp), %rdi
addq $0xe0, %rdi
callq 0x5ac0
shll $0x3, %eax
movl %eax, -0x130(%rbp)
movl -0x130(%rbp), %eax
movl $0x10, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
je 0x4e64
leaq 0xf0fd(%rip), %rdi      # 0x13f5c
callq 0xb1f0
callq 0xeac0
movq -0x8(%rbp), %rdi
leaq -0x118(%rbp), %rsi
addq $0xe0, %rsi
callq 0x59c0
movq -0x48(%rbp), %rsi
movl -0x130(%rbp), %edx
movl $0x4, %edi
callq 0xd340
callq 0xd880
movl -0x28(%rbp), %edi
callq 0xd1d0
jmp 0x4f7e
movl -0x28(%rbp), %edi
callq 0xd1d0
jmp 0x4f7e
movq -0x48(%rbp), %rdi
callq 0xd2e0
jmp 0x4f7e
cmpl $0x7, -0x70(%rbp)
jne 0x4ed9
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x4f90
jmp 0x4f7e
leaq 0xf08d(%rip), %rdi      # 0x13f6d
callq 0xb150
movq 0x1710c(%rip), %rax     # 0x1bff8
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
leaq 0xfa2d(%rip), %rsi      # 0x14927
movb $0x0, %al
callq 0x10d0
leaq 0xf09c(%rip), %rdi      # 0x13fa4
callq 0xb150
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rsi
leaq 0xf0b9(%rip), %rdx      # 0x13fd5
callq 0x5b90
movq -0x60(%rbp), %rdi
callq 0xb250
cmpl $0x0, %eax
jne 0x4f3b
leaq 0xf0c4(%rip), %rdi      # 0x13ffa
callq 0xb150
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rsi
leaq 0xf154(%rip), %rdx      # 0x1409e
callq 0x4bc0
callq 0xd8b0
jmp 0x4f7e
movq 0x1709b(%rip), %rax     # 0x1bff8
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
leaq 0xf9bc(%rip), %rsi      # 0x14927
movb $0x0, %al
callq 0x10d0
leaq 0xf151(%rip), %rdi      # 0x140ca
callq 0xb150
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
nopw (%rax,%rax)