// File: /workspace/github_c_makefile_star2_O1/fm4dd[P]learn-ssl/keytest.c
// Function: main
int main() {
   EVP_PKEY *pkey;
   FILE *fp;
   const char *type;
   int keysize = 0;

   /* ---------------------------------------------------------- *
    * Read private key from file into EVP_KEY structure          *
    * ---------------------------------------------------------- */
   pkey = EVP_PKEY_new();
   fp = fopen (CERTKEY, "r");
   PEM_read_PrivateKey( fp, &pkey, NULL, NULL);
   printf("Key File: %s loaded\n", CERTKEY);
   fclose(fp);

   /* ---------------------------------------------------------- *
    * Check the key type we loaded from file                     *
    * values are in evp.h: NONE RSA RSA2 DSA DSA1 DSA2 DSA3 DSA4 *
    * DH DHX EC HMAC CMAC SCRYPT.. All prefixed with EVP_KEY_xxx *
    * ---------------------------------------------------------- */
   int keyid = EVP_PKEY_get_id(pkey);
   if (EVP_PKEY_is_a(pkey, "RSA")) {
      type = "RSA";
      keysize = EVP_PKEY_get_bits(pkey);
   }
   else if (EVP_PKEY_is_a(pkey, "EC")) {
      keysize = EVP_PKEY_size(pkey);
   }

  /* ---------------------------------------------------------- *
   * Validate key parameters are correct, e.g. for RSA n = p*q  *
   * ---------------------------------------------------------- */
  EVP_PKEY_CTX *ctx;
  ctx = EVP_PKEY_CTX_new(pkey, NULL);
  if(EVP_PKEY_check(ctx) == 1)
     printf("Keycheck: validation success\n");
  else
     printf("Keycheck: validation failed\n");

  /* ---------------------------------------------------------- *
   * Here we print the key length and the curve type            *
   * ---------------------------------------------------------- */
  printf("Key Info: type %d %s with %d bits\n", keyid, type, keysize);

  /* ---------------------------------------------------------- *
   * Here we print the private/public key data in PEM format.   *
   * ---------------------------------------------------------- */
  if(!PEM_write_PrivateKey(stdout, pkey, NULL, NULL, 0, 0, NULL))
    printf("Error writing private key data in PEM format");

  if(!PEM_write_PUBKEY(stdout, pkey))
    printf("Error writing public key data in PEM format");
  exit(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
callq 0x1110
leaq 0x8(%rsp), %r14
movq %rax, (%r14)
leaq 0xdc8(%rip), %r15       # 0x2004
leaq 0xdd6(%rip), %rsi       # 0x2019
movq %r15, %rdi
callq 0x10a0
movq %rax, %r12
xorl %ebx, %ebx
movq %rax, %rdi
movq %r14, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1060
leaq 0xdb5(%rip), %rdi       # 0x201b
movq %r15, %rsi
xorl %eax, %eax
callq 0x1030
movq %r12, %rdi
callq 0x1080
movq (%r14), %rdi
callq 0x1070
movl %eax, %ebp
movq (%r14), %rdi
leaq 0xda4(%rip), %rsi       # 0x2030
callq 0x10c0
movq (%r14), %rdi
testl %eax, %eax
jne 0x12b4
leaq 0xd95(%rip), %rsi       # 0x2034
callq 0x10c0
testl %eax, %eax
je 0x12bb
movq 0x8(%rsp), %rdi
callq 0x1100
jmp 0x12b9
callq 0x1090
movl %eax, %ebx
movq 0x8(%rsp), %rdi
xorl %esi, %esi
callq 0x1050
movq %rax, %rdi
callq 0x10e0
cmpl $0x1, %eax
leaq 0xdf6(%rip), %rax       # 0x20cf
leaq 0xdd3(%rip), %rdi       # 0x20b3
cmoveq %rax, %rdi
callq 0x10d0
leaq 0xd47(%rip), %rdi       # 0x2037
leaq 0xd39(%rip), %rdx       # 0x2030
movl %ebp, %esi
movl %ebx, %ecx
xorl %eax, %eax
callq 0x1030
movq 0x2cc7(%rip), %rbx      # 0x3fd0
movq (%rbx), %rdi
movq 0x8(%rsp), %rsi
movq $0x0, (%rsp)
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x1040
testl %eax, %eax
jne 0x133a
leaq 0xd27(%rip), %rdi       # 0x205a
xorl %eax, %eax
callq 0x1030
movq (%rbx), %rdi
movq 0x8(%rsp), %rsi
callq 0x10f0
testl %eax, %eax
jne 0x1359
leaq 0xd35(%rip), %rdi       # 0x2087
xorl %eax, %eax
callq 0x1030
xorl %edi, %edi
callq 0x10b0