// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl 0x28(%rdi), %eax
cmpq $0x6, %rax
ja 0x4395
movq %rdi, %rbx
leaq 0x5554(%rip), %rcx      # 0x9548
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%rbx), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x429e
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4819
movq 0x8(%rbx), %rdi
callq 0x44df
movq 0xa0d9(%rip), %rdi      # 0xe108
callq 0x8227
movq %rax, %r14
movq 0xa0ca(%rip), %rdi      # 0xe108
callq 0x823b
movq 0x18(%r14), %rax
movq (%rax), %rdi
movq 0x20(%rbx), %rsi
callq 0x8412
movq %rax, %rbx
movq 0xa0ab(%rip), %rdi      # 0xe108
movq (%rax), %rsi
callq 0x81e3
leaq 0x58e3(%rip), %rdi      # 0x994f
callq 0x1070
leaq 0x5886(%rip), %rdi      # 0x98fe
jmp 0x416d
xorl %r14d, %r14d
movq 0x18(%rbx), %rax
movslq 0x8(%rax), %rcx
cmpq %rcx, %r14
jge 0x40a1
movq (%rax), %rax
movq (%rax,%r14,8), %rax
movq (%rax), %rdi
callq 0x37ee
incq %r14
jmp 0x4080
movl %ecx, %r13d
leaq 0x58a4(%rip), %r14      # 0x994f
leaq 0x9cfe(%rip), %r12      # 0xddb0
leaq 0x55af(%rip), %r15      # 0x9668
testl %r13d, %r13d
jle 0x40de
leaq -0x1(%r13), %rbp
movq %r14, %rdi
callq 0x1070
movq -0x8(%r12,%r13,8), %rsi
movq %r15, %rdi
xorl %eax, %eax
callq 0x10a0
movq %rbp, %r13
jmp 0x40b9
movq 0x8(%rbx), %rax
movq (%rax), %rax
movq 0x18(%rax), %rbx
leaq 0x5791(%rip), %rdi      # 0x9881
callq 0x1070
leaq 0x557b(%rip), %rdi      # 0x9677
movq %rbx, %rsi
xorl %eax, %eax
callq 0x10a0
leaq 0x5828(%rip), %rdi      # 0x9935
callq 0x1070
movq 0x9fff(%rip), %rdi      # 0xe118
pushq $0x8
popq %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8269
movq 0x8(%rbx), %rdi
callq 0x44df
movq 0x9fc9(%rip), %rdi      # 0xe108
callq 0x8227
movq %rax, %r14
movq 0x9fba(%rip), %rdi      # 0xe108
callq 0x823b
movq 0x18(%r14), %rax
movq (%rax), %rdi
movq 0x20(%rbx), %rsi
callq 0x8412
movq %rax, %rbx
leaq 0x57e2(%rip), %rdi      # 0x994f
callq 0x1070
movl 0x8(%rbx), %esi
leaq 0x5516(%rip), %rdi      # 0x9692
xorl %eax, %eax
callq 0x10a0
leaq 0x56ea(%rip), %rdi      # 0x9874
jmp 0x4339
movq 0x8(%rbx), %rdi
callq 0x3fd2
movq 0x9f69(%rip), %rdi      # 0xe108
callq 0x8227
movq %rax, %r14
movq 0x9f5a(%rip), %rdi      # 0xe108
callq 0x823b
movq 0x10(%rbx), %rdi
callq 0x3919
leaq 0x5768(%rip), %rdi      # 0x992b
callq 0x1070
leaq 0x5780(%rip), %rdi      # 0x994f
callq 0x1070
cmpl $0x0, 0xc(%r14)
movl 0x10(%r14), %eax
jle 0x42be
testl %eax, %eax
jle 0x42d1
leaq 0x56e3(%rip), %rdi      # 0x98d5
callq 0x1070
jmp 0x42e3
movq 0x8(%rbx), %rdi
callq 0x44df
leaq 0x5743(%rip), %rdi      # 0x994f
callq 0x1070
leaq 0x5687(%rip), %rdi      # 0x989f
callq 0x1070
leaq 0x568c(%rip), %rdi      # 0x98b0
callq 0x1070
leaq 0x568b(%rip), %rdi      # 0x98bb
callq 0x1070
leaq 0x56ef(%rip), %rdi      # 0x992b
callq 0x1070
leaq 0x567c(%rip), %rdi      # 0x98c4
jmp 0x4339
movq 0x8(%rbx), %rdi
callq 0x44df
leaq 0x56f2(%rip), %rdi      # 0x994f
callq 0x1070
leaq 0x5636(%rip), %rdi      # 0x989f
callq 0x1070
leaq 0x563b(%rip), %rdi      # 0x98b0
callq 0x1070
leaq 0x563a(%rip), %rdi      # 0x98bb
callq 0x1070
leaq 0x569e(%rip), %rdi      # 0x992b
callq 0x1070
leaq 0x55f5(%rip), %rdi      # 0x988e
jmp 0x4339
movq 0x8(%rax), %rdi
testq %rdi, %rdi
je 0x434c
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3919
cmpl $0x2, %eax
jl 0x42f1
leaq 0x560b(%rip), %rdi      # 0x98d5
callq 0x1070
jmp 0x4303
movl 0x4(%r14), %esi
leaq 0x53a6(%rip), %rdi      # 0x9682
xorl %eax, %eax
callq 0x10a0
leaq 0x55f9(%rip), %rdi      # 0x98e3
callq 0x1070
jmp 0x4326
movl 0x4(%r14), %esi
leaq 0x5386(%rip), %rdi      # 0x9682
xorl %eax, %eax
callq 0x10a0
leaq 0x55d9(%rip), %rdi      # 0x98e3
callq 0x1070
cmpl $0x1, 0x4(%r14)
jne 0x4326
cmpl $0x2, 0x10(%r14)
jge 0x4326
leaq 0x55eb(%rip), %rdi      # 0x990f
jmp 0x432d
leaq 0x55d1(%rip), %rdi      # 0x98fe
callq 0x1070
leaq 0x55fc(%rip), %rdi      # 0x9935
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1070
movq 0x18(%rax), %r14
testq %r14, %r14
je 0x4395
movq 0x9dd4(%rip), %rdi      # 0xe130
movq %r14, %rsi
callq 0x8528
testb %al, %al
je 0x43a4
movq 0x9dc1(%rip), %rdi      # 0xe130
movq %r14, %rsi
callq 0x8575
leaq 0x52df(%rip), %rdi      # 0x965d
movl %eax, %esi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x10a0
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
callq 0x4449
testq %rax, %rax
je 0x43c7
movq %rax, %rbx
movl 0x14(%rax), %esi
leaq 0x5266(%rip), %rdi      # 0x9624
xorl %eax, %eax
callq 0x10a0
jmp 0x43e4
movq %r14, %rdi
callq 0x4494
movq %rax, %rbx
movq 0x8(%rax), %rsi
leaq 0x52c4(%rip), %rdi      # 0x96a1
xorl %eax, %eax
callq 0x10a0
movq (%rbx), %rax
cmpl $0x0, 0xc(%rax)
jne 0x4405
cmpl $0x1, 0x4(%rax)
jne 0x43f9
cmpl $0x0, 0x10(%rax)
je 0x4440
leaq 0x54fe(%rip), %rdi      # 0x98fe
callq 0x1070
leaq 0x5529(%rip), %rdi      # 0x9935
callq 0x1070
movq 0x9d00(%rip), %rdi      # 0xe118
movq (%rbx), %rax
movl 0x8(%rax), %esi
callq 0x8269
movq 0x9cde(%rip), %rdi      # 0xe108
movq (%rbx), %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x81e3
leaq 0x54c8(%rip), %rdi      # 0x990f
jmp 0x4400