// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movl $0x1, %esi
leaq -0x10(%rbp), %rdx
callq 0x20390
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movl $0x2, %esi
callq 0x20550
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jl 0x316b6
movl $0x1, %eax
movq %rax, -0x30(%rbp)
jmp 0x316c2
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rdx
movl $0x3, %esi
callq 0x205e0
movq %rax, %rdi
movq -0x10(%rbp), %rsi
callq 0x31cd0
movq %rax, -0x28(%rbp)
movl $0x1, %eax
cmpq -0x28(%rbp), %rax
jg 0x3170e
movq -0x28(%rbp), %rcx
addq $-0x1, %rcx
movq %rcx, -0x28(%rbp)
movb $0x1, %al
cmpq -0x10(%rbp), %rcx
movb %al, -0x31(%rbp)
jle 0x3172c
movq -0x8(%rbp), %rdi
movl $0x3, %esi
leaq 0x5caf(%rip), %rdx      # 0x373cd
callq 0x1fab0
cmpl $0x0, %eax
setne %al
movb %al, -0x31(%rbp)
movb -0x31(%rbp), %al
cmpq $0x0, -0x20(%rbp)
jne 0x3177c
jmp 0x31738
xorl %eax, %eax
cmpq $0x0, -0x28(%rbp)
movb %al, -0x32(%rbp)
jle 0x31760
movq -0x18(%rbp), %rax
movq -0x28(%rbp), %rcx
movsbl (%rax,%rcx), %eax
andl $0xc0, %eax
cmpl $0x80, %eax
sete %al
movb %al, -0x32(%rbp)
movb -0x32(%rbp), %al
testb $0x1, %al
jne 0x31769
jmp 0x31777
movq -0x28(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x31738
jmp 0x31883
movq -0x18(%rbp), %rax
movq -0x28(%rbp), %rcx
movsbl (%rax,%rcx), %eax
andl $0xc0, %eax
cmpl $0x80, %eax
jne 0x317a6
movq -0x8(%rbp), %rdi
leaq 0x5c44(%rip), %rsi      # 0x373e3
movb $0x0, %al
callq 0x1fbf0
cmpq $0x0, -0x20(%rbp)
jge 0x3181c
jmp 0x317af
xorl %eax, %eax
cmpq $0x0, -0x20(%rbp)
movb %al, -0x33(%rbp)
jge 0x317c6
cmpq $0x0, -0x28(%rbp)
setg %al
movb %al, -0x33(%rbp)
movb -0x33(%rbp), %al
testb $0x1, %al
jne 0x317cf
jmp 0x3181a
jmp 0x317d1
movq -0x28(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x28(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x28(%rbp)
movb %al, -0x34(%rbp)
jle 0x31805
movq -0x18(%rbp), %rax
movq -0x28(%rbp), %rcx
movsbl (%rax,%rcx), %eax
andl $0xc0, %eax
cmpl $0x80, %eax
sete %al
movb %al, -0x34(%rbp)
movb -0x34(%rbp), %al
testb $0x1, %al
jne 0x317d1
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x317af
jmp 0x31881
movq -0x20(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x20(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x20(%rbp)
movb %al, -0x35(%rbp)
jle 0x31842
movq -0x28(%rbp), %rax
cmpq -0x10(%rbp), %rax
setl %al
movb %al, -0x35(%rbp)
movb -0x35(%rbp), %al
testb $0x1, %al
jne 0x3184b
jmp 0x3187f
jmp 0x3184d
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq -0x28(%rbp), %rcx
movsbl (%rax,%rcx), %eax
andl $0xc0, %eax
cmpl $0x80, %eax
je 0x3184d
movq -0x20(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x31828
jmp 0x31881
jmp 0x31883
cmpq $0x0, -0x20(%rbp)
jne 0x3189d
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
addq $0x1, %rsi
callq 0x6be0
jmp 0x318a6
movq -0x8(%rbp), %rdi
callq 0x6b60
movl $0x1, %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)