#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 */
TYPE_1__ *asn1_get_enc_ptr(int /*<<< orphan*/ **, int /*<<< orphan*/ const *);
int /*<<< orphan*/ free(int /*<<< orphan*/);
int /*<<< orphan*/ malloc(int);
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;
  free(enc->enc);
  enc->enc = 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   1040 <asn1_get_enc_ptr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    117f <asn1_enc_save+0x3f>
movl   $0x1,-0x4(%rbp)
jmp    11e5 <asn1_enc_save+0xa5>
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%edi
call   1030 <free@plt>
mov    -0x1c(%rbp),%edi
call   1060 <malloc@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    -0x30(%rbp),%rax
cmpl   $0x0,0x10(%rax)
jne    11b6 <asn1_enc_save+0x76>
movl   $0x0,-0x4(%rbp)
jmp    11e5 <asn1_enc_save+0xa5>
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <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   1040 <asn1_get_enc_ptr@plt>
mov    $0x1,%r15d
test   %rax,%rax
je     1193 <asn1_enc_save+0x53>
mov    %rax,%rbx
mov    0x10(%rax),%edi
call   1030 <free@plt>
mov    %ebp,%edi
call   1060 <malloc@plt>
mov    %eax,0x10(%rbx)
test   %eax,%eax
je     1190 <asn1_enc_save+0x50>
mov    %eax,%edi
mov    %r14,%rsi
mov    %ebp,%edx
call   1050 <memcpy@plt>
mov    %ebp,(%rbx)
movq   $0x0,0x8(%rbx)
jmp    1193 <asn1_enc_save+0x53>
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 %43
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 = call i32 @free(i32 %20)
%22 = load i32, i32* %8
%23 = call i32 @malloc(i32 %22)
%24 = load %struct.TYPE_3__*, %struct.TYPE_3__** %10
%25 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %24, i32 0, i32 2
store i32 %23, i32* %25
%26 = load %struct.TYPE_3__*, %struct.TYPE_3__** %10
%27 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %26, i32 0, i32 2
%28 = load i32, i32* %27
%29 = icmp ne i32 %28, 0
br i1 %29, label %31, label %30
30: ; preds = %17
store i32 0, i32* %5
br label %43
31: ; preds = %17
%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 = load i8*, i8** %7
%36 = load i32, i32* %8
%37 = call i32 @memcpy(i32 %34, i8* %35, i32 %36)
%38 = load i32, i32* %8
%39 = load %struct.TYPE_3__*, %struct.TYPE_3__** %10
%40 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %39, i32 0, i32 0
store i32 %38, i32* %40
%41 = load %struct.TYPE_3__*, %struct.TYPE_3__** %10
%42 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %41, i32 0, i32 1
store i64 0, i64* %42
store i32 1, i32* %5
br label %43
43: ; preds = %31, %30, %16
%44 = load i32, i32* %5
ret i32 %44
}

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 %17, 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 = tail call i32 @free(i32 %9)
%11 = tail call i32 @malloc(i32 %2)
store i32 %11, i32* %8
%12 = icmp eq i32 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %7
%14 = tail call i32 @memcpy(i32 %11, i8* %1, i32 %2)
%15 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %5, i64 0, i32 0
store i32 %2, i32* %15
%16 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %5, i64 0, i32 1
store i64 0, i64* %16
br label %17
17: ; preds = %7, %4, %13
%18 = phi i32 [ 1, %13 ], [ 1, %4 ], [ 0, %7 ]
ret i32 %18
}