// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
leaq 0x2c401(%rip), %rax     # 0x307a4
movq (%rax), %rcx
movq %rcx, -0x28(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x20(%rbp)
movq 0x10(%rax), %rax
movq %rax, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x10(%rbp), %rdi
movl $0x1, %esi
leaq -0x30(%rbp), %rdx
callq 0x4140
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
movl $0x2, %esi
movl $0x8, %edx
callq 0x41b0
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movl $0x3, %esi
xorl %eax, %eax
movl %eax, %edx
leaq -0x40(%rbp), %rcx
callq 0x40d0
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x441e
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x61c0
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movl $0x4, %esi
leaq 0x2f0bf(%rip), %rdx     # 0x334ed
leaq 0x70d2b(%rip), %rcx     # 0x75160
callq 0x4090
movl %eax, -0x14(%rbp)
movl $0x1, -0x4c(%rbp)
cmpl $0x9, -0x4c(%rbp)
jg 0x4469
movq -0x10(%rbp), %rdi
movl -0x4c(%rbp), %esi
addl $0x4, %esi
movl $0x5, %edx
callq 0x41f0
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x4444
movq -0x10(%rbp), %rdi
leaq 0x10c(%rip), %rsi       # 0x4580
movl $0x9, %edx
callq 0x4070
movq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rdx
leaq -0x28(%rbp), %rdi
callq 0x6e40
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x44bf
movq -0x10(%rbp), %rdi
callq 0x4240
movq -0x10(%rbp), %rdi
leaq 0x2ab8f(%rip), %rsi     # 0x2f03d
callq 0x4260
movl $0x2, -0x4(%rbp)
jmp 0x456d
movq -0x58(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x5c(%rbp)
je 0x4506
movq -0x58(%rbp), %rdi
callq 0x7c20
movq -0x10(%rbp), %rdi
callq 0x4240
movq -0x10(%rbp), %rax
movq %rax, -0x68(%rbp)
movl -0x5c(%rbp), %edi
callq 0x7b70
movq -0x68(%rbp), %rdi
movq %rax, %rsi
callq 0x4260
movl $0x2, -0x4(%rbp)
jmp 0x456d
movq -0x10(%rbp), %rdi
movq -0x58(%rbp), %rax
movq (%rax), %rsi
addq $0x18, %rsi
callq 0x4200
movq -0x10(%rbp), %rdi
movl $0x1, %edx
xorl %ecx, %ecx
xorl %eax, %eax
movl %eax, %r9d
movl %edx, %esi
movq %r9, %r8
callq 0x4280
movl %eax, -0x60(%rbp)
movq -0x58(%rbp), %rdi
callq 0x7c20
cmpl $0x0, -0x60(%rbp)
je 0x4566
movq -0x10(%rbp), %rdi
callq 0x4240
movq -0x10(%rbp), %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x4160
movl $0x2, -0x4(%rbp)
jmp 0x456d
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)