// File: /workspace/github_c_makefile_star2_O1/stetre[P]moongl/src/teximage.c
// Function: TextureSubImage
static int TextureSubImage(lua_State *L)
    {
    intptr_t data;
    size_t len;
    int arg = 1;
    GLint v1, v2, v3, v4, v5, v6;
    GLenum target;
    GLuint texture = checktargetorname(L, arg++, &target, DOMAIN_TEXTURE_TARGET);
    GLint level = luaL_checkinteger(L, arg++);
    GLenum format = checkformat(L, arg++);
    GLenum type = checktype(L, arg++);
    GLint64 bound_buffer = getUint(L, GL_PIXEL_UNPACK_BUFFER_BINDING);
    if(bound_buffer == 0) /* no buffer is bound to GL_PIXEL_UNPACK_BUFFER */
        {
        if(lua_isnil(L, arg)) /* no pixel transfer */
            { data = 0; arg++; }
        else if(lua_isstring(L, arg))
            data = (intptr_t)luaL_checkstring(L, arg++);
        else if(lua_istable(L, arg))
            data = (intptr_t)checkdataptr(L, arg++, &len);
        else
            return luaL_argerror(L, arg, "invalid type");
        }
    else /* a buffer is bound to GL_PIXEL_UNPACK_BUFFER, so data must be an offset */
        data = luaL_checkinteger(L, arg++);
    v1 = luaL_checkinteger(L, arg++);
    v2 = luaL_checkinteger(L, arg++);
    if(lua_isnoneornil(L, arg))
        {
        if(texture==0)
            glTexSubImage1D(target, level, v1, v2, format, type, (void*)data);
        else
            glTextureSubImage1D(texture, level, v1, v2, format, type, (void*)data);
        CheckError(L);
        return 0;
        }
    v3 = luaL_checkinteger(L, arg++);
    v4 = luaL_checkinteger(L, arg++);
    if(lua_isnoneornil(L, arg))
        {
        if(texture==0)
            glTexSubImage2D(target, level, v1, v2, v3, v4, format, type, (void*)data);
        else
            glTextureSubImage2D(texture, level, v1, v2, v3, v4, format, type, (void*)data);
        CheckError(L);
        return 0;
        }
    v5 = luaL_checkinteger(L, arg++);
    v6 = luaL_checkinteger(L, arg++);
    if(texture==0)
        glTexSubImage3D(target,level, v1, v2, v3, v4, v5, v6,format,type,(void*)data);
    else
        glTextureSubImage3D(texture,level,v1, v2, v3, v4, v5, v6,format,type,(void*)data); 
    CheckError(L);
    return 0;
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
leaq 0xc(%rsp), %rdx
movl $0x1, %esi
movl $0x13, %ecx
callq 0x11430
movl %eax, %ebp
movq %rbx, %rdi
movl $0x2, %esi
callq 0x11af0
movq %rax, %r14
movq %rbx, %rdi
movl $0x12, %esi
movl $0x3, %edx
callq 0x11160
movl %eax, %r12d
movq %rbx, %rdi
movl $0x7, %esi
movl $0x4, %edx
callq 0x11160
movl %eax, %r13d
movq %rbx, %rdi
movl $0x88ef, %esi           # imm = 0x88EF
callq 0x11a70
testl %eax, %eax
movq %r14, 0x10(%rsp)
movq %rbx, %rdi
movl $0x5, %esi
je 0x3751e
callq 0x11af0
movq %rax, (%rsp)
movq %rbx, %rdi
movl $0x6, %esi
callq 0x11af0
movq %rax, %r14
movq %rbx, %rdi
movl $0x7, %esi
callq 0x11af0
movq %rax, %r15
movq %rbx, %rdi
movl $0x8, %esi
callq 0x11860
testl %eax, %eax
jle 0x37554
movq %r13, 0x18(%rsp)
movq %r12, 0x20(%rsp)
movq %rbx, %rdi
movl $0x8, %esi
callq 0x11af0
movq %rax, %r12
movq %rbx, %rdi
movl $0x9, %esi
callq 0x11af0
movq %rax, %r13
movq %rbx, %rdi
movl $0xa, %esi
callq 0x11860
testl %eax, %eax
jle 0x37585
movq %rbx, %rdi
movl $0xa, %esi
callq 0x11af0
movq %rax, 0x28(%rsp)
movq %rbx, %rdi
movl $0xb, %esi
callq 0x11af0
testl %ebp, %ebp
je 0x375cb
movq 0x1f7c5(%rip), %r10     # 0x56cd8
subq $0x8, %rsp
movl %ebp, %edi
jmp 0x375da
callq 0x11860
testl %eax, %eax
je 0x375be
movq %rbx, %rdi
movl $0x5, %esi
callq 0x110b0
movq %rbx, %rdi
movl $0x5, %esi
testl %eax, %eax
je 0x3762d
xorl %edx, %edx
callq 0x11450
jmp 0x3746d
testl %ebp, %ebp
je 0x37605
movq 0x1f5a5(%rip), %rax     # 0x56b08
subq $0x8, %rsp
movl %ebp, %edi
movq 0x18(%rsp), %rsi
movl %r14d, %edx
movl %r15d, %ecx
movl %r12d, %r8d
movl %r13d, %r9d
pushq 0x8(%rsp)
callq *(%rax)
jmp 0x37627
testl %ebp, %ebp
je 0x3764e
movq 0x1f37c(%rip), %rax     # 0x56910
subq $0x8, %rsp
movl %ebp, %edi
movq 0x18(%rsp), %rsi
movl %r14d, %edx
movl %r15d, %ecx
movl %r12d, %r8d
movl %r13d, %r9d
pushq 0x8(%rsp)
pushq 0x28(%rsp)
pushq 0x38(%rsp)
callq *(%rax)
jmp 0x37678
movq $0x0, (%rsp)
jmp 0x37471
movq 0x1f9d6(%rip), %r10     # 0x56fa8
movl 0xc(%rsp), %edi
subq $0x8, %rsp
movq 0x18(%rsp), %rsi
movl %r14d, %edx
movl %r15d, %ecx
movl %r12d, %r8d
movl %r13d, %r9d
pushq 0x8(%rsp)
pushq 0x28(%rsp)
pushq 0x38(%rsp)
pushq %rax
pushq 0x50(%rsp)
callq *(%r10)
addq $0x30, %rsp
jmp 0x3767c
movl 0xc(%rsp), %edi
subq $0x8, %rsp
movq 0x18(%rsp), %rsi
movl %r14d, %edx
movl %r15d, %ecx
movl %r12d, %r8d
movl %r13d, %r9d
pushq 0x8(%rsp)
callq 0x11240
addq $0x10, %rsp
jmp 0x3767c
callq 0x11860
cmpl $0x5, %eax
jne 0x37695
leaq 0x30(%rsp), %rdx
movq %rbx, %rdi
movl $0x5, %esi
callq 0x11b20
jmp 0x3746d
movl 0xc(%rsp), %edi
subq $0x8, %rsp
movq 0x18(%rsp), %rsi
movl %r14d, %edx
movl %r15d, %ecx
movl %r12d, %r8d
movl %r13d, %r9d
pushq 0x8(%rsp)
pushq 0x28(%rsp)
pushq 0x38(%rsp)
callq 0x11960
addq $0x20, %rsp
movq %rbx, %rdi
callq 0x11880
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7b5c(%rip), %rdx      # 0x3f1f8
movq %rbx, %rdi
movl $0x5, %esi
callq 0x11940
jmp 0x37686