// File: /workspace/github_c_makefile_star2_O2/craigbarnes[P]lua-gumbo/gumbo/parse.c
// Function: parse
static int parse(lua_State *L)
{
    GumboOptions options = kGumboDefaultOptions;
    options.max_errors = 0;
    size_t input_len;
    const char *input = luaL_checklstring(L, 1, &input_len);
    options.tab_stop = (int)luaL_optinteger(L, 2, 8);

    size_t tagname_len;
    const char *tagname = luaL_optlstring(L, 3, NULL, &tagname_len);
    if (tagname != NULL) {
        options.fragment_context = gumbo_tagn_enum(tagname, tagname_len);
    }

    static const char *namespaces[] = {"html", "svg", "math", NULL};
    options.fragment_namespace = luaL_checkoption(L, 4, "html", namespaces);

    for (int i = 1; i <= nupvalues; i++) {
        luaL_checktype(L, i + 4, LUA_TTABLE);
    }
    lua_pushcclosure(L, push_document, nupvalues);

    GumboOutput *output = gumbo_parse_with_options(&options, input, input_len);
    if (unlikely(output == NULL)) {
        lua_pushnil(L);
        lua_pushliteral(L, "gumbo_parse_with_options() returned NULL");
        return 2;
    }

    GumboOutputStatus status = output->status;
    if (unlikely(status != GUMBO_STATUS_OK)) {
        gumbo_destroy_output(output);
        lua_pushnil(L);
        lua_pushstring(L, gumbo_status_to_string(status));
        return 2;
    }

    lua_pushlightuserdata(L, &output->document->v.document);
    int err = lua_pcall(L, 1, 1, 0);
    gumbo_destroy_output(output);
    if (unlikely(err != 0)) { // LUA_OK
        lua_pushnil(L);
        lua_pushvalue(L, -2);
        return 2;
    }
    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
leaq 0x1154c(%rip), %rax     # 0x176d4
movups (%rax), %xmm0
movaps %xmm0, (%rsp)
movl 0x10(%rax), %eax
movl %eax, 0x10(%rsp)
andl $0x0, 0xc(%rsp)
pushq $0x1
popq %r15
leaq 0x20(%rsp), %rdx
movl %r15d, %esi
callq 0x4140
movq %rax, %r14
pushq $0x2
popq %rbp
pushq $0x8
popq %rdx
movq %rbx, %rdi
movl %ebp, %esi
callq 0x41a0
movl %eax, (%rsp)
pushq $0x3
popq %rsi
leaq 0x18(%rsp), %rcx
movq %rbx, %rdi
xorl %edx, %edx
callq 0x40d0
testq %rax, %rax
je 0x61ea
movq 0x18(%rsp), %rsi
movq %rax, %rdi
callq 0x7441
movl %eax, 0x10(%rsp)
leaq 0x13bf8(%rip), %rdx     # 0x19de9
leaq 0x4df68(%rip), %rcx     # 0x54160
pushq $0x4
popq %rsi
movq %rbx, %rdi
callq 0x4090
movl %eax, 0x14(%rsp)
pushq $0x9
popq %r13
pushq $0x5
popq %r12
subl $0x1, %r13d
jb 0x6229
leal 0x4(%r15), %esi
movq %rbx, %rdi
movl %r12d, %edx
callq 0x41e0
incl %r15d
jmp 0x620f
leaq 0xc8(%rip), %rsi        # 0x62f8
pushq $0x9
popq %rdx
movq %rbx, %rdi
callq 0x4070
movq 0x20(%rsp), %rdx
movq %rsp, %rdi
movq %r14, %rsi
callq 0x438b
testq %rax, %rax
je 0x62a7
movq %rax, %r14
movl 0x20(%rax), %r15d
testl %r15d, %r15d
jne 0x62bb
movq (%r14), %rsi
addq $0x18, %rsi
movq %rbx, %rdi
callq 0x41f0
pushq $0x1
popq %r15
movq %rbx, %rdi
movl %r15d, %esi
movl %r15d, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x4280
movl %eax, %r12d
movq %r14, %rdi
callq 0x7ba7
testl %r12d, %r12d
jne 0x62e0
movl %r15d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x4240
leaq 0xfd87(%rip), %rsi      # 0x1603d
movq %rbx, %rdi
jmp 0x62d9
movq %r14, %rdi
callq 0x7ba7
movq %rbx, %rdi
callq 0x4240
movl %r15d, %edi
callq 0x7a56
movq %rbx, %rdi
movq %rax, %rsi
callq 0x4260
jmp 0x62f3
movq %rbx, %rdi
callq 0x4240
pushq $-0x2
popq %rsi
movq %rbx, %rdi
callq 0x4150
movl %ebp, %r15d
jmp 0x6295