// File: /workspace/github_c_makefile_star2_O1/yutopp[P]cc/parser.c
// Function: parse_expr_postfix
ParserResult parse_expr_postfix(Parser *parser) {
    ParserResult res;
    state_t _parser_state = save_state(parser);

    Node* gen_node;

    res = parse_expr_primary(parser); ErrProp;
    gen_node = res.value.node;

    for(;;) {
        _parser_state = save_state(parser);

        res = current_token(parser);
        if (res.result == PARSER_ERROR) {
            rewind_state(parser, _parser_state);
            goto total_passed;
        }
        forward_token(parser);

        NodeExprPostfixKind d;
        Node* nodes[1] = {NULL};
        switch(res.value.token->kind) {
        case TOK_KIND_LPAREN:
            res = parse_argument_expr_list(parser); // Optional
            d = NODE_EXPR_POSTFIX_KIND_FUNC_CALL;
            nodes[0] = NULL;
            if (res.result == PARSER_OK) {
                nodes[0] = res.value.node;
            }

            res = assume_token(parser, TOK_KIND_RPAREN);
            if (res.result == PARSER_ERROR) {
                goto total_passed;
            }
            forward_token(parser);
            break;

        case TOK_KIND_LBRACKET:
            res = assume_token(parser, TOK_KIND_RBRACKET);
            if (res.result == PARSER_ERROR) {
                goto total_passed;
            }
            forward_token(parser);
            break;

        default:
            goto total_passed;
        }

        Node* node = node_arena_malloc(parser->arena);
        node->kind = NODE_EXPR_POSTFIX;
        node->value.expr_postfix.kind = d;
        node->value.expr_postfix.lhs = gen_node;

        switch(d) {
        case NODE_EXPR_POSTFIX_KIND_FUNC_CALL:
            node->value.expr_postfix.rhs = nodes[0]; // Nullable
            break;
        default:
            assert(0); // TODO: error handling...
        }

        gen_node = node;
    }

total_passed:
    rewind_state(parser, _parser_state);

    res.result = PARSER_OK;
    res.value.node = gen_node;

    return res;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %r12
movq 0x10(%rsi), %rbp
movq %rsi, (%rsp)
callq 0x1f63
cmpl $0x0, (%r12)
movq %r12, 0x38(%rsp)
je 0x2c9e
movq (%rsp), %rbx
movq (%rbx), %rdi
movq 0x10(%rbx), %r12
movq %r12, %rsi
callq 0x3216
movq %rax, %r15
testq %rax, %rax
je 0x2c21
incq 0x10(%rbx)
movl (%r15), %eax
cmpl $0x1e, %eax
je 0x2c33
cmpl $0x1c, %eax
jne 0x2c5d
movq %r15, %rdi
callq 0x1b54
movq %rax, %r12
xorl %ebx, %ebx
movq %rax, %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x1130
movq %rax, %r13
movq %r12, %rdi
callq 0x1040
movq (%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x3876
movl $0x8, (%rax)
movl %r13d, 0x8(%rax)
movb $0x1, %cl
jmp 0x2c59
movq %r12, 0x10(%rbx)
movl $0x1, %edx
xorl %ebx, %ebx
movq %r15, %rax
xorl %ecx, %ecx
jmp 0x2c74
movq %r15, %rdi
callq 0x1b54
movq %rax, %r12
movq (%rsp), %rax
movq 0x8(%rax), %rdi
callq 0x3876
movl $0x9, (%rax)
movq %r12, 0x8(%rax)
movb $0x1, %cl
xorl %ebx, %ebx
xorl %edx, %edx
jmp 0x2c74
movq (%rsp), %rax
movq %r12, 0x10(%rax)
movl $0x1, %ebx
xorl %ecx, %ecx
movq %r15, %rax
movl $0x1, %edx
movq 0x38(%rsp), %r12
movl %edx, (%r12)
movl %ebx, 0x8(%r12)
movq %r15, 0x10(%r12)
movq %rax, 0x18(%r12)
testb %cl, %cl
jne 0x2c9e
movl $0x1, %eax
movl %eax, (%r12)
movl %eax, 0x8(%r12)
cmpl $0x1, (%r12)
jne 0x2cb2
movq (%rsp), %rax
movq %rbp, 0x10(%rax)
jmp 0x2f20
movq 0x18(%r12), %rbx
leaq 0x24(%rsp), %r13
leaq 0xc(%r12), %rax
movq %rax, 0x58(%rsp)
leaq 0x18(%rsp), %r14
movq (%rsp), %rbp
movq (%rbp), %rdi
movq 0x10(%rbp), %r15
movq %r15, %rsi
callq 0x3216
testq %rax, %rax
je 0x2cf3
movl $0x0, (%r12)
movq %rax, 0x18(%r12)
jmp 0x2d04
movl $0x1, (%r12)
movl $0x0, 0x8(%r12)
cmpl $0x1, (%r12)
movq %r15, 0x60(%rsp)
je 0x2f06
movq 0x10(%rbp), %rcx
incq %rcx
movq %rcx, 0x10(%rbp)
movq 0x18(%r12), %rax
movl (%rax), %eax
cmpl $0x6, %eax
je 0x2d83
cmpl $0x4, %eax
jne 0x2da6
movq %rcx, 0x48(%rsp)
movq %rbx, 0x50(%rsp)
movl $0x8, %edi
callq 0x30b4
movq %r14, %rdi
movq %rax, 0x40(%rsp)
movq %rbp, %rsi
callq 0x2a71
movl 0x18(%rsp), %eax
movl 0x1c(%rsp), %r12d
movl 0x20(%rsp), %ebx
movq (%r13), %rcx
movq %rcx, 0x8(%rsp)
movl 0x8(%r13), %ecx
movl %ecx, 0x10(%rsp)
movq 0x30(%rsp), %r13
cmpl $0x1, %eax
jne 0x2dae
movq 0x40(%rsp), %r14
jmp 0x2dfb
movq %r12, %rdi
movq %rbp, %rsi
movl $0x7, %edx
callq 0x24f0
xorl %r15d, %r15d
cmpl $0x1, (%r12)
jne 0x2ed3
jmp 0x2efb
xorl %r15d, %r15d
jmp 0x2efb
leaq 0x24(%rsp), %r15
movq (%rsp), %rbp
movq 0x40(%rsp), %r14
movq %r14, %rdi
callq 0x31d0
movq %r13, (%rax)
leaq 0x18(%rsp), %rdi
movq %rbp, %rsi
callq 0x2a71
movl 0x18(%rsp), %eax
movl 0x1c(%rsp), %r12d
movl 0x20(%rsp), %ebx
movq (%r15), %rcx
movq %rcx, 0x8(%rsp)
movl 0x8(%r15), %ecx
movl %ecx, 0x10(%rsp)
movq 0x30(%rsp), %r13
cmpl $0x1, %eax
jne 0x2dbc
movq %r14, %rdi
callq 0x322b
movq %rax, %r15
xorl %eax, %eax
testq %r15, %r15
je 0x2e1b
movq %r14, %r13
movq (%rsp), %rbp
movq 0x48(%rsp), %rdx
jmp 0x2e3a
movq %r14, %rdi
callq 0x31af
movq (%rsp), %rbp
movq 0x48(%rsp), %rdx
movq %rdx, 0x10(%rbp)
movl $0x1, %eax
movl $0x2, %ebx
movq 0x38(%rsp), %rcx
movl %eax, (%rcx)
movl %r12d, 0x4(%rcx)
movq %rcx, %r12
movl %ebx, 0x8(%rcx)
movl 0x10(%rsp), %eax
movq 0x58(%rsp), %rcx
movl %eax, 0x8(%rcx)
movq 0x8(%rsp), %rax
movq %rax, (%rcx)
movq %r13, 0x18(%r12)
testq %r15, %r15
leaq 0x18(%rsp), %r14
je 0x2e90
movq 0x8(%rbp), %rdi
callq 0x3876
movl $0xb, (%rax)
movq %r13, 0x8(%rax)
movl $0x0, (%r12)
movq %rax, 0x18(%r12)
jmp 0x2e94
movq %rdx, 0x10(%rbp)
leaq 0x24(%rsp), %r13
movl (%r12), %ebx
movq 0x18(%r12), %r15
movq %r12, %rdi
movq %rbp, %rsi
movl $0x5, %edx
callq 0x24f0
cmpl $0x1, (%r12)
jne 0x2ec3
xorl %r15d, %r15d
movq 0x50(%rsp), %rbx
jmp 0x2efb
testl %ebx, %ebx
movl $0x0, %eax
cmovneq %rax, %r15
movq 0x50(%rsp), %rbx
incq 0x10(%rbp)
movq 0x8(%rbp), %rdi
callq 0x3876
movl $0x7, (%rax)
movl $0x0, 0x8(%rax)
movq %rbx, 0x10(%rax)
movq %r15, 0x18(%rax)
movb $0x1, %r15b
movq %rax, %rbx
testb %r15b, %r15b
jne 0x2ccf
jmp 0x2f0a
movq %r15, 0x10(%rbp)
movq 0x60(%rsp), %rax
movq %rax, 0x10(%rbp)
movl $0x0, (%r12)
movq %rbx, 0x18(%r12)
movq %r12, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop