// File: /workspace/github_c_makefile_star2_O3/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl 0x28(%rdi), %eax
cmpq $0x6, %rax
ja 0x4403
movq %rdi, %rbx
leaq 0x54aa(%rip), %rcx      # 0x9548
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%rbx), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x4348
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x477e
movq 0x8(%rbx), %rdi
callq 0x44a9
movq 0xa034(%rip), %rdi      # 0xe108
callq 0x8825
movq %rax, %r14
movq 0xa025(%rip), %rdi      # 0xe108
callq 0x8839
movq 0x18(%r14), %rax
movq (%rax), %rdi
movq 0x20(%rbx), %rsi
callq 0x8a1e
movq %rax, %rbx
movq 0xa006(%rip), %rdi      # 0xe108
movq (%rax), %rsi
callq 0x87e1
leaq 0x583e(%rip), %rdi      # 0x994f
callq 0x1070
leaq 0x57e1(%rip), %rdi      # 0x98fe
jmp 0x4217
movq 0x18(%rbx), %rax
cmpl $0x0, 0x8(%rax)
jle 0x418b
xorl %r14d, %r14d
movq (%rax), %rax
movq (%rax,%r14,8), %rax
movq (%rax), %rdi
callq 0x382d
incq %r14
movq 0x18(%rbx), %rax
movslq 0x8(%rax), %r12
cmpq %r12, %r14
jl 0x412f
testl %r12d, %r12d
jle 0x418b
incq %r12
leaq 0x57f2(%rip), %r14      # 0x994f
leaq 0x9c4c(%rip), %r13      # 0xddb0
leaq 0x54fd(%rip), %r15      # 0x9668
movq %r14, %rdi
callq 0x1070
movq -0x10(%r13,%r12,8), %rsi
movq %r15, %rdi
xorl %eax, %eax
callq 0x10a0
decq %r12
cmpq $0x1, %r12
ja 0x416b
movq 0x8(%rbx), %rax
movq (%rax), %rax
movq 0x18(%rax), %rbx
leaq 0x56e4(%rip), %rdi      # 0x9881
callq 0x1070
leaq 0x54ce(%rip), %rdi      # 0x9677
movq %rbx, %rsi
xorl %eax, %eax
callq 0x10a0
leaq 0x577b(%rip), %rdi      # 0x9935
callq 0x1070
movq 0x9f52(%rip), %rdi      # 0xe118
movl $0x8, %esi
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x886b
movq 0x8(%rbx), %rdi
callq 0x44a9
movq 0x9f1f(%rip), %rdi      # 0xe108
callq 0x8825
movq %rax, %r14
movq 0x9f10(%rip), %rdi      # 0xe108
callq 0x8839
movq 0x18(%r14), %rax
movq (%rax), %rdi
movq 0x20(%rbx), %rsi
callq 0x8a1e
movq %rax, %rbx
leaq 0x5738(%rip), %rdi      # 0x994f
callq 0x1070
movl 0x8(%rbx), %esi
leaq 0x546c(%rip), %rdi      # 0x9692
xorl %eax, %eax
callq 0x10a0
leaq 0x5640(%rip), %rdi      # 0x9874
jmp 0x43de
movq 0x8(%rbx), %rdi
callq 0x407e
movq 0x9ebf(%rip), %rdi      # 0xe108
callq 0x8825
movq %rax, %r14
movq 0x9eb0(%rip), %rdi      # 0xe108
callq 0x8839
movq 0x10(%rbx), %rdi
callq 0x395f
leaq 0x56be(%rip), %rdi      # 0x992b
callq 0x1070
leaq 0x56d6(%rip), %rdi      # 0x994f
callq 0x1070
cmpl $0x0, 0xc(%r14)
movl 0x10(%r14), %eax
jle 0x4363
testl %eax, %eax
jle 0x4376
leaq 0x5639(%rip), %rdi      # 0x98d5
callq 0x1070
jmp 0x4388
movq 0x8(%rbx), %rdi
callq 0x44a9
leaq 0x5699(%rip), %rdi      # 0x994f
callq 0x1070
leaq 0x55dd(%rip), %rdi      # 0x989f
callq 0x1070
leaq 0x55e2(%rip), %rdi      # 0x98b0
callq 0x1070
leaq 0x55e1(%rip), %rdi      # 0x98bb
callq 0x1070
leaq 0x5645(%rip), %rdi      # 0x992b
callq 0x1070
leaq 0x55d2(%rip), %rdi      # 0x98c4
jmp 0x43de
movq 0x8(%rbx), %rdi
callq 0x44a9
leaq 0x5648(%rip), %rdi      # 0x994f
callq 0x1070
leaq 0x558c(%rip), %rdi      # 0x989f
callq 0x1070
leaq 0x5591(%rip), %rdi      # 0x98b0
callq 0x1070
leaq 0x5590(%rip), %rdi      # 0x98bb
callq 0x1070
leaq 0x55f4(%rip), %rdi      # 0x992b
callq 0x1070
leaq 0x554b(%rip), %rdi      # 0x988e
jmp 0x43de
movq 0x8(%rax), %rdi
testq %rdi, %rdi
je 0x43ec
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x395f
cmpl $0x2, %eax
jl 0x4396
leaq 0x5566(%rip), %rdi      # 0x98d5
callq 0x1070
jmp 0x43a8
movl 0x4(%r14), %esi
leaq 0x5301(%rip), %rdi      # 0x9682
xorl %eax, %eax
callq 0x10a0
leaq 0x5554(%rip), %rdi      # 0x98e3
callq 0x1070
jmp 0x43cb
movl 0x4(%r14), %esi
leaq 0x52e1(%rip), %rdi      # 0x9682
xorl %eax, %eax
callq 0x10a0
leaq 0x5534(%rip), %rdi      # 0x98e3
callq 0x1070
cmpl $0x1, 0x4(%r14)
jne 0x43cb
cmpl $0x2, 0x10(%r14)
jge 0x43cb
leaq 0x5546(%rip), %rdi      # 0x990f
jmp 0x43d2
leaq 0x552c(%rip), %rdi      # 0x98fe
callq 0x1070
leaq 0x5557(%rip), %rdi      # 0x9935
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x1070
movq 0x18(%rax), %rdi
testq %rdi, %rdi
je 0x4403
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x4870
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq