// File: /workspace/github_c_makefile_star2_O1/tylerneylon[P]APIsWithLua/lua/lutf8lib.c
// Function: byteoffset
static int byteoffset (lua_State *L) {
  size_t len;
  const char *s = luaL_checklstring(L, 1, &len);
  lua_Integer n  = luaL_checkinteger(L, 2);
  lua_Integer posi = (n >= 0) ? 1 : len + 1;
  posi = u_posrelat(luaL_optinteger(L, 3, posi), len);
  luaL_argcheck(L, 1 <= posi && --posi <= (lua_Integer)len, 3,
                   "position out of range");
  if (n == 0) {
    /* find beginning of current byte sequence */
    while (posi > 0 && iscont(s + posi)) posi--;
  }
  else {
    if (iscont(s + posi))
      luaL_error(L, "initial position is a continuation byte");
    if (n < 0) {
       while (n < 0 && posi > 0) {  /* move back */
         do {  /* find beginning of previous character */
           posi--;
         } while (posi > 0 && iscont(s + posi));
         n++;
       }
     }
     else {
       n--;  /* do not move for 1st character */
       while (n > 0 && posi < (lua_Integer)len) {
         do {  /* find beginning of next character */
           posi++;
         } while (iscont(s + posi));  /* (cannot pass final '\0') */
         n--;
       }
     }
  }
  if (n == 0)  /* did it find given character? */
    lua_pushinteger(L, posi + 1);
  else  /* no such character */
    lua_pushnil(L);
  return 1;  
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
leaq 0x8(%rsp), %r13
movl $0x1, %esi
movq %r13, %rdx
callq 0x14535
movq %rax, %r15
movq %rbx, %rdi
movl $0x2, %esi
callq 0x1465a
movq %rax, %r12
movq (%r13), %rax
incq %rax
testq %r12, %r12
movl $0x1, %edx
cmovsq %rax, %rdx
movq %rbx, %rdi
movl $0x3, %esi
callq 0x146c5
movq %rax, %r14
movq (%r13), %rax
testq %r14, %r14
jns 0x1f6a0
movq %r14, %rcx
negq %rcx
cmpq %rcx, %rax
jae 0x1f69a
xorl %r14d, %r14d
jmp 0x1f6a0
addq %rax, %r14
incq %r14
testq %r14, %r14
jle 0x1f6ad
decq %r14
cmpq %rax, %r14
jle 0x1f6c1
leaq 0x4348(%rip), %rdx      # 0x239fc
movq %rbx, %rdi
movl $0x3, %esi
callq 0x13ea8
testq %r12, %r12
je 0x1f72a
movb (%r15,%r14), %al
andb $-0x40, %al
negb %al
jno 0x1f6e1
leaq 0x433b(%rip), %rsi      # 0x23a12
movq %rbx, %rdi
xorl %eax, %eax
callq 0x13f8e
testq %r12, %r12
js 0x1f74b
leaq -0x1(%r12), %rax
cmpq $0x2, %r12
jl 0x1f797
movq 0x8(%rsp), %rcx
cmpq %rcx, %r14
jge 0x1f797
movb 0x1(%r15,%r14), %dl
incq %r14
andb $-0x40, %dl
negb %dl
jo 0x1f703
leaq -0x1(%rax), %r12
cmpq $0x2, %rax
jl 0x1f7a2
movq %r12, %rax
cmpq %rcx, %r14
jl 0x1f703
jmp 0x1f7a2
testq %r14, %r14
jle 0x1f7a2
movb (%r15,%r14), %al
andb $-0x40, %al
negb %al
jno 0x1f7a2
leaq -0x1(%r14), %rax
cmpq $0x1, %r14
movq %rax, %r14
jg 0x1f72f
xorl %r14d, %r14d
jmp 0x1f7a2
testq %r14, %r14
jle 0x1f79c
movq %r12, %rax
testq %r14, %r14
movl $0x1, %edx
cmovleq %r14, %rdx
decq %rdx
movq %r14, %rcx
cmpq $0x2, %r14
jl 0x1f77f
leaq -0x1(%rcx), %r14
movb -0x1(%r15,%rcx), %sil
andb $-0x40, %sil
negb %sil
jo 0x1f762
jmp 0x1f782
movq %rdx, %r14
leaq 0x1(%rax), %r12
cmpq $-0x2, %rax
jg 0x1f7a2
movq %r12, %rax
cmpq $0x1, %rcx
jg 0x1f753
jmp 0x1f7a2
movq %rax, %r12
jmp 0x1f7a2
movl $0x1, %r12d
testq %r12, %r12
je 0x1f7b1
movq %rbx, %rdi
callq 0x63bd
jmp 0x1f7bf
incq %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x63e6
movl $0x1, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq