// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x22b0, %rsp           # imm = 0x22B0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movl $0x1, %esi
leaq -0x10(%rbp), %rdx
callq 0x20390
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movl $0x2, %esi
leaq -0x18(%rbp), %rdx
callq 0x20390
movq %rax, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movl $0x3, %esi
callq 0x61f0
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rdx
addq $0x1, %rdx
movl $0x4, %esi
callq 0x205e0
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x5e, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x44(%rbp)
movq $0x0, -0x50(%rbp)
movb $0x1, %al
cmpl $0x3, -0x34(%rbp)
movb %al, -0x22a1(%rbp)
je 0x2cc34
movb $0x1, %al
cmpl $0x4, -0x34(%rbp)
movb %al, -0x22a1(%rbp)
je 0x2cc34
movb $0x1, %al
cmpl $0x6, -0x34(%rbp)
movb %al, -0x22a1(%rbp)
je 0x2cc34
movb $0x1, %al
cmpl $0x5, -0x34(%rbp)
movb %al, -0x22a1(%rbp)
je 0x2cc34
movq -0x8(%rbp), %rdi
movl $0x3, %esi
leaq 0xa42d(%rip), %rdx      # 0x37050
callq 0x1fab0
cmpl $0x0, %eax
setne %al
movb %al, -0x22a1(%rbp)
movb -0x22a1(%rbp), %al
movq -0x8(%rbp), %rdi
leaq -0x2298(%rbp), %rsi
callq 0x20aa0
cmpl $0x0, -0x44(%rbp)
je 0x2cc68
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x10(%rbp), %rcx
movq -0x28(%rbp), %r8
movq -0x18(%rbp), %r9
leaq -0x278(%rbp), %rdi
callq 0x2e2d0
movq -0x50(%rbp), %rax
cmpq -0x40(%rbp), %rax
jge 0x2cd9b
leaq -0x278(%rbp), %rdi
callq 0x2e330
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
leaq -0x278(%rbp), %rdi
callq 0x2e350
movq %rax, -0x22a0(%rbp)
cmpq $0x0, %rax
je 0x2cd0f
movq -0x22a0(%rbp), %rax
cmpq -0x30(%rbp), %rax
je 0x2cd0f
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rdx
movq -0x22a0(%rbp), %rcx
movl -0x34(%rbp), %r8d
leaq -0x278(%rbp), %rdi
leaq -0x2298(%rbp), %rsi
callq 0x2fa70
movq -0x22a0(%rbp), %rax
movq %rax, -0x30(%rbp)
movq %rax, -0x20(%rbp)
jmp 0x2cd8e
movq -0x20(%rbp), %rax
cmpq -0x270(%rbp), %rax
jae 0x2cd8a
movq -0x2288(%rbp), %rcx
movb $0x1, %al
cmpq -0x2290(%rbp), %rcx
movb %al, -0x22a2(%rbp)
jb 0x2cd52
leaq -0x2298(%rbp), %rdi
movl $0x1, %esi
callq 0x20630
cmpq $0x0, %rax
setne %al
movb %al, -0x22a2(%rbp)
movb -0x22a2(%rbp), %al
movq -0x20(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rbp)
movb (%rax), %dl
movq -0x2298(%rbp), %rax
movq -0x2288(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x2288(%rbp)
movb %dl, (%rax,%rcx)
jmp 0x2cd8c
jmp 0x2cd9b
jmp 0x2cd8e
cmpl $0x0, -0x44(%rbp)
je 0x2cd96
jmp 0x2cd9b
jmp 0x2cc88
movq -0x20(%rbp), %rsi
movq -0x270(%rbp), %rdx
movq -0x20(%rbp), %rax
subq %rax, %rdx
leaq -0x2298(%rbp), %rdi
callq 0x208a0
leaq -0x2298(%rbp), %rdi
callq 0x20940
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x6be0
movl $0x2, %eax
addq $0x22b0, %rsp           # imm = 0x22B0
popq %rbp
retq