// File: /workspace/github_c_makefile_star2_O1/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 0x42c2
movq %rdi, %rbx
leaq 0x65ee(%rip), %rcx      # 0xa548
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%rbx), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x4207
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x4653
movq 0x8(%rbx), %rdi
callq 0x437e
movq 0xb178(%rip), %rdi      # 0xf108
callq 0x8bf2
movq %rax, %r14
movq 0xb169(%rip), %rdi      # 0xf108
callq 0x8c06
movq 0x18(%r14), %rax
movq (%rax), %rdi
movq 0x20(%rbx), %rsi
callq 0x8def
movq %rax, %rbx
movq 0xb14a(%rip), %rdi      # 0xf108
movq (%rax), %rsi
callq 0x8baf
leaq 0x6982(%rip), %rdi      # 0xa94f
callq 0x1070
leaq 0x6925(%rip), %rdi      # 0xa8fe
jmp 0x40d6
movq 0x18(%rbx), %rax
movl 0x8(%rax), %ecx
testl %ecx, %ecx
jle 0x400b
xorl %r14d, %r14d
movq (%rax), %rax
movq (%rax,%r14,8), %rax
movq (%rax), %rdi
callq 0x36e7
incq %r14
movq 0x18(%rbx), %rax
movslq 0x8(%rax), %rcx
cmpq %rcx, %r14
jl 0x3fec
testl %ecx, %ecx
jle 0x404a
movl %ecx, %r12d
incq %r12
leaq 0x6933(%rip), %r14      # 0xa94f
leaq 0xad8d(%rip), %r13      # 0xedb0
leaq 0x663e(%rip), %r15      # 0xa668
movq %r14, %rdi
callq 0x1070
movq -0x10(%r13,%r12,8), %rsi
movq %r15, %rdi
xorl %eax, %eax
callq 0x10a0
decq %r12
cmpq $0x1, %r12
jg 0x402a
movq 0x8(%rbx), %rax
movq (%rax), %rax
movq 0x18(%rax), %rbx
leaq 0x6825(%rip), %rdi      # 0xa881
callq 0x1070
leaq 0x660f(%rip), %rdi      # 0xa677
movq %rbx, %rsi
xorl %eax, %eax
callq 0x10a0
leaq 0x68bc(%rip), %rdi      # 0xa935
callq 0x1070
movq 0xb093(%rip), %rdi      # 0xf118
movl $0x8, %esi
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x8c38
movq 0x8(%rbx), %rdi
callq 0x437e
movq 0xb060(%rip), %rdi      # 0xf108
callq 0x8bf2
movq %rax, %r14
movq 0xb051(%rip), %rdi      # 0xf108
callq 0x8c06
movq 0x18(%r14), %rax
movq (%rax), %rdi
movq 0x20(%rbx), %rsi
callq 0x8def
movq %rax, %rbx
leaq 0x6879(%rip), %rdi      # 0xa94f
callq 0x1070
movl 0x8(%rbx), %esi
leaq 0x65ad(%rip), %rdi      # 0xa692
xorl %eax, %eax
callq 0x10a0
leaq 0x6781(%rip), %rdi      # 0xa874
jmp 0x429d
movq 0x8(%rbx), %rdi
callq 0x3f3a
movq 0xb000(%rip), %rdi      # 0xf108
callq 0x8bf2
movq %rax, %r14
movq 0xaff1(%rip), %rdi      # 0xf108
callq 0x8c06
movq 0x10(%rbx), %rdi
callq 0x3819
leaq 0x67ff(%rip), %rdi      # 0xa92b
callq 0x1070
leaq 0x6817(%rip), %rdi      # 0xa94f
callq 0x1070
cmpl $0x0, 0xc(%r14)
movl 0x10(%r14), %eax
jle 0x4222
testl %eax, %eax
jle 0x4235
leaq 0x677a(%rip), %rdi      # 0xa8d5
callq 0x1070
jmp 0x4247
movq 0x8(%rbx), %rdi
callq 0x437e
leaq 0x67da(%rip), %rdi      # 0xa94f
callq 0x1070
leaq 0x671e(%rip), %rdi      # 0xa89f
callq 0x1070
leaq 0x6723(%rip), %rdi      # 0xa8b0
callq 0x1070
leaq 0x6722(%rip), %rdi      # 0xa8bb
callq 0x1070
leaq 0x6786(%rip), %rdi      # 0xa92b
callq 0x1070
leaq 0x6713(%rip), %rdi      # 0xa8c4
jmp 0x429d
movq 0x8(%rbx), %rdi
callq 0x437e
leaq 0x6789(%rip), %rdi      # 0xa94f
callq 0x1070
leaq 0x66cd(%rip), %rdi      # 0xa89f
callq 0x1070
leaq 0x66d2(%rip), %rdi      # 0xa8b0
callq 0x1070
leaq 0x66d1(%rip), %rdi      # 0xa8bb
callq 0x1070
leaq 0x6735(%rip), %rdi      # 0xa92b
callq 0x1070
leaq 0x668c(%rip), %rdi      # 0xa88e
jmp 0x429d
movq 0x8(%rax), %rdi
testq %rdi, %rdi
je 0x42ab
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x3819
cmpl $0x2, %eax
jl 0x4255
leaq 0x66a7(%rip), %rdi      # 0xa8d5
callq 0x1070
jmp 0x4267
movl 0x4(%r14), %esi
leaq 0x6442(%rip), %rdi      # 0xa682
xorl %eax, %eax
callq 0x10a0
leaq 0x6695(%rip), %rdi      # 0xa8e3
callq 0x1070
jmp 0x428a
movl 0x4(%r14), %esi
leaq 0x6422(%rip), %rdi      # 0xa682
xorl %eax, %eax
callq 0x10a0
leaq 0x6675(%rip), %rdi      # 0xa8e3
callq 0x1070
cmpl $0x1, 0x4(%r14)
jne 0x428a
cmpl $0x2, 0x10(%r14)
jge 0x428a
leaq 0x6687(%rip), %rdi      # 0xa90f
jmp 0x4291
leaq 0x666d(%rip), %rdi      # 0xa8fe
callq 0x1070
leaq 0x6698(%rip), %rdi      # 0xa935
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x1070
movq 0x18(%rax), %rdi
testq %rdi, %rdi
je 0x42c2
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x4745
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq