#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_4__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int length;
  int /*<<< orphan*/ data;
};
typedef TYPE_1__ ASN1_STRING;

/* Variables and functions */
int ASN1_object_size(int /*<<< orphan*/, int, int);
int /*<<< orphan*/ ASN1_put_object(unsigned char **, int, int, int, int);
int V_ASN1_BIT_STRING;
int V_ASN1_SEQUENCE;
int V_ASN1_SET;
int i2d_ASN1_BIT_STRING(TYPE_1__ *, unsigned char **);
int /*<<< orphan*/ memcpy(unsigned char *, int /*<<< orphan*/, int);
int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass) {
  int ret, r, constructed;
  unsigned char *p;
  if (a == NULL)
    return (0);
  if (tag == V_ASN1_BIT_STRING)
    return (i2d_ASN1_BIT_STRING(a, pp));
  ret = a->length;
  r = ASN1_object_size(0, ret, tag);
  if (pp == NULL)
    return (r);
  p = *pp;
  if ((tag == V_ASN1_SEQUENCE) || (tag == V_ASN1_SET))
    constructed = 1;
  else
    constructed = 0;
  ASN1_put_object(&p, constructed, ret, tag, xclass);
  memcpy(p, a->data, a->length);
  p += a->length;
  *pp = p;
  return (r);
}


x86 assembly (clang, -O0):
<i2d_ASN1_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116d <i2d_ASN1_bytes+0x2d>
movl   $0x0,-0x4(%rbp)
jmp    1256 <i2d_ASN1_bytes+0x116>
mov    -0x1c(%rbp),%eax
mov    0x2e81(%rip),%rcx
cmp    (%rcx),%eax
jne    1194 <i2d_ASN1_bytes+0x54>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <i2d_ASN1_BIT_STRING@plt>
mov    %eax,-0x4(%rbp)
jmp    1256 <i2d_ASN1_bytes+0x116>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
mov    -0x1c(%rbp),%edx
xor    %edi,%edi
call   1060 <ASN1_object_size@plt>
mov    %eax,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c3 <i2d_ASN1_bytes+0x83>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1256 <i2d_ASN1_bytes+0x116>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2df0(%rip),%rcx
cmp    (%rcx),%eax
je     11f2 <i2d_ASN1_bytes+0xb2>
mov    -0x1c(%rbp),%eax
mov    0x2dee(%rip),%rcx
cmp    (%rcx),%eax
jne    11fe <i2d_ASN1_bytes+0xbe>
movl   $0x1,-0x2c(%rbp)
jmp    1205 <i2d_ASN1_bytes+0xc5>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
lea    -0x38(%rbp),%rdi
call   1050 <ASN1_put_object@plt>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
call   1040 <memcpy@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i2d_ASN1_bytes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     117c <i2d_ASN1_bytes+0x3c>
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2e99(%rip),%rax
cmp    %edx,(%rax)
jne    1181 <i2d_ASN1_bytes+0x41>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <i2d_ASN1_BIT_STRING@plt>
xor    %r12d,%r12d
jmp    11e7 <i2d_ASN1_bytes+0xa7>
mov    %ecx,%r15d
mov    (%rbx),%r13d
xor    %edi,%edi
mov    %r13d,%esi
mov    %ebp,%edx
call   1060 <ASN1_object_size@plt>
mov    %eax,%r12d
test   %r14,%r14
je     11e7 <i2d_ASN1_bytes+0xa7>
mov    0x2e26(%rip),%rax
cmp    %ebp,(%rax)
sete   %al
mov    0x2e2a(%rip),%rcx
cmp    %ebp,(%rcx)
mov    (%r14),%rcx
mov    %rcx,(%rsp)
sete   %cl
or     %al,%cl
movzbl %cl,%esi
mov    %rsp,%rdi
mov    %r13d,%edx
mov    %ebp,%ecx
mov    %r15d,%r8d
call   1050 <ASN1_put_object@plt>
mov    (%rsp),%rdi
mov    (%rbx),%edx
mov    0x4(%rbx),%esi
call   1040 <memcpy@plt>
movslq (%rbx),%rax
add    (%rsp),%rax
mov    %rax,(%r14)
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32, i32 }
@V_ASN1_BIT_STRING = global i32 0
@V_ASN1_SEQUENCE = global i32 0
@V_ASN1_SET = global i32 0
define i32 @i2d_ASN1_bytes(%struct.TYPE_4__* %0, i8** %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca %struct.TYPE_4__*
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
store %struct.TYPE_4__* %0, %struct.TYPE_4__** %6
store i8** %1, i8*** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%14 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%15 = icmp eq %struct.TYPE_4__* %14, null
br i1 %15, label %16, label %17
16: ; preds = %4
store i32 0, i32* %5
br label %71
17: ; preds = %4
%18 = load i32, i32* %8
%19 = load i32, i32* @V_ASN1_BIT_STRING
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %25
21: ; preds = %17
%22 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%23 = load i8**, i8*** %7
%24 = call i32 @i2d_ASN1_BIT_STRING(%struct.TYPE_4__* %22, i8** %23)
store i32 %24, i32* %5
br label %71
25: ; preds = %17
%26 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%27 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %26, i32 0, i32 0
%28 = load i32, i32* %27
store i32 %28, i32* %10
%29 = load i32, i32* %10
%30 = load i32, i32* %8
%31 = call i32 @ASN1_object_size(i32 0, i32 %29, i32 %30)
store i32 %31, i32* %11
%32 = load i8**, i8*** %7
%33 = icmp eq i8** %32, null
br i1 %33, label %34, label %36
34: ; preds = %25
%35 = load i32, i32* %11
store i32 %35, i32* %5
br label %71
36: ; preds = %25
%37 = load i8**, i8*** %7
%38 = load i8*, i8** %37
store i8* %38, i8** %13
%39 = load i32, i32* %8
%40 = load i32, i32* @V_ASN1_SEQUENCE
%41 = icmp eq i32 %39, %40
br i1 %41, label %46, label %42
42: ; preds = %36
%43 = load i32, i32* %8
%44 = load i32, i32* @V_ASN1_SET
%45 = icmp eq i32 %43, %44
br i1 %45, label %46, label %47
46: ; preds = %42, %36
store i32 1, i32* %12
br label %48
47: ; preds = %42
store i32 0, i32* %12
br label %48
48: ; preds = %47, %46
%49 = load i32, i32* %12
%50 = load i32, i32* %10
%51 = load i32, i32* %8
%52 = load i32, i32* %9
%53 = call i32 @ASN1_put_object(i8** %13, i32 %49, i32 %50, i32 %51, i32 %52)
%54 = load i8*, i8** %13
%55 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%56 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %55, i32 0, i32 1
%57 = load i32, i32* %56
%58 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%59 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %58, i32 0, i32 0
%60 = load i32, i32* %59
%61 = call i32 @memcpy(i8* %54, i32 %57, i32 %60)
%62 = load %struct.TYPE_4__*, %struct.TYPE_4__** %6
%63 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %62, i32 0, i32 0
%64 = load i32, i32* %63
%65 = load i8*, i8** %13
%66 = sext i32 %64 to i64
%67 = getelementptr inbounds i8, i8* %65, i64 %66
store i8* %67, i8** %13
%68 = load i8*, i8** %13
%69 = load i8**, i8*** %7
store i8* %68, i8** %69
%70 = load i32, i32* %11
store i32 %70, i32* %5
br label %71
71: ; preds = %48, %34, %21, %16
%72 = load i32, i32* %5
ret i32 %72
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32, i32 }
@V_ASN1_BIT_STRING = global i32 0
@V_ASN1_SEQUENCE = global i32 0
@V_ASN1_SET = global i32 0
define i32 @i2d_ASN1_bytes(%struct.TYPE_4__* %0, i8** %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = bitcast i8** %5 to i8*
%7 = icmp eq %struct.TYPE_4__* %0, null
br i1 %7, label %36, label %8
8: ; preds = %4
%9 = load i32, i32* @V_ASN1_BIT_STRING
%10 = icmp eq i32 %9, %2
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 @i2d_ASN1_BIT_STRING(%struct.TYPE_4__* %0, i8** %1)
br label %36
13: ; preds = %8
%14 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 0
%15 = load i32, i32* %14
%16 = tail call i32 @ASN1_object_size(i32 0, i32 %15, i32 %2)
%17 = icmp eq i8** %1, null
br i1 %17, label %36, label %18
18: ; preds = %13
%19 = load i8*, i8** %1
store i8* %19, i8** %5
%20 = load i32, i32* @V_ASN1_SEQUENCE
%21 = icmp eq i32 %20, %2
%22 = load i32, i32* @V_ASN1_SET
%23 = icmp eq i32 %22, %2
%24 = select i1 %21, i1 true, i1 %23
%25 = zext i1 %24 to i32
%26 = call i32 @ASN1_put_object(i8** %5, i32 %25, i32 %15, i32 %2, i32 %3)
%27 = load i8*, i8** %5
%28 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 1
%29 = load i32, i32* %28
%30 = load i32, i32* %14
%31 = call i32 @memcpy(i8* %27, i32 %29, i32 %30)
%32 = load i32, i32* %14
%33 = load i8*, i8** %5
%34 = sext i32 %32 to i64
%35 = getelementptr inbounds i8, i8* %33, i64 %34
store i8* %35, i8** %1
br label %36
36: ; preds = %13, %4, %18, %11
%37 = phi i32 [ %12, %11 ], [ %16, %18 ], [ 0, %4 ], [ %16, %13 ]
ret i32 %37
}