user: 请显示与下面列出的汇编代码相匹配的C语言实现：

```asm
<sign_by_pkey>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  xor    %r12d,%r12d
  push   %rbp
  mov    %rcx,%rbp
  push   %rbx
  sub    $0x28,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x18(%rsp)
  xor    %eax,%eax
  movq   $0x0,0x8(%rsp)
  test   %rcx,%rcx
  je     L132
  mov    %rsi,%r13
  mov    %rdx,%rbx
  call   <get_evp_pkey@plt>
  mov    %rax,%r12
  test   %rax,%rax
  je     L109
  xor    %esi,%esi
  mov    %rax,%rdi
  call   <EVP_PKEY_CTX_new@plt>
  mov    %rax,%r14
  test   %rax,%rax
  je     L53
  mov    %rax,%rdi
  call   <EVP_PKEY_sign_init@plt>
  test   %rax,%rax
  jle    L47
  lea    0x10(%rsp),%rsi
  mov    %r14,%rdi
  movq   $0x0,0x10(%rsp)
  call   <EVP_PKEY_CTX_get_signature_md@plt>
  cmpq   $0x0,0x10(%rsp)
  lea    D13(%rip),%rdx
  lea    D108(%rip),%rdi
  mov    %eax,%esi
  lea    D45(%rip),%rax
  cmove  %rax,%rdx
  xor    %eax,%eax
  call   <printf@plt>
  xor    %eax,%eax
  call   <EVP_sha256@plt>
  mov    %r14,%rdi
  mov    %eax,%esi
  call   <EVP_PKEY_CTX_set_signature_md@plt>
  test   %rax,%rax
  jle    L105
  lea    0x8(%rsp),%r15
  xor    %esi,%esi
  mov    %rbx,%r8
  mov    %r13,%rcx
  mov    %r15,%rdx
  mov    %r14,%rdi
  call   <EVP_PKEY_sign@plt>
  test   %rax,%rax
  jle    L154
  mov    0x8(%rsp),%rdi
  call   <malloc@plt>
  mov    %rax,0x0(%rbp)
  mov    %rax,%rsi
  test   %rax,%rax
  je     L166
  mov    %rbx,%r8
  mov    %r13,%rcx
  mov    %r15,%rdx
  mov    %r14,%rdi
  call   <EVP_PKEY_sign@plt>
  test   %rax,%rax
  jle    L157
  nopl   (%rax)
L132:
  mov    %r12,%rdi
  call   <EVP_PKEY_free@plt>
  mov    0x8(%rsp),%rsi
  xor    %eax,%eax
  lea    D57(%rip),%rdi
  call   <printf@plt>
  cmpq   $0x0,0x8(%rsp)
  je     L55
  xor    %ebx,%ebx
  lea    D48(%rip),%r12
  nopl   0x0(%rax)
L114:
  mov    0x0(%rbp),%rax
  mov    %r12,%rdi
  mov    (%rax,%rbx,4),%esi
  xor    %eax,%eax
  add    $0x1,%rbx
  call   <printf@plt>
  cmp    %rbx,0x8(%rsp)
  ja     L114
L55:
  mov    0x18(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L113
  add    $0x28,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L109:
  lea    D29(%rip),%rdi
  call   <puts@plt>
  jmp    L132
  nopl   0x0(%rax)
L47:
  lea    D68(%rip),%rdi
  call   <puts@plt>
  jmp    L132
  nopl   0x0(%rax)
L53:
  lea    D77(%rip),%rdi
  call   <puts@plt>
  jmp    L132
L105:
  lea    D72(%rip),%rdi
  call   <puts@plt>
  jmp    L132
L157:
  lea    D43(%rip),%rdi
  call   <puts@plt>
  jmp    L132
L154:
  lea    D89(%rip),%rdi
  call   <puts@plt>
  jmp    L132
L166:
  lea    D33(%rip),%rdi
  call   <puts@plt>
  jmp    L132
L113:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: read_data
arguments: data_tag: D13
datatype: string
name: read_data
arguments: data_tag: D108
datatype: string
name: read_data
arguments: data_tag: D45
datatype: string
name: read_data
arguments: data_tag: D57
datatype: string
name: read_data
arguments: data_tag: D48
datatype: string
name: read_data
arguments: data_tag: D29
datatype: string
name: read_data
arguments: data_tag: D68
datatype: string
name: read_data
arguments: data_tag: D77
datatype: string
name: read_data
arguments: data_tag: D72
datatype: string
name: read_data
arguments: data_tag: D43
datatype: string
name: read_data
arguments: data_tag: D89
datatype: string
name: read_data
arguments: data_tag: D33
datatype: string

tool: D13: not null

tool: D108: md_type = %d%s


tool: D45: null

tool: D57: sign_len = %d


tool: D48: %02x 

tool: D29: Failed to load private key.

tool: D68: Failed to do sign init

tool: D77: Failed to create pkey ctx

tool: D72: Fail to set signature md

tool: D43: Failed to sign with pkey

tool: D89: Failed to get sign len

tool: D33: Failed to allocate mem for sign

assistant: ```c
int sign_by_pkey(const char *pkey_file, uint8_t *sign_data, size_t sdata_len, uint8_t **out) {
  size_t sign_len = 0;
  EVP_PKEY_CTX *ctx;
  EVP_PKEY *pkey = NULL;
  do {
    if (!out)
      break;
    if (!(pkey = get_evp_pkey(pkey_file))) {
      printf("Failed to load private key."
             "\n");
      break;
    }
    ctx = EVP_PKEY_CTX_new(pkey, NULL);
    if (!ctx) {
      printf("Failed to create pkey ctx"
             "\n");
      break;
    }
    if (EVP_PKEY_sign_init(ctx) <= 0) {
      printf("Failed to do sign init"
             "\n");
      break;
    }
    EVP_MD *md_ptr = NULL;
    int md_type = EVP_PKEY_CTX_get_signature_md(ctx, &md_ptr);
    printf("md_type = %d%s\n", md_type, md_ptr ? "not null" : "null");
    if (EVP_PKEY_CTX_set_signature_md(ctx, EVP_sha256()) <= 0) {
      printf("Fail to set signature md"
             "\n");
      break;
    }
    if (EVP_PKEY_sign(ctx, NULL, &sign_len, sign_data, sdata_len) <= 0) {
      printf("Failed to get sign len"
             "\n");
      break;
    }
    *out = malloc(sign_len);
    if (!*out) {
      printf("Failed to allocate mem for sign"
             "\n");
      break;
    }
    if (EVP_PKEY_sign(ctx, *out, &sign_len, sign_data, sdata_len) <= 0) {
      printf("Failed to sign with pkey"
             "\n");
      break;
    }
  } while (0);
  EVP_PKEY_free(pkey);
  printf("sign_len = %d\n", sign_len);
  for (int i = 0; i < sign_len; i++) {
    printf("%02x ", (*out)[i]);
  }
  return 0;
}
```