// File: /workspace/github_c_makefile_star2_O3/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 0xeaa7(%rip), %rsi      # 0x1213d
movq %rdx, %rdi
callq 0x11692
movl 0x4(%rbx), %ecx
testb %al, %al
je 0x36ef
cmpl $0x1, %ecx
jne 0x3761
movq %r15, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x5f11
movq %rax, %rbx
cmpl $0x2, (%rax)
je 0x38ae
movq 0x8(%rbx), %rax
movq (%rax), %rax
movl (%rax), %edi
cmpl $0x6, %edi
jne 0x380e
movq %rbx, %rdi
xorl %esi, %esi
callq 0x107b7
movq %rax, %rbx
xorb $0x1, 0x18(%rax)
jmp 0x38ae
cmpl $0x2, %ecx
jne 0x3772
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1075b
movq %rax, %r13
movq %rbx, %rdi
xorl %esi, %esi
callq 0x107b7
movq %rax, %r12
movq %r15, %rdi
movq %r13, %rsi
callq 0x5be8
movq %rax, %rbx
movl (%rax), %edi
cmpl $0x6, %edi
jne 0x379b
leaq 0xea5b(%rip), %rsi      # 0x12185
movq %r14, %rdi
callq 0x11692
testb %al, %al
je 0x373c
cmpb $0x1, 0x18(%rbx)
jne 0x3759
leaq 0xf72b(%rip), %rsi      # 0x12e6e
movq %r14, %rdi
callq 0x11692
testb %al, %al
je 0x37d6
cmpb $0x1, 0x18(%rbx)
jne 0x37d6
movq %r12, %rdi
jmp 0x38a9
leaq 0xe992(%rip), %rdi      # 0x120fa
movq %r14, %rsi
movl $0x1, %edx
jmp 0x3781
leaq 0xe981(%rip), %rdi      # 0x120fa
movq %r14, %rsi
movl $0x2, %edx
xorl %eax, %eax
callq 0xfe6b
movq %rax, %r14
movq %rbx, %rdi
callq 0x1029f
movq %r14, %rax
jmp 0x38b1
callq 0xfc74
movq %rax, %r15
movl $0x6, %edi
callq 0xfc74
leaq 0xe98d(%rip), %rdi      # 0x12141
movq %r14, %rsi
xorl %edx, %edx
movq %r15, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0xfe6b
movq %rax, %r14
movq %rbx, %rdi
callq 0x1029f
movq %r12, %rdi
jmp 0x378e
movq %r15, %rdi
movq %r12, %rsi
callq 0x5be8
movq %rax, %r15
movl (%rax), %edi
cmpl $0x6, %edi
jne 0x383e
leaq 0xe993(%rip), %rsi      # 0x12185
movq %r14, %rdi
callq 0x11692
testb %al, %al
je 0x3884
cmpb $0x1, 0x18(%rbx)
jne 0x387f
movb 0x18(%r15), %al
jmp 0x3881
callq 0xfc74
movq %rax, %r15
movl $0x6, %edi
callq 0xfc74
leaq 0xe91a(%rip), %rdi      # 0x12141
movq %r14, %rsi
xorl %edx, %edx
movq %r15, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0xfe6b
jmp 0x3788
callq 0xfc74
movq %rax, %r12
movl $0x6, %edi
callq 0xfc74
leaq 0xe8ea(%rip), %rdi      # 0x12141
movq %r14, %rsi
movl $0x1, %edx
movq %r12, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0xfe6b
movq %rax, %r14
movq %rbx, %rdi
callq 0x1029f
movq %r15, %rdi
jmp 0x378e
xorl %eax, %eax
movb %al, 0x18(%rbx)
leaq 0xf5e3(%rip), %rsi      # 0x12e6e
movq %r14, %rdi
callq 0x11692
testb %al, %al
je 0x38a6
movb $0x1, %al
cmpb $0x0, 0x18(%rbx)
jne 0x38a3
movb 0x18(%r15), %al
movb %al, 0x18(%rbx)
movq %r15, %rdi
callq 0x1029f
movq %rbx, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq