#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*/ X509V3_CTX;
typedef int /*<<< orphan*/ ASN1_TYPE;

/* Variables and functions */
int /*<<< orphan*/ ASN1_TYPE_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *ASN1_generate_v3(char *, int /*<<< orphan*/ *);
long i2d_ASN1_TYPE(int /*<<< orphan*/ *, unsigned char **);
unsigned char *generic_asn1(char *value, X509V3_CTX *ctx, long *ext_len) {
  ASN1_TYPE *typ;
  unsigned char *ext_der = NULL;
  typ = ASN1_generate_v3(value, ctx);
  if (typ == NULL)
    return NULL;
  *ext_len = i2d_ASN1_TYPE(typ, &ext_der);
  ASN1_TYPE_free(typ);
  return ext_der;
}


x86 assembly (clang, -O0):
<generic_asn1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <ASN1_generate_v3@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1175 <generic_asn1+0x45>
movq   $0x0,-0x8(%rbp)
jmp    119d <generic_asn1+0x6d>
mov    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <i2d_ASN1_TYPE@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rdi
call   1030 <ASN1_TYPE_free@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generic_asn1>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
movq   $0x0,(%rsp)
call   1050 <ASN1_generate_v3@plt>
test   %rax,%rax
je     1168 <generic_asn1+0x38>
mov    %rax,%rbx
mov    %rsp,%rsi
mov    %rax,%rdi
call   1040 <i2d_ASN1_TYPE@plt>
mov    %rax,(%r14)
mov    %rbx,%rdi
call   1030 <ASN1_TYPE_free@plt>
mov    (%rsp),%rax
jmp    116a <generic_asn1+0x3a>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @generic_asn1(i8* %0, i32* %1, i64* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i64*
%8 = alloca i32*
%9 = alloca i8*
store i8* %0, i8** %5
store i32* %1, i32** %6
store i64* %2, i64** %7
store i8* null, i8** %9
%10 = load i8*, i8** %5
%11 = load i32*, i32** %6
%12 = call i32* @ASN1_generate_v3(i8* %10, i32* %11)
store i32* %12, i32** %8
%13 = load i32*, i32** %8
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %16
15: ; preds = %3
store i8* null, i8** %4
br label %23
16: ; preds = %3
%17 = load i32*, i32** %8
%18 = call i64 @i2d_ASN1_TYPE(i32* %17, i8** %9)
%19 = load i64*, i64** %7
store i64 %18, i64* %19
%20 = load i32*, i32** %8
%21 = call i32 @ASN1_TYPE_free(i32* %20)
%22 = load i8*, i8** %9
store i8* %22, i8** %4
br label %23
23: ; preds = %16, %15
%24 = load i8*, i8** %4
ret i8* %24
}

LLVM IR (-O2):
define i8* @generic_asn1(i8* %0, i32* %1, i64* nocapture writeonly %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%6 = tail call i32* @ASN1_generate_v3(i8* %0, i32* %1)
%7 = icmp eq i32* %6, null
br i1 %7, label %12, label %8
8: ; preds = %3
%9 = call i64 @i2d_ASN1_TYPE(i32* %6, i8** %4)
store i64 %9, i64* %2
%10 = call i32 @ASN1_TYPE_free(i32* %6)
%11 = load i8*, i8** %4
br label %12
12: ; preds = %3, %8
%13 = phi i8* [ %11, %8 ], [ null, %3 ]
ret i8* %13
}