user: 请从给定的汇编指令推导出C源代码:

```asm
<load_programs>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x30,%rsp
  mov    %rdi,-0x18(%rbp)
  mov    %rsi,-0x20(%rbp)
  mov    %edx,-0x24(%rbp)
  mov    %rcx,-0x30(%rbp)
  movq   $0xffffffff80000000,-0x8(%rbp)
  movl   $0x0,-0xc(%rbp)
  jmp    L16
L42:
  mov    -0xc(%rbp),%eax
  movslq %eax,%rdx
  mov    %rdx,%rax
  shl    $0x2,%rax
  add    %rdx,%rax
  shl    $0x3,%rax
  mov    %rax,%rdx
  mov    -0x20(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%rdx
  mov    D0(%rip),%rax
  mov    (%rax),%rax
  cmp    %rax,%rdx
  jne    L4
  mov    -0xc(%rbp),%eax
  movslq %eax,%rdx
  mov    %rdx,%rax
  shl    $0x2,%rax
  add    %rdx,%rax
  shl    $0x3,%rax
  mov    %rax,%rdx
  mov    -0x20(%rbp),%rax
  add    %rdx,%rax
  mov    0x18(%rax),%rdx
  mov    -0xc(%rbp),%eax
  movslq %eax,%rcx
  mov    %rcx,%rax
  shl    $0x2,%rax
  add    %rcx,%rax
  shl    $0x3,%rax
  mov    %rax,%rcx
  mov    -0x20(%rbp),%rax
  add    %rcx,%rax
  mov    0x10(%rax),%eax
  movslq %eax,%rcx
  mov    -0x18(%rbp),%rax
  add    %rax,%rcx
  mov    -0xc(%rbp),%eax
  movslq %eax,%rsi
  mov    %rsi,%rax
  shl    $0x2,%rax
  add    %rsi,%rax
  shl    $0x3,%rax
  mov    %rax,%rsi
  mov    -0x20(%rbp),%rax
  add    %rsi,%rax
  mov    0x8(%rax),%rax
  sub    -0x30(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <memcpy@plt>
  mov    -0xc(%rbp),%eax
  movslq %eax,%rdx
  mov    %rdx,%rax
  shl    $0x2,%rax
  add    %rdx,%rax
  shl    $0x3,%rax
  mov    %rax,%rdx
  mov    -0x20(%rbp),%rax
  add    %rdx,%rax
  mov    0x18(%rax),%rcx
  mov    -0xc(%rbp),%eax
  movslq %eax,%rdx
  mov    %rdx,%rax
  shl    $0x2,%rax
  add    %rdx,%rax
  shl    $0x3,%rax
  mov    %rax,%rdx
  mov    -0x20(%rbp),%rax
  add    %rdx,%rax
  mov    0x20(%rax),%rax
  cmp    %rax,%rcx
  jae    L39
  mov    -0xc(%rbp),%eax
  movslq %eax,%rdx
  mov    %rdx,%rax
  shl    $0x2,%rax
  add    %rdx,%rax
  shl    $0x3,%rax
  mov    %rax,%rdx
  mov    -0x20(%rbp),%rax
  add    %rdx,%rax
  mov    0x20(%rax),%rcx
  mov    -0xc(%rbp),%eax
  movslq %eax,%rdx
  mov    %rdx,%rax
  shl    $0x2,%rax
  add    %rdx,%rax
  shl    $0x3,%rax
  mov    %rax,%rdx
  mov    -0x20(%rbp),%rax
  add    %rdx,%rax
  mov    0x18(%rax),%rax
  sub    %rax,%rcx
  mov    %rcx,%rdx
  mov    -0xc(%rbp),%eax
  movslq %eax,%rcx
  mov    %rcx,%rax
  shl    $0x2,%rax
  add    %rcx,%rax
  shl    $0x3,%rax
  mov    %rax,%rcx
  mov    -0x20(%rbp),%rax
  add    %rcx,%rax
  mov    0x8(%rax),%rsi
  mov    -0xc(%rbp),%eax
  movslq %eax,%rcx
  mov    %rcx,%rax
  shl    $0x2,%rax
  add    %rcx,%rax
  shl    $0x3,%rax
  mov    %rax,%rcx
  mov    -0x20(%rbp),%rax
  add    %rcx,%rax
  mov    0x18(%rax),%rax
  add    %rsi,%rax
  sub    -0x30(%rbp),%rax
  mov    $0x0,%esi
  mov    %rax,%rdi
  call   <memset@plt>
L39:
  mov    -0xc(%rbp),%eax
  movslq %eax,%rdx
  mov    %rdx,%rax
  shl    $0x2,%rax
  add    %rdx,%rax
  shl    $0x3,%rax
  mov    %rax,%rdx
  mov    -0x20(%rbp),%rax
  add    %rdx,%rax
  mov    0x8(%rax),%rcx
  mov    -0xc(%rbp),%eax
  movslq %eax,%rdx
  mov    %rdx,%rax
  shl    $0x2,%rax
  add    %rdx,%rax
  shl    $0x3,%rax
  mov    %rax,%rdx
  mov    -0x20(%rbp),%rax
  add    %rdx,%rax
  mov    0x20(%rax),%rax
  add    %rcx,%rax
  cmp    %rax,-0x8(%rbp)
  jae    L4
  mov    -0xc(%rbp),%eax
  movslq %eax,%rdx
  mov    %rdx,%rax
  shl    $0x2,%rax
  add    %rdx,%rax
  shl    $0x3,%rax
  mov    %rax,%rdx
  mov    -0x20(%rbp),%rax
  add    %rdx,%rax
  mov    0x8(%rax),%rcx
  mov    -0xc(%rbp),%eax
  movslq %eax,%rdx
  mov    %rdx,%rax
  shl    $0x2,%rax
  add    %rdx,%rax
  shl    $0x3,%rax
  mov    %rax,%rdx
  mov    -0x20(%rbp),%rax
  add    %rdx,%rax
  mov    0x20(%rax),%rax
  add    %rcx,%rax
  mov    %rax,-0x8(%rbp)
L4:
  addl   $0x1,-0xc(%rbp)
L16:
  mov    -0xc(%rbp),%eax
  cmp    -0x24(%rbp),%eax
  jl     L42
  mov    -0x8(%rbp),%rax
  leave
  ret
```

assistant: ```c
unsigned long load_programs(unsigned char *image, Elf64_Phdr *hdrs, int nhdr, unsigned long offset) {
  int i;
  unsigned long end = 0xffffffff80000000UL;
  for (i = 0; i < nhdr; i++) {
    if (hdrs[i].p_type == PT_LOAD) {
      memcpy((void *)(hdrs[i].p_vaddr - offset), image + hdrs[i].p_offset, hdrs[i].p_filesz);
      if (hdrs[i].p_filesz < hdrs[i].p_memsz) {
        memset((void *)(hdrs[i].p_vaddr + hdrs[i].p_filesz - offset), 0, hdrs[i].p_memsz - hdrs[i].p_filesz);
      }
      if (end < hdrs[i].p_vaddr + hdrs[i].p_memsz) {
        end = hdrs[i].p_vaddr + hdrs[i].p_memsz;
      }
    }
  }
  return end;
}
```