#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*/ ASN1_ITEM;

/* Variables and functions */
int /*<<< orphan*/ ASN1_F_ASN1_ITEM_DUP;
void *ASN1_item_d2i(int /*<<< orphan*/ *, unsigned char const **, long,
                    int /*<<< orphan*/ const *);
long ASN1_item_i2d(void *, unsigned char **, int /*<<< orphan*/ const *);
int /*<<< orphan*/ ASN1err(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ ERR_R_MALLOC_FAILURE;
int /*<<< orphan*/ free(unsigned char *);
void *ASN1_item_dup(const ASN1_ITEM *it, void *x) {
  unsigned char *b = NULL;
  const unsigned char *p;
  long i;
  void *ret;
  if (x == NULL)
    return (NULL);
  i = ASN1_item_i2d(x, &b, it);
  if (b == NULL) {
    ASN1err(ASN1_F_ASN1_ITEM_DUP, ERR_R_MALLOC_FAILURE);
    return (NULL);
  }
  p = b;
  ret = ASN1_item_d2i(NULL, &p, i, it);
  free(b);
  return (ret);
}


x86 assembly (clang, -O0):
<ASN1_item_dup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1170 <ASN1_item_dup+0x30>
movq   $0x0,-0x8(%rbp)
jmp    11e6 <ASN1_item_dup+0xa6>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    -0x20(%rbp),%rsi
call   1060 <ASN1_item_i2d@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b4 <ASN1_item_dup+0x74>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
call   1040 <ASN1err@plt>
movq   $0x0,-0x8(%rbp)
jmp    11e6 <ASN1_item_dup+0xa6>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rdx
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%edi
lea    -0x28(%rbp),%rsi
call   1050 <ASN1_item_d2i@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ASN1_item_dup>:
push   %rbx
sub    $0x10,%rsp
movq   $0x0,(%rsp)
test   %rsi,%rsi
je     11ab <ASN1_item_dup+0x6b>
mov    %rdi,%rbx
mov    %rsp,%rax
mov    %rsi,%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
call   1060 <ASN1_item_i2d@plt>
mov    (%rsp),%rcx
test   %rcx,%rcx
je     1194 <ASN1_item_dup+0x54>
mov    %rcx,0x8(%rsp)
lea    0x8(%rsp),%rsi
xor    %edi,%edi
mov    %rax,%rdx
mov    %rbx,%rcx
call   1050 <ASN1_item_d2i@plt>
mov    %rax,%rbx
mov    (%rsp),%rdi
call   1030 <free@plt>
jmp    11ad <ASN1_item_dup+0x6d>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
call   1040 <ASN1err@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@ASN1_F_ASN1_ITEM_DUP = global i32 0
@ERR_R_MALLOC_FAILURE = global i32 0
define i8* @ASN1_item_dup(i32* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
store i32* %0, i32** %4
store i8* %1, i8** %5
store i8* null, i8** %6
%10 = load i8*, i8** %5
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %2
store i8* null, i8** %3
br label %31
13: ; preds = %2
%14 = load i8*, i8** %5
%15 = load i32*, i32** %4
%16 = call i64 @ASN1_item_i2d(i8* %14, i8** %6, i32* %15)
store i64 %16, i64* %8
%17 = load i8*, i8** %6
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %23
19: ; preds = %13
%20 = load i32, i32* @ASN1_F_ASN1_ITEM_DUP
%21 = load i32, i32* @ERR_R_MALLOC_FAILURE
%22 = call i32 @ASN1err(i32 %20, i32 %21)
store i8* null, i8** %3
br label %31
23: ; preds = %13
%24 = load i8*, i8** %6
store i8* %24, i8** %7
%25 = load i64, i64* %8
%26 = load i32*, i32** %4
%27 = call i8* @ASN1_item_d2i(i32* null, i8** %7, i64 %25, i32* %26)
store i8* %27, i8** %9
%28 = load i8*, i8** %6
%29 = call i32 @free(i8* %28)
%30 = load i8*, i8** %9
store i8* %30, i8** %3
br label %31
31: ; preds = %23, %19, %12
%32 = load i8*, i8** %3
ret i8* %32
}

LLVM IR (-O2):
@ASN1_F_ASN1_ITEM_DUP = global i32 0
@ERR_R_MALLOC_FAILURE = global i32 0
define i8* @ASN1_item_dup(i32* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = bitcast i8** %4 to i8*
%7 = icmp eq i8* %1, null
br i1 %7, label %20, label %8
8: ; preds = %2
%9 = call i64 @ASN1_item_i2d(i8* %1, i8** %3, i32* %0)
%10 = load i8*, i8** %3
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %8
%13 = load i32, i32* @ASN1_F_ASN1_ITEM_DUP
%14 = load i32, i32* @ERR_R_MALLOC_FAILURE
%15 = call i32 @ASN1err(i32 %13, i32 %14)
br label %20
16: ; preds = %8
store i8* %10, i8** %4
%17 = call i8* @ASN1_item_d2i(i32* null, i8** %4, i64 %9, i32* %0)
%18 = load i8*, i8** %3
%19 = call i32 @free(i8* %18)
br label %20
20: ; preds = %2, %16, %12
%21 = phi i8* [ null, %12 ], [ %17, %16 ], [ null, %2 ]
ret i8* %21
}