// File: /workspace/github_c_makefile_star2_O1/bhk[P]tooltree/lua/../opensource/lua-5.2.3/src/lstrlib.c
// Function: str_gsub
static int str_gsub (lua_State *L) {
  size_t srcl, lp;
  const char *src = luaL_checklstring(L, 1, &srcl);
  const char *p = luaL_checklstring(L, 2, &lp);
  int tr = lua_type(L, 3);
  size_t max_s = luaL_optinteger(L, 4, srcl+1);
  int anchor = (*p == '^');
  size_t n = 0;
  MatchState ms;
  luaL_Buffer b;
  luaL_argcheck(L, tr == LUA_TNUMBER || tr == LUA_TSTRING ||
                   tr == LUA_TFUNCTION || tr == LUA_TTABLE, 3,
                      "string/function/table expected");
  luaL_buffinit(L, &b);
  if (anchor) {
    p++; lp--;  /* skip anchor character */
  }
  ms.L = L;
  ms.matchdepth = MAXCCALLS;
  ms.src_init = src;
  ms.src_end = src+srcl;
  ms.p_end = p + lp;
  while (n < max_s) {
    const char *e;
    ms.level = 0;
    lua_assert(ms.matchdepth == MAXCCALLS);
    e = match(&ms, src, p);
    if (e) {
      n++;
      add_value(&ms, &b, src, e, tr);
    }
    if (e && e>src) /* non empty match? */
      src = e;  /* skip it */
    else if (src < ms.src_end)
      luaL_addchar(&b, *src++);
    else break;
    if (anchor) break;
  }
  luaL_addlstring(&b, src, ms.src_end-src);
  luaL_pushresult(&b);
  lua_pushinteger(L, n);  /* number of substitutions */
  return 2;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2298, %rsp           # imm = 0x2298
movq %rdi, %r14
leaq 0x40(%rsp), %rbx
movl $0x1, %esi
movq %rbx, %rdx
callq 0x9559
movq %rax, %r12
leaq 0x8(%rsp), %rdx
movq %r14, %rdi
movl $0x2, %esi
callq 0x9559
movq %rax, %r13
movq %r14, %rdi
movl $0x3, %esi
callq 0x7889
movl %eax, %r15d
movq (%rbx), %rdx
incq %rdx
movq %r14, %rdi
movl $0x4, %esi
callq 0x9769
movq %rax, 0x38(%rsp)
movb (%r13), %bl
cmpb $0x5e, %bl
setne 0x7(%rsp)
movq %r15, 0x30(%rsp)
leal -0x3(%r15), %eax
cmpl $0x4, %eax
jb 0x1560e
leaq 0xc467(%rip), %rdx      # 0x21a68
movq %r14, %rdi
movl $0x3, %esi
callq 0x8f3e
leaq 0x278(%rsp), %rsi
movq %r14, %rdi
callq 0x999b
cmpb $0x5e, %bl
jne 0x1562b
incq %r13
decq 0x8(%rsp)
leaq 0x48(%rsp), %rcx
movq %r14, 0x18(%rsp)
movq %r14, 0x20(%rcx)
movl $0xc8, (%rcx)
movq %r12, 0x8(%rcx)
movq 0x40(%rsp), %rax
addq %r12, %rax
movq %rax, 0x10(%rcx)
movq 0x8(%rsp), %rax
addq %r13, %rax
movq %rax, 0x18(%rcx)
xorl %ebx, %ebx
movq %r13, 0x20(%rsp)
cmpq 0x38(%rsp), %rbx
jae 0x1595e
movl $0x0, 0x70(%rsp)
leaq 0x48(%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x16036
movq %rax, %r14
testq %rax, %rax
je 0x158de
incq %rbx
movq 0x68(%rsp), %r15
movq 0x30(%rsp), %rax
cmpl $0x5, %eax
je 0x156df
cmpl $0x6, %eax
jne 0x15758
movq %r15, %rdi
movl $0x3, %esi
callq 0x7869
leaq 0x48(%rsp), %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x1648e
movq %r15, %rdi
movl %eax, %esi
movl $0x1, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x85f1
jmp 0x156fe
leaq 0x48(%rsp), %rdi
xorl %esi, %esi
movq %r12, %rdx
movq %r14, %rcx
callq 0x1680b
movq %r15, %rdi
movl $0x3, %esi
callq 0x809f
movq %r15, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x7bb6
movq %r15, %rdi
testl %eax, %eax
je 0x158b6
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x7907
testl %eax, %eax
jne 0x158d1
movq %r15, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x7889
movq %r15, %rdi
movl %eax, %esi
callq 0x78aa
movq %r15, %rdi
leaq 0xc33e(%rip), %rsi      # 0x21a87
movq %rax, %rdx
xorl %eax, %eax
callq 0x9024
jmp 0x158d1
movq %r15, %rdi
movl $0x3, %esi
leaq 0x10(%rsp), %rdx
callq 0x7bdc
cmpq $0x0, 0x10(%rsp)
je 0x158af
movq %rax, %r15
movq %r14, %rax
subq %r12, %rax
movq %rax, 0x28(%rsp)
xorl %r13d, %r13d
cmpb $0x25, (%r15,%r13)
jne 0x15817
leaq 0x1(%r13), %rbp
callq 0x65f0
movq (%rax), %rcx
movzbl 0x1(%r15,%r13), %eax
testb $0x8, 0x1(%rcx,%rax,2)
jne 0x15860
cmpb $0x25, %al
je 0x157cb
movq 0x68(%rsp), %rdi
leaq 0xc2e9(%rip), %rsi      # 0x21aa8
movl $0x25, %edx
xorl %eax, %eax
callq 0x9024
movq 0x288(%rsp), %rax
cmpq 0x280(%rsp), %rax
jb 0x157ef
movl $0x1, %esi
leaq 0x278(%rsp), %rdi
callq 0x97c0
movb (%r15,%rbp), %al
movq 0x278(%rsp), %rcx
movq 0x288(%rsp), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, 0x288(%rsp)
movb %al, (%rcx,%rdx)
jmp 0x1589e
movq 0x288(%rsp), %rax
cmpq 0x280(%rsp), %rax
jb 0x1583b
movl $0x1, %esi
leaq 0x278(%rsp), %rdi
callq 0x97c0
movb (%r15,%r13), %al
movq 0x278(%rsp), %rcx
movq 0x288(%rsp), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, 0x288(%rsp)
movb %al, (%rcx,%rdx)
jmp 0x158a1
cmpb $0x30, %al
jne 0x1587b
leaq 0x278(%rsp), %rdi
movq %r12, %rsi
movq 0x28(%rsp), %rdx
callq 0x9869
jmp 0x1589e
movsbl %al, %esi
addl $-0x31, %esi
leaq 0x48(%rsp), %rdi
movq %r12, %rdx
movq %r14, %rcx
callq 0x1680b
leaq 0x278(%rsp), %rdi
callq 0x9918
movq %rbp, %r13
incq %r13
cmpq 0x10(%rsp), %r13
jb 0x15787
movq 0x20(%rsp), %r13
jmp 0x158de
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x7697
movq %r14, %rdx
subq %r12, %rdx
movq %r15, %rdi
movq %r12, %rsi
callq 0x7dc7
leaq 0x278(%rsp), %rdi
callq 0x9918
testq %r14, %r14
setne %cl
cmpq %r12, %r14
seta %dl
movb 0x7(%rsp), %al
testb %dl, %cl
jne 0x15951
cmpq 0x58(%rsp), %r12
jae 0x1594c
movq 0x288(%rsp), %rax
cmpq 0x280(%rsp), %rax
jb 0x1591d
movl $0x1, %esi
leaq 0x278(%rsp), %rdi
callq 0x97c0
movb (%r12), %al
incq %r12
movq 0x278(%rsp), %rcx
movq 0x288(%rsp), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, 0x288(%rsp)
movb %al, (%rcx,%rdx)
movq %r12, %r14
movb 0x7(%rsp), %al
jmp 0x15951
xorl %eax, %eax
movq %r12, %r14
movq %r14, %r12
testb %al, %al
jne 0x15662
jmp 0x15961
movq %r12, %r14
movq 0x58(%rsp), %rdx
subq %r14, %rdx
leaq 0x278(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x9869
movq %r15, %rdi
callq 0x98d0
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x7d87
movl $0x2, %eax
addq $0x2298, %rsp           # imm = 0x2298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq