// File: /workspace/github_c_makefile_star2_O1/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 0x14535
movq %rax, %r12
leaq 0x18(%rsp), %rdx
movq %r14, %rdi
movl $0x2, %esi
callq 0x14535
movq %rax, %r15
movq %r14, %rdi
movl $0x3, %esi
callq 0x5f7f
movl %eax, %r13d
movq (%rbx), %rdx
incq %rdx
movq %r14, %rdi
movl $0x4, %esi
callq 0x146c5
movq %rax, %rbp
movb (%r15), %bl
cmpb $0x5e, %bl
setne 0x7(%rsp)
movq %r13, 0x40(%rsp)
leal -0x3(%r13), %eax
cmpl $0x4, %eax
jb 0x1c9af
leaq 0x6cee(%rip), %rdx      # 0x23690
movq %r14, %rdi
movl $0x3, %esi
callq 0x13ea8
leaq 0x278(%rsp), %rsi
movq %r14, %rdi
callq 0x149f7
cmpb $0x5e, %bl
jne 0x1c9cc
incq %r15
decq 0x18(%rsp)
leaq 0x50(%rsp), %rcx
movq %r14, 0x28(%rsp)
movq %r14, 0x18(%rcx)
movl $0xc8, 0x20(%rcx)
movq %r12, (%rcx)
movq 0x48(%rsp), %rax
addq %r12, %rax
movq %rax, 0x8(%rcx)
movq 0x18(%rsp), %rax
addq %r15, %rax
movq %rax, 0x10(%rcx)
xorl %r14d, %r14d
movq $0x0, 0x8(%rsp)
movq %r15, 0x30(%rsp)
movq %rbp, 0x10(%rsp)
cmpq %rbp, 0x8(%rsp)
jge 0x1cd41
movb $0x0, 0x74(%rsp)
leaq 0x50(%rsp), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x1dbdd
movq %rax, %r13
testq %rax, %rax
sete %al
cmpq %r14, %r13
sete %cl
orb %al, %cl
je 0x1caa6
cmpq 0x58(%rsp), %r12
jae 0x1caf6
movq 0x288(%rsp), %rax
cmpq 0x280(%rsp), %rax
jb 0x1ca74
movl $0x1, %esi
leaq 0x278(%rsp), %rdi
callq 0x146f3
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 %r14, %r13
movb 0x7(%rsp), %al
jmp 0x1cd36
incq 0x8(%rsp)
movq 0x68(%rsp), %rbp
movq 0x40(%rsp), %rax
cmpl $0x5, %eax
je 0x1cb00
movq %rbp, %rdi
movl $0x3, %esi
cmpl $0x6, %eax
jne 0x1cb79
callq 0x5f5b
leaq 0x50(%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x1e03a
movq %rbp, %rdi
movl %eax, %esi
movl $0x1, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x6e22
jmp 0x1cb1f
xorl %eax, %eax
movq %r14, %r13
jmp 0x1cd36
leaq 0x50(%rsp), %rdi
xorl %esi, %esi
movq %r12, %rdx
movq %r13, %rcx
callq 0x1e3b8
movq %rbp, %rdi
movl $0x3, %esi
callq 0x6710
movq %rbp, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x6223
movq %rbp, %rdi
testl %eax, %eax
je 0x1cd02
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x6008
testl %eax, %eax
jne 0x1cd1d
movq %rbp, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x5f7f
movq %rbp, %rdi
movl %eax, %esi
callq 0x5fa0
movq %rbp, %rdi
leaq 0x6b45(%rip), %rsi      # 0x236af
movq %rax, %rdx
xorl %eax, %eax
callq 0x13f8e
jmp 0x1cd1d
leaq 0x20(%rsp), %rdx
callq 0x6249
cmpq $0x0, 0x20(%rsp)
je 0x1ccf4
movq %rax, %r14
movq %r13, %rax
subq %r12, %rax
movq %rax, 0x38(%rsp)
xorl %r15d, %r15d
cmpb $0x25, (%r14,%r15)
jne 0x1cc2e
leaq 0x1(%r15), %rbx
callq 0x5540
movq (%rax), %rcx
movzbl 0x1(%r14,%r15), %eax
testb $0x8, 0x1(%rcx,%rax,2)
jne 0x1cc77
cmpb $0x25, %al
je 0x1cbe2
movq %rbp, %rdi
leaq 0x6afa(%rip), %rsi      # 0x236d0
movl $0x25, %edx
xorl %eax, %eax
callq 0x13f8e
movq 0x288(%rsp), %rax
cmpq 0x280(%rsp), %rax
jb 0x1cc06
movl $0x1, %esi
leaq 0x278(%rsp), %rdi
callq 0x146f3
movb (%r14,%rbx), %al
movq 0x278(%rsp), %rcx
movq 0x288(%rsp), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, 0x288(%rsp)
movb %al, (%rcx,%rdx)
jmp 0x1cce3
movq 0x288(%rsp), %rax
cmpq 0x280(%rsp), %rax
jb 0x1cc52
movl $0x1, %esi
leaq 0x278(%rsp), %rdi
callq 0x146f3
movb (%r14,%r15), %al
movq 0x278(%rsp), %rcx
movq 0x288(%rsp), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, 0x288(%rsp)
movb %al, (%rcx,%rdx)
jmp 0x1cce6
cmpb $0x30, %al
jne 0x1cc92
leaq 0x278(%rsp), %rdi
movq %r12, %rsi
movq 0x38(%rsp), %rdx
callq 0x1487e
jmp 0x1cce3
movsbl %al, %esi
addl $-0x31, %esi
leaq 0x50(%rsp), %rdi
movq %r12, %rdx
movq %r13, %rcx
callq 0x1e3b8
movq %rbp, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %edx, %edx
callq 0x14fc6
movq %rbp, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x5da2
movq %rbp, %rdi
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x5d51
leaq 0x278(%rsp), %rdi
callq 0x14958
movq %rbx, %r15
incq %r15
cmpq 0x20(%rsp), %r15
jb 0x1cba0
movq %r13, %r12
movb 0x7(%rsp), %al
movq 0x30(%rsp), %r15
jmp 0x1cd31
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
callq 0x5d51
movq %r13, %rdx
subq %r12, %rdx
movq %rbp, %rdi
movq %r12, %rsi
callq 0x63fa
leaq 0x278(%rsp), %rdi
callq 0x14958
movq %r13, %r12
movb 0x7(%rsp), %al
movq 0x10(%rsp), %rbp
movq %r13, %r14
testb %al, %al
jne 0x1ca12
movq 0x58(%rsp), %rdx
subq %r12, %rdx
leaq 0x278(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x1487e
movq %r14, %rdi
callq 0x148ef
movq 0x28(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x63e6
movl $0x2, %eax
addq $0x2298, %rsp           # imm = 0x2298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq