#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_5__ TYPE_2__;
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int /*<<< orphan*/ *octet_string;
};
struct TYPE_5__ {
  scalar_t__ type;
  TYPE_1__ value;
};
typedef TYPE_2__ ASN1_TYPE;

/* Variables and functions */
int /*<<< orphan*/ ASN1_R_DATA_IS_WRONG;
unsigned char *ASN1_STRING_data(int /*<<< orphan*/ *);
int ASN1_STRING_length(int /*<<< orphan*/ *);
int /*<<< orphan*/ ASN1error(int /*<<< orphan*/);
scalar_t__ V_ASN1_OCTET_STRING;
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int ASN1_TYPE_get_octetstring(const ASN1_TYPE *a, unsigned char *data,
                              int max_len) {
  int ret, num;
  unsigned char *p;
  if ((a->type != V_ASN1_OCTET_STRING) || (a->value.octet_string == NULL)) {
    ASN1error(ASN1_R_DATA_IS_WRONG);
    return (-1);
  }
  p = ASN1_STRING_data(a->value.octet_string);
  ret = ASN1_STRING_length(a->value.octet_string);
  if (ret < max_len)
    num = ret;
  else
    num = max_len;
  memcpy(data, p, num);
  return (ret);
}


x86 assembly (clang, -O0):
<ASN1_TYPE_get_octetstring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2e77(%rip),%rcx
cmp    (%rcx),%rax
jne    1179 <ASN1_TYPE_get_octetstring+0x39>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    1193 <ASN1_TYPE_get_octetstring+0x53>
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
call   1060 <ASN1error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e7 <ASN1_TYPE_get_octetstring+0xa7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <ASN1_STRING_data@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <ASN1_STRING_length@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11cb <ASN1_TYPE_get_octetstring+0x8b>
mov    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    11d1 <ASN1_TYPE_get_octetstring+0x91>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ASN1_TYPE_get_octetstring>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    (%rdi),%rax
mov    0x2e87(%rip),%rcx
cmp    (%rcx),%rax
jne    118e <ASN1_TYPE_get_octetstring+0x4e>
mov    %rdi,%rbx
mov    0x8(%rdi),%rdi
test   %rdi,%rdi
je     118e <ASN1_TYPE_get_octetstring+0x4e>
mov    %edx,%ebp
mov    %rsi,%r14
call   1040 <ASN1_STRING_data@plt>
mov    %rax,%r15
mov    0x8(%rbx),%rdi
call   1030 <ASN1_STRING_length@plt>
mov    %eax,%ebx
cmp    %ebp,%eax
cmovl  %eax,%ebp
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1050 <memcpy@plt>
jmp    11a1 <ASN1_TYPE_get_octetstring+0x61>
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
call   1060 <ASN1error@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.TYPE_5__ = type { i64, %struct.TYPE_4__ }
%struct.TYPE_4__ = type { i32* }
@V_ASN1_OCTET_STRING = global i64 0
@ASN1_R_DATA_IS_WRONG = global i32 0
define i32 @ASN1_TYPE_get_octetstring(%struct.TYPE_5__* nocapture %0, i8* %1, i32 %2) {
%4 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %0, i64 0, i32 0
%5 = load i64, i64* %4
%6 = load i64, i64* @V_ASN1_OCTET_STRING
%7 = icmp eq i64 %5, %6
br i1 %7, label %8, label %12
8: ; preds = %3
%9 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %0, i64 0, i32 1, i32 0
%10 = load i32*, i32** %9
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %8, %3
%13 = load i32, i32* @ASN1_R_DATA_IS_WRONG
%14 = tail call i32 @ASN1error(i32 %13)
br label %22
15: ; preds = %8
%16 = tail call i8* @ASN1_STRING_data(i32* %10)
%17 = load i32*, i32** %9
%18 = tail call i32 @ASN1_STRING_length(i32* %17)
%19 = icmp slt i32 %18, %2
%20 = select i1 %19, i32 %18, i32 %2
%21 = tail call i32 @memcpy(i8* %1, i8* %16, i32 %20)
br label %22
22: ; preds = %15, %12
%23 = phi i32 [ -1, %12 ], [ %18, %15 ]
ret i32 %23
}