#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;
  scalar_t__ data;
};
typedef TYPE_1__ BUF_MEM;

/* Variables and functions */
int /*<<< orphan*/ ASN1_F_COLLECT_DATA;
int /*<<< orphan*/ ASN1err(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ BUF_MEM_grow_clean(TYPE_1__ *, int);
int /*<<< orphan*/ ERR_R_MALLOC_FAILURE;
int /*<<< orphan*/ memcpy(scalar_t__, unsigned char *, long);
int collect_data(BUF_MEM *buf, unsigned char **p, long plen) {
  int len;
  if (buf) {
    len = buf->length;
    if (!BUF_MEM_grow_clean(buf, len + plen)) {
      ASN1err(ASN1_F_COLLECT_DATA, ERR_R_MALLOC_FAILURE);
      return 0;
    }
    memcpy(buf->data + len, *p, plen);
  }
  *p += plen;
  return 1;
}


x86 assembly (clang, -O0):
<collect_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11b6 <collect_data+0x86>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x24(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %eax,%esi
call   1050 <BUF_MEM_grow_clean@plt>
cmp    $0x0,%eax
jne    1197 <collect_data+0x67>
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
mov    0x2e64(%rip),%rax
mov    (%rax),%esi
call   1030 <ASN1err@plt>
movl   $0x0,-0x4(%rbp)
jmp    11cb <collect_data+0x9b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
movslq -0x24(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<collect_data>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
test   %rdi,%rdi
je     1168 <collect_data+0x38>
mov    %rdi,%rbx
movslq (%rdi),%r12
lea    (%r15,%r12,1),%esi
call   1050 <BUF_MEM_grow_clean@plt>
test   %eax,%eax
je     1172 <collect_data+0x42>
add    0x8(%rbx),%r12
mov    (%r14),%rsi
mov    %r12,%rdi
mov    %r15,%rdx
call   1040 <memcpy@plt>
add    %r15,(%r14)
mov    $0x1,%eax
jmp    118b <collect_data+0x5b>
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
call   1030 <ASN1err@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_4__ = type { i32, i64 }
@ASN1_F_COLLECT_DATA = global i32 0
@ERR_R_MALLOC_FAILURE = global i32 0
define i32 @collect_data(%struct.TYPE_4__* %0, i8** %1, i64 %2) {
%4 = alloca i32
%5 = alloca %struct.TYPE_4__*
%6 = alloca i8**
%7 = alloca i64
%8 = alloca i32
store %struct.TYPE_4__* %0, %struct.TYPE_4__** %5
store i8** %1, i8*** %6
store i64 %2, i64* %7
%9 = load %struct.TYPE_4__*, %struct.TYPE_4__** %5
%10 = icmp ne %struct.TYPE_4__* %9, null
br i1 %10, label %11, label %38
11: ; preds = %3
%12 = load %struct.TYPE_4__*, %struct.TYPE_4__** %5
%13 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %12, i32 0, i32 0
%14 = load i32, i32* %13
store i32 %14, i32* %8
%15 = load %struct.TYPE_4__*, %struct.TYPE_4__** %5
%16 = load i32, i32* %8
%17 = sext i32 %16 to i64
%18 = load i64, i64* %7
%19 = add nsw i64 %17, %18
%20 = trunc i64 %19 to i32
%21 = call i32 @BUF_MEM_grow_clean(%struct.TYPE_4__* %15, i32 %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %27, label %23
23: ; preds = %11
%24 = load i32, i32* @ASN1_F_COLLECT_DATA
%25 = load i32, i32* @ERR_R_MALLOC_FAILURE
%26 = call i32 @ASN1err(i32 %24, i32 %25)
store i32 0, i32* %4
br label %43
27: ; preds = %11
%28 = load %struct.TYPE_4__*, %struct.TYPE_4__** %5
%29 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %28, i32 0, i32 1
%30 = load i64, i64* %29
%31 = load i32, i32* %8
%32 = sext i32 %31 to i64
%33 = add nsw i64 %30, %32
%34 = load i8**, i8*** %6
%35 = load i8*, i8** %34
%36 = load i64, i64* %7
%37 = call i32 @memcpy(i64 %33, i8* %35, i64 %36)
br label %38
38: ; preds = %27, %3
%39 = load i64, i64* %7
%40 = load i8**, i8*** %6
%41 = load i8*, i8** %40
%42 = getelementptr inbounds i8, i8* %41, i64 %39
store i8* %42, i8** %40
store i32 1, i32* %4
br label %43
43: ; preds = %38, %23
%44 = load i32, i32* %4
ret i32 %44
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32, i64 }
@ASN1_F_COLLECT_DATA = global i32 0
@ERR_R_MALLOC_FAILURE = global i32 0
define i32 @collect_data(%struct.TYPE_4__* %0, i8** nocapture %1, i64 %2) {
%4 = icmp eq %struct.TYPE_4__* %0, null
br i1 %4, label %23, label %5
5: ; preds = %3
%6 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 0
%7 = load i32, i32* %6
%8 = trunc i64 %2 to i32
%9 = add i32 %7, %8
%10 = tail call i32 @BUF_MEM_grow_clean(%struct.TYPE_4__* %0, i32 %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %5
%13 = load i32, i32* @ASN1_F_COLLECT_DATA
%14 = load i32, i32* @ERR_R_MALLOC_FAILURE
%15 = tail call i32 @ASN1err(i32 %13, i32 %14)
br label %26
16: ; preds = %5
%17 = sext i32 %7 to i64
%18 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 1
%19 = load i64, i64* %18
%20 = add nsw i64 %19, %17
%21 = load i8*, i8** %1
%22 = tail call i32 @memcpy(i64 %20, i8* %21, i64 %2)
br label %23
23: ; preds = %16, %3
%24 = load i8*, i8** %1
%25 = getelementptr inbounds i8, i8* %24, i64 %2
store i8* %25, i8** %1
br label %26
26: ; preds = %23, %12
%27 = phi i32 [ 1, %23 ], [ 0, %12 ]
ret i32 %27
}