// File: /workspace/github_c_makefile_star2_O0/deplinenoise[P]tundra/src/LuaProfiler.cpp
// Function: t2::FindFunction(lua_State*, lua_Debug*, unsigned int*)
static FunctionMeta* FindFunction(lua_State* L, lua_Debug* ar, uint32_t* hash_out)
{
  // This is slow, it involves string formatting. It's mostly OK, because we're
  // careful not to include this in the timings. It will of course affect cache
  // and other things. Not that we can make a lot of informed decisions about
  // that in an interpreted language anyway.
  if (!lua_getinfo(L, "Sn", ar))
    Croak("couldn't get debug info for function call");

  char buffer[1024];
  snprintf(buffer, sizeof(buffer), "%s;%s;%s;%d",
      ar->name ? ar->name : "", ar->namewhat ? ar->namewhat : "", ar->source, ar->linedefined);
  buffer[(sizeof buffer)-1] = 0;

  const uint32_t hash = Djb2Hash(buffer);
  *hash_out = hash;
  FunctionMeta** r = HashTableLookup(&s_Profiler.m_Functions, hash, buffer);

  if (!r) {
    FunctionMeta* meta = LinearAllocate<FunctionMeta>(s_Profiler.m_Allocator);
    HashTableInsert(&s_Profiler.m_Functions, hash, StrDup(s_Profiler.m_Allocator, buffer), meta);
    return meta;
  }
  
  return *r;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x470, %rsp            # imm = 0x470
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0x427f5(%rip), %rsi     # 0x4d73b
callq 0x2db40
cmpl $0x0, %eax
jne 0xaf5e
leaq 0x427e7(%rip), %rdi     # 0x4d73e
movb $0x0, %al
callq 0xba60
leaq -0x420(%rbp), %rax
movq %rax, -0x440(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0xaf88
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x448(%rbp)
jmp 0xaf98
leaq 0x4503b(%rip), %rax     # 0x4ffca
movq %rax, -0x448(%rbp)
jmp 0xaf98
movq -0x448(%rbp), %rax
movq %rax, -0x450(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0xafc2
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x458(%rbp)
jmp 0xafd2
leaq 0x45001(%rip), %rax     # 0x4ffca
movq %rax, -0x458(%rbp)
jmp 0xafd2
movq -0x450(%rbp), %rcx
movq -0x440(%rbp), %rdi
movq -0x458(%rbp), %r8
movq -0x18(%rbp), %rax
movq 0x20(%rax), %r9
movq -0x18(%rbp), %rax
movl 0x30(%rax), %eax
movl $0x400, %esi            # imm = 0x400
leaq 0x42766(%rip), %rdx     # 0x4d768
movl %eax, (%rsp)
movb $0x0, %al
callq 0x6740
movb $0x0, -0x21(%rbp)
leaq -0x420(%rbp), %rdi
callq 0xbd20
movl %eax, -0x424(%rbp)
movl -0x424(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl -0x424(%rbp), %esi
leaq -0x420(%rbp), %rdx
leaq 0x5893e(%rip), %rdi     # 0x63980
addq $0x18, %rdi
callq 0xb300
movq %rax, -0x430(%rbp)
cmpq $0x0, -0x430(%rbp)
jne 0xb0bb
movq 0x5892d(%rip), %rdi     # 0x63990
callq 0xb360
movq %rax, -0x438(%rbp)
movl -0x424(%rbp), %eax
movl %eax, -0x45c(%rbp)
movq 0x5890e(%rip), %rdi     # 0x63990
leaq -0x420(%rbp), %rsi
callq 0xb3e0
movl -0x45c(%rbp), %esi
movq %rax, %rdx
leaq 0x588e2(%rip), %rdi     # 0x63980
addq $0x18, %rdi
leaq -0x438(%rbp), %rcx
callq 0xb390
movq -0x438(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xb0c9
movq -0x430(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x470, %rsp            # imm = 0x470
popq %rbp
retq
nopw %cs:(%rax,%rax)