// File: /workspace/github_c_makefile_star2_O3/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 %rsi, %r14
movq %rdi, %r12
movq 0x10(%rsi), %r15
leaq 0x18(%rsp), %rbx
movq %rbx, %rdi
callq 0x1f6c
movl 0x4(%rbx), %r13d
movl 0xc(%rbx), %ebp
cmpl $0x0, (%rbx)
movq %r12, 0x38(%rsp)
je 0x2970
movq (%r14), %rdi
movq 0x10(%r14), %rsi
callq 0x2ef6
movq %rax, %rbx
testq %rax, %rax
je 0x297c
incq 0x10(%r14)
movl (%rbx), %eax
cmpl $0x1e, %eax
je 0x29a7
cmpl $0x1c, %eax
jne 0x297c
movq %rbx, %rdi
callq 0x1b54
movq %rax, %r15
movq %rax, %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x1140
movq %rax, %r12
movq %r15, %rdi
callq 0x1040
movq 0x8(%r14), %rdi
callq 0x354a
movq %rax, %r15
movl $0x8, (%rax)
movl %r12d, 0x8(%rax)
movq 0x38(%rsp), %r12
jmp 0x29c8
movq 0x28(%rsp), %rbx
movq 0x30(%rsp), %r15
jmp 0x29c8
movl $0x1, %eax
movl %eax, (%r12)
movl %r13d, 0x4(%r12)
movl %eax, 0x8(%r12)
movl %ebp, 0xc(%r12)
movq %rbx, 0x10(%r12)
movq %rbx, 0x18(%r12)
movq %r15, 0x10(%r14)
jmp 0x2c11
movq %rbx, %rdi
callq 0x1b54
movq %rax, %r15
movq 0x8(%r14), %rdi
callq 0x354a
movl $0x9, (%rax)
movq %r15, 0x8(%rax)
movq %rax, %r15
xorl %eax, %eax
movl %eax, (%r12)
movl %r13d, 0x4(%r12)
movl %ebp, 0xc(%r12)
movq %rbx, 0x10(%r12)
movq %r15, 0x18(%r12)
movq (%r14), %rdi
movq 0x10(%r14), %rbp
movq %rbp, %rsi
callq 0x2ef6
movq %rax, %rdx
xorl %eax, %eax
movl %eax, 0x8(%r12)
testq %rdx, %rdx
je 0x2bfd
leaq 0xc(%r12), %rax
movq %rax, 0x40(%rsp)
leaq 0x24(%rsp), %rcx
leaq 0x18(%rsp), %r13
movq 0x10(%r14), %rsi
incq %rsi
movq %rsi, 0x10(%r14)
movl (%rdx), %eax
cmpl $0x6, %eax
movq %rdx, 0x60(%rsp)
je 0x2afb
cmpl $0x4, %eax
jne 0x2bfd
movq %rsi, 0x48(%rsp)
movq %rbp, 0x50(%rsp)
movq %r15, 0x58(%rsp)
movl $0x8, %edi
movq %rcx, %rbx
callq 0x2d9c
movq %rax, %r15
movq %r13, %rdi
movq %r14, %rsi
callq 0x27c4
movl 0x18(%rsp), %eax
movl 0x1c(%rsp), %r12d
movq (%rbx), %rcx
movq %rcx, 0x8(%rsp)
movl 0x8(%rbx), %ecx
movl %ecx, 0x10(%rsp)
cmpl $0x1, %eax
je 0x2ac0
movq 0x30(%rsp), %rbp
movq %r15, %rdi
callq 0x2eb0
movq %rbp, (%rax)
movq %r13, %rdi
movq %r14, %rsi
callq 0x27c4
movl 0x18(%rsp), %eax
movl 0x1c(%rsp), %r12d
movq (%rbx), %rcx
movq %rcx, 0x8(%rsp)
movl 0x8(%rbx), %ecx
movl %ecx, 0x10(%rsp)
movq 0x30(%rsp), %rbp
cmpl $0x1, %eax
jne 0x2a88
movq %r15, %rdi
callq 0x2f0b
testq %rax, %rax
je 0x2b1a
movl 0x10(%rsp), %eax
movl %eax, 0x20(%rsp)
movq 0x8(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x8(%r14), %rdi
callq 0x354a
movq %rax, %r13
movl $0xb, (%rax)
movq %r15, 0x8(%rax)
movq 0x10(%r14), %rsi
jmp 0x2b40
movq (%r14), %rdi
callq 0x2ef6
testq %rax, %rax
je 0x2bea
cmpl $0x7, (%rax)
jne 0x2bee
xorl %r13d, %r13d
jmp 0x2b7c
movq %r15, %rdi
callq 0x2e8f
movl 0x10(%rsp), %eax
movl %eax, 0x20(%rsp)
movq 0x8(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x48(%rsp), %rsi
movq %rsi, 0x10(%r14)
xorl %r13d, %r13d
movq 0x38(%rsp), %rax
movl %r12d, 0x4(%rax)
movq %rax, %r12
movl 0x20(%rsp), %eax
movq 0x40(%rsp), %rcx
movl %eax, 0x8(%rcx)
movq 0x18(%rsp), %rax
movq %rax, (%rcx)
movq (%r14), %rdi
callq 0x2ef6
testq %rax, %rax
movq 0x58(%rsp), %r15
movq 0x50(%rsp), %rbp
je 0x2bea
cmpl $0x5, (%rax)
jne 0x2bee
incq 0x10(%r14)
movq 0x8(%r14), %rdi
callq 0x354a
movq %rax, %rbx
movl $0x7, (%rax)
xorl %eax, %eax
movl %eax, 0x8(%rbx)
movq %r15, 0x10(%rbx)
movq %r13, 0x18(%rbx)
movq (%r14), %rdi
movq 0x10(%r14), %rbp
movq %rbp, %rsi
callq 0x2ef6
xorl %ecx, %ecx
movq %rbx, %r15
testq %rax, %rax
sete %cl
movq 0x60(%rsp), %rdx
cmovneq %rax, %rdx
movl %ecx, (%r12)
movl $0x0, %ecx
movl %ecx, 0x8(%r12)
movq %rdx, 0x18(%r12)
movq %rax, %rdx
leaq 0x24(%rsp), %rcx
leaq 0x18(%rsp), %r13
jne 0x2a18
jmp 0x2c00
xorl %ecx, %ecx
jmp 0x2bf3
movl $0x1, %ecx
movl %ecx, 0x8(%r12)
movq %rax, 0x10(%r12)
movq %r15, %rbx
movq %rbp, 0x10(%r14)
movl $0x0, (%r12)
movq %rbx, 0x18(%r12)
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq