#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 */
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*/ ASN1error(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) {
    ASN1error(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    11dd <ASN1_item_dup+0x9d>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    -0x20(%rbp),%rsi
call   1050 <ASN1_item_i2d@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ab <ASN1_item_dup+0x6b>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
call   1060 <ASN1error@plt>
movq   $0x0,-0x8(%rbp)
jmp    11dd <ASN1_item_dup+0x9d>
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   1040 <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     11a2 <ASN1_item_dup+0x62>
mov    %rdi,%rbx
mov    %rsp,%rax
mov    %rsi,%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
call   1050 <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   1040 <ASN1_item_d2i@plt>
mov    %rax,%rbx
mov    (%rsp),%rdi
call   1030 <free@plt>
jmp    11a4 <ASN1_item_dup+0x64>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
call   1060 <ASN1error@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@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 %30
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 %22
19: ; preds = %13
%20 = load i32, i32* @ERR_R_MALLOC_FAILURE
%21 = call i32 @ASN1error(i32 %20)
store i8* null, i8** %3
br label %30
22: ; preds = %13
%23 = load i8*, i8** %6
store i8* %23, i8** %7
%24 = load i64, i64* %8
%25 = load i32*, i32** %4
%26 = call i8* @ASN1_item_d2i(i32* null, i8** %7, i64 %24, i32* %25)
store i8* %26, i8** %9
%27 = load i8*, i8** %6
%28 = call i32 @free(i8* %27)
%29 = load i8*, i8** %9
store i8* %29, i8** %3
br label %30
30: ; preds = %22, %19, %12
%31 = load i8*, i8** %3
ret i8* %31
}

LLVM IR (-O2):
@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 %19, 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 %15
12: ; preds = %8
%13 = load i32, i32* @ERR_R_MALLOC_FAILURE
%14 = call i32 @ASN1error(i32 %13)
br label %19
15: ; preds = %8
store i8* %10, i8** %4
%16 = call i8* @ASN1_item_d2i(i32* null, i8** %4, i64 %9, i32* %0)
%17 = load i8*, i8** %3
%18 = call i32 @free(i8* %17)
br label %19
19: ; preds = %2, %15, %12
%20 = phi i8* [ null, %12 ], [ %16, %15 ], [ null, %2 ]
ret i8* %20
}