// File: /workspace/github_c_makefile_star2_O3/tylerneylon[P]APIsWithLua/lua/lstrlib.c
// Function: str_gsub
static int str_gsub (lua_State *L) {
  size_t srcl, lp;
  const char *src = luaL_checklstring(L, 1, &srcl);  /* subject */
  const char *p = luaL_checklstring(L, 2, &lp);  /* pattern */
  const char *lastmatch = NULL;  /* end of last match */
  int tr = lua_type(L, 3);  /* replacement type */
  lua_Integer max_s = luaL_optinteger(L, 4, srcl + 1);  /* max replacements */
  int anchor = (*p == '^');
  lua_Integer n = 0;  /* replacement count */
  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 */
  }
  prepstate(&ms, L, src, srcl, p, lp);
  while (n < max_s) {
    const char *e;
    reprepstate(&ms);  /* (re)prepare state for new match */
    if ((e = match(&ms, src, p)) != NULL && e != lastmatch) {  /* match? */
      n++;
      add_value(&ms, &b, src, e, tr);  /* add replacement to buffer */
      src = lastmatch = e;
    }
    else if (src < ms.src_end)  /* otherwise, skip one character */
      luaL_addchar(&b, *src++);
    else break;  /* end of subject */
    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 0x48(%rsp), %rbx
movl $0x1, %esi
movq %rbx, %rdx
callq 0x14fff
movq %rax, %r12
leaq 0x10(%rsp), %rdx
movq %r14, %rdi
movl $0x2, %esi
callq 0x14fff
movq %rax, %r15
movq %r14, %rdi
movl $0x3, %esi
callq 0x608f
movq (%rbx), %rdx
movq %r14, %rbx
movq %rax, %r14
incq %rdx
movq %rbx, %rdi
movl $0x4, %esi
callq 0x1518f
movq %rax, 0x40(%rsp)
movb (%r15), %al
movb %al, 0x7(%rsp)
leal -0x3(%r14), %eax
cmpl $0x4, %eax
jb 0x1d569
leaq 0x71ec(%rip), %rdx      # 0x24748
movq %rbx, %rdi
movl $0x3, %esi
callq 0x1497c
leaq 0x278(%rsp), %rsi
movq %rbx, %rdi
callq 0x154c8
movq 0x10(%rsp), %rax
cmpb $0x5e, 0x7(%rsp)
jne 0x1d590
incq %r15
decq %rax
movq %rax, 0x10(%rsp)
leaq 0x50(%rsp), %rdx
movq %rbx, 0x20(%rsp)
movq %rbx, 0x18(%rdx)
movl $0xc8, 0x20(%rdx)
movq %r12, (%rdx)
movq 0x48(%rsp), %rcx
addq %r12, %rcx
movq %rcx, 0x8(%rdx)
addq %r15, %rax
movq %rax, 0x10(%rdx)
xorl %ebx, %ebx
movq $0x0, 0x8(%rsp)
movq %r15, 0x30(%rsp)
movq %r14, 0x28(%rsp)
movq 0x8(%rsp), %rax
cmpq 0x40(%rsp), %rax
jge 0x1d8ef
movb $0x0, 0x74(%rsp)
leaq 0x50(%rsp), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x1e785
movq %rax, %r13
testq %rax, %rax
sete %al
cmpq %rbx, %r13
sete %cl
orb %al, %cl
je 0x1d665
cmpq 0x58(%rsp), %r12
jae 0x1d8ef
movq 0x288(%rsp), %rax
cmpq 0x280(%rsp), %rax
jb 0x1d63f
movl $0x1, %esi
leaq 0x278(%rsp), %rdi
callq 0x151bd
movq 0x288(%rsp), %rax
movb (%r12), %cl
incq %r12
movq 0x278(%rsp), %rdx
leaq 0x1(%rax), %rsi
movq %rsi, 0x288(%rsp)
movb %cl, (%rdx,%rax)
movq %rbx, %r13
jmp 0x1d8e1
incq 0x8(%rsp)
movq 0x68(%rsp), %rbx
cmpl $0x5, %r14d
je 0x1d6b2
movq %rbx, %rdi
movl $0x3, %esi
cmpl $0x6, %r14d
jne 0x1d72b
callq 0x606b
leaq 0x50(%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x1eb8a
movq %rbx, %rdi
movl %eax, %esi
movl $0x1, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x6f67
jmp 0x1d6d1
leaq 0x50(%rsp), %rdi
xorl %esi, %esi
movq %r12, %rdx
movq %r13, %rcx
callq 0x1ef07
movq %rbx, %rdi
movl $0x3, %esi
callq 0x682e
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x6333
movq %rbx, %rdi
testl %eax, %eax
je 0x1d8b6
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x6111
testl %eax, %eax
jne 0x1d8d1
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x608f
movq %rbx, %rdi
movl %eax, %esi
callq 0x60b0
movq %rbx, %rdi
leaq 0x704b(%rip), %rsi      # 0x24767
movq %rax, %rdx
xorl %eax, %eax
callq 0x14a62
jmp 0x1d8d1
leaq 0x18(%rsp), %rdx
callq 0x6359
cmpq $0x0, 0x18(%rsp)
je 0x1d8a7
movq %rax, %r14
movq %r13, %rax
subq %r12, %rax
movq %rax, 0x38(%rsp)
xorl %r15d, %r15d
movb (%r14,%r15), %al
cmpb $0x25, %al
jne 0x1d7e1
leaq 0x1(%r15), %rbp
callq 0x5530
movq (%rax), %rcx
movzbl 0x1(%r14,%r15), %eax
testb $0x8, 0x1(%rcx,%rax,2)
jne 0x1d82a
cmpb $0x25, %al
je 0x1d795
movq %rbx, %rdi
leaq 0x6fff(%rip), %rsi      # 0x24788
movl $0x25, %edx
xorl %eax, %eax
callq 0x14a62
movq 0x288(%rsp), %rax
cmpq 0x280(%rsp), %rax
jb 0x1d7c1
movl $0x1, %esi
leaq 0x278(%rsp), %rdi
callq 0x151bd
movq 0x288(%rsp), %rax
movb (%r14,%rbp), %cl
movq 0x278(%rsp), %rdx
leaq 0x1(%rax), %rsi
movq %rsi, 0x288(%rsp)
movb %cl, (%rdx,%rax)
jmp 0x1d896
movq 0x288(%rsp), %rcx
cmpq 0x280(%rsp), %rcx
jb 0x1d811
movl $0x1, %esi
leaq 0x278(%rsp), %rdi
callq 0x151bd
movb (%r14,%r15), %al
movq 0x288(%rsp), %rcx
movq 0x278(%rsp), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x288(%rsp)
movb %al, (%rdx,%rcx)
jmp 0x1d899
cmpb $0x30, %al
jne 0x1d845
leaq 0x278(%rsp), %rdi
movq %r12, %rsi
movq 0x38(%rsp), %rdx
callq 0x1534f
jmp 0x1d896
movsbl %al, %esi
addl $-0x31, %esi
leaq 0x50(%rsp), %rdi
movq %r12, %rdx
movq %r13, %rcx
callq 0x1ef07
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %edx, %edx
callq 0x15ab1
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x5eb2
movq %rbx, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x5d4d
leaq 0x278(%rsp), %rdi
callq 0x15429
movq %rbp, %r15
incq %r15
cmpq 0x18(%rsp), %r15
jb 0x1d752
movq %r13, %r12
movq 0x30(%rsp), %r15
movq 0x28(%rsp), %r14
jmp 0x1d8e1
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x5d4d
movq %r13, %rdx
subq %r12, %rdx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x650a
leaq 0x278(%rsp), %rdi
callq 0x15429
movq %r13, %r12
movq %r13, %rbx
cmpb $0x5e, 0x7(%rsp)
jne 0x1d5d0
movq 0x58(%rsp), %rdx
subq %r12, %rdx
leaq 0x278(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1534f
movq %rbx, %rdi
callq 0x153c0
movq 0x20(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x64f6
movl $0x2, %eax
addq $0x2298, %rsp           # imm = 0x2298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq