// File: /workspace/github_c_makefile_star2_O0/sebbekarlsson[P]cola/src/parse.c
// Function: parse_factor
ast_node* parse_factor(parse_state* state, scope* sc) {
    token* tok = state->current_token;

    if (tok->type == _OP_PLUS) {
        parse_eat(state, _OP_PLUS);
        ast_node_unaryop* node = init_ast_node_unaryop(tok, parse_factor(state, sc));
        ast_node_set_scope((ast_node*) node, (struct scope*) sc);
        // invalid pointer type
        return (ast_node*) node;

    } else if (tok->type == _OP_SUBTRACT) {
        parse_eat(state, _OP_SUBTRACT);
        ast_node_unaryop* node = init_ast_node_unaryop(tok, parse_factor(state, sc));
        ast_node_set_scope((ast_node*) node, (struct scope*) sc);
        // invalid pointer type
        return (ast_node*) node;

    } else if (tok->type == _NOT_EQUALS) {
        parse_eat(state, _NOT_EQUALS);
        ast_node_unaryop* node = init_ast_node_unaryop(tok, parse_factor(state, sc));
        ast_node_set_scope((ast_node*) node, (struct scope*) sc);
        // invalid pointer type
        return (ast_node*) node;

    } else if (tok->type == _INTEGER) {
        return (ast_node*) parse_integer(state, sc);
    } else if (tok->type == _FLOAT) {
        return (ast_node*) parse_float(state, sc);
    } else if (tok->type == _CHAR) {
        parse_eat(state, _CHAR);
        ast_node_char* node = init_ast_node_char(tok, tok->value[0]);
        ast_node_set_scope((ast_node*) node, (struct scope*) sc);
        // invalid pointer type
        return (ast_node*) node;

    } else if (tok->type == _STRING) {
        parse_eat(state, _STRING);
        ast_node_string* node = init_ast_node_string(tok, tok->value);
        ast_node_set_scope((ast_node*) node, (struct scope*) sc);
        // invalid pointer type
        return (ast_node*) node;
    
    } else if (tok->type == _TYPE_COMPONENT) {
        return (ast_node*) parse_component(state, sc);
    } else if (tok->type == _ID) {
        return (ast_node*) parse_variable(state, sc);
    } else if (tok->type == _FUNCTION_CALL) {
        return (ast_node*) parse_function_call(state, sc);
    } else if (tok->type == _LPAREN) {
        parse_eat(state, _LPAREN);
        ast_node* node = parse_expr(state, sc);
        ast_node_set_scope((ast_node*) node, (struct scope*) sc);
        parse_eat(state, _RPAREN);
        return node;
    } else if (tok->type == _LBRACKET) {
        ast_node_vector* node = parse_vector(state, sc);
        ast_node_set_scope((ast_node*) node, (struct scope*) sc);
        return (ast_node*) node;
    } else {
        printf("Unexpected token_type: `%d`\n", tok->type);
        return (void*)0;
    }

    return (ast_node*) parse_expr(state,sc );
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x5, (%rax)
jne 0x4fc2
movq -0x10(%rbp), %rdi
movl $0x5, %esi
callq 0x4520
movq -0x20(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x4f50
movq -0x60(%rbp), %rdi
movq %rax, %rsi
callq 0x18f0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x12f0
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x5232
movq -0x20(%rbp), %rax
cmpl $0x6, (%rax)
jne 0x5018
movq -0x10(%rbp), %rdi
movl $0x6, %esi
callq 0x4520
movq -0x20(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x4f50
movq -0x68(%rbp), %rdi
movq %rax, %rsi
callq 0x18f0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x12f0
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x5232
movq -0x20(%rbp), %rax
cmpl $0x1a, (%rax)
jne 0x506e
movq -0x10(%rbp), %rdi
movl $0x1a, %esi
callq 0x4520
movq -0x20(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x4f50
movq -0x70(%rbp), %rdi
movq %rax, %rsi
callq 0x18f0
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x12f0
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x5232
movq -0x20(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x508d
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x4580
movq %rax, -0x8(%rbp)
jmp 0x5232
movq -0x20(%rbp), %rax
cmpl $0x27, (%rax)
jne 0x50ac
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x49f0
movq %rax, -0x8(%rbp)
jmp 0x5232
movq -0x20(%rbp), %rax
cmpl $0x26, (%rax)
jne 0x50f5
movq -0x10(%rbp), %rdi
movl $0x26, %esi
callq 0x4520
movq -0x20(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movsbl (%rax), %esi
callq 0x13f0
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x12f0
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x5232
movq -0x20(%rbp), %rax
cmpl $0x3, (%rax)
jne 0x513b
movq -0x10(%rbp), %rdi
movl $0x3, %esi
callq 0x4520
movq -0x20(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x18a0
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x12f0
movq -0x48(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x5232
movq -0x20(%rbp), %rax
cmpl $0x2f, (%rax)
jne 0x515a
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x5240
movq %rax, -0x8(%rbp)
jmp 0x5232
movq -0x20(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x5179
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x4e10
movq %rax, -0x8(%rbp)
jmp 0x5232
movq -0x20(%rbp), %rax
cmpl $0x1c, (%rax)
jne 0x5198
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x4e60
movq %rax, -0x8(%rbp)
jmp 0x5232
movq -0x20(%rbp), %rax
cmpl $0xc, (%rax)
jne 0x51e5
movq -0x10(%rbp), %rdi
movl $0xc, %esi
callq 0x4520
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x4670
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x12f0
movq -0x10(%rbp), %rdi
movl $0xd, %esi
callq 0x4520
movq -0x50(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x5232
movq -0x20(%rbp), %rax
cmpl $0x22, (%rax)
jne 0x5216
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x4920
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x12f0
movq -0x58(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x5232
movq -0x20(%rbp), %rax
movl (%rax), %esi
leaq 0x2058(%rip), %rdi      # 0x727b
movb $0x0, %al
callq 0x1080
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)