// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movl $0x0, -0x4(%rbp)
movl $0x0, -0x24(%rbp)
callq 0x1100
movq %rax, -0x10(%rbp)
leaq 0xdce(%rip), %rdi       # 0x2004
leaq 0xddc(%rip), %rsi       # 0x2019
callq 0x10a0
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
leaq -0x10(%rbp), %rsi
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rdx
callq 0x1060
leaq 0xdba(%rip), %rdi       # 0x201b
leaq 0xd9c(%rip), %rsi       # 0x2004
movb $0x0, %al
callq 0x1030
movq -0x18(%rbp), %rdi
callq 0x1080
movq -0x10(%rbp), %rdi
callq 0x1070
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
leaq 0xda1(%rip), %rsi       # 0x2030
callq 0x10c0
cmpl $0x0, %eax
je 0x12b2
leaq 0xd90(%rip), %rax       # 0x2030
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1090
movl %eax, -0x24(%rbp)
jmp 0x12d5
movq -0x10(%rbp), %rdi
leaq 0xd77(%rip), %rsi       # 0x2034
callq 0x10c0
cmpl $0x0, %eax
je 0x12d3
movq -0x10(%rbp), %rdi
callq 0x10f0
movl %eax, -0x24(%rbp)
jmp 0x12d5
movq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1050
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x10d0
cmpl $0x1, %eax
jne 0x1304
leaq 0xd3c(%rip), %rdi       # 0x2037
movb $0x0, %al
callq 0x1030
jmp 0x1312
leaq 0xd4a(%rip), %rdi       # 0x2055
movb $0x0, %al
callq 0x1030
movl -0x28(%rbp), %esi
movq -0x20(%rbp), %rdx
movl -0x24(%rbp), %ecx
leaq 0xd4f(%rip), %rdi       # 0x2072
movb $0x0, %al
callq 0x1030
movq 0x2c9f(%rip), %rax      # 0x3fd0
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
xorl %eax, %eax
movl %eax, %r9d
xorl %r8d, %r8d
movq %r9, %rdx
movq %r9, %rcx
movq $0x0, (%rsp)
callq 0x1040
cmpl $0x0, %eax
jne 0x1366
leaq 0xd36(%rip), %rdi       # 0x2095
movb $0x0, %al
callq 0x1030
movq 0x2c63(%rip), %rax      # 0x3fd0
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0x10e0
cmpl $0x0, %eax
jne 0x138c
leaq 0xd3d(%rip), %rdi       # 0x20c2
movb $0x0, %al
callq 0x1030
xorl %edi, %edi
callq 0x10b0