// File: /workspace/github_c_makefile_star2_O2/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 $0x22a8, %rsp           # imm = 0x22A8
movq %rdi, %r15
pushq $0x1
popq %rsi
leaq 0x48(%rsp), %rbx
movq %rbx, %rdx
callq 0x9264
movq %rax, %r14
pushq $0x2
popq %rsi
leaq 0x18(%rsp), %rdx
movq %r15, %rdi
callq 0x9264
movq %rax, %rbp
pushq $0x3
popq %rsi
movq %r15, %rdi
callq 0x7624
movl %eax, %r13d
movq (%rbx), %rdx
incq %rdx
pushq $0x4
popq %rsi
movq %r15, %rdi
callq 0x9456
movq %rax, 0x38(%rsp)
movb (%rbp), %al
movb %al, 0xf(%rsp)
leal -0x3(%r13), %eax
cmpl $0x4, %eax
jb 0x142cb
leaq 0xb788(%rip), %rdx      # 0x1fa48
pushq $0x3
popq %rsi
movq %r15, %rdi
callq 0x8c84
leaq 0x288(%rsp), %rsi
movq %r15, %rdi
callq 0x9657
movq 0x18(%rsp), %rax
cmpb $0x5e, 0xf(%rsp)
jne 0x142f2
incq %rbp
decq %rax
movq %rax, 0x18(%rsp)
leaq 0x58(%rsp), %rdx
movq %r15, 0x20(%rsp)
movq %r15, 0x20(%rdx)
movl $0xc8, (%rdx)
movq %r14, 0x8(%rdx)
movq 0x48(%rsp), %rcx
addq %r14, %rcx
movq %rcx, 0x10(%rdx)
addq %rbp, %rax
movq %rax, 0x18(%rdx)
pushq $-0x1
popq %rdi
xorl %ebx, %ebx
movq %rbp, 0x30(%rsp)
movq %r13, 0x28(%rsp)
cmpq 0x38(%rsp), %rbx
jae 0x14620
movl %edi, %r15d
andl $0x0, 0x80(%rsp)
leaq 0x58(%rsp), %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x14c9c
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x143a7
movq %rbx, 0x40(%rsp)
movq 0x78(%rsp), %rbx
cmpl $0x5, %r13d
je 0x143af
cmpl $0x6, %r13d
jne 0x14425
movq %rbx, %rdi
pushq $0x3
popq %rsi
callq 0x7604
leaq 0x58(%rsp), %rdi
movq %r14, %rsi
movq 0x10(%rsp), %rdx
callq 0x15077
movq %rbx, %rdi
movl %eax, %esi
pushq $0x1
popq %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x835f
jmp 0x143ce
movl %r15d, %edi
jmp 0x145b9
leaq 0x58(%rsp), %rdi
xorl %esi, %esi
movq %r14, %rdx
movq 0x10(%rsp), %rcx
callq 0x153f3
movq %rbx, %rdi
pushq $0x3
popq %rsi
callq 0x7df9
movq %rbx, %rdi
movl %r15d, %r12d
movl %r15d, %esi
callq 0x7943
movq %rbx, %rdi
testl %eax, %eax
je 0x1457c
movl %r12d, %esi
callq 0x76a0
testl %eax, %eax
jne 0x14597
movq %rbx, %rdi
movl %r15d, %esi
callq 0x7624
movq %rbx, %rdi
movl %eax, %esi
callq 0x7643
movq %rbx, %rdi
leaq 0xb651(%rip), %rsi      # 0x1fa67
movq %rax, %rdx
xorl %eax, %eax
callq 0x8d68
jmp 0x14597
movq %rbx, %rdi
pushq $0x3
popq %rsi
leaq 0x50(%rsp), %rdx
callq 0x7967
movq %rax, %rbx
movq 0x10(%rsp), %r12
subq %r14, %r12
xorl %ebp, %ebp
movl %r15d, %edi
cmpq 0x50(%rsp), %rbp
jae 0x14570
movb (%rbx,%rbp), %al
cmpb $0x25, %al
jne 0x144db
leaq 0x1(%rbp), %r13
callq 0x65e0
movq (%rax), %rcx
movzbl 0x1(%rbx,%rbp), %eax
testb $0x8, 0x1(%rcx,%rax,2)
jne 0x14524
cmpb $0x25, %al
je 0x14491
movq 0x78(%rsp), %rdi
leaq 0xb601(%rip), %rsi      # 0x1fa88
pushq $0x25
popq %rdx
xorl %eax, %eax
callq 0x8d68
movq 0x298(%rsp), %rax
cmpq 0x290(%rsp), %rax
jb 0x144bb
leaq 0x288(%rsp), %rdi
pushq $0x1
popq %rsi
callq 0x94ad
movq 0x298(%rsp), %rax
movb (%rbx,%r13), %cl
movq 0x288(%rsp), %rdx
leaq 0x1(%rax), %rsi
movq %rsi, 0x298(%rsp)
movb %cl, (%rdx,%rax)
jmp 0x14562
movq 0x298(%rsp), %rcx
cmpq 0x290(%rsp), %rcx
jb 0x1450b
leaq 0x288(%rsp), %rdi
pushq $0x1
popq %rsi
callq 0x94ad
movl %r15d, %edi
movb (%rbx,%rbp), %al
movq 0x298(%rsp), %rcx
movq 0x288(%rsp), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x298(%rsp)
movb %al, (%rdx,%rcx)
jmp 0x14568
cmpb $0x30, %al
jne 0x1453d
leaq 0x288(%rsp), %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x9559
jmp 0x14562
movsbl %al, %esi
addl $-0x31, %esi
leaq 0x58(%rsp), %rdi
movq %r14, %rdx
movq 0x10(%rsp), %rcx
callq 0x153f3
leaq 0x288(%rsp), %rdi
callq 0x95f4
movq %r13, %rbp
movl %r15d, %edi
incq %rbp
jmp 0x14445
movq 0x30(%rsp), %rbp
movq 0x28(%rsp), %r13
jmp 0x145a7
pushq $-0x2
popq %rsi
callq 0x7437
movq 0x10(%rsp), %rdx
subq %r14, %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x7b27
leaq 0x288(%rsp), %rdi
callq 0x95f4
movl %r15d, %edi
movq 0x40(%rsp), %rbx
incq %rbx
movq 0x10(%rsp), %rax
cmpq %r14, %rax
ja 0x1460d
cmpq 0x68(%rsp), %r14
jae 0x14620
movq 0x298(%rsp), %rax
cmpq 0x290(%rsp), %rax
jb 0x145ed
leaq 0x288(%rsp), %rdi
pushq $0x1
popq %rsi
callq 0x94ad
movl %r15d, %edi
movq 0x298(%rsp), %rax
movb (%r14), %cl
incq %r14
movq 0x288(%rsp), %rdx
leaq 0x1(%rax), %rsi
movq %rsi, 0x298(%rsp)
movb %cl, (%rdx,%rax)
movq %r14, %rax
movq %rax, %r14
cmpb $0x5e, 0xf(%rsp)
movq %rax, %rsi
jne 0x1432c
jmp 0x14623
movq %r14, %rsi
movq 0x68(%rsp), %rdx
subq %rsi, %rdx
movq %rbx, %r14
leaq 0x288(%rsp), %rbx
movq %rbx, %rdi
callq 0x9559
movq %rbx, %rdi
callq 0x95ae
movq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x7af1
pushq $0x2
popq %rax
addq $0x22a8, %rsp           # imm = 0x22A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq