#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ X509_EXTENSION;
struct TYPE_3__ {
  void *(*d2i)(int /*<<< orphan*/ *, unsigned char const **, int);
  scalar_t__ it;
};
typedef TYPE_1__ X509V3_EXT_METHOD;
typedef int /*<<< orphan*/ ASN1_STRING;

/* Variables and functions */
int /*<<< orphan*/ ASN1_ITEM_ptr(scalar_t__);
unsigned char *ASN1_STRING_get0_data(int /*<<< orphan*/ *);
int ASN1_STRING_length(int /*<<< orphan*/ *);
void *ASN1_item_d2i(int /*<<< orphan*/ *, unsigned char const **, int,
                    int /*<<< orphan*/);
TYPE_1__ *X509V3_EXT_get(int /*<<< orphan*/ *);
int /*<<< orphan*/ *X509_EXTENSION_get_data(int /*<<< orphan*/ *);
void *stub1(int /*<<< orphan*/ *, unsigned char const **, int);
void *X509V3_EXT_d2i(X509_EXTENSION *ext) {
  const X509V3_EXT_METHOD *method;
  const unsigned char *p;
  ASN1_STRING *extvalue;
  int extlen;
  if ((method = X509V3_EXT_get(ext)) == NULL)
    return NULL;
  extvalue = X509_EXTENSION_get_data(ext);
  p = ASN1_STRING_get0_data(extvalue);
  extlen = ASN1_STRING_length(extvalue);
  if (method->it)
    return ASN1_item_d2i(NULL, &p, extlen, ASN1_ITEM_ptr(method->it));
  return method->d2i(NULL, &p, extlen);
}


x86 assembly (clang, -O0):
<X509V3_EXT_d2i>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <X509V3_EXT_get@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1190 <X509V3_EXT_d2i+0x30>
movq   $0x0,-0x8(%rbp)
jmp    120b <X509V3_EXT_d2i+0xab>
mov    -0x10(%rbp),%rdi
call   1050 <X509_EXTENSION_get_data@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <ASN1_STRING_get0_data@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <ASN1_STRING_length@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     11f3 <X509V3_EXT_d2i+0x93>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <ASN1_ITEM_ptr@plt>
mov    -0x30(%rbp),%edx
mov    %eax,%ecx
xor    %eax,%eax
mov    %eax,%edi
lea    -0x20(%rbp),%rsi
call   1060 <ASN1_item_d2i@plt>
mov    %rax,-0x8(%rbp)
jmp    120b <X509V3_EXT_d2i+0xab>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    -0x2c(%rbp),%edx
xor    %ecx,%ecx
mov    %ecx,%edi
lea    -0x20(%rbp),%rsi
call   *%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<X509V3_EXT_d2i>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbp
call   1080 <X509V3_EXT_get@plt>
test   %rax,%rax
je     11b2 <X509V3_EXT_d2i+0x52>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1050 <X509_EXTENSION_get_data@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1070 <ASN1_STRING_get0_data@plt>
mov    %rax,(%rsp)
mov    %rbp,%rdi
call   1030 <ASN1_STRING_length@plt>
mov    %eax,%ebp
mov    0x8(%rbx),%rdi
test   %rdi,%rdi
je     11b6 <X509V3_EXT_d2i+0x56>
call   1040 <ASN1_ITEM_ptr@plt>
mov    %rsp,%rsi
xor    %edi,%edi
mov    %ebp,%edx
mov    %eax,%ecx
call   1060 <ASN1_item_d2i@plt>
jmp    11bf <X509V3_EXT_d2i+0x5f>
xor    %eax,%eax
jmp    11bf <X509V3_EXT_d2i+0x5f>
mov    %rsp,%rsi
xor    %edi,%edi
mov    %ebp,%edx
call   *(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i8* (i32*, i8**, i32)*, i64 }
define i8* @X509V3_EXT_d2i(i32* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca %struct.TYPE_3__*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
store i32* %0, i32** %3
%8 = load i32*, i32** %3
%9 = call %struct.TYPE_3__* @X509V3_EXT_get(i32* %8)
store %struct.TYPE_3__* %9, %struct.TYPE_3__** %4
%10 = icmp eq %struct.TYPE_3__* %9, null
br i1 %10, label %11, label %12
11: ; preds = %1
store i8* null, i8** %2
br label %36
12: ; preds = %1
%13 = load i32*, i32** %3
%14 = call i32* @X509_EXTENSION_get_data(i32* %13)
store i32* %14, i32** %6
%15 = load i32*, i32** %6
%16 = call i8* @ASN1_STRING_get0_data(i32* %15)
store i8* %16, i8** %5
%17 = load i32*, i32** %6
%18 = call i32 @ASN1_STRING_length(i32* %17)
store i32 %18, i32* %7
%19 = load %struct.TYPE_3__*, %struct.TYPE_3__** %4
%20 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %19, i32 0, i32 1
%21 = load i64, i64* %20
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %30
23: ; preds = %12
%24 = load i32, i32* %7
%25 = load %struct.TYPE_3__*, %struct.TYPE_3__** %4
%26 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %25, i32 0, i32 1
%27 = load i64, i64* %26
%28 = call i32 @ASN1_ITEM_ptr(i64 %27)
%29 = call i8* @ASN1_item_d2i(i32* null, i8** %5, i32 %24, i32 %28)
store i8* %29, i8** %2
br label %36
30: ; preds = %12
%31 = load %struct.TYPE_3__*, %struct.TYPE_3__** %4
%32 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %31, i32 0, i32 0
%33 = load i8* (i32*, i8**, i32)*, i8* (i32*, i8**, i32)** %32
%34 = load i32, i32* %7
%35 = call i8* %33(i32* null, i8** %5, i32 %34)
store i8* %35, i8** %2
br label %36
36: ; preds = %30, %23, %11
%37 = load i8*, i8** %2
ret i8* %37
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i8* (i32*, i8**, i32)*, i64 }
define i8* @X509V3_EXT_d2i(i32* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = tail call %struct.TYPE_3__* @X509V3_EXT_get(i32* %0)
%5 = icmp eq %struct.TYPE_3__* %4, null
br i1 %5, label %20, label %6
6: ; preds = %1
%7 = tail call i32* @X509_EXTENSION_get_data(i32* %0)
%8 = tail call i8* @ASN1_STRING_get0_data(i32* %7)
store i8* %8, i8** %2
%9 = tail call i32 @ASN1_STRING_length(i32* %7)
%10 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %4, i64 0, i32 1
%11 = load i64, i64* %10
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %6
%14 = tail call i32 @ASN1_ITEM_ptr(i64 %11)
%15 = call i8* @ASN1_item_d2i(i32* null, i8** %2, i32 %9, i32 %14)
br label %20
16: ; preds = %6
%17 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %4, i64 0, i32 0
%18 = load i8* (i32*, i8**, i32)*, i8* (i32*, i8**, i32)** %17
%19 = call i8* %18(i32* null, i8** %2, i32 %9)
br label %20
20: ; preds = %1, %16, %13
%21 = phi i8* [ %15, %13 ], [ %19, %16 ], [ null, %1 ]
ret i8* %21
}