// File: /workspace/github_c_makefile_star2_O3/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, %r15
leaq 0x40(%rsp), %rbx
movl $0x1, %esi
movq %rbx, %rdx
callq 0x9690
movq %rax, %r14
leaq 0x10(%rsp), %rdx
movq %r15, %rdi
movl $0x2, %esi
callq 0x9690
movq %rax, %r13
movq %r15, %rdi
movl $0x3, %esi
callq 0x7992
movl %eax, %r12d
movq (%rbx), %rdx
incq %rdx
movq %r15, %rdi
movl $0x4, %esi
callq 0x98a0
movq %rax, 0x38(%rsp)
movb (%r13), %al
movb %al, 0x7(%rsp)
movq %r12, 0x8(%rsp)
leal -0x3(%r12), %eax
cmpl $0x4, %eax
jb 0x15745
leaq 0xc328(%rip), %rdx      # 0x21a60
movq %r15, %rdi
movl $0x3, %esi
callq 0x905e
leaq 0x278(%rsp), %rsi
movq %r15, %rdi
callq 0x9ad7
movq 0x10(%rsp), %rax
cmpb $0x5e, 0x7(%rsp)
jne 0x1576c
incq %r13
decq %rax
movq %rax, 0x10(%rsp)
leaq 0x48(%rsp), %rdx
movq %r15, 0x20(%rsp)
movq %r15, 0x20(%rdx)
movl $0xc8, (%rdx)
movq %r14, 0x8(%rdx)
movq 0x40(%rsp), %rcx
addq %r14, %rcx
movq %rcx, 0x10(%rdx)
addq %r13, %rax
movq %rax, 0x18(%rdx)
xorl %ebp, %ebp
movq 0x8(%rsp), %r15
movq %r13, 0x28(%rsp)
cmpq 0x38(%rsp), %rbp
jae 0x15a8a
movl $0x0, 0x70(%rsp)
leaq 0x48(%rsp), %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x1616c
testq %rax, %rax
je 0x15a27
movq %rax, %r12
movq 0x68(%rsp), %rbx
cmpl $0x5, %r15d
je 0x1581a
cmpl $0x6, %r15d
jne 0x15893
movq %rbx, %rdi
movl $0x3, %esi
callq 0x7972
leaq 0x48(%rsp), %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x1656c
movq %rbx, %rdi
movl %eax, %esi
movl $0x1, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x8715
jmp 0x15839
leaq 0x48(%rsp), %rdi
xorl %esi, %esi
movq %r14, %rdx
movq %r12, %rcx
callq 0x168e8
movq %rbx, %rdi
movl $0x3, %esi
callq 0x81a3
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x7cc4
movq %rbx, %rdi
testl %eax, %eax
je 0x159f7
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x7a10
testl %eax, %eax
jne 0x15a12
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x7992
movq %rbx, %rdi
movl %eax, %esi
callq 0x79b3
movq %rbx, %rdi
leaq 0xc1fb(%rip), %rsi      # 0x21a7f
movq %rax, %rdx
xorl %eax, %eax
callq 0x9144
jmp 0x15a12
movq %rbx, %rdi
movl $0x3, %esi
leaq 0x18(%rsp), %rdx
callq 0x7cea
cmpq $0x0, 0x18(%rsp)
je 0x159eb
movq %rax, %r15
movq %r12, %rax
subq %r14, %rax
movq %rax, 0x30(%rsp)
xorl %r13d, %r13d
movb (%r15,%r13), %al
cmpb $0x25, %al
jne 0x15953
leaq 0x1(%r13), %rbx
callq 0x65f0
movq (%rax), %rcx
movzbl 0x1(%r15,%r13), %eax
testb $0x8, 0x1(%rcx,%rax,2)
jne 0x1599c
cmpb $0x25, %al
je 0x15907
movq 0x68(%rsp), %rdi
leaq 0xc1a5(%rip), %rsi      # 0x21aa0
movl $0x25, %edx
xorl %eax, %eax
callq 0x9144
movq 0x288(%rsp), %rax
cmpq 0x280(%rsp), %rax
jb 0x15933
movl $0x1, %esi
leaq 0x278(%rsp), %rdi
callq 0x98f7
movq 0x288(%rsp), %rax
movb (%r15,%rbx), %cl
movq 0x278(%rsp), %rdx
leaq 0x1(%rax), %rsi
movq %rsi, 0x288(%rsp)
movb %cl, (%rdx,%rax)
jmp 0x159da
movq 0x288(%rsp), %rcx
cmpq 0x280(%rsp), %rcx
jb 0x15983
movl $0x1, %esi
leaq 0x278(%rsp), %rdi
callq 0x98f7
movb (%r15,%r13), %al
movq 0x288(%rsp), %rcx
movq 0x278(%rsp), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x288(%rsp)
movb %al, (%rdx,%rcx)
jmp 0x159dd
cmpb $0x30, %al
jne 0x159b7
leaq 0x278(%rsp), %rdi
movq %r14, %rsi
movq 0x30(%rsp), %rdx
callq 0x99a5
jmp 0x159da
movsbl %al, %esi
addl $-0x31, %esi
leaq 0x48(%rsp), %rdi
movq %r14, %rdx
movq %r12, %rcx
callq 0x168e8
leaq 0x278(%rsp), %rdi
callq 0x9a54
movq %rbx, %r13
incq %r13
cmpq 0x18(%rsp), %r13
jb 0x158c2
movq 0x28(%rsp), %r13
movq 0x8(%rsp), %r15
jmp 0x15a1f
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x7688
movq %r12, %rdx
subq %r14, %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x7ecb
leaq 0x278(%rsp), %rdi
callq 0x9a54
incq %rbp
cmpq %r14, %r12
ja 0x15a7a
cmpq 0x58(%rsp), %r14
jae 0x15a8a
movq 0x288(%rsp), %rax
cmpq 0x280(%rsp), %rax
jb 0x15a5a
movl $0x1, %esi
leaq 0x278(%rsp), %rdi
callq 0x98f7
movq 0x288(%rsp), %rax
movb (%r14), %cl
incq %r14
movq 0x278(%rsp), %rdx
leaq 0x1(%rax), %rsi
movq %rsi, 0x288(%rsp)
movb %cl, (%rdx,%rax)
movq %r14, %r12
movq %r12, %r14
cmpb $0x5e, 0x7(%rsp)
jne 0x157a3
jmp 0x15a8d
movq %r14, %r12
movq 0x58(%rsp), %rdx
subq %r12, %rdx
leaq 0x278(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x99a5
movq %rbx, %rdi
callq 0x9a0c
movq 0x20(%rsp), %rdi
movq %rbp, %rsi
callq 0x7e95
movl $0x2, %eax
addq $0x2298, %rsp           # imm = 0x2298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq