// File: /workspace/github_c_makefile_star2_O2/voithos[P]awl/src/builtins.c
// Function: builtin_bool_op
awlval* builtin_bool_op(awlenv* e, awlval* a, char* op) {
    if (streq(op, "not")) {
        AWLASSERT_ARGCOUNT(a, 1, op);
        EVAL_SINGLE_ARG(e, a, 0);
        AWLASSERT_TYPE(a, 0, AWLVAL_BOOL, op);

        awlval* x = awlval_take(a, 0);
        x->bln = !x->bln;
        return x;
    }

    AWLASSERT_ARGCOUNT(a, 2, op);

    awlval* x = awlval_pop(a, 0);
    awlval* y = awlval_take(a, 0);

    x = awlval_eval(e, x);
    if (x->type != AWLVAL_BOOL) {
        awlval* err = awlval_err(
                "function '%s' passed incorrect type for arg %i; got %s, expected %s",
                op, 0, awlval_type_name(x->type), awlval_type_name(AWLVAL_BOOL));
        awlval_del(x);
        awlval_del(y);
        return err;
    }

    if ((streq(op, "and") && !x->bln) || (streq(op, "or") && x->bln)) {
        awlval_del(y);
        return x;
    }

    y = awlval_eval(e, y);
    if (y->type != AWLVAL_BOOL) {
        awlval* err = awlval_err(
                "function '%s' passed incorrect type for arg %i; got %s, expected %s",
                op, 1, awlval_type_name(y->type), awlval_type_name(AWLVAL_BOOL));
        awlval_del(x);
        awlval_del(y);
        return err;
    }

    if (streq(op, "and")) {
        x->bln = x->bln && y->bln;
    }
    if (streq(op, "or")) {
        x->bln = x->bln || y->bln;
    }

    awlval_del(y);
    return x;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %r15
leaq 0xd254(%rip), %rsi      # 0x1013d
movq %rdx, %rdi
callq 0xf0d6
movl 0x4(%rbx), %ecx
testb %al, %al
je 0x2f42
cmpl $0x1, %ecx
jne 0x2fb0
movq %r15, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x55b2
movq %rax, %rbx
cmpl $0x2, (%rax)
je 0x30e9
movq 0x8(%rbx), %rax
movq (%rax), %rax
movl (%rax), %edi
cmpl $0x6, %edi
jne 0x304f
movq %rbx, %rdi
xorl %esi, %esi
callq 0xe31b
movq %rax, %rbx
xorb $0x1, 0x18(%rax)
jmp 0x30e9
cmpl $0x2, %ecx
jne 0x2fbb
movq %rbx, %rdi
xorl %esi, %esi
callq 0xe2bf
movq %rax, %r13
movq %rbx, %rdi
xorl %esi, %esi
callq 0xe31b
movq %rax, %r12
movq %r15, %rdi
movq %r13, %rsi
callq 0x52a8
movq %rax, %rbx
movl (%rax), %edi
cmpl $0x6, %edi
jne 0x2fe2
leaq 0xd208(%rip), %rsi      # 0x10185
movq %r14, %rdi
callq 0xf0d6
testb %al, %al
je 0x2f8f
cmpb $0x1, 0x18(%rbx)
jne 0x2fa8
leaq 0xded0(%rip), %rsi      # 0x10e66
movq %r14, %rdi
callq 0xf0d6
testb %al, %al
je 0x301b
cmpb $0x1, 0x18(%rbx)
jne 0x301b
movq %r12, %rdi
jmp 0x30e4
leaq 0xd143(%rip), %rdi      # 0x100fa
pushq $0x1
jmp 0x2fc4
leaq 0xd138(%rip), %rdi      # 0x100fa
pushq $0x2
popq %rdx
movq %r14, %rsi
xorl %eax, %eax
callq 0xdb45
movq %rax, %r14
movq %rbx, %rdi
callq 0xded1
movq %r14, %rax
jmp 0x30ec
callq 0xd97c
movq %rax, %r15
pushq $0x6
popq %rdi
callq 0xd97c
leaq 0xd148(%rip), %rdi      # 0x10141
movq %r14, %rsi
xorl %edx, %edx
movq %r15, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0xdb45
movq %rax, %r14
movq %rbx, %rdi
callq 0xded1
movq %r12, %rdi
jmp 0x2fd5
movq %r15, %rdi
movq %r12, %rsi
callq 0x52a8
movq %rax, %r15
movl (%rax), %edi
cmpl $0x6, %edi
jne 0x307d
leaq 0xd14e(%rip), %rsi      # 0x10185
movq %r14, %rdi
callq 0xf0d6
testb %al, %al
je 0x30bf
cmpb $0x1, 0x18(%rbx)
jne 0x30ba
movb 0x18(%r15), %al
jmp 0x30bc
callq 0xd97c
movq %rax, %r15
pushq $0x6
popq %rdi
callq 0xd97c
leaq 0xd0db(%rip), %rdi      # 0x10141
movq %r14, %rsi
xorl %edx, %edx
movq %r15, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0xdb45
jmp 0x2fcf
callq 0xd97c
movq %rax, %r12
pushq $0x6
popq %rdi
callq 0xd97c
leaq 0xd0ad(%rip), %rdi      # 0x10141
pushq $0x1
popq %rdx
movq %r14, %rsi
movq %r12, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0xdb45
movq %rax, %r14
movq %rbx, %rdi
callq 0xded1
movq %r15, %rdi
jmp 0x2fd5
xorl %eax, %eax
movb %al, 0x18(%rbx)
leaq 0xdda0(%rip), %rsi      # 0x10e66
movq %r14, %rdi
callq 0xf0d6
testb %al, %al
je 0x30e1
movb $0x1, %al
cmpb $0x0, 0x18(%rbx)
jne 0x30de
movb 0x18(%r15), %al
movb %al, 0x18(%rbx)
movq %r15, %rdi
callq 0xded1
movq %rbx, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq