#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_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  scalar_t__ data;
};
typedef TYPE_1__ BUF_MEM;
typedef int /*<<< orphan*/ BIO;
typedef int /*<<< orphan*/ ASN1_ITEM;

/* Variables and functions */
void *ASN1_item_d2i(void *, unsigned char const **, int,
                    int /*<<< orphan*/ const *);
int /*<<< orphan*/ BUF_MEM_free(TYPE_1__ *);
int asn1_d2i_read_bio(int /*<<< orphan*/ *, TYPE_1__ **);
void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x) {
  BUF_MEM *b = NULL;
  const unsigned char *p;
  void *ret = NULL;
  int len;
  len = asn1_d2i_read_bio(in, &b);
  if (len < 0)
    goto err;
  p = (const unsigned char *)b->data;
  ret = ASN1_item_d2i(x, &p, len, it);
err:
  if (b != NULL)
    BUF_MEM_free(b);
  return (ret);
}


x86 assembly (clang, -O0):
<ASN1_item_d2i_bio>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <asn1_d2i_read_bio@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    1173 <ASN1_item_d2i_bio+0x43>
jmp    1196 <ASN1_item_d2i_bio+0x66>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x34(%rbp),%edx
mov    -0x8(%rbp),%rcx
lea    -0x28(%rbp),%rsi
call   1050 <ASN1_item_d2i@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11aa <ASN1_item_d2i_bio+0x7a>
mov    -0x20(%rbp),%rdi
call   1040 <BUF_MEM_free@plt>
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ASN1_item_d2i_bio>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%rbx
mov    %rsi,%rax
mov    %rdi,%r14
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
call   1030 <asn1_d2i_read_bio@plt>
test   %eax,%eax
js     117e <ASN1_item_d2i_bio+0x4e>
mov    0x8(%rsp),%rcx
mov    (%rcx),%rcx
mov    %rcx,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
mov    %r14,%rcx
call   1050 <ASN1_item_d2i@plt>
mov    %rax,%rbx
jmp    1180 <ASN1_item_d2i_bio+0x50>
xor    %ebx,%ebx
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     118f <ASN1_item_d2i_bio+0x5f>
call   1040 <BUF_MEM_free@plt>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i64 }
define i8* @ASN1_item_d2i_bio(i32* %0, i32* %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca %struct.TYPE_4__*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i8* %2, i8** %6
store %struct.TYPE_4__* null, %struct.TYPE_4__** %7
store i8* null, i8** %9
%11 = load i32*, i32** %5
%12 = call i32 @asn1_d2i_read_bio(i32* %11, %struct.TYPE_4__** %7)
store i32 %12, i32* %10
%13 = load i32, i32* %10
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %3
br label %25
16: ; preds = %3
%17 = load %struct.TYPE_4__*, %struct.TYPE_4__** %7
%18 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %17, i32 0, i32 0
%19 = load i64, i64* %18
%20 = inttoptr i64 %19 to i8*
store i8* %20, i8** %8
%21 = load i8*, i8** %6
%22 = load i32, i32* %10
%23 = load i32*, i32** %4
%24 = call i8* @ASN1_item_d2i(i8* %21, i8** %8, i32 %22, i32* %23)
store i8* %24, i8** %9
br label %25
25: ; preds = %16, %15
%26 = load %struct.TYPE_4__*, %struct.TYPE_4__** %7
%27 = icmp ne %struct.TYPE_4__* %26, null
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load %struct.TYPE_4__*, %struct.TYPE_4__** %7
%30 = call i32 @BUF_MEM_free(%struct.TYPE_4__* %29)
br label %31
31: ; preds = %28, %25
%32 = load i8*, i8** %9
ret i8* %32
}

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