// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/external/lua-5.1.5/src/lstrlib.c
// Function: str_gsub
static int str_gsub (lua_State *L) {
  size_t srcl;
  const char *src = luaL_checklstring(L, 1, &srcl);
  const char *p = luaL_checkstring(L, 2);
  int  tr = lua_type(L, 3);
  int max_s = luaL_optint(L, 4, srcl+1);
  int anchor = (*p == '^') ? (p++, 1) : 0;
  int 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);
  ms.L = L;
  ms.src_init = src;
  ms.src_end = src+srcl;
  while (n < max_s) {
    const char *e;
    ms.level = 0;
    e = match(&ms, src, p);
    if (e) {
      n++;
      add_value(&ms, &b, src, e);
    }
    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 $0x2278, %rsp           # imm = 0x2278
movq %rdi, %r15
leaq 0x10(%rsp), %rdx
movl $0x1, %esi
callq 0x5b1b3
movq %rax, %rbx
xorl %r14d, %r14d
movq %r15, %rdi
movl $0x2, %esi
xorl %edx, %edx
callq 0x5b1b3
movq %rax, %r13
movq 0x18(%r15), %rax
leaq 0x20(%rax), %rcx
cmpq 0x10(%r15), %rcx
setae %dl
cmpq 0xe4654(%rip), %rcx     # 0x150fd0
sete %cl
orb %dl, %cl
jne 0x6c990
movl 0x28(%rax), %eax
addl $-0x3, %eax
cmpl $0x4, %eax
setb %r14b
movq 0x10(%rsp), %rdx
incq %rdx
movq %r15, %rdi
movl $0x4, %esi
callq 0x5b45e
movq %rax, 0x38(%rsp)
movb (%r13), %al
xorl %ecx, %ecx
cmpb $0x5e, %al
sete %dl
testb %r14b, %r14b
je 0x6cdcf
movb %dl, %cl
addq %rcx, %r13
cmpb $0x5e, %al
setne %bpl
leaq 0x278(%rsp), %rax
movq %r15, -0x8(%rax)
movq %rax, -0x18(%rax)
movl $0x0, -0x10(%rax)
leaq 0x40(%rsp), %rcx
movq %r15, 0x20(%rsp)
movq %r15, 0x10(%rcx)
movq %rbx, (%rcx)
movq 0x10(%rsp), %rax
addq %rbx, %rax
movq %rax, 0x8(%rcx)
xorl %r15d, %r15d
movq %r13, 0x28(%rsp)
movb %bpl, 0xf(%rsp)
cmpl 0x38(%rsp), %r15d
jge 0x6cd28
movl $0x0, 0x58(%rsp)
leaq 0x40(%rsp), %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x6d498
movq %rax, %r14
testq %rax, %rax
je 0x6ccab
movq 0x50(%rsp), %r12
movq 0x10(%r12), %rax
movq 0x18(%r12), %rcx
addq $0x20, %rcx
cmpq %rax, %rcx
leaq 0x80cba(%rip), %rdx     # 0xed710
cmovaeq %rdx, %rcx
cmpq %rdx, %rcx
je 0x6ca64
movl 0x8(%rcx), %edx
jmp 0x6ca69
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
incl %r15d
leal -0x3(%rdx), %esi
cmpl $0x2, %esi
jb 0x6cac8
cmpl $0x5, %edx
je 0x6cc12
cmpl $0x6, %edx
jne 0x6cc4d
movq (%rcx), %rdx
movq %rdx, (%rax)
movl 0x8(%rcx), %ecx
movl %ecx, 0x8(%rax)
addq $0x10, 0x10(%r12)
leaq 0x40(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x6d8d2
notl %eax
movslq %eax, %rsi
shlq $0x4, %rsi
addq 0x10(%r12), %rsi
movq %r12, %rdi
movl $0x1, %edx
callq 0x594c2
jmp 0x6cc4d
movq %r15, 0x30(%rsp)
movq %r12, %rdi
movl $0x3, %esi
leaq 0x18(%rsp), %rdx
callq 0x58042
cmpq $0x0, 0x18(%rsp)
je 0x6cc03
movq %rax, %r12
movq %r14, %r13
subq %rbx, %r13
xorl %r15d, %r15d
cmpb $0x25, (%r12,%r15)
jne 0x6cb6a
leaq 0x1(%r15), %rbp
callq 0xb6e0
movq (%rax), %rcx
movzbl 0x1(%r12,%r15), %eax
testb $0x8, 0x1(%rcx,%rax,2)
jne 0x6cbb6
leaq 0x2278(%rsp), %rax
cmpq %rax, 0x260(%rsp)
jb 0x6cb4b
leaq 0x260(%rsp), %rdi
callq 0x5ba5e
testl %eax, %eax
je 0x6cb4b
leaq 0x260(%rsp), %rdi
callq 0x5ba94
movb (%r12,%rbp), %al
movq 0x260(%rsp), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x260(%rsp)
movb %al, (%rcx)
jmp 0x6cbf2
leaq 0x2278(%rsp), %rax
cmpq %rax, 0x260(%rsp)
jb 0x6cb9a
leaq 0x260(%rsp), %rdi
callq 0x5ba5e
testl %eax, %eax
je 0x6cb9a
leaq 0x260(%rsp), %rdi
callq 0x5ba94
movb (%r12,%r15), %al
movq 0x260(%rsp), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x260(%rsp)
movb %al, (%rcx)
jmp 0x6cbf5
cmpb $0x30, %al
jne 0x6cbcf
leaq 0x260(%rsp), %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x5b99f
jmp 0x6cbf2
movsbl %al, %esi
addl $-0x31, %esi
leaq 0x40(%rsp), %rdi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x6dc89
leaq 0x260(%rsp), %rdi
callq 0x5bb17
movq %rbp, %r15
incq %r15
cmpq 0x18(%rsp), %r15
jb 0x6caf7
movq 0x28(%rsp), %r13
movq 0x30(%rsp), %r15
jmp 0x6cca6
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x6dc89
movq 0x10(%r12), %rcx
movq 0x18(%r12), %rsi
addq $0x20, %rsi
cmpq %rcx, %rsi
jb 0x6cc3e
leaq 0x80ad2(%rip), %rsi     # 0xed710
addq $-0x10, %rcx
movq %r12, %rdi
movq %rcx, %rdx
callq 0x58a83
movq 0x10(%r12), %rcx
movslq -0x8(%rcx), %rax
addq $-0x10, %rcx
testq %rax, %rax
je 0x6cc83
cmpl $0x1, %eax
jne 0x6cc69
cmpl $0x0, (%rcx)
je 0x6cc83
cmpq 0xe4360(%rip), %rcx     # 0x150fd0
je 0x6cd96
leal -0x5(%rax), %edx
cmpl $-0x3, %edx
ja 0x6cc99
jmp 0x6cd96
movq %rcx, 0x10(%r12)
movq %r14, %rdx
subq %rbx, %rdx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x58391
leaq 0x260(%rsp), %rdi
callq 0x5bb17
movb 0xf(%rsp), %bpl
testq %r14, %r14
setne %cl
cmpq %rbx, %r14
seta %dl
movl %ebp, %eax
testb %dl, %cl
jne 0x6cd1b
cmpq 0x48(%rsp), %rbx
jae 0x6cd16
leaq 0x2278(%rsp), %rax
cmpq %rax, 0x260(%rsp)
jb 0x6ccf4
leaq 0x260(%rsp), %rdi
callq 0x5ba5e
testl %eax, %eax
je 0x6ccf4
leaq 0x260(%rsp), %rdi
callq 0x5ba94
movb (%rbx), %al
incq %rbx
movq 0x260(%rsp), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x260(%rsp)
movb %al, (%rcx)
movq %rbx, %r14
movl %ebp, %eax
jmp 0x6cd1b
xorl %eax, %eax
movq %rbx, %r14
movq %r14, %rbx
testb %al, %al
jne 0x6ca0a
jmp 0x6cd2b
movq %rbx, %r14
movq 0x48(%rsp), %rdx
subq %r14, %rdx
leaq 0x260(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5b99f
movq %rbx, %rdi
callq 0x5ba5e
movq 0x10(%rbx), %rdi
movl 0x8(%rbx), %esi
callq 0x59be2
movl $0x1, 0x8(%rbx)
movq 0x20(%rsp), %rcx
movq 0x10(%rcx), %rax
cvtsi2sd %r15d, %xmm0
movsd %xmm0, (%rax)
movl $0x3, 0x8(%rax)
addq $0x10, 0x10(%rcx)
movl $0x2, %eax
addq $0x2278, %rsp           # imm = 0x2278
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq 0xe4233(%rip), %rcx     # 0x150fd0
sete %cl
cmpl $-0x1, %eax
sete %dl
orb %cl, %dl
je 0x6cdb3
leaq 0x7a89f(%rip), %rdx     # 0xe7650
jmp 0x6cdbe
leaq 0xe1e36(%rip), %rcx     # 0x14ebf0
movq (%rcx,%rax,8), %rdx
leaq 0x82137(%rip), %rsi     # 0xeeefc
movq %r12, %rdi
xorl %eax, %eax
callq 0x5af61
leaq 0x82107(%rip), %rdx     # 0xeeedd
movq %r15, %rdi
movl $0x3, %esi
callq 0x5aeac