#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;
  int /*<<< orphan*/ enc;
  scalar_t__ modified;
};
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*/ memcpy(unsigned char *, int /*<<< orphan*/, int);
int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval,
                     const ASN1_ITEM *it) {
  ASN1_ENCODING *enc;
  enc = asn1_get_enc_ptr(pval, it);
  if (!enc || enc->modified)
    return 0;
  if (out) {
    memcpy(*out, enc->enc, enc->len);
    *out += enc->len;
  }
  if (len)
    *len = enc->len;
  return 1;
}


x86 assembly (clang, -O0):
<asn1_enc_restore>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <asn1_get_enc_ptr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1163 <asn1_enc_restore+0x43>
mov    -0x30(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     116f <asn1_enc_restore+0x4f>
movl   $0x0,-0x4(%rbp)
jmp    11c7 <asn1_enc_restore+0xa7>
cmpq   $0x0,-0x18(%rbp)
je     11a9 <asn1_enc_restore+0x89>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x30(%rbp),%rax
mov    (%rax),%edx
call   1040 <memcpy@plt>
mov    -0x30(%rbp),%rax
mov    (%rax),%edx
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
movslq %edx,%rdx
add    %rdx,%rcx
mov    %rcx,(%rax)
cmpq   $0x0,-0x10(%rbp)
je     11c0 <asn1_enc_restore+0xa0>
mov    -0x30(%rbp),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<asn1_enc_restore>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rdx,%rdi
mov    %rcx,%rsi
call   1030 <asn1_get_enc_ptr@plt>
mov    %rax,%rbx
xor    %eax,%eax
test   %rbx,%rbx
je     116e <asn1_enc_restore+0x4e>
cmpq   $0x0,0x8(%rbx)
jne    116e <asn1_enc_restore+0x4e>
test   %r15,%r15
je     115f <asn1_enc_restore+0x3f>
mov    (%r15),%rdi
mov    (%rbx),%edx
mov    0x4(%rbx),%esi
call   1040 <memcpy@plt>
movslq (%rbx),%rax
add    %rax,(%r15)
mov    $0x1,%eax
test   %r14,%r14
je     116e <asn1_enc_restore+0x4e>
mov    (%rbx),%ecx
mov    %ecx,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i32, i64 }
define i32 @asn1_enc_restore(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*** %8
%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 %16, label %21
16: ; preds = %4
%17 = load %struct.TYPE_3__*, %struct.TYPE_3__** %10
%18 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %17, i32 0, i32 2
%19 = load i64, i64* %18
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %16, %4
store i32 0, i32* %5
br label %51
22: ; preds = %16
%23 = load i8**, i8*** %7
%24 = icmp ne i8** %23, null
br i1 %24, label %25, label %42
25: ; preds = %22
%26 = load i8**, i8*** %7
%27 = load i8*, i8** %26
%28 = load %struct.TYPE_3__*, %struct.TYPE_3__** %10
%29 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %28, i32 0, i32 1
%30 = load i32, i32* %29
%31 = load %struct.TYPE_3__*, %struct.TYPE_3__** %10
%32 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %31, i32 0, i32 0
%33 = load i32, i32* %32
%34 = call i32 @memcpy(i8* %27, i32 %30, i32 %33)
%35 = load %struct.TYPE_3__*, %struct.TYPE_3__** %10
%36 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %35, i32 0, i32 0
%37 = load i32, i32* %36
%38 = load i8**, i8*** %7
%39 = load i8*, i8** %38
%40 = sext i32 %37 to i64
%41 = getelementptr inbounds i8, i8* %39, i64 %40
store i8* %41, i8** %38
br label %42
42: ; preds = %25, %22
%43 = load i32*, i32** %6
%44 = icmp ne i32* %43, null
br i1 %44, label %45, label %50
45: ; preds = %42
%46 = load %struct.TYPE_3__*, %struct.TYPE_3__** %10
%47 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %46, i32 0, i32 0
%48 = load i32, i32* %47
%49 = load i32*, i32** %6
store i32 %48, i32* %49
br label %50
50: ; preds = %45, %42
store i32 1, i32* %5
br label %51
51: ; preds = %50, %21
%52 = load i32, i32* %5
ret i32 %52
}

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