// File: /workspace/github_cpp_makefile_star2_O1/WayfireWM[P]wf-utils/wayfire/parser/lambda_rule_parser.cpp
// Function: wf::lambda_rule_parser_t::parse(wf::lexer_t&, std::function<bool ()>, std::function<bool ()>)
std::shared_ptr<lambda_rule_t> lambda_rule_parser_t::parse(lexer_t &lexer, lambda_t if_lambda, lambda_t else_lambda)
{
    std::string signal;
    std::shared_ptr<condition_t> condition;

    try
    {
        // Expect the first symbol to be the 'on' keyword.
        auto symbol = lexer.parse_symbol();
        if ((symbol.type != symbol_t::type_t::KEYWORD) || (get_string(symbol.value) != "on"))
        {
            throw std::runtime_error("Lambda rule parser error. Expected 'on' keyword.");
        }

        // Expect a signal next.
        symbol = lexer.parse_symbol();
        if (symbol.type != symbol_t::type_t::SIGNAL)
        {
            throw std::runtime_error("Lambda rule parser error. Expected signal.");
        }
        signal = get_string(symbol.value);

        // Expect the 'if' keyword next.
        symbol = lexer.parse_symbol();
        if ((symbol.type != symbol_t::type_t::KEYWORD) || (get_string(symbol.value) != "if"))
        {
            throw std::runtime_error("Lambda rule parser error. Expected 'if' keyword.");
        }

        // Delegate to logical condition parser.
        condition = condition_parser_t().parse(lexer);

        // Expect the lexer to be at the end - 1.
        lexer.parse_symbol();
        symbol = lexer.parse_symbol();
        if (symbol.type != symbol_t::type_t::END)
        {
            std::string error = "Lambda rule parser error. Unexpected symbol: ";
            error.append(to_string(symbol));
            throw std::runtime_error(error);
        }
    }
    catch (std::runtime_error &e)
    {
        std::cout << "Malformed input:" << std::endl;
        std::cout << lexer.text() << std::endl;
        std::string pad;
        auto pos = lexer.current_symbol_position();
        for (std::size_t i = 0; i < pos; ++i)
        {
            pad.append(" ");
        }
        pad.append("^ ");
        std::cout << pad << e.what() << std::endl;
    }

    auto rule = std::make_shared<lambda_rule_t>(signal, condition);
    if (rule != nullptr)
    {
        rule->setIfLambda(if_lambda);
        rule->setElseLambda(else_lambda);
    }
    return rule;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
movq %rdx, %r12
movq %rdi, 0x80(%rsp)
leaq 0x98(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
vxorps %xmm0, %xmm0, %xmm0
vmovaps %xmm0, 0x70(%rsp)
leaq 0xd8(%rsp), %rdi
movq %rdx, %rsi
movq %r8, 0xa8(%rsp)
movq %rcx, 0xb0(%rsp)
callq 0x7384
movl 0xd8(%rsp), %ebp
movb $0x1, %r14b
cmpl $0x4, %ebp
jne 0xa697
leaq 0xe0(%rsp), %rsi
leaq 0x148(%rsp), %rdi
callq 0xb4ee
leaq 0x2b51(%rip), %rsi      # 0xd1d5
leaq 0x148(%rsp), %rdi
callq 0x5080
testl %eax, %eax
setne %r14b
cmpl $0x4, %ebp
jne 0xa6bd
leaq 0x158(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xa6bd
movq 0x158(%rsp), %rsi
incq %rsi
callq 0x5230
testb %r14b, %r14b
jne 0xaa2a
leaq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x7384
leaq 0x18(%rsp), %rbp
movl -0x8(%rbp), %eax
leaq 0xe0(%rsp), %r13
movl %eax, -0x8(%r13)
leaq 0xb8(%rsp), %rdi
movq %r13, (%rdi)
movzbl 0x20(%rbp), %eax
leaq 0x8d63(%rip), %r15      # 0x13460
movq %rbp, %rsi
callq *(%r15,%rax,8)
movzbl 0x38(%rsp), %eax
leaq 0x8610(%rip), %r14      # 0x12d20
leaq 0xb8(%rsp), %rdi
movq %rbp, %rsi
callq *(%r14,%rax,8)
cmpl $0x6, 0xd8(%rsp)
jne 0xaa48
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0xb4ee
leaq 0x88(%rsp), %rdi
leaq 0x10(%rsp), %rbp
movq %rbp, %rsi
callq 0x52a0
movq (%rbp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xa76a
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5230
leaq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x7384
leaq 0x18(%rsp), %rbp
movl -0x8(%rbp), %eax
movl %eax, 0xd8(%rsp)
leaq 0xb8(%rsp), %rdi
movq %r13, (%rdi)
movzbl 0x20(%rbp), %eax
movq %rbp, %rsi
callq *(%r15,%rax,8)
movzbl 0x38(%rsp), %eax
leaq 0xb8(%rsp), %rdi
movq %rbp, %rsi
callq *(%r14,%rax,8)
movl 0xd8(%rsp), %ebp
movb $0x1, %bl
cmpl $0x4, %ebp
jne 0xa7e7
leaq 0xb8(%rsp), %rdi
movq %r13, %rsi
callq 0xb4ee
leaq 0x29f3(%rip), %rsi      # 0xd1c8
leaq 0xb8(%rsp), %rdi
callq 0x5080
testl %eax, %eax
setne %bl
cmpl $0x4, %ebp
jne 0xa80d
leaq 0xc8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xa80d
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x5230
testb %bl, %bl
jne 0xaa66
leaq 0x10(%rsp), %rdi
callq 0x92e8
leaq 0x50(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movq %r12, %rdx
callq 0x9322
vmovaps 0x50(%rsp), %xmm0
vxorps %xmm1, %xmm1, %xmm1
vmovaps %xmm1, 0x50(%rsp)
movq 0x78(%rsp), %rdi
vmovaps %xmm0, 0x70(%rsp)
testq %rdi, %rdi
je 0xa856
callq 0x6968
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0xa865
callq 0x6968
leaq 0x28(%rsp), %rsi
movzbl 0x20(%rsi), %eax
leaq 0xf(%rsp), %rdi
callq *(%r14,%rax,8)
movb $-0x1, 0x48(%rsp)
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0xa88b
callq 0x6968
leaq 0x168(%rsp), %rdi
movq %r12, %rsi
callq 0x7384
leaq 0x170(%rsp), %rsi
movzbl 0x20(%rsi), %eax
leaq 0x10(%rsp), %rdi
callq *(%r14,%rax,8)
movb $-0x1, 0x190(%rsp)
leaq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x7384
leaq 0x18(%rsp), %rbp
movl -0x8(%rbp), %eax
movl %eax, 0xd8(%rsp)
leaq 0x50(%rsp), %rdi
movq %r13, (%rdi)
movzbl 0x20(%rbp), %eax
movq %rbp, %rsi
callq *(%r15,%rax,8)
movzbl 0x38(%rsp), %eax
leaq 0x50(%rsp), %rdi
movq %rbp, %rsi
callq *(%r14,%rax,8)
cmpl $0x0, 0xd8(%rsp)
jne 0xaa98
movzbl 0x100(%rsp), %eax
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
callq *(%r14,%rax,8)
movq 0x80(%rsp), %rbx
movq $0x0, (%rbx)
leaq 0x8(%rbx), %r12
leaq 0x10(%rsp), %rdx
leaq 0x88(%rsp), %rcx
leaq 0x70(%rsp), %r8
movq %r12, %rdi
movq %rbx, %rsi
callq 0xaebc
movq (%rbx), %r13
testq %r13, %r13
je 0xa9e1
leaq 0x128(%rsp), %rdi
movq 0xb0(%rsp), %rsi
callq 0xadea
leaq 0x128(%rsp), %rsi
movq %r13, %rdi
callq 0xb0e2
movq 0x138(%rsp), %rax
testq %rax, %rax
je 0xa99a
leaq 0x128(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq (%rbx), %r15
leaq 0x108(%rsp), %rdi
movq 0xa8(%rsp), %rsi
callq 0xadea
leaq 0x108(%rsp), %rsi
movq %r15, %rdi
callq 0xb15e
movq 0x118(%rsp), %rax
testq %rax, %rax
je 0xa9e1
leaq 0x108(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0xa9f0
callq 0x6968
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0xaa15
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x5230
movq %rbx, %rax
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x10, %edi
callq 0x5110
movq %rax, %r13
leaq 0x2f45(%rip), %rsi      # 0xd983
movq %rax, %rdi
callq 0x50d0
jmp 0xaa82
movl $0x10, %edi
callq 0x5110
movq %rax, %r13
leaq 0x2f58(%rip), %rsi      # 0xd9b4
movq %rax, %rdi
callq 0x50d0
jmp 0xaa82
movl $0x10, %edi
callq 0x5110
movq %rax, %r13
leaq 0x2f65(%rip), %rsi      # 0xd9df
movq %rax, %rdi
callq 0x50d0
movq 0x9567(%rip), %rsi      # 0x13ff0
movq 0x9528(%rip), %rdx      # 0x13fb8
movq %r13, %rdi
callq 0x5370
leaq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
movq %rax, (%rdi)
leaq 0x2f64(%rip), %rsi      # 0xda10
leaq 0x2f8a(%rip), %rdx      # 0xda3d
callq 0x6382
leaq 0x50(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x8caf
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
leaq 0x10(%rsp), %rdi
callq 0x5090
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xaaf9
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x5230
movl $0x10, %edi
callq 0x5110
movq %rax, %r13
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0x5350
movq 0x94d6(%rip), %rsi      # 0x13ff0
movq 0x9497(%rip), %rdx      # 0x13fb8
movq %r13, %rdi
callq 0x5370
jmp 0xab5e
movq %rdx, %rbp
movq %rax, %rbx
movq %r13, %rdi
callq 0x51a0
jmp 0xab64
movq %rdx, %rbp
movq %rax, %rbx
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xab64
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x5230
jmp 0xab64
movq %rdx, %rbp
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xaca0
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5230
jmp 0xaca0
jmp 0xac3b
jmp 0xac3b
jmp 0xac9a
jmp 0xaba1
jmp 0xac9a
jmp 0xaba1
movq %rdx, %rbp
movq %rax, %rbx
movq %r13, %rdi
callq 0x51a0
jmp 0xaca0
jmp 0xac9a
movq %rax, %rbx
movq 0x118(%rsp), %rax
testq %rax, %rax
je 0xac50
leaq 0x108(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0xac50
jmp 0xac3b
movq %rax, %rbx
movq 0x138(%rsp), %rax
testq %rax, %rax
je 0xac50
leaq 0x128(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0xac50
jmp 0xac3b
jmp 0xac3b
jmp 0xac3b
jmp 0xac3b
jmp 0xac9a
jmp 0xac3b
jmp 0xac3b
movq %rdx, %rbp
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0xae7c
jmp 0xaca0
jmp 0xac9a
jmp 0xac3b
movq %rax, %rbx
jmp 0xac5e
jmp 0xac3b
jmp 0xac9a
jmp 0xac9a
jmp 0xac3b
movq %rax, %rdi
callq 0x6209
jmp 0xac9a
movq %rdx, %rbp
movq %rax, %rbx
jmp 0xacad
movq %rax, %rbx
movq (%r12), %rdi
testq %rdi, %rdi
je 0xac5e
callq 0x6968
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0xac6d
callq 0x6968
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0xac92
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x5230
movq %rbx, %rdi
callq 0x5390
movq %rdx, %rbp
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
callq 0x7562
cmpl $0x1, %ebp
jne 0xac5e
movq %rbx, %rdi
callq 0x50e0
movq %rax, %rbx
movq 0x9304(%rip), %rdi      # 0x13fc8
leaq 0x2d73(%rip), %rsi      # 0xda3e
movl $0x10, %edx
callq 0x5270
movq 0x92ec(%rip), %rdi      # 0x13fc8
callq 0x5100
movq %r12, %rdi
callq 0x789e
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq 0x92d1(%rip), %rdi      # 0x13fc8
callq 0x5270
movq %rax, %rdi
callq 0x5100
leaq 0x20(%rsp), %r14
movq %r14, -0x10(%r14)
movq $0x0, -0x8(%r14)
movb $0x0, (%r14)
movq %r12, %rdi
callq 0x78a4
movq %rax, %r12
testq %rax, %rax
je 0xad45
leaq 0x233a(%rip), %rbp      # 0xd06a
leaq 0x10(%rsp), %r13
movq %r13, %rdi
movq %rbp, %rsi
callq 0x53b0
decq %r12
jne 0xad35
leaq 0x2d03(%rip), %rsi      # 0xda4f
leaq 0x10(%rsp), %rdi
callq 0x53b0
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq 0x9261(%rip), %rdi      # 0x13fc8
callq 0x5270
movq %rax, %r12
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
movq %r12, %rdi
movq %rax, %rsi
callq 0x5210
movq %rax, %rdi
callq 0x5100
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0xada2
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5230
callq 0x5360
movq 0x80(%rsp), %rbx
jmp 0xa922
jmp 0xac2e
jmp 0xadc0
movq %rax, %rbx
jmp 0xadda
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0xadda
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5230
callq 0x5360
jmp 0xac5e
jmp 0xac3b
nop