#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ EVP_PKEY;

/* Variables and functions */
int /*<<< orphan*/ ERR_print_errors_fp(int /*<<< orphan*/);
int /*<<< orphan*/ EVP_PKEY_free(int /*<<< orphan*/ *);
int EVP_PKEY_id(int /*<<< orphan*/ *);
int /*<<< orphan*/ *d2i_AutoPrivateKey(int /*<<< orphan*/ *,
                                       unsigned char const **, size_t);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int test_d2i_AutoPrivateKey(const unsigned char *input, size_t input_len,
                            int expected_id) {
  int ret = 0;
  const unsigned char *p;
  EVP_PKEY *pkey = NULL;
  p = input;
  pkey = d2i_AutoPrivateKey(NULL, &p, input_len);
  if (pkey == NULL || p != input + input_len) {
    fprintf(stderr, "d2i_AutoPrivateKey failed\n");
    goto done;
  }
  if (EVP_PKEY_id(pkey) != expected_id) {
    fprintf(stderr, "Did not decode expected type\n");
    goto done;
  }
  ret = 1;
done:
  if (!ret) {
    ERR_print_errors_fp(stderr);
  }
  EVP_PKEY_free(pkey);
  return ret;
}


x86 assembly (clang, -O0):
<test_d2i_AutoPrivateKey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%edi
lea    -0x20(%rbp),%rsi
call   1050 <d2i_AutoPrivateKey@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11af <test_d2i_AutoPrivateKey+0x5f>
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rcx
add    -0x10(%rbp),%rcx
cmp    %rcx,%rax
je     11c9 <test_d2i_AutoPrivateKey+0x79>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
lea    0xe41(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11fc <test_d2i_AutoPrivateKey+0xac>
mov    -0x28(%rbp),%rdi
call   1060 <EVP_PKEY_id@plt>
cmp    -0x14(%rbp),%eax
je     11f5 <test_d2i_AutoPrivateKey+0xa5>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
lea    0xe30(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11fc <test_d2i_AutoPrivateKey+0xac>
movl   $0x1,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    1214 <test_d2i_AutoPrivateKey+0xc4>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
call   1070 <ERR_print_errors_fp@plt>
mov    -0x28(%rbp),%rdi
call   1030 <EVP_PKEY_free@plt>
mov    -0x18(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_d2i_AutoPrivateKey>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%rbp
mov    %rdi,%rbx
mov    %rdi,(%rsp)
mov    %rsp,%rsi
xor    %edi,%edi
mov    %rbp,%rdx
call   1050 <d2i_AutoPrivateKey@plt>
mov    %rax,%r15
lea    0xe85(%rip),%rsi
test   %rax,%rax
je     11a2 <test_d2i_AutoPrivateKey+0x52>
add    %rbp,%rbx
cmp    %rbx,(%rsp)
jne    11a2 <test_d2i_AutoPrivateKey+0x52>
mov    %r15,%rdi
call   1060 <EVP_PKEY_id@plt>
mov    $0x1,%ebx
cmp    %r14d,%eax
je     11b9 <test_d2i_AutoPrivateKey+0x69>
lea    0xe79(%rip),%rsi
mov    0x2e37(%rip),%rbx
mov    (%rbx),%edi
call   1040 <fprintf@plt>
mov    (%rbx),%edi
call   1070 <ERR_print_errors_fp@plt>
xor    %ebx,%ebx
mov    %r15,%rdi
call   1030 <EVP_PKEY_free@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"d2i_AutoPrivateKey failed\0A\00"
@.str.1 = [30 x i8] c"Did not decode expected type\0A\00"
define i32 @test_d2i_AutoPrivateKey(i8* %0, i64 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32*
store i8* %0, i8** %4
store i64 %1, i64* %5
store i32 %2, i32* %6
store i32 0, i32* %7
store i32* null, i32** %9
%10 = load i8*, i8** %4
store i8* %10, i8** %8
%11 = load i64, i64* %5
%12 = call i32* @d2i_AutoPrivateKey(i32* null, i8** %8, i64 %11)
store i32* %12, i32** %9
%13 = load i32*, i32** %9
%14 = icmp eq i32* %13, null
br i1 %14, label %21, label %15
15: ; preds = %3
%16 = load i8*, i8** %8
%17 = load i8*, i8** %4
%18 = load i64, i64* %5
%19 = getelementptr inbounds i8, i8* %17, i64 %18
%20 = icmp ne i8* %16, %19
br i1 %20, label %21, label %24
21: ; preds = %15, %3
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %33
24: ; preds = %15
%25 = load i32*, i32** %9
%26 = call i32 @EVP_PKEY_id(i32* %25)
%27 = load i32, i32* %6
%28 = icmp ne i32 %26, %27
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %33
32: ; preds = %24
store i32 1, i32* %7
br label %33
33: ; preds = %32, %29, %21
%34 = load i32, i32* %7
%35 = icmp ne i32 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %33
%37 = load i32, i32* @stderr
%38 = call i32 @ERR_print_errors_fp(i32 %37)
br label %39
39: ; preds = %36, %33
%40 = load i32*, i32** %9
%41 = call i32 @EVP_PKEY_free(i32* %40)
%42 = load i32, i32* %7
ret i32 %42
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"d2i_AutoPrivateKey failed\0A\00"
@.str.1 = [30 x i8] c"Did not decode expected type\0A\00"
define i32 @test_d2i_AutoPrivateKey(i8* %0, i64 %1, i32 %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
store i8* %0, i8** %4
%6 = call i32* @d2i_AutoPrivateKey(i32* null, i8** %4, i64 %1)
%7 = icmp ne i32* %6, null
%8 = load i8*, i8** %4
%9 = getelementptr inbounds i8, i8* %0, i64 %1
%10 = icmp eq i8* %8, %9
%11 = select i1 %7, i1 %10, i1 false
br i1 %11, label %12, label %15
12: ; preds = %3
%13 = call i32 @EVP_PKEY_id(i32* %6)
%14 = icmp eq i32 %13, %2
br i1 %14, label %21, label %15
15: ; preds = %12, %3
%16 = phi i8* [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), %3 ], [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), %12 ]
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* %16)
%19 = load i32, i32* @stderr
%20 = call i32 @ERR_print_errors_fp(i32 %19)
br label %21
21: ; preds = %12, %15
%22 = phi i32 [ 0, %15 ], [ 1, %12 ]
%23 = call i32 @EVP_PKEY_free(i32* %6)
ret i32 %22
}