// File: /workspace/github_c_makefile_star2_O2/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, %r15
pushq $0x1
popq %rsi
leaq 0x40(%rsp), %rbx
movq %rbx, %rdx
callq 0x13131
movq %rax, %r14
pushq $0x2
popq %rsi
leaq 0x10(%rsp), %rdx
movq %r15, %rdi
callq 0x13131
movq %rax, %rbp
pushq $0x3
popq %rsi
movq %r15, %rdi
callq 0x5d12
movl %eax, %r12d
movq (%rbx), %rdx
incq %rdx
pushq $0x4
popq %rsi
movq %r15, %rdi
callq 0x132b0
movq %rax, 0x38(%rsp)
movb (%rbp), %al
movb %al, 0x7(%rsp)
movq %r12, 0x28(%rsp)
leal -0x3(%r12), %eax
cmpl $0x4, %eax
jb 0x1ae6c
leaq 0x694f(%rip), %rdx      # 0x217b0
pushq $0x3
popq %rsi
movq %r15, %rdi
callq 0x12af2
leaq 0x278(%rsp), %rsi
movq %r15, %rdi
callq 0x13589
movq 0x10(%rsp), %rax
cmpb $0x5e, 0x7(%rsp)
jne 0x1ae93
incq %rbp
decq %rax
movq %rax, 0x10(%rsp)
leaq 0x50(%rsp), %rdx
movq %r15, 0x18(%rsp)
movq %r15, 0x18(%rdx)
movl $0xc8, 0x20(%rdx)
movq %r14, (%rdx)
movq 0x40(%rsp), %rcx
addq %r14, %rcx
movq %rcx, 0x8(%rdx)
addq %rbp, %rax
movq %rax, 0x10(%rdx)
xorl %ebx, %ebx
xorl %r15d, %r15d
movq %rbp, 0x20(%rsp)
cmpq 0x38(%rsp), %r15
jge 0x1b1ca
movb $0x0, 0x74(%rsp)
leaq 0x50(%rsp), %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x1bf5a
movq %rax, %r13
testq %rax, %rax
sete %al
cmpq %rbx, %r13
sete %cl
orb %al, %cl
je 0x1af55
cmpq 0x58(%rsp), %r14
jae 0x1b1ca
movq 0x288(%rsp), %rax
cmpq 0x280(%rsp), %rax
jb 0x1af30
leaq 0x278(%rsp), %rdi
pushq $0x1
popq %rsi
callq 0x132de
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 %rbx, %r13
jmp 0x1b1bc
incq %r15
movq %r15, 0x8(%rsp)
movq 0x68(%rsp), %r12
movq 0x28(%rsp), %rax
cmpl $0x5, %eax
je 0x1afa4
movq %r12, %rdi
pushq $0x3
popq %rsi
cmpl $0x6, %eax
jne 0x1b015
callq 0x5cee
leaq 0x50(%rsp), %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x1c33a
movq %r12, %rdi
movl %eax, %esi
pushq $0x1
popq %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x6bb0
jmp 0x1afc1
leaq 0x50(%rsp), %rdi
xorl %esi, %esi
movq %r14, %rdx
movq %r13, %rcx
callq 0x1c6a2
movq %r12, %rdi
pushq $0x3
popq %rsi
callq 0x648d
pushq $-0x1
popq %rbx
movq %r12, %rdi
movl %ebx, %esi
callq 0x5fa6
movq %r12, %rdi
testl %eax, %eax
je 0x1b18e
movl %ebx, %esi
callq 0x5d8e
testl %eax, %eax
jne 0x1b1a7
movq %r12, %rdi
movl %ebx, %esi
callq 0x5d12
movq %r12, %rdi
movl %eax, %esi
callq 0x5d31
movq %r12, %rdi
leaq 0x67c9(%rip), %rsi      # 0x217cf
movq %rax, %rdx
xorl %eax, %eax
callq 0x12bd6
jmp 0x1b1a7
leaq 0x48(%rsp), %rdx
callq 0x5fca
movq %rax, %rbx
movq %r13, %rax
subq %r14, %rax
movq %rax, 0x30(%rsp)
xorl %ebp, %ebp
cmpq 0x48(%rsp), %rbp
jae 0x1b184
movb (%rbx,%rbp), %al
cmpb $0x25, %al
jne 0x1b0bf
leaq 0x1(%rbp), %r15
callq 0x5520
movq (%rax), %rcx
movzbl 0x1(%rbx,%rbp), %eax
testb $0x8, 0x1(%rcx,%rax,2)
jne 0x1b105
cmpb $0x25, %al
je 0x1b075
movq %r12, %rdi
leaq 0x6785(%rip), %rsi      # 0x217f0
pushq $0x25
popq %rdx
xorl %eax, %eax
callq 0x12bd6
movq 0x288(%rsp), %rax
cmpq 0x280(%rsp), %rax
jb 0x1b09f
leaq 0x278(%rsp), %rdi
pushq $0x1
popq %rsi
callq 0x132de
movq 0x288(%rsp), %rax
movb (%rbx,%r15), %cl
movq 0x278(%rsp), %rdx
leaq 0x1(%rax), %rsi
movq %rsi, 0x288(%rsp)
movb %cl, (%rdx,%rax)
jmp 0x1b179
movq 0x288(%rsp), %rcx
cmpq 0x280(%rsp), %rcx
jb 0x1b0ec
leaq 0x278(%rsp), %rdi
pushq $0x1
popq %rsi
callq 0x132de
movb (%rbx,%rbp), %al
movq 0x288(%rsp), %rcx
movq 0x278(%rsp), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x288(%rsp)
movb %al, (%rdx,%rcx)
jmp 0x1b17c
cmpb $0x30, %al
jne 0x1b120
leaq 0x278(%rsp), %rdi
movq %r14, %rsi
movq 0x30(%rsp), %rdx
callq 0x13460
jmp 0x1b179
movsbl %al, %esi
addl $-0x31, %esi
leaq 0x50(%rsp), %rdi
movq %r14, %rdx
movq %r13, %rcx
callq 0x1c6a2
movq %r12, %rdi
pushq $-0x1
popq %rsi
xorl %edx, %edx
callq 0x13b27
movq %r12, %rdi
movq %r13, %rbp
movq %r14, %r13
pushq $-0x2
popq %r14
movl %r14d, %esi
pushq $-0x1
popq %rdx
callq 0x5b7f
movq %r12, %rdi
movl %r14d, %esi
movq %r13, %r14
movq %rbp, %r13
callq 0x5b31
leaq 0x278(%rsp), %rdi
callq 0x13515
movq %r15, %rbp
incq %rbp
jmp 0x1b02f
movq %r13, %r14
movq 0x20(%rsp), %rbp
jmp 0x1b1b7
pushq $-0x2
popq %rsi
callq 0x5b31
movq %r13, %rdx
subq %r14, %rdx
movq %r12, %rdi
movq %r14, %rsi
callq 0x616f
leaq 0x278(%rsp), %rdi
callq 0x13515
movq %r13, %r14
movq 0x8(%rsp), %r15
movq %r13, %rbx
cmpb $0x5e, 0x7(%rsp)
jne 0x1aec8
movq 0x58(%rsp), %rdx
subq %r14, %rdx
leaq 0x278(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x13460
movq %rbx, %rdi
callq 0x134ba
movq 0x18(%rsp), %rdi
movq %r15, %rsi
callq 0x615b
pushq $0x2
popq %rax
addq $0x2298, %rsp           # imm = 0x2298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq