#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 */
struct TYPE_3__ {
  int len;
  scalar_t__ modified;
  int /*<<< orphan*/ enc;
};
typedef int /*<<< orphan*/ ASN1_VALUE;
typedef int /*<<< orphan*/ ASN1_ITEM;
typedef TYPE_1__ ASN1_ENCODING;

/* Variables and functions */
int /*<<< orphan*/ OPENSSL_free(int /*<<< orphan*/);
int /*<<< orphan*/ OPENSSL_malloc(int);
TYPE_1__ *asn1_get_enc_ptr(int /*<<< orphan*/ **, int /*<<< orphan*/ const *);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/, unsigned char const *, int);
int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen,
                  const ASN1_ITEM *it) {
  ASN1_ENCODING *enc;
  enc = asn1_get_enc_ptr(pval, it);
  if (!enc)
    return 1;
  if (enc->enc)
    OPENSSL_free(enc->enc);
  enc->enc = OPENSSL_malloc(inlen);
  if (!enc->enc)
    return 0;
  memcpy(enc->enc, in, inlen);
  enc->len = inlen;
  enc->modified = 0;
  return 1;
}


x86 assembly (clang, -O0):
<asn1_enc_save>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <asn1_get_enc_ptr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    117f <asn1_enc_save+0x3f>
movl   $0x1,-0x4(%rbp)
jmp    11f3 <asn1_enc_save+0xb3>
mov    -0x30(%rbp),%rax
cmpl   $0x0,0x10(%rax)
je     1199 <asn1_enc_save+0x59>
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%edi
call   1060 <OPENSSL_free@plt>
mov    -0x1c(%rbp),%edi
call   1050 <OPENSSL_malloc@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    -0x30(%rbp),%rax
cmpl   $0x0,0x10(%rax)
jne    11c4 <asn1_enc_save+0x84>
movl   $0x0,-0x4(%rbp)
jmp    11f3 <asn1_enc_save+0xb3>
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x1c(%rbp),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
movq   $0x0,0x8(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<asn1_enc_save>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rcx,%rsi
call   1030 <asn1_get_enc_ptr@plt>
mov    $0x1,%r15d
test   %rax,%rax
je     1197 <asn1_enc_save+0x57>
mov    %rax,%rbx
mov    0x10(%rax),%edi
test   %edi,%edi
je     116e <asn1_enc_save+0x2e>
call   1060 <OPENSSL_free@plt>
mov    %ebp,%edi
call   1050 <OPENSSL_malloc@plt>
mov    %eax,0x10(%rbx)
test   %eax,%eax
je     1194 <asn1_enc_save+0x54>
mov    %eax,%edi
mov    %r14,%rsi
mov    %ebp,%edx
call   1040 <memcpy@plt>
mov    %ebp,(%rbx)
movq   $0x0,0x8(%rbx)
jmp    1197 <asn1_enc_save+0x57>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i64, i32 }
define i32 @asn1_enc_save(i32** %0, i8* %1, i32 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32**
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca %struct.TYPE_3__*
store i32** %0, i32*** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32* %3, i32** %9
%11 = load i32**, i32*** %6
%12 = load i32*, i32** %9
%13 = call %struct.TYPE_3__* @asn1_get_enc_ptr(i32** %11, i32* %12)
store %struct.TYPE_3__* %13, %struct.TYPE_3__** %10
%14 = load %struct.TYPE_3__*, %struct.TYPE_3__** %10
%15 = icmp ne %struct.TYPE_3__* %14, null
br i1 %15, label %17, label %16
16: ; preds = %4
store i32 1, i32* %5
br label %49
17: ; preds = %4
%18 = load %struct.TYPE_3__*, %struct.TYPE_3__** %10
%19 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %18, i32 0, i32 2
%20 = load i32, i32* %19
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %17
%23 = load %struct.TYPE_3__*, %struct.TYPE_3__** %10
%24 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %23, i32 0, i32 2
%25 = load i32, i32* %24
%26 = call i32 @OPENSSL_free(i32 %25)
br label %27
27: ; preds = %22, %17
%28 = load i32, i32* %8
%29 = call i32 @OPENSSL_malloc(i32 %28)
%30 = load %struct.TYPE_3__*, %struct.TYPE_3__** %10
%31 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %30, i32 0, i32 2
store i32 %29, i32* %31
%32 = load %struct.TYPE_3__*, %struct.TYPE_3__** %10
%33 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %32, i32 0, i32 2
%34 = load i32, i32* %33
%35 = icmp ne i32 %34, 0
br i1 %35, label %37, label %36
36: ; preds = %27
store i32 0, i32* %5
br label %49
37: ; preds = %27
%38 = load %struct.TYPE_3__*, %struct.TYPE_3__** %10
%39 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %38, i32 0, i32 2
%40 = load i32, i32* %39
%41 = load i8*, i8** %7
%42 = load i32, i32* %8
%43 = call i32 @memcpy(i32 %40, i8* %41, i32 %42)
%44 = load i32, i32* %8
%45 = load %struct.TYPE_3__*, %struct.TYPE_3__** %10
%46 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %45, i32 0, i32 0
store i32 %44, i32* %46
%47 = load %struct.TYPE_3__*, %struct.TYPE_3__** %10
%48 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %47, i32 0, i32 1
store i64 0, i64* %48
store i32 1, i32* %5
br label %49
49: ; preds = %37, %36, %16
%50 = load i32, i32* %5
ret i32 %50
}

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