// File: /workspace/github_c_makefile_star2_O0/chgzm[P]minic/generator.c
// Function: process_postfix_expr_right
static void process_postfix_expr_right(const PostfixExprNode* node) {
    switch (node->postfix_expr_type) {
    // primary-expression
    case PS_PRIMARY: {
        process_primary_expr_right(node->primary_expr_node);
        break;
    }
    // postfix-expression ( {assignment-expression}* )
    case PS_LPAREN: {
        for (int i = 0; i < node->assign_expr_nodes->size; ++i) {
            const AssignExprNode* assign_expr_node = node->assign_expr_nodes->elements[i];
            process_conditional_expr(assign_expr_node->conditional_expr_node);
        }

        for (int j = node->assign_expr_nodes->size - 1; j >= 0; --j) {
            printf("  pop rax\n");
            printf("  mov %s, rax\n", arg_registers[j]);
        }

        const char* identifier = node->postfix_expr_node->primary_expr_node->identifier;
        printf("  mov rax, 0\n");
        printf("  call %s\n", identifier);
        printf("  push rax\n");
        intstack_push(size_stack, 8);

        break;
    }
    // postfix-expression [ expression ]
    case PS_LSQUARE: {
        process_postfix_expr_right(node->postfix_expr_node);

        Type* type1 = stack_top(type_stack);
        stack_pop(type_stack);

        process_expr(node->expr_node);

        printf("  pop rdi\n");
        printf("  pop rax\n");

        if (type1->array_size > 0) {
            if (type1->ptr_count > 0) {
                printf("  imul rdi, 8\n");
            } else {
                printf("  imul rdi, %d\n", type1->type_size);
            }

            printf("  add rax, rdi\n");
            printf("  mov rax, [rax]\n");
        }
        else {
            if (type1->ptr_count > 1) {
                printf("  imul rdi, 8\n");
            } else {
                printf("  imul rdi, %d\n", type1->type_size);
            }
            printf("  add rax, rdi\n");
            if (type1->type_size == 1 && type1->ptr_count < 2) {
                printf("  movzx eax, BYTE PTR [rax]\n");
            } else {
                printf("  mov rax, [rax]\n");
            } 
        }
        printf("  push rax\n");

        break;
    }
    // postfix-expression . identifier
    case PS_DOT: {
        process_postfix_expr_left(node->postfix_expr_node);

        Type* type2 = stack_top(type_stack);
        stack_pop(type_stack);

        const FieldInfo* field_info1 = strptrmap_get(type2->struct_info->field_info_map, node->identifier);

        printf("  pop rax\n");
        printf("  add rax, %d\n", field_info1->offset);
        printf("  push [rax]\n");
        break;        
    }
    // postfix-expression -> identifier
    case PS_ARROW: {
        process_postfix_expr_left(node->postfix_expr_node);

        Type* type3 = stack_top(type_stack);
        stack_pop(type_stack);

        const FieldInfo* field_info2 = strptrmap_get(type3->struct_info->field_info_map, node->identifier);
        stack_push(type_stack, field_info2->type);

        printf("  pop rax\n");
        printf("  mov rax, [rax]\n");
        printf("  add rax, %d\n", field_info2->offset);
        printf("  push [rax]\n");

        break;        
    }
    // postfix-expression ++
    case PS_INC: {
        process_postfix_expr_left(node->postfix_expr_node);
        printf("  pop rax\n");
        printf("  mov rdi, [rax]\n");
        printf("  push rdi\n");
        printf("  push 1\n");
        printf("  pop rdi\n");
        printf("  add [rax], rdi\n");
        break;                       
    }
    // postfix-expression --
    case PS_DEC: {
        process_postfix_expr_left(node->postfix_expr_node);
        printf("  pop rax\n");
        printf("  mov rdi, [rax]\n");
        printf("  push rdi\n");
        printf("  push 1\n");
        printf("  pop rdi\n");
        printf("  sub [rax], rdi\n");
        break;                       
    }
    default: {
        // @todo
        break;
    }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movl 0x28(%rax), %eax
movq %rax, -0x58(%rbp)
subq $0x6, %rax
ja 0x5bc9
movq -0x58(%rbp), %rax
leaq 0x9db0(%rip), %rcx      # 0xf56c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%rbp), %rax
movq (%rax), %rdi
callq 0x5d10
jmp 0x5bcb
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpl 0x8(%rcx), %eax
jge 0x581b
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq (%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0x47f0
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x57dd
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movl 0x8(%rax), %eax
subl $0x1, %eax
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jl 0x5868
leaq 0x9eab(%rip), %rdi      # 0xf6e4
movb $0x0, %al
callq 0x1090
movslq -0x1c(%rbp), %rcx
leaq 0xf895(%rip), %rax      # 0x150e0
movq (%rax,%rcx,8), %rsi
leaq 0xa0a9(%rip), %rdi      # 0xf8ff
movb $0x0, %al
callq 0x1090
movl -0x1c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x582c
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movq %rax, -0x28(%rbp)
leaq 0xa064(%rip), %rdi      # 0xf8e6
movb $0x0, %al
callq 0x1090
movq -0x28(%rbp), %rsi
leaq 0xa07a(%rip), %rdi      # 0xf90e
movb $0x0, %al
callq 0x1090
leaq 0x9e2b(%rip), %rdi      # 0xf6cd
movb $0x0, %al
callq 0x1090
movq 0xf890(%rip), %rdi      # 0x15140
movl $0x8, %esi
callq 0xe810
jmp 0x5bcb
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x5790
movq 0xf85d(%rip), %rdi      # 0x15130
callq 0xe760
movq %rax, -0x30(%rbp)
movq 0xf84d(%rip), %rdi      # 0x15130
callq 0xe7a0
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x4c20
leaq 0x9ddd(%rip), %rdi      # 0xf6d9
movb $0x0, %al
callq 0x1090
leaq 0x9dda(%rip), %rdi      # 0xf6e4
movb $0x0, %al
callq 0x1090
movq -0x30(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jle 0x5968
movq -0x30(%rbp), %rax
cmpl $0x0, 0x10(%rax)
jle 0x5935
leaq 0x9fed(%rip), %rdi      # 0xf919
movb $0x0, %al
callq 0x1090
jmp 0x594a
movq -0x30(%rbp), %rax
movl 0x4(%rax), %esi
leaq 0x9fe5(%rip), %rdi      # 0xf928
movb $0x0, %al
callq 0x1090
leaq 0x9f18(%rip), %rdi      # 0xf869
movb $0x0, %al
callq 0x1090
leaq 0x9f75(%rip), %rdi      # 0xf8d4
movb $0x0, %al
callq 0x1090
jmp 0x59d9
movq -0x30(%rbp), %rax
cmpl $0x1, 0x10(%rax)
jle 0x5982
leaq 0x9fa0(%rip), %rdi      # 0xf919
movb $0x0, %al
callq 0x1090
jmp 0x5997
movq -0x30(%rbp), %rax
movl 0x4(%rax), %esi
leaq 0x9f98(%rip), %rdi      # 0xf928
movb $0x0, %al
callq 0x1090
leaq 0x9ecb(%rip), %rdi      # 0xf869
movb $0x0, %al
callq 0x1090
movq -0x30(%rbp), %rax
cmpl $0x1, 0x4(%rax)
jne 0x59c9
movq -0x30(%rbp), %rax
cmpl $0x2, 0x10(%rax)
jge 0x59c9
leaq 0x9f78(%rip), %rdi      # 0xf938
movb $0x0, %al
callq 0x1090
jmp 0x59d7
leaq 0x9f04(%rip), %rdi      # 0xf8d4
movb $0x0, %al
callq 0x1090
jmp 0x59d9
leaq 0x9ced(%rip), %rdi      # 0xf6cd
movb $0x0, %al
callq 0x1090
jmp 0x5bcb
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x5d80
movq 0xf730(%rip), %rdi      # 0x15130
callq 0xe760
movq %rax, -0x38(%rbp)
movq 0xf720(%rip), %rdi      # 0x15130
callq 0xe7a0
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0xeb80
movq %rax, -0x40(%rbp)
leaq 0x9cac(%rip), %rdi      # 0xf6e4
movb $0x0, %al
callq 0x1090
movq -0x40(%rbp), %rax
movl 0x8(%rax), %esi
leaq 0x9f08(%rip), %rdi      # 0xf955
movb $0x0, %al
callq 0x1090
leaq 0x9f09(%rip), %rdi      # 0xf964
movb $0x0, %al
callq 0x1090
jmp 0x5bcb
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x5d80
movq 0xf6b5(%rip), %rdi      # 0x15130
callq 0xe760
movq %rax, -0x48(%rbp)
movq 0xf6a5(%rip), %rdi      # 0x15130
callq 0xe7a0
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rax
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0xeb80
movq %rax, -0x50(%rbp)
movq 0xf67d(%rip), %rdi      # 0x15130
movq -0x50(%rbp), %rax
movq (%rax), %rsi
callq 0xe6e0
leaq 0x9c1e(%rip), %rdi      # 0xf6e4
movb $0x0, %al
callq 0x1090
leaq 0x9e00(%rip), %rdi      # 0xf8d4
movb $0x0, %al
callq 0x1090
movq -0x50(%rbp), %rax
movl 0x8(%rax), %esi
leaq 0x9e6c(%rip), %rdi      # 0xf955
movb $0x0, %al
callq 0x1090
leaq 0x9e6d(%rip), %rdi      # 0xf964
movb $0x0, %al
callq 0x1090
jmp 0x5bcb
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x5d80
leaq 0x9bcd(%rip), %rdi      # 0xf6e4
movb $0x0, %al
callq 0x1090
leaq 0x9d81(%rip), %rdi      # 0xf8a6
movb $0x0, %al
callq 0x1090
leaq 0x9e3f(%rip), %rdi      # 0xf972
movb $0x0, %al
callq 0x1090
leaq 0x9cae(%rip), %rdi      # 0xf7ef
movb $0x0, %al
callq 0x1090
leaq 0x9b8a(%rip), %rdi      # 0xf6d9
movb $0x0, %al
callq 0x1090
leaq 0x9c3e(%rip), %rdi      # 0xf79b
movb $0x0, %al
callq 0x1090
jmp 0x5bcb
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x5d80
leaq 0x9b6a(%rip), %rdi      # 0xf6e4
movb $0x0, %al
callq 0x1090
leaq 0x9d1e(%rip), %rdi      # 0xf8a6
movb $0x0, %al
callq 0x1090
leaq 0x9ddc(%rip), %rdi      # 0xf972
movb $0x0, %al
callq 0x1090
leaq 0x9c4b(%rip), %rdi      # 0xf7ef
movb $0x0, %al
callq 0x1090
leaq 0x9b27(%rip), %rdi      # 0xf6d9
movb $0x0, %al
callq 0x1090
leaq 0x9bed(%rip), %rdi      # 0xf7ad
movb $0x0, %al
callq 0x1090
jmp 0x5bcb
jmp 0x5bcb
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)