#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*/ ASN1error(int /*<<< orphan*/);
int /*<<< orphan*/ BUF_MEM_grow_clean(TYPE_1__ *, int);
int /*<<< orphan*/ ERR_R_MALLOC_FAILURE;
int /*<<< orphan*/ memcpy(scalar_t__, unsigned char const *, long);
int collect_data(BUF_MEM *buf, const unsigned char **p, long plen) {
  int len;
  if (buf) {
    len = buf->length;
    if (!BUF_MEM_grow_clean(buf, len + plen)) {
      ASN1error(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     11ad <collect_data+0x7d>
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   1040 <BUF_MEM_grow_clean@plt>
cmp    $0x0,%eax
jne    118e <collect_data+0x5e>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
call   1050 <ASN1error@plt>
movl   $0x0,-0x4(%rbp)
jmp    11c2 <collect_data+0x92>
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   1030 <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   1040 <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   1030 <memcpy@plt>
add    %r15,(%r14)
mov    $0x1,%eax
jmp    1182 <collect_data+0x52>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
call   1050 <ASN1error@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 }
@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 %37
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 %26, label %23
23: ; preds = %11
%24 = load i32, i32* @ERR_R_MALLOC_FAILURE
%25 = call i32 @ASN1error(i32 %24)
store i32 0, i32* %4
br label %42
26: ; preds = %11
%27 = load %struct.TYPE_4__*, %struct.TYPE_4__** %5
%28 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %27, i32 0, i32 1
%29 = load i64, i64* %28
%30 = load i32, i32* %8
%31 = sext i32 %30 to i64
%32 = add nsw i64 %29, %31
%33 = load i8**, i8*** %6
%34 = load i8*, i8** %33
%35 = load i64, i64* %7
%36 = call i32 @memcpy(i64 %32, i8* %34, i64 %35)
br label %37
37: ; preds = %26, %3
%38 = load i64, i64* %7
%39 = load i8**, i8*** %6
%40 = load i8*, i8** %39
%41 = getelementptr inbounds i8, i8* %40, i64 %38
store i8* %41, i8** %39
store i32 1, i32* %4
br label %42
42: ; preds = %37, %23
%43 = load i32, i32* %4
ret i32 %43
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i32, i64 }
@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 %22, 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 %15
12: ; preds = %5
%13 = load i32, i32* @ERR_R_MALLOC_FAILURE
%14 = tail call i32 @ASN1error(i32 %13)
br label %25
15: ; preds = %5
%16 = sext i32 %7 to i64
%17 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %0, i64 0, i32 1
%18 = load i64, i64* %17
%19 = add nsw i64 %18, %16
%20 = load i8*, i8** %1
%21 = tail call i32 @memcpy(i64 %19, i8* %20, i64 %2)
br label %22
22: ; preds = %15, %3
%23 = load i8*, i8** %1
%24 = getelementptr inbounds i8, i8* %23, i64 %2
store i8* %24, i8** %1
br label %25
25: ; preds = %22, %12
%26 = phi i32 [ 1, %22 ], [ 0, %12 ]
ret i32 %26
}