// File: /workspace/github_c_makefile_star2_O1/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 0xea57(%rip), %rsi      # 0x1213d
movq %rdx, %rdi
callq 0x11b89
movl 0x4(%rbx), %ecx
testb %al, %al
je 0x373f
cmpl $0x1, %ecx
jne 0x37b1
movq %r15, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x61cd
movq %rax, %rbx
cmpl $0x2, (%rax)
je 0x38fe
movq 0x8(%rbx), %rax
movq (%rax), %rax
movl (%rax), %edi
cmpl $0x6, %edi
jne 0x385e
movq %rbx, %rdi
xorl %esi, %esi
callq 0x10c7f
movq %rax, %rbx
xorb $0x1, 0x18(%rax)
jmp 0x38fe
cmpl $0x2, %ecx
jne 0x37c2
movq %rbx, %rdi
xorl %esi, %esi
callq 0x10c23
movq %rax, %r13
movq %rbx, %rdi
xorl %esi, %esi
callq 0x10c7f
movq %rax, %r12
movq %r15, %rdi
movq %r13, %rsi
callq 0x5e90
movq %rax, %rbx
movl (%rax), %edi
cmpl $0x6, %edi
jne 0x37eb
leaq 0xea0b(%rip), %rsi      # 0x12185
movq %r14, %rdi
callq 0x11b89
testb %al, %al
je 0x378c
cmpb $0x1, 0x18(%rbx)
jne 0x37a9
leaq 0xf683(%rip), %rsi      # 0x12e16
movq %r14, %rdi
callq 0x11b89
testb %al, %al
je 0x3826
cmpb $0x1, 0x18(%rbx)
jne 0x3826
movq %r12, %rdi
jmp 0x38f9
leaq 0xe942(%rip), %rdi      # 0x120fa
movq %r14, %rsi
movl $0x1, %edx
jmp 0x37d1
leaq 0xe931(%rip), %rdi      # 0x120fa
movq %r14, %rsi
movl $0x2, %edx
xorl %eax, %eax
callq 0x1032f
movq %rax, %r14
movq %rbx, %rdi
callq 0x10767
movq %r14, %rax
jmp 0x3901
callq 0x10138
movq %rax, %r15
movl $0x6, %edi
callq 0x10138
leaq 0xe93d(%rip), %rdi      # 0x12141
movq %r14, %rsi
xorl %edx, %edx
movq %r15, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x1032f
movq %rax, %r14
movq %rbx, %rdi
callq 0x10767
movq %r12, %rdi
jmp 0x37de
movq %r15, %rdi
movq %r12, %rsi
callq 0x5e90
movq %rax, %r15
movl (%rax), %edi
cmpl $0x6, %edi
jne 0x388e
leaq 0xe943(%rip), %rsi      # 0x12185
movq %r14, %rdi
callq 0x11b89
testb %al, %al
je 0x38d4
cmpb $0x1, 0x18(%rbx)
jne 0x38cf
movb 0x18(%r15), %al
jmp 0x38d1
callq 0x10138
movq %rax, %r15
movl $0x6, %edi
callq 0x10138
leaq 0xe8ca(%rip), %rdi      # 0x12141
movq %r14, %rsi
xorl %edx, %edx
movq %r15, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x1032f
jmp 0x37d8
callq 0x10138
movq %rax, %r12
movl $0x6, %edi
callq 0x10138
leaq 0xe89a(%rip), %rdi      # 0x12141
movq %r14, %rsi
movl $0x1, %edx
movq %r12, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x1032f
movq %rax, %r14
movq %rbx, %rdi
callq 0x10767
movq %r15, %rdi
jmp 0x37de
xorl %eax, %eax
movb %al, 0x18(%rbx)
leaq 0xf53b(%rip), %rsi      # 0x12e16
movq %r14, %rdi
callq 0x11b89
testb %al, %al
je 0x38f6
movb $0x1, %al
cmpb $0x0, 0x18(%rbx)
jne 0x38f3
movb 0x18(%r15), %al
movb %al, 0x18(%rbx)
movq %r15, %rdi
callq 0x10767
movq %rbx, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq