// File: /workspace/github_c_makefile_star2_O2/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 $0x48, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq 0x10(%rsi), %r13
leaq 0x20(%rsp), %r15
movq %r15, %rdi
callq 0x1b60
cmpl $0x0, (%r15)
je 0x25f6
movq 0x10(%r14), %r12
movq %rsp, %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x1ee7
cmpl $0x1, (%r15)
pushq $0x1
popq %rbp
je 0x25b0
incq 0x10(%r14)
movq 0x18(%rsp), %rdi
movl (%rdi), %eax
cmpl $0x1e, %eax
je 0x257e
cmpl $0x1c, %eax
jne 0x25a4
callq 0x17f0
movq %rax, %r15
pushq $0xa
popq %rdx
movq %rax, %rdi
xorl %esi, %esi
callq 0x1140
movq %rax, %r12
movq %r15, %rdi
callq 0x1040
movq 0x8(%r14), %rdi
callq 0x2f4c
movl $0x8, (%rax)
movl %r12d, 0x8(%rax)
jmp 0x2599
callq 0x17f0
movq %rax, %r15
movq 0x8(%r14), %rdi
callq 0x2f4c
movl $0x9, (%rax)
movq %r15, 0x8(%rax)
andl $0x0, (%rsp)
movq %rax, 0x18(%rsp)
jmp 0x25b4
movl %ebp, (%rsp)
movl %ebp, 0x8(%rsp)
movq %rdi, 0x10(%rsp)
movq %r12, 0x10(%r14)
movl (%rsp), %eax
movl 0x4(%rsp), %ecx
movl 0x8(%rsp), %edx
movl 0xc(%rsp), %esi
movq 0x10(%rsp), %rdi
movq %rdi, 0x30(%rsp)
movq 0x18(%rsp), %rdi
movq %rdi, 0x38(%rsp)
movl %eax, 0x20(%rsp)
movl %ecx, 0x24(%rsp)
movl %edx, 0x28(%rsp)
movl %esi, 0x2c(%rsp)
cmpl $0x0, 0x20(%rsp)
je 0x25f6
movl %ebp, 0x20(%rsp)
movl %ebp, 0x28(%rsp)
movl 0x20(%rsp), %eax
movl 0x24(%rsp), %ecx
movl 0x28(%rsp), %edx
movl 0x2c(%rsp), %esi
movq 0x30(%rsp), %rdi
movq %rdi, 0x10(%rbx)
movq 0x38(%rsp), %rdi
movq %rdi, 0x18(%rbx)
movl %eax, (%rbx)
movl %ecx, 0x4(%rbx)
movl %edx, 0x8(%rbx)
movl %esi, 0xc(%rbx)
cmpl $0x1, (%rbx)
jne 0x2631
movq %r13, 0x10(%r14)
jmp 0x2738
movq 0x18(%rbx), %rbp
movq 0x10(%r14), %r15
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1ee7
cmpl $0x1, (%rbx)
je 0x272d
movq 0x10(%r14), %r12
incq %r12
movq %r12, 0x10(%r14)
movq 0x18(%rbx), %rax
movl (%rax), %eax
cmpl $0x6, %eax
je 0x268a
cmpl $0x4, %eax
jne 0x272d
movq %rsp, %rdi
movq %r14, %rsi
leaq -0x23b(%rip), %rdx      # 0x243e
callq 0x1ae6
cmpl $0x1, (%rsp)
jne 0x26a6
movq %r12, 0x10(%r14)
jmp 0x26c7
movq %rbx, %rdi
movq %r14, %rsi
pushq $0x7
popq %rdx
callq 0x1f9f
cmpl $0x1, (%rbx)
je 0x272d
xorl %r12d, %r12d
jmp 0x2706
movq 0x8(%r14), %rdi
callq 0x2f4c
movl $0xb, (%rax)
movq 0x18(%rsp), %rcx
movq %rcx, 0x8(%rax)
andl $0x0, (%rsp)
movq %rax, 0x18(%rsp)
movups (%rsp), %xmm0
movq 0x10(%rsp), %rax
movq %rax, 0x10(%rbx)
movq 0x18(%rsp), %rax
movq %rax, 0x18(%rbx)
movups %xmm0, (%rbx)
movl (%rbx), %r13d
movq 0x18(%rbx), %r12
movq %rbx, %rdi
movq %r14, %rsi
pushq $0x5
popq %rdx
callq 0x1f9f
cmpl $0x1, (%rbx)
je 0x272d
testl %r13d, %r13d
movl $0x0, %eax
cmovneq %rax, %r12
incq 0x10(%r14)
movq 0x8(%r14), %rdi
callq 0x2f4c
movl $0x7, (%rax)
andl $0x0, 0x8(%rax)
movq %rbp, 0x10(%rax)
movq %r12, 0x18(%rax)
movq %rax, %rbp
jmp 0x2635
movq %r15, 0x10(%r14)
andl $0x0, (%rbx)
movq %rbp, 0x18(%rbx)
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop