user: Converte this assembly snippet into its equivalent C code:

```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     L172
  mov    %rsi,%r13
  mov    %rdx,%rbx
  call   <get_evp_pkey@plt>
  mov    %rax,%r12
  test   %rax,%rax
  je     L116
  xor    %esi,%esi
  mov    %rax,%rdi
  call   <EVP_PKEY_CTX_new@plt>
  mov    %rax,%r14
  test   %rax,%rax
  je     L89
  mov    %rax,%rdi
  call   <EVP_PKEY_sign_init@plt>
  test   %rax,%rax
  jle    L52
  lea    0x10(%rsp),%rsi
  mov    %r14,%rdi
  movq   $0x0,0x10(%rsp)
  call   <EVP_PKEY_CTX_get_signature_md@plt>
  cmpq   $0x0,0x10(%rsp)
  lea    D114(%rip),%rdx
  lea    D54(%rip),%rdi
  mov    %eax,%esi
  lea    D20(%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    L171
  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    L84
  mov    0x8(%rsp),%rdi
  call   <malloc@plt>
  mov    %rax,0x0(%rbp)
  mov    %rax,%rsi
  test   %rax,%rax
  je     L97
  mov    %rbx,%r8
  mov    %r13,%rcx
  mov    %r15,%rdx
  mov    %r14,%rdi
  call   <EVP_PKEY_sign@plt>
  test   %rax,%rax
  jle    L103
  nopl   (%rax)
L172:
  mov    %r12,%rdi
  call   <EVP_PKEY_free@plt>
  mov    0x8(%rsp),%rsi
  xor    %eax,%eax
  lea    D102(%rip),%rdi
  call   <printf@plt>
  cmpq   $0x0,0x8(%rsp)
  je     L73
  xor    %ebx,%ebx
  lea    D81(%rip),%r12
  nopl   0x0(%rax)
L121:
  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     L121
L73:
  mov    0x18(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L117
  add    $0x28,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L116:
  lea    D64(%rip),%rdi
  call   <puts@plt>
  jmp    L172
  nopl   0x0(%rax)
L52:
  lea    D48(%rip),%rdi
  call   <puts@plt>
  jmp    L172
  nopl   0x0(%rax)
L89:
  lea    D74(%rip),%rdi
  call   <puts@plt>
  jmp    L172
L171:
  lea    D63(%rip),%rdi
  call   <puts@plt>
  jmp    L172
L103:
  lea    D77(%rip),%rdi
  call   <puts@plt>
  jmp    L172
L84:
  lea    D107(%rip),%rdi
  call   <puts@plt>
  jmp    L172
L97:
  lea    D53(%rip),%rdi
  call   <puts@plt>
  jmp    L172
L117:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: parse_data
arguments: tag: D114
type: string
name: parse_data
arguments: tag: D54
type: string
name: parse_data
arguments: tag: D20
type: string
name: parse_data
arguments: tag: D102
type: string
name: parse_data
arguments: tag: D81
type: string
name: parse_data
arguments: tag: D64
type: string
name: parse_data
arguments: tag: D48
type: string
name: parse_data
arguments: tag: D74
type: string
name: parse_data
arguments: tag: D63
type: string
name: parse_data
arguments: tag: D77
type: string
name: parse_data
arguments: tag: D107
type: string
name: parse_data
arguments: tag: D53
type: string

tool: D114: not null

tool: D54: md_type = %d%s


tool: D20: null

tool: D102: sign_len = %d


tool: D81: %02x 

tool: D64: Failed to load private key.

tool: D48: Failed to do sign init

tool: D74: Failed to create pkey ctx

tool: D63: Fail to set signature md

tool: D77: Failed to sign with pkey

tool: D107: Failed to get sign len

tool: D53: 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;
}
```