// File: /workspace/github_c_makefile_star2_O3/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 0x14fff
movq %rax, %r15
movq %rbx, %rdi
movl $0x2, %esi
callq 0x15124
movq %rax, %r12
movq (%r13), %rax
incq %rax
testq %r12, %r12
movl $0x1, %edx
cmovsq %rax, %rdx
movq %rbx, %rdi
movl $0x3, %esi
callq 0x1518f
movq %rax, %r14
movq (%r13), %rax
testq %r14, %r14
jns 0x20524
movq %r14, %rcx
negq %rcx
cmpq %rcx, %rax
jae 0x2051e
xorl %r14d, %r14d
jmp 0x20531
addq %rax, %r14
incq %r14
testq %r14, %r14
jle 0x20531
decq %r14
cmpq %rax, %r14
jle 0x20545
leaq 0x457c(%rip), %rdx      # 0x24ab4
movq %rbx, %rdi
movl $0x3, %esi
callq 0x1497c
testq %r12, %r12
je 0x205a5
movb (%r15,%r14), %al
andb $-0x40, %al
negb %al
jno 0x20565
leaq 0x456f(%rip), %rsi      # 0x24aca
movq %rbx, %rdi
xorl %eax, %eax
callq 0x14a62
testq %r12, %r12
js 0x205c6
leaq -0x1(%r12), %rcx
cmpq $0x1, %r12
je 0x205f9
movq 0x8(%rsp), %rdx
cmpq %rdx, %r14
jge 0x205f9
movb 0x1(%r15,%r14), %al
incq %r14
andb $-0x40, %al
negb %al
jo 0x20583
leaq -0x1(%rcx), %rax
cmpq $0x2, %rcx
jl 0x20607
movq %rax, %rcx
cmpq %rdx, %r14
jl 0x20583
jmp 0x20607
testq %r14, %r14
jle 0x20616
movb (%r15,%r14), %al
andb $-0x40, %al
negb %al
jno 0x20616
leaq -0x1(%r14), %rax
cmpq $0x1, %r14
movq %rax, %r14
jg 0x205aa
xorl %r14d, %r14d
jmp 0x20616
testq %r14, %r14
jle 0x2060c
cmpq $0x1, %r14
jbe 0x205fe
movb -0x1(%r15,%r14), %al
decq %r14
andb $-0x40, %al
negb %al
jo 0x205cb
leaq 0x1(%r12), %rax
cmpq $-0x2, %r12
jg 0x20607
leaq 0x1(%r14), %rcx
movq %rax, %r12
cmpq $0x1, %rcx
jg 0x205cb
jmp 0x20607
movq %rcx, %rax
jmp 0x20607
incq %r12
xorl %r14d, %r14d
movq %r12, %rax
testq %rax, %rax
je 0x20616
movq %rbx, %rdi
callq 0x64cd
jmp 0x20624
incq %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x64f6
movl $0x1, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq