// File: /workspace/github_cpp_makefile_star2_O3/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 $0x158, %rsp            # imm = 0x158
leaq 0x98(%rsp), %rax
vxorps %xmm0, %xmm0, %xmm0
movq %rdx, %r12
movq %rcx, 0xb0(%rsp)
movq %rdi, %rbx
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
vmovaps %xmm0, 0x70(%rsp)
leaq 0xb8(%rsp), %rdi
movq %rdx, %rsi
movq %rbx, 0x80(%rsp)
movq %r8, 0xa8(%rsp)
callq 0x738e
cmpl $0x4, 0xb8(%rsp)
jne 0xa882
leaq 0xc0(%rsp), %r13
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0xb34c
leaq 0x10(%rsp), %r14
leaq 0x1cbc(%rip), %rsi      # 0xc1d5
movq %r14, %rdi
callq 0x5080
movq (%r14), %rdi
movl %eax, %ebp
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xa53d
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5230
testl %ebp, %ebp
jne 0xa882
leaq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x738e
leaq 0x18(%rsp), %rbp
leaq 0x50(%rsp), %rdi
leaq 0x7efd(%rip), %rbx      # 0x12460
movl -0x8(%rbp), %eax
movq %r13, (%rdi)
movl %eax, 0xb8(%rsp)
movzbl 0x20(%rbp), %eax
movq %rbp, %rsi
callq *(%rbx,%rax,8)
movzbl 0x38(%rsp), %eax
leaq 0x779a(%rip), %r15      # 0x11d20
leaq 0x50(%rsp), %rdi
movq %rbp, %rsi
callq *(%r15,%rax,8)
cmpl $0x6, 0xb8(%rsp)
jne 0xa8be
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0xb34c
leaq 0x10(%rsp), %r14
leaq 0x88(%rsp), %rdi
movq %r14, %rsi
callq 0x52a0
movq (%r14), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xa5dc
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5230
leaq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x738e
leaq 0x18(%rsp), %rbp
leaq 0x50(%rsp), %rdi
movl -0x8(%rbp), %eax
movq %r13, (%rdi)
movl %eax, 0xb8(%rsp)
movzbl 0x20(%rbp), %eax
movq %rbp, %rsi
callq *(%rbx,%rax,8)
movzbl 0x38(%rsp), %eax
leaq 0x50(%rsp), %rdi
movq %rbp, %rsi
callq *(%r15,%rax,8)
cmpl $0x4, 0xb8(%rsp)
jne 0xa8a0
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0xb34c
leaq 0x10(%rsp), %r14
leaq 0x1b86(%rip), %rsi      # 0xc1c8
movq %r14, %rdi
callq 0x5080
movq (%r14), %rdi
movl %eax, %ebp
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xa666
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5230
testl %ebp, %ebp
jne 0xa8a0
leaq 0x10(%rsp), %rdi
callq 0x9200
leaq 0x50(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movq %r12, %rdx
callq 0x923a
vmovaps 0x50(%rsp), %xmm0
movq 0x78(%rsp), %rdi
vxorps %xmm1, %xmm1, %xmm1
vmovaps %xmm1, 0x50(%rsp)
vmovaps %xmm0, 0x70(%rsp)
testq %rdi, %rdi
je 0xa6be
callq 0x6972
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0xa6be
callq 0x6972
leaq 0x28(%rsp), %rsi
movzbl 0x20(%rsi), %eax
leaq 0xf(%rsp), %rdi
callq *(%r15,%rax,8)
movb $-0x1, 0x48(%rsp)
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0xa6e4
callq 0x6972
leaq 0x128(%rsp), %rdi
movq %r12, %rsi
callq 0x738e
leaq 0x130(%rsp), %rsi
movzbl 0x20(%rsi), %eax
leaq 0x10(%rsp), %rdi
callq *(%r15,%rax,8)
movb $-0x1, 0x150(%rsp)
leaq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x738e
leaq 0x18(%rsp), %rbp
leaq 0x50(%rsp), %rdi
movl -0x8(%rbp), %eax
movq %r13, (%rdi)
movl %eax, 0xb8(%rsp)
movzbl 0x20(%rbp), %eax
movq %rbp, %rsi
callq *(%rbx,%rax,8)
movzbl 0x38(%rsp), %eax
leaq 0x50(%rsp), %rdi
movq %rbp, %rsi
callq *(%r15,%rax,8)
movq 0x80(%rsp), %rbx
cmpl $0x0, 0xb8(%rsp)
jne 0xa8f0
movzbl 0xe0(%rsp), %eax
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
callq *(%r15,%rax,8)
leaq 0x8(%rbx), %r12
movq $0x0, (%rbx)
leaq 0x10(%rsp), %rdx
leaq 0x88(%rsp), %rcx
leaq 0x70(%rsp), %r8
movq %r12, %rdi
movq %rbx, %rsi
callq 0xad1a
movq (%rbx), %r13
testq %r13, %r13
je 0xa839
movq 0xb0(%rsp), %rsi
leaq 0x108(%rsp), %rdi
callq 0xac48
leaq 0x108(%rsp), %rsi
movq %r13, %rdi
callq 0xaf3a
movq 0x118(%rsp), %rax
testq %rax, %rax
je 0xa7f2
leaq 0x108(%rsp), %rdi
movl $0x3, %edx
movq %rdi, %rsi
callq *%rax
movq (%rbx), %r15
movq 0xa8(%rsp), %rsi
leaq 0xe8(%rsp), %rdi
callq 0xac48
leaq 0xe8(%rsp), %rsi
movq %r15, %rdi
callq 0xafb6
movq 0xf8(%rsp), %rax
testq %rax, %rax
je 0xa839
leaq 0xe8(%rsp), %rdi
movl $0x3, %edx
movq %rdi, %rsi
callq *%rax
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0xa848
callq 0x6972
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0xa86d
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x5230
movq %rbx, %rax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x10, %edi
callq 0x5110
movq %rax, %r13
leaq 0x20d5(%rip), %rsi      # 0xc96b
movq %rax, %rdi
callq 0x50d0
jmp 0xa8da
movl $0x10, %edi
callq 0x5110
movq %rax, %r13
leaq 0x2113(%rip), %rsi      # 0xc9c7
movq %rax, %rdi
callq 0x50d0
jmp 0xa8da
movl $0x10, %edi
callq 0x5110
movq %rax, %r13
leaq 0x20ca(%rip), %rsi      # 0xc99c
movq %rax, %rdi
callq 0x50d0
movq 0x870f(%rip), %rsi      # 0x12ff0
movq 0x86d0(%rip), %rdx      # 0x12fb8
movq %r13, %rdi
callq 0x5370
leaq 0x20(%rsp), %rax
leaq 0x10(%rsp), %rdi
movq %rax, (%rdi)
leaq 0x20f4(%rip), %rsi      # 0xc9f8
leaq 0x211a(%rip), %rdx      # 0xca25
callq 0x6386
leaq 0x50(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x8bd7
movq 0x58(%rsp), %rdx
movq 0x50(%rsp), %rsi
leaq 0x10(%rsp), %rdi
callq 0x5090
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xa951
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 0x867e(%rip), %rsi      # 0x12ff0
movq 0x863f(%rip), %rdx      # 0x12fb8
movq %r13, %rdi
callq 0x5370
jmp 0xa9b6
movq %r13, %rdi
movq %rdx, %rbp
movq %rax, %r14
callq 0x51a0
jmp 0xa9bc
leaq 0x60(%rsp), %rcx
movq %rdx, %rbp
movq %rax, %r14
movq -0x10(%rcx), %rdi
cmpq %rcx, %rdi
je 0xa9bc
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x5230
jmp 0xa9bc
movq %rdx, %rbp
movq %rax, %r14
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xaafe
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5230
jmp 0xaafe
jmp 0xaa87
jmp 0xaa87
jmp 0xaaf8
jmp 0xaa91
movq %rax, %r14
movq 0xf8(%rsp), %rax
testq %rax, %rax
je 0xaaae
leaq 0xe8(%rsp), %rdi
movl $0x3, %edx
movq %rdi, %rsi
callq *%rax
jmp 0xaaae
jmp 0xaa87
movq %rax, %r14
movq 0x118(%rsp), %rax
testq %rax, %rax
je 0xaaae
leaq 0x108(%rsp), %rdi
movl $0x3, %edx
movq %rdi, %rsi
callq *%rax
jmp 0xaaae
jmp 0xaa87
jmp 0xaa87
jmp 0xaa87
jmp 0xaa87
jmp 0xaaf8
jmp 0xaa87
jmp 0xaa87
leaq 0x10(%rsp), %rdi
movq %rdx, %rbp
movq %rax, %r14
callq 0xacda
jmp 0xaafe
jmp 0xaaf8
jmp 0xaa91
jmp 0xaaf8
jmp 0xaa87
jmp 0xaa87
movq %rax, %r14
jmp 0xaabc
jmp 0xaaf8
jmp 0xaaf8
jmp 0xaa87
movq %rax, %rdi
callq 0x6209
jmp 0xaaf8
movq %r13, %rdi
movq %rdx, %rbp
movq %rax, %r14
callq 0x51a0
jmp 0xaafe
jmp 0xaaf8
movq %rdx, %rbp
movq %rax, %r14
jmp 0xab0b
movq %rax, %r14
movq (%r12), %rdi
testq %rdi, %rdi
je 0xaabc
callq 0x6972
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0xaacb
callq 0x6972
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0xaaf0
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x5230
movq %r14, %rdi
callq 0x5390
movq %rdx, %rbp
movq %rax, %r14
leaq 0xb8(%rsp), %rdi
callq 0x7568
cmpl $0x1, %ebp
jne 0xaabc
movq %r14, %rdi
callq 0x50e0
movq %rax, %r14
movq 0x84a6(%rip), %rdi      # 0x12fc8
leaq 0x1efd(%rip), %rsi      # 0xca26
movl $0x10, %edx
callq 0x5270
movq 0x848e(%rip), %rdi      # 0x12fc8
callq 0x5100
movq %r12, %rdi
callq 0x788e
movq 0x8(%rax), %rdx
movq (%rax), %rsi
movq 0x8473(%rip), %rdi      # 0x12fc8
callq 0x5270
movq %rax, %rdi
callq 0x5100
leaq 0x20(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq $0x0, -0x8(%rbx)
movb $0x0, (%rbx)
movq %r12, %rdi
callq 0x7894
movq %rax, %r12
testq %rax, %rax
je 0xaba2
leaq 0x14dd(%rip), %rbp      # 0xc06a
leaq 0x10(%rsp), %r13
movq %r13, %rdi
movq %rbp, %rsi
callq 0x53b0
decq %r12
jne 0xab92
leaq 0x1e8e(%rip), %rsi      # 0xca37
leaq 0x10(%rsp), %rdi
callq 0x53b0
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rsi
movq 0x8404(%rip), %rdi      # 0x12fc8
callq 0x5270
movq (%r14), %r15
movq %r14, %rdi
movq %rax, %r12
callq *0x10(%r15)
movq %r12, %rdi
movq %rax, %rsi
callq 0x5210
movq %rax, %rdi
callq 0x5100
movq 0x10(%rsp), %rdi
cmpq %rbx, %rdi
je 0xac00
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5230
callq 0x5360
movq 0x80(%rsp), %rbx
jmp 0xa77a
jmp 0xaa7c
jmp 0xac1e
movq %rax, %r14
jmp 0xac38
movq 0x10(%rsp), %rdi
movq %rax, %r14
cmpq %rbx, %rdi
je 0xac38
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x5230
callq 0x5360
jmp 0xaabc
jmp 0xaa87
nop