// File: /workspace/github_c_makefile_star2_O0/johnvtan[P]ccccc/parse.c
// Function: parse_unary
static expr_t *parse_unary(list_t *tokens, env_t *env) {
    if (!tokens || !tokens->len) {
        UNREACHABLE("wtf you doin\n");
    }

    if (match(tokens, TOK_BANG)) {
        debug("Found unary bang\n");
        return new_unary_expr(UNARY_LOGICAL_NEG, parse_unary(tokens, env));
    }

    if (match(tokens, TOK_TILDE)) {
        debug("Found unary tilde\n");
        return new_unary_expr(UNARY_BITWISE_COMP, parse_unary(tokens, env));
    }

    if (match(tokens, TOK_MINUS)) {
        debug("Found unary neg\n");
        return new_unary_expr(UNARY_MATH_NEG, parse_unary(tokens, env));
    }

    if (match(tokens, TOK_INCREMENT)) {
        debug("Found preincrement\n");
        expr_t *lhs = parse_unary(tokens, env);
        if (!is_valid_lhs(lhs)) {
            UNREACHABLE("Compile error: invalid lhs for preincrement operator\n");
        }
        expr_t *rhs = new_bin_expr(BIN_ADD, lhs, new_primary_int(1));
        return new_assign(lhs, rhs);
    }

    if (match(tokens, TOK_DECREMENT)) {
        debug("Found predecrement\n");
        expr_t *lhs = parse_unary(tokens, env);
        if (!is_valid_lhs(lhs)) {
            debug("lhs type: %d\n", (int)lhs->type);
            UNREACHABLE("Compile error: invalid lhs for predecrement operator\n");
        }
        expr_t *rhs = new_bin_expr(BIN_SUB, lhs, new_primary_int(1));
        return new_assign(lhs, rhs);
    }

    // Thanks 9cc
    return parse_postfix(tokens, env);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x6f11
movq -0x10(%rbp), %rax
cmpl $0x0, 0x18(%rax)
jne 0x6f3e
jmp 0x6f13
leaq 0x20ea(%rip), %rdi      # 0x9004
leaq 0x28c0(%rip), %rsi      # 0x97e1
movl $0x145, %edx            # imm = 0x145
leaq 0x2a10(%rip), %rcx      # 0x993d
movb $0x0, %al
callq 0x1070
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1110
movq -0x10(%rbp), %rdi
movl $0x16, %esi
callq 0x56a0
testb $0x1, %al
jne 0x6f52
jmp 0x6f79
jmp 0x6f54
jmp 0x6f56
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x6ef0
movq %rax, %rsi
movl $0x2, %edi
callq 0x7150
movq %rax, -0x8(%rbp)
jmp 0x7141
movq -0x10(%rbp), %rdi
movl $0x15, %esi
callq 0x56a0
testb $0x1, %al
jne 0x6f8d
jmp 0x6fb4
jmp 0x6f8f
jmp 0x6f91
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x6ef0
movq %rax, %rsi
movl $0x1, %edi
callq 0x7150
movq %rax, -0x8(%rbp)
jmp 0x7141
movq -0x10(%rbp), %rdi
movl $0x14, %esi
callq 0x56a0
testb $0x1, %al
jne 0x6fc8
jmp 0x6fec
jmp 0x6fca
jmp 0x6fcc
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x6ef0
movq %rax, %rsi
xorl %edi, %edi
callq 0x7150
movq %rax, -0x8(%rbp)
jmp 0x7141
movq -0x10(%rbp), %rdi
movl $0x17, %esi
callq 0x56a0
testb $0x1, %al
jne 0x7003
jmp 0x708c
jmp 0x7005
jmp 0x7007
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x6ef0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
callq 0x6670
testb $0x1, %al
jne 0x7052
jmp 0x7027
leaq 0x1fd6(%rip), %rdi      # 0x9004
leaq 0x27ac(%rip), %rsi      # 0x97e1
movl $0x15b, %edx            # imm = 0x15B
leaq 0x290a(%rip), %rcx      # 0x994b
movb $0x0, %al
callq 0x1070
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1110
movq -0x20(%rbp), %rax
movq %rax, -0x40(%rbp)
movl $0x1, %edi
callq 0x63c0
movq -0x40(%rbp), %rsi
movq %rax, %rdx
xorl %edi, %edi
callq 0x6770
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x66b0
movq %rax, -0x8(%rbp)
jmp 0x7141
movq -0x10(%rbp), %rdi
movl $0x18, %esi
callq 0x56a0
testb $0x1, %al
jne 0x70a3
jmp 0x7130
jmp 0x70a5
jmp 0x70a7
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x6ef0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x6670
testb $0x1, %al
jne 0x70f6
jmp 0x70c7
jmp 0x70c9
jmp 0x70cb
leaq 0x1f32(%rip), %rdi      # 0x9004
leaq 0x2708(%rip), %rsi      # 0x97e1
movl $0x166, %edx            # imm = 0x166
leaq 0x289c(%rip), %rcx      # 0x9981
movb $0x0, %al
callq 0x1070
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x1110
movq -0x30(%rbp), %rax
movq %rax, -0x48(%rbp)
movl $0x1, %edi
callq 0x63c0
movq -0x48(%rbp), %rsi
movq %rax, %rdx
movl $0x1, %edi
callq 0x6770
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x66b0
movq %rax, -0x8(%rbp)
jmp 0x7141
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x7270
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)